Search in sources :

Example 6 with UPnPStateVariable

use of org.osgi.service.upnp.UPnPStateVariable in project felix by apache.

the class UPnPActionImpl method invoke.

/* (non-Javadoc)
	 * @see org.osgi.service.upnp.UPnPAction#invoke(java.util.Dictionary)
	 */
public Dictionary invoke(Dictionary args) throws Exception {
    /*TODO 
		check if I have understood wath this method should do
		*/
    /*
		 * I look for argument and value and then I add them to ArgumentList
		 */
    ArgumentList argsList = new ArgumentList();
    argsList = act.getInputArgumentList();
    for (int i = 0; i < argsList.size(); i++) {
        /*			
			 * I assert that .getArgument(i) will return to me an Argument with only the name of the
			 * Argument and not it's value. I'll set the associated value by myself and
			 * Also I assert that the Argument are ordered
			 */
        Argument argument = argsList.getArgument(i);
        String argumentName = argument.getName();
        // String relateVar=argument.getRelatedStateVariableName();
        UPnPStateVariable stateVar = this.getStateVariable(argumentName);
        String upnpType = stateVar.getUPnPDataType();
        /*Class javaClass=stateVar.getJavaDataType();*/
        // setting the value related to the input argument
        argument.setValue(Converter.toString(args.get(argumentName), upnpType));
    }
    act.setInArgumentValues(argsList);
    if (act.postControlAction() == true) {
        // TODO check what happen if I don't have any output argument
        Properties outDic = new Properties();
        ArgumentList outArgs = act.getOutputArgumentList();
        if (outArgs.size() == 0) {
            return null;
        }
        for (int i = 0; i < outArgs.size(); i++) {
            Argument argument = outArgs.getArgument(i);
            String argumentName = outArgs.getArgument(i).getName();
            // String relateVar=argument.getRelatedStateVariableName();
            UPnPStateVariable stateVar = getStateVariable(argumentName);
            // String javaType=stateVar.getJavaDataType().getName();
            // TODO rember to catch number exception
            String upnpType = stateVar.getUPnPDataType();
            outDic.put(argumentName, Converter.parseString(argument.getValue(), upnpType));
        }
        return outDic;
    } else {
        UPnPStatus controlStatus = act.getControlStatus();
        throw new UPnPException(controlStatus.getCode(), controlStatus.getDescription());
    }
}
Also used : Argument(org.cybergarage.upnp.Argument) UPnPStatus(org.cybergarage.upnp.UPnPStatus) UPnPStateVariable(org.osgi.service.upnp.UPnPStateVariable) ArgumentList(org.cybergarage.upnp.ArgumentList) Properties(java.util.Properties) UPnPException(org.osgi.service.upnp.UPnPException)

Example 7 with UPnPStateVariable

use of org.osgi.service.upnp.UPnPStateVariable in project felix by apache.

the class SliderEditor method setData.

public void setData(UPnPAction action) {
    table.deleteMyCellEditors();
    String[] names = action.getInputArgumentNames();
    size = 0;
    this.names = names;
    if (names != null) {
        values = new String[names.length];
        related = new String[names.length];
        types = new String[names.length];
        for (int i = 0; i < names.length; i++) {
            values[i] = "";
            UPnPStateVariable currentStateVar = action.getStateVariable(names[i]);
            related[i] = currentStateVar.getName();
            String javaType = currentStateVar.getJavaDataType().toString();
            javaType = javaType.substring(javaType.lastIndexOf('.') + 1);
            String upnpType = currentStateVar.getUPnPDataType();
            types[i] = javaType + " \\ " + upnpType;
            // handle allowed value list
            if (currentStateVar.getAllowedValues() != null) {
                String[] av = currentStateVar.getAllowedValues();
                JComboBox comboBox = new JComboBox();
                for (int j = 0; j < av.length; j++) {
                    comboBox.addItem(av[j]);
                }
                // preset the first value from list
                values[i] = av[0];
                table.setMyCellEditor(new DefaultCellEditor(comboBox), i);
            }
            // handle default value
            if (currentStateVar.getDefaultValue() != null) {
                String val = currentStateVar.getDefaultValue().toString();
                if (val.length() > 0)
                    values[i] = val;
            }
            // handle range values
            if ((currentStateVar.getMaximum() != null) && (currentStateVar.getMinimum() != null)) {
                int max = currentStateVar.getMaximum().intValue();
                int min = currentStateVar.getMinimum().intValue();
                int value = min;
                try {
                    value = Integer.parseInt(values[i]);
                } catch (NumberFormatException ignored) {
                }
                table.setMyCellEditor(new SliderEditor(min, max, value), i);
            }
        }
        size = names.length;
    }
    this.fireTableChanged(new TableModelEvent(this));
    this.fireTableStructureChanged();
}
Also used : JComboBox(javax.swing.JComboBox) TableModelEvent(javax.swing.event.TableModelEvent) UPnPStateVariable(org.osgi.service.upnp.UPnPStateVariable) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 8 with UPnPStateVariable

use of org.osgi.service.upnp.UPnPStateVariable in project felix by apache.

