/****************************************************************** * * CyberUPnP for Java * * Copyright (C) Satoshi Konno 2002-2004 * * File: Action.java * * Revision; * * 12/05/02 * - first revision. * 08/30/03 * - Gordano Sassaroli * - Problem : When invoking an action that has at least one out parameter, an error message is returned * - Error : The action post method gets the entire list of arguments instead of only the in arguments * 01/04/04 * - Added UPnP status methods. * - Changed about new ActionListener interface. * 01/05/04 * - Added clearOutputAgumentValues() to initialize the output values before calling performActionListener(). * 07/09/04 * - Thanks for Dimas and Stefano Lenzi * - Changed postControlAction() to set the status code to the UPnPStatus. * ******************************************************************/ package org.cybergarage.upnp; import org.cybergarage.xml.*; import org.cybergarage.util.*; import org.cybergarage.upnp.xml.*; import org.cybergarage.upnp.control.*; public class Action { //////////////////////////////////////////////// // Constants //////////////////////////////////////////////// public final static String ELEM_NAME = "action"; //////////////////////////////////////////////// // Member //////////////////////////////////////////////// private Node serviceNode; private Node actionNode; private Node getServiceNode() { return serviceNode; } public Service getService() { return new Service(getServiceNode()); } public Node getActionNode() { return actionNode; } //////////////////////////////////////////////// // Constructor //////////////////////////////////////////////// public Action(Node serviceNode, Node actionNode) { this.serviceNode = serviceNode; this.actionNode = actionNode; } public Action(Action action) { this.serviceNode = action.getServiceNode(); this.actionNode = action.getActionNode(); } //////////////////////////////////////////////// // Mutex //////////////////////////////////////////////// private Mutex mutex = new Mutex(); public void lock() { mutex.lock(); } public void unlock() { mutex.unlock(); } //////////////////////////////////////////////// // isActionNode //////////////////////////////////////////////// public static boolean isActionNode(Node node) { return Action.ELEM_NAME.equals(node.getName()); } //////////////////////////////////////////////// // name //////////////////////////////////////////////// private final static String NAME = "name"; public void setName(String value) { getActionNode().setNode(NAME, value); } public String getName() { return getActionNode().getNodeValue(NAME); } //////////////////////////////////////////////// // argumentList //////////////////////////////////////////////// public ArgumentList getArgumentList() { ArgumentList argumentList = new ArgumentList(); Node argumentListNode = getActionNode().getNode(ArgumentList.ELEM_NAME); if (argumentListNode == null) return argumentList; int nodeCnt = argumentListNode.getNNodes(); for (int n=0; n (08/30/03) ArgumentList actionArgList = getArgumentList(); ArgumentList actionInputArgList = getInputArgumentList(); ActionRequest ctrlReq = new ActionRequest(); ctrlReq.setRequest(this, actionInputArgList); if (Debug.isOn() == true) ctrlReq.print(); ActionResponse ctrlRes = ctrlReq.post(); if (Debug.isOn() == true) ctrlRes.print(); setControlResponse(ctrlRes); // Thanks for Dimas and Stefano Lenzi (07/09/04) int statCode = ctrlRes.getStatusCode(); setStatus(statCode); if (ctrlRes.isSuccessful() == false) return false; ArgumentList outArgList = ctrlRes.getResponse(); actionArgList.set(outArgList); return true; } //////////////////////////////////////////////// // Debug //////////////////////////////////////////////// public void print() { System.out.println("Action : " + getName()); ArgumentList argList = getArgumentList(); int nArgs = argList.size(); for (int n=0; n