org.fourthline.cling.model.meta.LocalService Java Examples
The following examples show how to use
org.fourthline.cling.model.meta.LocalService.
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: ReceivingSubscribe.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
protected OutgoingSubscribeResponseMessage processRenewal(LocalService service, IncomingSubscribeRequestMessage requestMessage) { subscription = getUpnpService().getRegistry().getLocalSubscription(requestMessage.getSubscriptionId()); // Error conditions UDA 1.0 section 4.1.1 and 4.1.2 if (subscription == null) { log.fine("Invalid subscription ID for renewal request: " + getInputMessage()); return new OutgoingSubscribeResponseMessage(UpnpResponse.Status.PRECONDITION_FAILED); } log.fine("Renewing subscription: " + subscription); subscription.setSubscriptionDuration(requestMessage.getRequestedTimeoutSeconds()); if (getUpnpService().getRegistry().updateLocalSubscription(subscription)) { return new OutgoingSubscribeResponseMessage(subscription); } else { log.fine("Subscription went away before it could be renewed: " + getInputMessage()); return new OutgoingSubscribeResponseMessage(UpnpResponse.Status.PRECONDITION_FAILED); } }
Example #2
Source File: StateVariableAccessor.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
public StateVariableValue read(final StateVariable<LocalService> stateVariable, final Object serviceImpl) throws Exception { class AccessCommand implements Command { Object result; public void execute(ServiceManager serviceManager) throws Exception { result = read(serviceImpl); if (stateVariable.getService().isStringConvertibleType(result)) { result = result.toString(); } } } AccessCommand cmd = new AccessCommand(); stateVariable.getService().getManager().execute(cmd); return new StateVariableValue(stateVariable, cmd.result); }
Example #3
Source File: QueryStateVariableExecutor.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
@Override protected void execute(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception { // Querying a state variable doesn't mean an actual "action" method on this instance gets invoked if (actionInvocation.getAction() instanceof QueryStateVariableAction) { if (!actionInvocation.getAction().getService().isSupportsQueryStateVariables()) { actionInvocation.setFailure( new ActionException(ErrorCode.INVALID_ACTION, "This service does not support querying state variables") ); } else { executeQueryStateVariable(actionInvocation, serviceImpl); } } else { throw new IllegalStateException( "This class can only execute QueryStateVariableAction's, not: " + actionInvocation.getAction() ); } }
Example #4
Source File: AbstractActionExecutor.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
/** * 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 File: BeyondUpnpService.java From BeyondUPnP with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); //Create LocalDevice LocalService localService = new AnnotationLocalServiceBinder().read(BeyondContentDirectoryService.class); localService.setManager(new DefaultServiceManager<>( localService, BeyondContentDirectoryService.class)); String macAddress = Utils.getMACAddress(Utils.WLAN0); //Generate UUID by MAC address UDN udn = UDN.valueOf(UUID.nameUUIDFromBytes(macAddress.getBytes()).toString()); try { mLocalDevice = new LocalDevice(new DeviceIdentity(udn), new UDADeviceType("MediaServer"), new DeviceDetails("Local Media Server"), new LocalService[]{localService}); } catch (ValidationException e) { e.printStackTrace(); } upnpService.getRegistry().addDevice(mLocalDevice); //LocalBinder instead of binder binder = new LocalBinder(); }
Example #6
Source File: UDA10DeviceDescriptorBinderImpl.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
protected void generateServiceList(Namespace namespace, Device deviceModel, Document descriptor, Element deviceElement) { if (!deviceModel.hasServices()) return; Element serviceListElement = appendNewElement(descriptor, deviceElement, ELEMENT.serviceList); for (Service service : deviceModel.getServices()) { Element serviceElement = appendNewElement(descriptor, serviceListElement, ELEMENT.service); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceType, service.getServiceType()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceId, service.getServiceId()); if (service instanceof RemoteService) { RemoteService rs = (RemoteService) service; appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, rs.getDescriptorURI()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, rs.getControlURI()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, rs.getEventSubscriptionURI()); } else if (service instanceof LocalService) { LocalService ls = (LocalService) service; appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, namespace.getDescriptorPath(ls)); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, namespace.getControlPath(ls)); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, namespace.getEventSubscriptionPath(ls)); } } }
Example #7
Source File: AbstractActionExecutor.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
/** * 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 #8
Source File: AnnotationLocalServiceBinder.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
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 #9
Source File: IncomingActionRequestMessage.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
public IncomingActionRequestMessage(StreamRequestMessage source, LocalService service) throws ActionException { super(source); SoapActionHeader soapActionHeader = getHeaders().getFirstHeader(UpnpHeader.Type.SOAPACTION, SoapActionHeader.class); if (soapActionHeader == null) { throw new ActionException(ErrorCode.INVALID_ACTION, "Missing SOAP action header"); } SoapActionType actionType = soapActionHeader.getValue(); this.action = service.getAction(actionType.getActionName()); if (this.action == null) { throw new ActionException(ErrorCode.INVALID_ACTION, "Service doesn't implement action: " + actionType.getActionName()); } if (!QueryStateVariableAction.ACTION_NAME.equals(actionType.getActionName())) { if (!service.getServiceType().implementsVersion(actionType.getServiceType())) { throw new ActionException(ErrorCode.INVALID_ACTION, "Service doesn't support the requested service version"); } } this.actionNamespace = actionType.getTypeString(); }
Example #10
Source File: IncomingActionRequestMessage.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
public IncomingActionRequestMessage(StreamRequestMessage source, LocalService service) throws ActionException { super(source); SoapActionHeader soapActionHeader = getHeaders().getFirstHeader(UpnpHeader.Type.SOAPACTION, SoapActionHeader.class); if (soapActionHeader == null) { throw new ActionException(ErrorCode.INVALID_ACTION, "Missing SOAP action header"); } SoapActionType actionType = soapActionHeader.getValue(); this.action = service.getAction(actionType.getActionName()); if (this.action == null) { throw new ActionException(ErrorCode.INVALID_ACTION, "Service doesn't implement action: " + actionType.getActionName()); } if (!QueryStateVariableAction.ACTION_NAME.equals(actionType.getActionName())) { if (!service.getServiceType().implementsVersion(actionType.getServiceType())) { throw new ActionException(ErrorCode.INVALID_ACTION, "Service doesn't support the requested service version"); } } this.actionNamespace = actionType.getTypeString(); }
Example #11
Source File: AnnotationLocalServiceBinder.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
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 #12
Source File: QueryStateVariableExecutor.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
@Override protected void execute(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception { // Querying a state variable doesn't mean an actual "action" method on this instance gets invoked if (actionInvocation.getAction() instanceof QueryStateVariableAction) { if (!actionInvocation.getAction().getService().isSupportsQueryStateVariables()) { actionInvocation.setFailure( new ActionException(ErrorCode.INVALID_ACTION, "This service does not support querying state variables") ); } else { executeQueryStateVariable(actionInvocation, serviceImpl); } } else { throw new IllegalStateException( "This class can only execute QueryStateVariableAction's, not: " + actionInvocation.getAction() ); } }
Example #13
Source File: AnnotationActionBinder.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
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 #14
Source File: UDA10DeviceDescriptorBinderImpl.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
protected void generateServiceList(Namespace namespace, Device deviceModel, Document descriptor, Element deviceElement) { if (!deviceModel.hasServices()) return; Element serviceListElement = appendNewElement(descriptor, deviceElement, ELEMENT.serviceList); for (Service service : deviceModel.getServices()) { Element serviceElement = appendNewElement(descriptor, serviceListElement, ELEMENT.service); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceType, service.getServiceType()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceId, service.getServiceId()); if (service instanceof RemoteService) { RemoteService rs = (RemoteService) service; appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, rs.getDescriptorURI()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, rs.getControlURI()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, rs.getEventSubscriptionURI()); } else if (service instanceof LocalService) { LocalService ls = (LocalService) service; appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, namespace.getDescriptorPath(ls)); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, namespace.getControlPath(ls)); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, namespace.getEventSubscriptionPath(ls)); } } }
Example #15
Source File: QueryStateVariableExecutor.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
protected void executeQueryStateVariable(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception { LocalService service = actionInvocation.getAction().getService(); String stateVariableName = actionInvocation.getInput("varName").toString(); StateVariable stateVariable = service.getStateVariable(stateVariableName); if (stateVariable == null) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "No state variable found: " + stateVariableName ); } StateVariableAccessor accessor; if ((accessor = service.getAccessor(stateVariable.getName())) == null) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "No accessor for state variable, can't read state: " + stateVariableName ); } try { setOutputArgumentValue( actionInvocation, actionInvocation.getAction().getOutputArgument("return"), accessor.read(stateVariable, serviceImpl).toString() ); } catch (Exception ex) { throw new ActionException(ErrorCode.ACTION_FAILED, ex.getMessage()); } }
Example #16
Source File: LocalGENASubscription.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
public LocalGENASubscription(LocalService service, Integer requestedDurationSeconds, List<URL> callbackURLs) throws Exception { super(service); setSubscriptionDuration(requestedDurationSeconds); log.fine("Reading initial state of local service at subscription time"); long currentTime = new Date().getTime(); this.currentValues.clear(); Collection<StateVariableValue> values = getService().getManager().getCurrentState(); log.finer("Got evented state variable values: " + values.size()); for (StateVariableValue value : values) { this.currentValues.put(value.getStateVariable().getName(), value); if (log.isLoggable(Level.FINEST)) { log.finer("Read state variable value '" + value.getStateVariable().getName() + "': " + value.toString()); } // Preserve "last sent" state for future moderation lastSentTimestamp.put(value.getStateVariable().getName(), currentTime); if (value.getStateVariable().isModeratedNumericType()) { lastSentNumericValue.put(value.getStateVariable().getName(), Long.valueOf(value.toString())); } } this.subscriptionId = SubscriptionIdHeader.PREFIX + UUID.randomUUID(); this.currentSequence = new UnsignedIntegerFourBytes(0); this.callbackURLs = callbackURLs; }
Example #17
Source File: DefaultServiceManager.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
protected T createServiceInstance() throws Exception { if (serviceClass == null) { throw new IllegalStateException("Subclass has to provide service class or override createServiceInstance()"); } try { // Use this constructor if possible return serviceClass.getConstructor(LocalService.class).newInstance(getService()); } catch (NoSuchMethodException ex) { log.fine("Creating new service implementation instance with no-arg constructor: " + serviceClass.getName()); return serviceClass.newInstance(); } }
Example #18
Source File: SubscriptionCallback.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
synchronized public void run() { if (getControlPoint() == null) { throw new IllegalStateException("Callback must be executed through ControlPoint"); } if (getService() instanceof LocalService) { establishLocalSubscription((LocalService) service); } else if (getService() instanceof RemoteService) { establishRemoteSubscription((RemoteService) service); } }
Example #19
Source File: QueryStateVariableExecutor.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
protected void executeQueryStateVariable(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception { LocalService service = actionInvocation.getAction().getService(); String stateVariableName = actionInvocation.getInput("varName").toString(); StateVariable stateVariable = service.getStateVariable(stateVariableName); if (stateVariable == null) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "No state variable found: " + stateVariableName ); } StateVariableAccessor accessor; if ((accessor = service.getAccessor(stateVariable.getName())) == null) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "No accessor for state variable, can't read state: " + stateVariableName ); } try { setOutputArgumentValue( actionInvocation, actionInvocation.getAction().getOutputArgument("return"), accessor.read(stateVariable, serviceImpl).toString() ); } catch (Exception ex) { throw new ActionException(ErrorCode.ACTION_FAILED, ex.getMessage()); } }
Example #20
Source File: AbstractActionExecutor.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
/** * Sets the output argument value on the {@link org.fourthline.cling.model.action.ActionInvocation}, considers string conversion. */ protected void setOutputArgumentValue(ActionInvocation<LocalService> actionInvocation, ActionArgument<LocalService> argument, Object result) throws ActionException { LocalService service = actionInvocation.getAction().getService(); if (result != null) { try { if (service.isStringConvertibleType(result)) { log.fine("Result of invocation matches convertible type, setting toString() single output argument value"); actionInvocation.setOutput(new ActionArgumentValue(argument, result.toString())); } else { log.fine("Result of invocation is Object, setting single output argument value"); actionInvocation.setOutput(new ActionArgumentValue(argument, result)); } } catch (InvalidValueException ex) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "Wrong type or invalid value for '" + argument.getName() + "': " + ex.getMessage(), ex ); } } else { log.fine("Result of invocation is null, not setting any output argument value(s)"); } }
Example #21
Source File: MethodActionExecutor.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
protected boolean isUseOutputArgumentAccessors(ActionInvocation<LocalService> actionInvocation) { for (ActionArgument argument : actionInvocation.getAction().getOutputArguments()) { // If there is one output argument for which we have an accessor, all arguments need accessors if (getOutputArgumentAccessors().get(argument) != null) { return true; } } return false; }
Example #22
Source File: AbstractActionExecutor.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
/** * Sets the output argument value on the {@link org.fourthline.cling.model.action.ActionInvocation}, considers string conversion. */ protected void setOutputArgumentValue(ActionInvocation<LocalService> actionInvocation, ActionArgument<LocalService> argument, Object result) throws ActionException { LocalService service = actionInvocation.getAction().getService(); if (result != null) { try { if (service.isStringConvertibleType(result)) { log.fine("Result of invocation matches convertible type, setting toString() single output argument value"); actionInvocation.setOutput(new ActionArgumentValue(argument, result.toString())); } else { log.fine("Result of invocation is Object, setting single output argument value"); actionInvocation.setOutput(new ActionArgumentValue(argument, result)); } } catch (InvalidValueException ex) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "Wrong type or invalid value for '" + argument.getName() + "': " + ex.getMessage(), ex ); } } else { log.fine("Result of invocation is null, not setting any output argument value(s)"); } }
Example #23
Source File: SubscriptionCallback.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
synchronized public void run() { if (getControlPoint() == null) { throw new IllegalStateException("Callback must be executed through ControlPoint"); } if (getService() instanceof LocalService) { establishLocalSubscription((LocalService) service); } else if (getService() instanceof RemoteService) { establishRemoteSubscription((RemoteService) service); } }
Example #24
Source File: DefaultServiceManager.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
protected T createServiceInstance() throws Exception { if (serviceClass == null) { throw new IllegalStateException("Subclass has to provide service class or override createServiceInstance()"); } try { // Use this constructor if possible return serviceClass.getConstructor(LocalService.class).newInstance(getService()); } catch (NoSuchMethodException ex) { log.fine("Creating new service implementation instance with no-arg constructor: " + serviceClass.getName()); return serviceClass.newInstance(); } }
Example #25
Source File: LocalGENASubscription.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
public LocalGENASubscription(LocalService service, Integer requestedDurationSeconds, List<URL> callbackURLs) throws Exception { super(service); setSubscriptionDuration(requestedDurationSeconds); log.fine("Reading initial state of local service at subscription time"); long currentTime = new Date().getTime(); this.currentValues.clear(); Collection<StateVariableValue> values = getService().getManager().getCurrentState(); log.finer("Got evented state variable values: " + values.size()); for (StateVariableValue value : values) { this.currentValues.put(value.getStateVariable().getName(), value); if (log.isLoggable(Level.FINEST)) { log.finer("Read state variable value '" + value.getStateVariable().getName() + "': " + value.toString()); } // Preserve "last sent" state for future moderation lastSentTimestamp.put(value.getStateVariable().getName(), currentTime); if (value.getStateVariable().isModeratedNumericType()) { lastSentNumericValue.put(value.getStateVariable().getName(), Long.valueOf(value.toString())); } } this.subscriptionId = SubscriptionIdHeader.PREFIX + UUID.randomUUID(); this.currentSequence = new UnsignedIntegerFourBytes(0); this.callbackURLs = callbackURLs; }
Example #26
Source File: IncomingUnsubscribeRequestMessage.java From DroidDLNA with GNU General Public License v3.0 | 4 votes |
public LocalService getService() { return service; }
Example #27
Source File: MethodActionExecutor.java From DroidDLNA with GNU General Public License v3.0 | 4 votes |
protected Object[] createInputArgumentValues(ActionInvocation<LocalService> actionInvocation, Method method) throws ActionException { LocalService service = actionInvocation.getAction().getService(); List values = new ArrayList(); int i = 0; for (ActionArgument<LocalService> argument : actionInvocation.getAction().getInputArguments()) { Class methodParameterType = method.getParameterTypes()[i]; ActionArgumentValue<LocalService> inputValue = actionInvocation.getInput(argument); // If it's a primitive argument, we need a value if (methodParameterType.isPrimitive() && (inputValue == null || inputValue.toString().length() == 0)) throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "Primitive action method argument '" + argument.getName() + "' requires input value, can't be null or empty string" ); // It's not primitive and we have no value, that's fine too if (inputValue == null) { values.add(i++, null); continue; } // If it's not null, maybe it was a string-convertible type, if so, try to instantiate it String inputCallValueString = inputValue.toString(); // Empty string means null and we can't instantiate Enums! if (inputCallValueString.length() > 0 && service.isStringConvertibleType(methodParameterType) && !methodParameterType.isEnum()) { try { Constructor<String> ctor = methodParameterType.getConstructor(String.class); log.finer("Creating new input argument value instance with String.class constructor of type: " + methodParameterType); Object o = ctor.newInstance(inputCallValueString); values.add(i++, o); } catch (Exception ex) { log.warning("Error preparing action method call: " + method); log.warning("Can't convert input argument string to desired type of '" + argument.getName() + "': " + ex); throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "Can't convert input argument string to desired type of '" + argument.getName() + "': " + ex ); } } else { // Or if it wasn't, just use the value without any conversion values.add(i++, inputValue.getValue()); } } if (method.getParameterTypes().length > 0 && RemoteClientInfo.class.isAssignableFrom(method.getParameterTypes()[method.getParameterTypes().length-1])) { if (actionInvocation instanceof RemoteActionInvocation && ((RemoteActionInvocation)actionInvocation).getRemoteClientInfo() != null) { log.finer("Providing remote client info as last action method input argument: " + method); values.add(i, ((RemoteActionInvocation)actionInvocation).getRemoteClientInfo()); } else { // Local call, no client info available values.add(i, null); } } return values.toArray(new Object[values.size()]); }
Example #28
Source File: IncomingSubscribeRequestMessage.java From DroidDLNA with GNU General Public License v3.0 | 4 votes |
public IncomingSubscribeRequestMessage(StreamRequestMessage source, LocalService service) { super(source); this.service = service; }
Example #29
Source File: IncomingSubscribeRequestMessage.java From DroidDLNA with GNU General Public License v3.0 | 4 votes |
public LocalService getService() { return service; }
Example #30
Source File: ServiceControlResource.java From DroidDLNA with GNU General Public License v3.0 | 4 votes |
public ServiceControlResource(URI localURI, LocalService model) { super(localURI, model); }