private void generateActionArgument(ActionArgument actionArgument, Document descriptor, Element actionElement) { Element actionArgumentElement = appendNewElement(descriptor, actionElement, ELEMENT.argument); appendNewElementIfNotNull(descriptor, actionArgumentElement, ELEMENT.name, actionArgument.getName()); appendNewElementIfNotNull(descriptor, actionArgumentElement, ELEMENT.direction, actionArgument.getDirection().toString().toLowerCase(Locale.ROOT)); if (actionArgument.isReturnValue()) { // TODO: UPNP VIOLATION: WMP12 will discard RenderingControl service if it contains <retval> tags log.warning("UPnP specification violation: Not producing <retval> element to be compatible with WMP12: " + actionArgument); // appendNewElement(descriptor, actionArgumentElement, ELEMENT.retval); } appendNewElementIfNotNull(descriptor, actionArgumentElement, ELEMENT.relatedStateVariable, actionArgument.getRelatedStateVariableName()); }
protected TableCellEditor createArgumentValueCellEditor(ActionArgument argument, ActionArgumentValue currentValue) { if (argument.getDatatype().getBuiltin() != null) { switch (argument.getDatatype().getBuiltin()) { case UI1: case UI2: case INT: case STRING: if (argument.getAction().getService().getStateVariable( argument.getRelatedStateVariableName() ).getTypeDetails().getAllowedValues() != null) {
public ActionArgument<S> deepCopy() { return new ActionArgument<>( getName(), getAliases(), getRelatedStateVariableName(), getDirection(), isReturnValue() ); }
@Override public String toString() { return "(" + getClass().getSimpleName() + ", " + getDirection() + ") " + getName(); } }
public ActionArgumentValue<S> getOutput(ActionArgument<S> argument) { return output.get(argument.getName()); }
public List<ValidationError> validate() { List<ValidationError> errors = new ArrayList<>(); if (getName() == null || getName().length() == 0) { errors.add(new ValidationError( getClass(), "name", "Argument without name of: " + getAction() )); } else if (!ModelUtil.isValidUDAName(getName())) { log.warning("UPnP specification violation of: " + getAction().getService().getDevice()); log.warning("Invalid argument name: " + this); } else if (getName().length() > 32) { log.warning("UPnP specification violation of: " + getAction().getService().getDevice()); log.warning("Argument name should be less than 32 characters: " + this); if (getDirection() == null) { errors.add(new ValidationError( getClass(), "direction", "Argument '"+getName()+"' requires a direction, either IN or OUT" )); if (isReturnValue() && getDirection() != ActionArgument.Direction.OUT) { errors.add(new ValidationError( getClass(), "direction", "Return value argument '" + getName() + "' must be direction OUT" ));
ActionArgument nodeActionArgument = (ActionArgument) node.getUserObject(); if (nodeActionArgument.getDirection().equals(ActionArgument.Direction.IN)) { setIcon(Application.createImageIcon(Workbench.class, "img/24/argument_in.png")); } else { setIcon(Application.createImageIcon(Workbench.class, "img/24/argument_out.png")); setToolTipText(nodeActionArgument.getRelatedStateVariableName() + ", " + nodeActionArgument.getDatatype().getDisplayString()); setText(nodeActionArgument.getName());
/** * Finds all element nodes in the list that match any argument name or argument * alias, throws {@link ActionException} if not all arguments were found. */ protected List<Node> getMatchingNodes(NodeList nodeList, ActionArgument[] args) throws ActionException { List<String> names = new ArrayList<>(); for (ActionArgument argument : args) { names.add(argument.getName()); names.addAll(Arrays.asList(argument.getAliases())); } List<Node> matches = new ArrayList<>(); for (int i = 0; i < nodeList.getLength(); i++) { Node child = nodeList.item(i); if (child.getNodeType() != Node.ELEMENT_NODE) continue; if (names.contains(getUnprefixedNodeName(child))) matches.add(child); } if (matches.size() < args.length) { throw new ActionException( ErrorCode.ARGUMENT_VALUE_INVALID, "Invalid number of input or output arguments in XML message, expected " + args.length + " but found " + matches.size() ); } return matches; }
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; } }
actionNode.add(actionArgumentNode); addIfNotNull(actionArgumentNode, i++ + " Direction: ", actionArgument.getDirection()); addIfNotNull(actionArgumentNode, "Related State Variable: ", actionArgument.getRelatedStateVariableName()); addIfNotNull(actionArgumentNode, "Datatype: ", actionArgument.getDatatype().getDisplayString());
public Action(String name, ActionArgument[] arguments) { this.name = name; if (arguments != null) { List<ActionArgument> inputList= new ArrayList<>(); List<ActionArgument> outputList = new ArrayList<>(); for (ActionArgument argument : arguments) { argument.setAction(this); if (argument.getDirection().equals(ActionArgument.Direction.IN)) inputList.add(argument); if (argument.getDirection().equals(ActionArgument.Direction.OUT)) outputList.add(argument); } this.arguments = arguments; this.inputArguments = inputList.toArray(new ActionArgument[inputList.size()]); this.outputArguments = outputList.toArray(new ActionArgument[outputList.size()]); } else { this.arguments = new ActionArgument[0]; this.inputArguments = new ActionArgument[0]; this.outputArguments = new ActionArgument[0]; } }
public ActionArgumentValue(ActionArgument<S> argument, Object value) throws InvalidValueException { super(argument.getDatatype(), value != null && value.getClass().isEnum() ? value.toString() : value); this.argument = argument; }
public TextArgumentValueCellEditor(ActionArgument argument, ActionArgumentValue argumentValue) { super(argument, argumentValue); textField.setEditable(argument.getDirection().equals(ActionArgument.Direction.IN)); textField.setText(argumentValue != null ? argumentValue.toString() : ""); }
public ActionArgument build() { return new ActionArgument(name, relatedStateVariable, direction, retval); }
protected String findActionArgumentValue(Map<String, String> entries, ActionArgument arg) { for (Map.Entry<String, String> entry : entries.entrySet()) { if (arg.isNameOrAlias(entry.getKey())) return entry.getValue(); } return null; }
public StateVariable<S> getRelatedStateVariable(ActionArgument argument) { return getStateVariable(argument.getRelatedStateVariableName()); }
public Datatype getDatatype() { return getAction().getService().getDatatype(this); }
public Action<S> deepCopy() { ActionArgument<S>[] actionArgumentsDupe = new ActionArgument[getArguments().length]; for (int i = 0; i < getArguments().length; i++) { ActionArgument arg = getArguments()[i]; actionArgumentsDupe[i] = arg.deepCopy(); } return new Action<>( getName(), actionArgumentsDupe ); }
public ActionArgumentValue<S> getInput(ActionArgument<S> argument) { return input.get(argument.getName()); }
public List<ValidationError> validate() { List<ValidationError> errors = new ArrayList(); if (getName() == null || getName().length() == 0) { errors.add(new ValidationError( getClass(), "name", "Argument without name of: " + getAction() )); } else if (!ModelUtil.isValidUDAName(getName())) { log.warning("UPnP specification violation of: " + getAction().getService().getDevice()); log.warning("Invalid argument name: " + this); } else if (getName().length() > 32) { log.warning("UPnP specification violation of: " + getAction().getService().getDevice()); log.warning("Argument name should be less than 32 characters: " + this); if (getDirection() == null) { errors.add(new ValidationError( getClass(), "direction", "Argument '"+getName()+"' requires a direction, either IN or OUT" )); if (isReturnValue() && getDirection() != ActionArgument.Direction.OUT) { errors.add(new ValidationError( getClass(), "direction", "Return value argument '" + getName() + "' must be direction OUT" ));