org.fourthline.cling.model.meta.Action Java Examples

The following examples show how to use org.fourthline.cling.model.meta.Action. 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 Project: TVRemoteIME   Author: kingthy   File: AnnotationActionBinder.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Action appendAction(Map<Action, ActionExecutor> actions) throws LocalServiceBindingException {

        String name;
        if (getAnnotation().name().length() != 0) {
            name = getAnnotation().name();
        } else {
            name = AnnotationLocalServiceBinder.toUpnpActionName(getMethod().getName());
        }

        log.fine("Creating action and executor: " + name);

        List<ActionArgument> inputArguments = createInputArguments();
        Map<ActionArgument<LocalService>, StateVariableAccessor> outputArguments = createOutputArguments();

        inputArguments.addAll(outputArguments.keySet());
        ActionArgument<LocalService>[] actionArguments =
                inputArguments.toArray(new ActionArgument[inputArguments.size()]);

        Action action = new Action(name, actionArguments);
        ActionExecutor executor = createExecutor(outputArguments);

        actions.put(action, executor);
        return action;
    }
 
Example #2
Source Project: TVRemoteIME   Author: kingthy   File: AnnotationLocalServiceBinder.java    License: GNU General Public License v2.0 6 votes vote down vote up
public LocalService read(Class<?> clazz, ServiceId id, ServiceType type,
                               boolean supportsQueryStateVariables, Set<Class> stringConvertibleTypes)
        throws LocalServiceBindingException {

    Map<StateVariable, StateVariableAccessor> stateVariables = readStateVariables(clazz, stringConvertibleTypes);
    Map<Action, ActionExecutor> actions = readActions(clazz, stateVariables, stringConvertibleTypes);

    // Special treatment of the state variable querying action
    if (supportsQueryStateVariables) {
        actions.put(new QueryStateVariableAction(), new QueryStateVariableExecutor());
    }

    try {
        return new LocalService(type, id, actions, stateVariables, stringConvertibleTypes, supportsQueryStateVariables);

    } catch (ValidationException ex) {
        log.severe("Could not validate device model: " + ex.toString());
        for (ValidationError validationError : ex.getErrors()) {
            log.severe(validationError.toString());
        }
        throw new LocalServiceBindingException("Validation of model failed, check the log");
    }
}
 
Example #3
Source Project: TVRemoteIME   Author: kingthy   File: AnnotationLocalServiceBinder.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected Map<Action, ActionExecutor> readActions(Class<?> clazz,
                                                  Map<StateVariable, StateVariableAccessor> stateVariables,
                                                  Set<Class> stringConvertibleTypes)
        throws LocalServiceBindingException {

    Map<Action, ActionExecutor> map = new HashMap();

    for (Method method : Reflections.getMethods(clazz, UpnpAction.class)) {
        AnnotationActionBinder actionBinder =
                new AnnotationActionBinder(method, stateVariables, stringConvertibleTypes);
        Action action = actionBinder.appendAction(map);
        if(isActionExcluded(action)) {
        	map.remove(action);
        }
    }

    return map;
}
 
Example #4
Source Project: TVRemoteIME   Author: kingthy   File: AbstractActionExecutor.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reads the output arguments after an action execution using accessors.
 *
 * @param action The action of which the output arguments are read.
 * @param instance The instance on which the accessors will be invoked.
 * @return <code>null</code> if the action has no output arguments, a single instance if it has one, an
 *         <code>Object[]</code> otherwise.
 * @throws Exception
 */
protected Object readOutputArgumentValues(Action<LocalService> action, Object instance) throws Exception {
    Object[] results = new Object[action.getOutputArguments().length];
    log.fine("Attempting to retrieve output argument values using accessor: " + results.length);

    int i = 0;
    for (ActionArgument outputArgument : action.getOutputArguments()) {
        log.finer("Calling acccessor method for: " + outputArgument);

        StateVariableAccessor accessor = getOutputArgumentAccessors().get(outputArgument);
        if (accessor != null) {
            log.fine("Calling accessor to read output argument value: " + accessor);
            results[i++] = accessor.read(instance);
        } else {
            throw new IllegalStateException("No accessor bound for: " + outputArgument);
        }
    }

    if (results.length == 1) {
        return results[0];
    }
    return results.length > 0 ? results : null;
}
 
