org.fourthline.cling.model.action.ActionArgumentValue Java Examples

The following examples show how to use org.fourthline.cling.model.action.ActionArgumentValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractClingAction.java    From portmapper with GNU General Public License v3.0 6 votes vote down vote up
private ActionArgumentValue<RemoteService>[] getArguments(final Action<RemoteService> action) {
    @SuppressWarnings("unchecked")
    final ActionArgument<RemoteService>[] actionArguments = action.getArguments();
    final Map<String, Object> argumentValues = getArgumentValues();
    final List<ActionArgumentValue<RemoteService>> actionArgumentValues = new ArrayList<>(actionArguments.length);

    for (final ActionArgument<RemoteService> actionArgument : actionArguments) {
        if (actionArgument.getDirection() == Direction.IN) {
            final Object value = argumentValues.get(actionArgument.getName());
            logger.trace("Action {}: add arg value for {}: {} (expected datatype: {})", action.getName(),
                    actionArgument, value, actionArgument.getDatatype().getDisplayString());
            actionArgumentValues.add(new ActionArgumentValue<>(actionArgument, value));
        }
    }
    @SuppressWarnings("unchecked")
    final ActionArgumentValue<RemoteService>[] array = actionArgumentValues
            .toArray(new ActionArgumentValue[0]);
    return array;
}
 
Example #2
Source File: SOAPActionProcessorImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The UPnP spec says that action arguments must be in the order as declared
 * by the service. This method however is lenient, the action argument nodes
 * in the XML can be in any order, as long as they are all there everything
 * is OK.
 */
protected ActionArgumentValue[] readArgumentValues(NodeList nodeList, ActionArgument[] args)
        throws ActionException {

    List<Node> nodes = getMatchingNodes(nodeList, args);

    ActionArgumentValue[] values = new ActionArgumentValue[args.length];

    for (int i = 0; i < args.length; i++) {
    	
        ActionArgument arg = args[i];
        Node node = findActionArgumentNode(nodes, arg);
        if(node == null) {
            throw new ActionException(
                    ErrorCode.ARGUMENT_VALUE_INVALID,
                    "Could not find argument '" + arg.getName() + "' node");
        }
        log.fine("Reading action argument: " + arg.getName());
        String value = XMLUtil.getTextContent(node);
        values[i] = createValue(arg, value);
    }
    return values;
}
 
Example #3
Source File: PullSOAPActionProcessorImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected ActionArgumentValue[] readArgumentValues(XmlPullParser xpp, ActionArgument[] args) throws Exception {
    // We're in the <ActionName>Response tag
    Map<String, String> matches = getMatchingNodes(xpp, args);

    ActionArgumentValue[] values = new ActionArgumentValue[args.length];

    for (int i = 0; i < args.length; i++) {

        ActionArgument arg = args[i];
        String value = findActionArgumentValue(matches, arg);
        if (value == null) {
            throw new ActionException(
                ErrorCode.ARGUMENT_VALUE_INVALID,
                "Could not find argument '" + arg.getName() + "' node");
        }

        log.fine("Reading action argument: " + arg.getName());
        values[i] = createValue(arg, value);
    }
    return values;
}
 
Example #4
Source File: PullSOAPActionProcessorImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected ActionArgumentValue[] readArgumentValues(XmlPullParser xpp, ActionArgument[] args) throws Exception {
    // We're in the <ActionName>Response tag
    Map<String, String> matches = getMatchingNodes(xpp, args);

    ActionArgumentValue[] values = new ActionArgumentValue[args.length];

    for (int i = 0; i < args.length; i++) {

        ActionArgument arg = args[i];
        String value = findActionArgumentValue(matches, arg);
        if (value == null) {
            throw new ActionException(
                ErrorCode.ARGUMENT_VALUE_INVALID,
                "Could not find argument '" + arg.getName() + "' node");
        }

        log.fine("Reading action argument: " + arg.getName());
        values[i] = createValue(arg, value);
    }
    return values;
}
 
Example #5
Source File: SOAPActionProcessorImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The UPnP spec says that action arguments must be in the order as declared
 * by the service. This method however is lenient, the action argument nodes
 * in the XML can be in any order, as long as they are all there everything
 * is OK.
 */
protected ActionArgumentValue[] readArgumentValues(NodeList nodeList, ActionArgument[] args)
        throws ActionException {

    List<Node> nodes = getMatchingNodes(nodeList, args);

    ActionArgumentValue[] values = new ActionArgumentValue[args.length];

    for (int i = 0; i < args.length; i++) {
    	
        ActionArgument arg = args[i];
        Node node = findActionArgumentNode(nodes, arg);
        if(node == null) {
            throw new ActionException(
                    ErrorCode.ARGUMENT_VALUE_INVALID,
                    "Could not find argument '" + arg.getName() + "' node");
        }
        log.fine("Reading action argument: " + arg.getName());
        String value = XMLUtil.getTextContent(node);
        values[i] = createValue(arg, value);
    }
    return values;
}
 