the class SliderEditor method setData.

public void setData(UPnPAction action, Object result) {
    Hashtable res = (Hashtable) result;
    String[] names = action.getOutputArgumentNames();
    size = 0;
    this.names = names;
    if (names != null) {
        values = new String[names.length];
        types = new String[names.length];
        related = new String[names.length];
        for (int i = 0; i < names.length; i++) {
            UPnPStateVariable currentStateVar = action.getStateVariable(names[i]);
            Object value = res.get(names[i]);
            values[i] = value.toString();
            related[i] = currentStateVar.getName();
            String javaType = currentStateVar.getJavaDataType().toString();
            javaType = javaType.substring(javaType.lastIndexOf('.') + 1);
            String upnpType = currentStateVar.getUPnPDataType();
            types[i] = javaType + " \\ " + upnpType;
        }
        size = names.length;
    }
    this.fireTableChanged(new TableModelEvent(this));
}
Also used : Hashtable(java.util.Hashtable) TableModelEvent(javax.swing.event.TableModelEvent) UPnPStateVariable(org.osgi.service.upnp.UPnPStateVariable)

Example 9 with UPnPStateVariable

use of org.osgi.service.upnp.UPnPStateVariable in project felix by apache.

the class TreePopup method doNodeAction.

private void doNodeAction(UPnPDeviceTreeNode node) {
    if (node == null) {
        clearPropertiesViewer();
        return;
    }
    if (node.category.equals(UPnPDeviceTreeNode.ACTION))
        Mediator.getPropertiesViewer().showActionPanel(true);
    else
        Mediator.getPropertiesViewer().showActionPanel(false);
    if (node.category.equals(UPnPDeviceTreeNode.SERVICE))
        Mediator.getPropertiesViewer().showSubscriptionPanel(true);
    else
        Mediator.getPropertiesViewer().showSubscriptionPanel(false);
    if (node.category.equals(UPnPDeviceTreeNode.DEVICE) || node.category.equals(UPnPDeviceTreeNode.ROOT_DEVICE)) {
        DeviceNode device = (DeviceNode) node.getUserObject();
        UPnPDevice upnpDevice = device.getDevice(Activator.context);
        makeProperties(upnpDevice);
    } else if (node.category.equals(UPnPDeviceTreeNode.SERVICE)) {
        UPnPService service = (UPnPService) node.getUserObject();
        makeProperties(service);
    } else if (node.category.equals(UPnPDeviceTreeNode.ACTION)) {
        UPnPAction action = (UPnPAction) node.getUserObject();
        makeProperties(action);
        Mediator.getPropertiesViewer().setAction(action);
    } else if (node.category.equals(UPnPDeviceTreeNode.STATE) || node.category.equals(UPnPDeviceTreeNode.EVENTED_STATE) || node.category.equals(UPnPDeviceTreeNode.SUBSCRIBED_STATE)) {
        UPnPStateVariable state = (UPnPStateVariable) node.getUserObject();
        makeProperties(state);
    }
}
Also used : DeviceNode(org.apache.felix.upnp.tester.discovery.DeviceNode) UPnPDevice(org.osgi.service.upnp.UPnPDevice) UPnPStateVariable(org.osgi.service.upnp.UPnPStateVariable) UPnPService(org.osgi.service.upnp.UPnPService) UPnPAction(org.osgi.service.upnp.UPnPAction)

Example 10 with UPnPStateVariable

use of org.osgi.service.upnp.UPnPStateVariable in project felix by apache.

the class Serializer method actionToJSON.

static final Map<String, Object> actionToJSON(UPnPAction action) {
    final Map<String, Object> json = new HashMap<String, Object>();
    // $NON-NLS-1$
    json.put("name", action.getName());
    final String[] names = action.getInputArgumentNames();
    if (names != null) {
        Object[] vars = new Object[names.length];
        for (int i = 0; i < names.length; i++) {
            final UPnPStateVariable variable = action.getStateVariable(names[i]);
            // $NON-NLS-1$
            vars[i] = variableToJSON(variable, names[i]);
        }
        // $NON-NLS-1$
        json.put("inVars", vars);
    }
    return json;
}
Also used : HashMap(java.util.HashMap) UPnPStateVariable(org.osgi.service.upnp.UPnPStateVariable)

Aggregations

UPnPStateVariable (org.osgi.service.upnp.UPnPStateVariable)10 Hashtable (java.util.Hashtable)3 UPnPDevice (org.osgi.service.upnp.UPnPDevice)3 UPnPService (org.osgi.service.upnp.UPnPService)3 Date (java.util.Date)2 Dictionary (java.util.Dictionary)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 TableModelEvent (javax.swing.event.TableModelEvent)2 Argument (org.cybergarage.upnp.Argument)2 ArgumentList (org.cybergarage.upnp.ArgumentList)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 UPnPAction (org.osgi.service.upnp.UPnPAction)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 Constructor (java.lang.reflect.Constructor)1 Calendar (java.util.Calendar)1 Enumeration (java.util.Enumeration)1 Vector (java.util.Vector)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 JComboBox (javax.swing.JComboBox)1