Example #5
Source Project: DroidDLNA   Author: offbye   File: AnnotationActionBinder.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Action appendAction(Map<Action, ActionExecutor> actions) throws LocalServiceBindingException {

        String name;
        if (getAnnotation().name().length() != 0) {
            name = getAnnotation().name();
        } else {
            name = AnnotationLocalServiceBinder.toUpnpActionName(getMethod().getName());
        }

        log.fine("Creating action and executor: " + name);

        List<ActionArgument> inputArguments = createInputArguments();
        Map<ActionArgument<LocalService>, StateVariableAccessor> outputArguments = createOutputArguments();

        inputArguments.addAll(outputArguments.keySet());
        ActionArgument<LocalService>[] actionArguments =
                inputArguments.toArray(new ActionArgument[inputArguments.size()]);

        Action action = new Action(name, actionArguments);
        ActionExecutor executor = createExecutor(outputArguments);

        actions.put(action, executor);
        return action;
    }
 
Example #6
Source Project: DroidDLNA   Author: offbye   File: AnnotationLocalServiceBinder.java    License: GNU General Public License v3.0 6 votes vote down vote up
public LocalService read(Class<?> clazz, ServiceId id, ServiceType type,
                               boolean supportsQueryStateVariables, Set<Class> stringConvertibleTypes)
        throws LocalServiceBindingException {

    Map<StateVariable, StateVariableAccessor> stateVariables = readStateVariables(clazz, stringConvertibleTypes);
    Map<Action, ActionExecutor> actions = readActions(clazz, stateVariables, stringConvertibleTypes);

    // Special treatment of the state variable querying action
    if (supportsQueryStateVariables) {
        actions.put(new QueryStateVariableAction(), new QueryStateVariableExecutor());
    }

    try {
        return new LocalService(type, id, actions, stateVariables, stringConvertibleTypes, supportsQueryStateVariables);

    } catch (ValidationException ex) {
        log.severe("Could not validate device model: " + ex.toString());
        for (ValidationError validationError : ex.getErrors()) {
            log.severe(validationError.toString());
        }
        throw new LocalServiceBindingException("Validation of model failed, check the log");
    }
}
 
Example #7
Source Project: DroidDLNA   Author: offbye   File: AnnotationLocalServiceBinder.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected Map<Action, ActionExecutor> readActions(Class<?> clazz,
                                                  Map<StateVariable, StateVariableAccessor> stateVariables,
                                                  Set<Class> stringConvertibleTypes)
        throws LocalServiceBindingException {

    Map<Action, ActionExecutor> map = new HashMap();

    for (Method method : Reflections.getMethods(clazz, UpnpAction.class)) {
        AnnotationActionBinder actionBinder =
                new AnnotationActionBinder(method, stateVariables, stringConvertibleTypes);
        Action action = actionBinder.appendAction(map);
        if(isActionExcluded(action)) {
        	map.remove(action);
        }
    }

    return map;
}
 
Example #8
Source Project: DroidDLNA   Author: offbye   File: AbstractActionExecutor.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reads the output arguments after an action execution using accessors.
 *
 * @param action The action of which the output arguments are read.
 * @param instance The instance on which the accessors will be invoked.
 * @return <code>null</code> if the action has no output arguments, a single instance if it has one, an
 *         <code>Object[]</code> otherwise.
 * @throws Exception
 */
protected Object readOutputArgumentValues(Action<LocalService> action, Object instance) throws Exception {
    Object[] results = new Object[action.getOutputArguments().length];
    log.fine("Attempting to retrieve output argument values using accessor: " + results.length);

    int i = 0;
    for (ActionArgument outputArgument : action.getOutputArguments()) {
        log.finer("Calling acccessor method for: " + outputArgument);

        StateVariableAccessor accessor = getOutputArgumentAccessors().get(outputArgument);
        if (accessor != null) {
            log.fine("Calling accessor to read output argument value: " + accessor);
            results[i++] = accessor.read(instance);
        } else {
            throw new IllegalStateException("No accessor bound for: " + outputArgument);
        }
    }

    if (results.length == 1) {
        return results[0];
    }
    return results.length > 0 ? results : null;
}
 
Example #9
Source Project: portmapper   Author: kaklakariada   File: AbstractClingAction.java    License: 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 #10
Source Project: TVRemoteIME   Author: kingthy   File: MutableService.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Action[] createActions() {
    Action[] array = new Action[actions.size()];
    int i = 0;
    for (MutableAction action : actions) {
        array[i++] = action.build();
    }
    return array;
}
 
Example #11
Source Project: TVRemoteIME   Author: kingthy   File: UDA10ServiceDescriptorBinderImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void generateActionList(Service serviceModel, Document descriptor, Element scpdElement) {

        Element actionListElement = appendNewElement(descriptor, scpdElement, ELEMENT.actionList);

        for (Action action : serviceModel.getActions()) {
            if (!action.getName().equals(QueryStateVariableAction.ACTION_NAME))
                generateAction(action, descriptor, actionListElement);
        }
    }
 