Example #6
Source File: GetProtocolInfo.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void success(ActionInvocation invocation) {
	try {
		ActionArgumentValue sink = invocation.getOutput("Sink");
		ActionArgumentValue source = invocation.getOutput("Source");

		received(invocation,
				sink != null ? new ProtocolInfos(sink.toString()) : null,
				source != null ? new ProtocolInfos(source.toString())
						: null);

	} catch (Exception ex) {
		invocation.setFailure(new ActionException(ErrorCode.ACTION_FAILED,
				"Can't parse ProtocolInfo response: " + ex, ex));
		failure(invocation, null);
	}
}
 
Example #7
Source File: GetProtocolInfo.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void success(ActionInvocation invocation) {
	try {
		ActionArgumentValue sink = invocation.getOutput("Sink");
		ActionArgumentValue source = invocation.getOutput("Source");

		received(invocation,
				sink != null ? new ProtocolInfos(sink.toString()) : null,
				source != null ? new ProtocolInfos(source.toString())
						: null);

	} catch (Exception ex) {
		invocation.setFailure(new ActionException(ErrorCode.ACTION_FAILED,
				"Can't parse ProtocolInfo response: " + ex, ex));
		failure(invocation, null);
	}
}
 
Example #8
Source File: MediaInfo.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public MediaInfo(Map<String, ActionArgumentValue> args) {
    this(
            (String) args.get("CurrentURI").getValue(),
            (String) args.get("CurrentURIMetaData").getValue(),
            (String) args.get("NextURI").getValue(),
            (String) args.get("NextURIMetaData").getValue(),

            (UnsignedIntegerFourBytes) args.get("NrTracks").getValue(),
            (String) args.get("MediaDuration").getValue(),
            StorageMedium.valueOrVendorSpecificOf((String) args.get("PlayMedium").getValue()),
            StorageMedium.valueOrVendorSpecificOf((String) args.get("RecordMedium").getValue()),
            RecordMediumWriteStatus.valueOrUnknownOf((String) args.get("WriteStatus").getValue())
    );
}
 
Example #9
Source File: AbstractClingAction.java    From portmapper with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ActionInvocation<RemoteService> getActionInvocation() {
    final Action<RemoteService> action = service.getAction(actionName);
    if (action == null) {
        throw new ClingRouterException("No action found for name '" + actionName + "'. Available actions: "
                + Arrays.toString(service.getActions()));
    }
    final ActionArgumentValue<RemoteService>[] argumentArray = getArguments(action);
    return new ActionInvocation<>(action, argumentArray);
}
 
Example #10
Source File: SOAPActionProcessorImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates an instance of {@link ActionArgumentValue} and wraps an
 * {@link InvalidValueException} as an {@link ActionException} with the
 * appropriate {@link ErrorCode}.
 */
protected ActionArgumentValue createValue(ActionArgument arg, String value) throws ActionException {
    try {
        return new ActionArgumentValue(arg, value);
    } catch (InvalidValueException ex) {
        throw new ActionException(
                ErrorCode.ARGUMENT_VALUE_INVALID,
                "Wrong type or invalid value for '" + arg.getName() + "': " + ex.getMessage(),
                ex
        );
    }
}
 
Example #11
Source File: DeviceCapabilities.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public DeviceCapabilities(Map<String, ActionArgumentValue> args) {
    this(
            StorageMedium.valueOfCommaSeparatedList((String) args.get("PlayMedia").getValue()),
            StorageMedium.valueOfCommaSeparatedList((String) args.get("RecMedia").getValue()),
            RecordQualityMode.valueOfCommaSeparatedList((String) args.get("RecQualityModes").getValue())
    );
}
 
Example #12
Source File: PositionInfo.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public PositionInfo(Map<String, ActionArgumentValue> args) {
    this(
            ((UnsignedIntegerFourBytes) args.get("Track").getValue()).getValue(),
            (String) args.get("TrackDuration").getValue(),
            (String) args.get("TrackMetaData").getValue(),
            (String) args.get("TrackURI").getValue(),
            (String) args.get("RelTime").getValue(),
            (String) args.get("AbsTime").getValue(),
            (Integer) args.get("RelCount").getValue(),
            (Integer) args.get("AbsCount").getValue()
    );
}
 
