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());
}
}
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();
}
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));
}
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);
}
}
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;
}
Aggregations