Example #12
Source Project: TVRemoteIME   Author: kingthy   File: UDA10ServiceDescriptorBinderImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void generateAction(Action action, Document descriptor, Element actionListElement) {

        Element actionElement = appendNewElement(descriptor, actionListElement, ELEMENT.action);

        appendNewElementIfNotNull(descriptor, actionElement, ELEMENT.name, action.getName());

        if (action.hasArguments()) {
            Element argumentListElement = appendNewElement(descriptor, actionElement, ELEMENT.argumentList);
            for (ActionArgument actionArgument : action.getArguments()) {
                generateActionArgument(actionArgument, descriptor, argumentListElement);
            }
        }
    }
 
Example #13
Source Project: TVRemoteIME   Author: kingthy   File: OutgoingActionResponseMessage.java    License: GNU General Public License v2.0 5 votes vote down vote up
public OutgoingActionResponseMessage(UpnpResponse.Status status, Action action) {
    super(new UpnpResponse(status));

    if (action != null) {
        if (action instanceof QueryStateVariableAction) {
            this.actionNamespace = Constants.NS_UPNP_CONTROL_10;
        } else {
            this.actionNamespace = action.getService().getServiceType().toString();
        }
    }

    addHeaders();
}
 
Example #14
Source Project: TVRemoteIME   Author: kingthy   File: RemoteActionInvocation.java    License: GNU General Public License v2.0 5 votes vote down vote up
public RemoteActionInvocation(Action action,
                              ActionArgumentValue[] input,
                              ActionArgumentValue[] output,
                              RemoteClientInfo remoteClientInfo) {
    super(action, input, output, null);
    this.remoteClientInfo = remoteClientInfo;
}
 
Example #15
Source Project: TVRemoteIME   Author: kingthy   File: ActionInvocation.java    License: GNU General Public License v2.0 5 votes vote down vote up
public ActionInvocation(Action<S> action,
                        ActionArgumentValue<S>[] input,
                        ActionArgumentValue<S>[] output,
                        ClientInfo clientInfo) {
    if (action == null) {
        throw new IllegalArgumentException("Action can not be null");
    }
    this.action = action;

    setInput(input);
    setOutput(output);

    this.clientInfo = clientInfo;
}
 
Example #16
Source Project: DroidDLNA   Author: offbye   File: MutableService.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Action[] createActions() {
    Action[] array = new Action[actions.size()];
    int i = 0;
    for (MutableAction action : actions) {
        array[i++] = action.build();
    }
    return array;
}
 
Example #17
Source Project: DroidDLNA   Author: offbye   File: UDA10ServiceDescriptorBinderImpl.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void generateActionList(Service serviceModel, Document descriptor, Element scpdElement) {

        Element actionListElement = appendNewElement(descriptor, scpdElement, ELEMENT.actionList);

        for (Action action : serviceModel.getActions()) {
            if (!action.getName().equals(QueryStateVariableAction.ACTION_NAME))
                generateAction(action, descriptor, actionListElement);
        }
    }
 
Example #18
Source Project: DroidDLNA   Author: offbye   File: UDA10ServiceDescriptorBinderImpl.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void generateAction(Action action, Document descriptor, Element actionListElement) {

        Element actionElement = appendNewElement(descriptor, actionListElement, ELEMENT.action);

        appendNewElementIfNotNull(descriptor, actionElement, ELEMENT.name, action.getName());

        if (action.hasArguments()) {
            Element argumentListElement = appendNewElement(descriptor, actionElement, ELEMENT.argumentList);
            for (ActionArgument actionArgument : action.getArguments()) {
                generateActionArgument(actionArgument, descriptor, argumentListElement);
            }
        }
    }
 
Example #19
Source Project: DroidDLNA   Author: offbye   File: OutgoingActionResponseMessage.java    License: GNU General Public License v3.0 5 votes vote down vote up
public OutgoingActionResponseMessage(UpnpResponse.Status status, Action action) {
    super(new UpnpResponse(status));

    if (action != null) {
        if (action instanceof QueryStateVariableAction) {
            this.actionNamespace = Constants.NS_UPNP_CONTROL_10;
        } else {
            this.actionNamespace = action.getService().getServiceType().toString();
        }
    }

    addHeaders();
}
 
Example #20
Source Project: DroidDLNA   Author: offbye   File: RemoteActionInvocation.java    License: GNU General Public License v3.0 5 votes vote down vote up
public RemoteActionInvocation(Action action,
                              ActionArgumentValue[] input,
                              ActionArgumentValue[] output,
                              RemoteClientInfo remoteClientInfo) {
    super(action, input, output, null);
    this.remoteClientInfo = remoteClientInfo;
}
 