Example #13
Source File: TransportInfo.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public TransportInfo(Map<String, ActionArgumentValue> args) {
    this(
            TransportState.valueOrCustomOf((String) args.get("CurrentTransportState").getValue()),
            TransportStatus.valueOrCustomOf((String) args.get("CurrentTransportStatus").getValue()),
            (String) args.get("CurrentSpeed").getValue()
    );
}
 
Example #14
Source File: PortMapping.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public PortMapping(Map<String, ActionArgumentValue<Service>> map) {
    this(
            (Boolean) map.get("NewEnabled").getValue(),
            (UnsignedIntegerFourBytes) map.get("NewLeaseDuration").getValue(),
            (String) map.get("NewRemoteHost").getValue(),
            (UnsignedIntegerTwoBytes) map.get("NewExternalPort").getValue(),
            (UnsignedIntegerTwoBytes) map.get("NewInternalPort").getValue(),
            (String) map.get("NewInternalClient").getValue(),
            Protocol.valueOf(map.get("NewProtocol").toString()),
            (String) map.get("NewPortMappingDescription").getValue()
    );
}
 
Example #15
Source File: SOAPActionProcessorImpl.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an instance of {@link ActionArgumentValue} and wraps an
 * {@link InvalidValueException} as an {@link ActionException} with the
 * appropriate {@link ErrorCode}.
 */
protected ActionArgumentValue createValue(ActionArgument arg, String value) throws ActionException {
    try {
        return new ActionArgumentValue(arg, value);
    } catch (InvalidValueException ex) {
        throw new ActionException(
                ErrorCode.ARGUMENT_VALUE_INVALID,
                "Wrong type or invalid value for '" + arg.getName() + "': " + ex.getMessage(),
                ex
        );
    }
}
 
Example #16
Source File: DeviceCapabilities.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public DeviceCapabilities(Map<String, ActionArgumentValue> args) {
    this(
            StorageMedium.valueOfCommaSeparatedList((String) args.get("PlayMedia").getValue()),
            StorageMedium.valueOfCommaSeparatedList((String) args.get("RecMedia").getValue()),
            RecordQualityMode.valueOfCommaSeparatedList((String) args.get("RecQualityModes").getValue())
    );
}
 
Example #17
Source File: PositionInfo.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public PositionInfo(Map<String, ActionArgumentValue> args) {
    this(
            ((UnsignedIntegerFourBytes) args.get("Track").getValue()).getValue(),
            (String) args.get("TrackDuration").getValue(),
            (String) args.get("TrackMetaData").getValue(),
            (String) args.get("TrackURI").getValue(),
            (String) args.get("RelTime").getValue(),
            (String) args.get("AbsTime").getValue(),
            (Integer) args.get("RelCount").getValue(),
            (Integer) args.get("AbsCount").getValue()
    );
}
 
Example #18
Source File: TransportInfo.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public TransportInfo(Map<String, ActionArgumentValue> args) {
    this(
            TransportState.valueOrCustomOf((String) args.get("CurrentTransportState").getValue()),
            TransportStatus.valueOrCustomOf((String) args.get("CurrentTransportStatus").getValue()),
            (String) args.get("CurrentSpeed").getValue()
    );
}
 
Example #19
Source File: PortMapping.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public PortMapping(Map<String, ActionArgumentValue<Service>> map) {
    this(
            (Boolean) map.get("NewEnabled").getValue(),
            (UnsignedIntegerFourBytes) map.get("NewLeaseDuration").getValue(),
            (String) map.get("NewRemoteHost").getValue(),
            (UnsignedIntegerTwoBytes) map.get("NewExternalPort").getValue(),
            (UnsignedIntegerTwoBytes) map.get("NewInternalPort").getValue(),
            (String) map.get("NewInternalClient").getValue(),
            Protocol.valueOf(map.get("NewProtocol").toString()),
            (String) map.get("NewPortMappingDescription").getValue()
    );
}
 
Example #20
Source File: MediaInfo.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public MediaInfo(Map<String, ActionArgumentValue> args) {
    this(
            (String) args.get("CurrentURI").getValue(),
            (String) args.get("CurrentURIMetaData").getValue(),
            (String) args.get("NextURI").getValue(),
            (String) args.get("NextURIMetaData").getValue(),

            (UnsignedIntegerFourBytes) args.get("NrTracks").getValue(),
            (String) args.get("MediaDuration").getValue(),
            StorageMedium.valueOrVendorSpecificOf((String) args.get("PlayMedium").getValue()),
            StorageMedium.valueOrVendorSpecificOf((String) args.get("RecordMedium").getValue()),
            RecordMediumWriteStatus.valueOrUnknownOf((String) args.get("WriteStatus").getValue())
    );
}