Example #21
Source Project: DroidDLNA   Author: offbye   File: ActionInvocation.java    License: GNU General Public License v3.0 5 votes vote down vote up
public ActionInvocation(Action<S> action,
                        ActionArgumentValue<S>[] input,
                        ActionArgumentValue<S>[] output,
                        ClientInfo clientInfo) {
    if (action == null) {
        throw new IllegalArgumentException("Action can not be null");
    }
    this.action = action;

    setInput(input);
    setOutput(output);

    this.clientInfo = clientInfo;
}
 
Example #22
Source Project: portmapper   Author: kaklakariada   File: AbstractClingAction.java    License: 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 #23
Source Project: TVRemoteIME   Author: kingthy   File: MutableAction.java    License: GNU General Public License v2.0 4 votes vote down vote up
public Action build() {
    return new Action(name, createActionArgumennts());
}
 
Example #24
Source Project: TVRemoteIME   Author: kingthy   File: AnnotationLocalServiceBinder.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Override this method to exclude action/methods after they have been discovered.
 */
protected  boolean isActionExcluded(Action action) {
	return false;
}
 
Example #25
Source Project: TVRemoteIME   Author: kingthy   File: OutgoingActionRequestMessage.java    License: GNU General Public License v2.0 4 votes vote down vote up
public OutgoingActionRequestMessage(Action action, UpnpRequest operation) {
    super(operation);

    getHeaders().add(
            UpnpHeader.Type.CONTENT_TYPE,
            new ContentTypeHeader(ContentTypeHeader.DEFAULT_CONTENT_TYPE_UTF8)
    );

    SoapActionHeader soapActionHeader;
    if (action instanceof QueryStateVariableAction) {
        log.fine("Adding magic control SOAP action header for state variable query action");
        soapActionHeader = new SoapActionHeader(
                new SoapActionType(
                        SoapActionType.MAGIC_CONTROL_NS, SoapActionType.MAGIC_CONTROL_TYPE, null, action.getName()
                )
        );
    } else {
        soapActionHeader = new SoapActionHeader(
                new SoapActionType(
                        action.getService().getServiceType(),
                        action.getName()
                )
        );
    }

    // We need to keep it for later, convenience for writing the SOAP body XML
    actionNamespace = soapActionHeader.getValue().getTypeString();

    if (getOperation().getMethod().equals(UpnpRequest.Method.POST)) {

        getHeaders().add(UpnpHeader.Type.SOAPACTION, soapActionHeader);
        log.fine("Added SOAP action header: " + soapActionHeader);

    /* TODO: Finish the M-POST crap (or not)
    } else if (getOperation().getMethod().equals(UpnpRequest.Method.MPOST)) {

        getHeaders().add(UpnpHeader.Type.MAN, new MANHeader(Constants.SOAP_NS_ENVELOPE, "01"));

        getHeaders().add(UpnpHeader.Type.SOAPACTION, soapActionHeader);
        getHeaders().setPrefix(UpnpHeader.Type.SOAPACTION, "01");
        log.fine("Added SOAP action header with prefix '01': " + getHeaders().getFirstHeader(UpnpHeader.Type.SOAPACTION).getString());
        */

    } else {
        throw new IllegalArgumentException("Can't send action with request method: " + getOperation().getMethod());
    }
}
 
Example #26
Source Project: TVRemoteIME   Author: kingthy   File: OutgoingActionResponseMessage.java    License: GNU General Public License v2.0 4 votes vote down vote up
public OutgoingActionResponseMessage(Action action) {
    this(UpnpResponse.Status.OK, action);
}
 
Example #27
Source Project: TVRemoteIME   Author: kingthy   File: IncomingActionRequestMessage.java    License: GNU General Public License v2.0 4 votes vote down vote up
public Action getAction() {
    return action;
}
 
Example #28
Source Project: TVRemoteIME   Author: kingthy   File: RemoteActionInvocation.java    License: GNU General Public License v2.0 4 votes vote down vote up
public RemoteActionInvocation(Action action,
                              RemoteClientInfo remoteClientInfo) {
    super(action);
    this.remoteClientInfo = remoteClientInfo;
}
 
Example #29
Source Project: TVRemoteIME   Author: kingthy   File: ActionInvocation.java    License: GNU General Public License v2.0 4 votes vote down vote up
public ActionInvocation(Action<S> action) {
    this(action, null, null, null);
}
 
Example #30
Source Project: TVRemoteIME   Author: kingthy   File: ActionInvocation.java    License: GNU General Public License v2.0 4 votes vote down vote up
public ActionInvocation(Action<S> action,
                        ClientInfo clientInfo) {
    this(action, null, null, clientInfo);
}