/* /*

Copyright (c) 2000-2002 Progress Software Corportation, All rights reserved.

/*
/*

Class: HandlerControlBlock

/*
/* */ import java.lang.*; import java.util.*; import javax.xml.namespace.*; import javax.xml.rpc.*; import javax.xml.soap.*; import javax.xml.rpc.handler.*; import javax.xml.rpc.holders.*; import javax.xml.rpc.encoding.*; import javax.xml.rpc.handler.HandlerChain; import javax.xml.rpc.handler.HandlerInfo; import javax.xml.rpc.handler.soap.*; import javax.xml.namespace.QName; import javax.xml.rpc.handler.GenericHandler; /** * The HandlerControlBlock class serves as an command and data interface between * the Web Service client application and a registered PscObjectIDHandler. * It doubles as the handler context Map object that is passed in a HandlerInfo * object during the handler registration process. */ public class HandlerControlBlock extends Hashtable { /* The following is a list of keys used to store various type of information */ /*Holds the Proxy object names the handler will recognize in the * return SOAP request headers */ public static final String OBJECT_IDS = "object.ids"; /* Enable debug mode and write debug messages to stdout. */ public static final String DEBUG = "debug"; /* Holds the last SOAP response's object ID header name. */ public static final String RESPONSE_ID_NAME= "response.id.name"; /* Holds the last SOAP response's object ID SOAPHeaderElement object */ public static final String RESPONSE_ID_ELEMENT = "response.id.element"; /* Holds the proxy object name that will be used to find the corresponding * SOAPHeaderElement from the REQUEST_ID_STORE store. */ public static final String REQUEST_ID_NAME = "request.id.name"; /* Holds the proxy object ID SOAPHeaderElement objects. Indexed by * proxy object name. */ public static final String REQUEST_ID_STORE = "request.id.store"; /* Holds the port-name of the proxy object/ID Handler this control block is * in control of. */ public static final String PORT_NAME = "portname"; /* * Standard object constructor. *
* @param objectNames is the array of Proxy object names the handler will * process. This list includes the object name that corresponds to the * handler and the names of any proxy object that can be created by the * proxy object. */ public HandlerControlBlock(String[] objectNames) { this.put(OBJECT_IDS, objectNames); this.put(REQUEST_ID_STORE, new Hashtable()); } /* * Get the Proxy Object name whose Object ID will be sent in the next * Web Service request by the handler. *
* @return the String proxy object name */ public String getRequestObjectIDName() { // Strip the trailing "ID" String proxyobj = (String)this.get(REQUEST_ID_NAME); return(proxyobj.substring(0, (proxyobj.length() - 2))); } /* * Set the Proxy Object name whose Object ID is sent in the next * SOAP request sent to the WSA. *
* @param objectName is the Proxy object name. It must match one of * the Proxy object names in the registered handler if not a null value. * A null parameter will clear the current value. */ public void setRequestObjectIDName(String objectName) throws Exception { if (null != objectName) { String targetName = objectName + "ID"; String matchName = null; String[] names = (String[])this.get(OBJECT_IDS); // Lookup the name to make sure a valid, registered, proxy // object name is present. // for (int i = 0; i < names.length; i++) { if (names[i].equals(targetName)) { matchName = targetName; break; } } // If no match, this is an exceptional condition. // if (null == matchName) { throw new Exception("The object name " + objectName + " is not registered."); } // All is ok, so record the name to use as an id to find a // corresponding object id in the REQUEST_ID_STORE. // this.put(REQUEST_ID_NAME, matchName); } else { this.remove(REQUEST_ID_NAME); } } /* * Get the String Object ID for a specific Proxy Object name. *
* @param objectName is the proxy object name to obtain the String * Object ID for. A null return indicates that no Object ID is * recorded for the object. */ public String getObjectNameID(String objectName) { String returnID = null; Hashtable ids = (Hashtable)this.get(REQUEST_ID_STORE); if (null != ids) { SOAPHeaderElement idElement = (SOAPHeaderElement)ids.get(objectName + "ID"); // if we have an element, do the XML parser thing to extract // the id. if (null != idElement) { returnID = extractID(idElement); } } return(returnID); } /* * Release (delete) any recorded object id for a given proxy object name. *
* @param objectName is the proxy object name to whose Object ID is * to be released. */ public void releaseObjectNameID(String objectName) { Hashtable ids = (Hashtable)this.get(REQUEST_ID_STORE); if (null != ids) { if (null != objectName) { // If the object name is the wildcard, then remove all names. // Otherwise remove only a single entry. // if ("*".equals(objectName)) { this.put(REQUEST_ID_STORE, new Hashtable()); } else { SOAPHeaderElement idElement = (SOAPHeaderElement)ids.get(objectName + "ID"); // if we have an element, do the XML parser thing to extract // the id. if (null != idElement) { ids.remove(objectName + "ID"); } } } } } /* * Return the String Proxy object name of the Object ID returned in the * last SOAP response received from the WSA. *
* @return A null return value indicates that the last response did * not return an Object ID. */ public String lastResponseObjectIDName() { return((String)this.get(RESPONSE_ID_NAME)); } /* * Return the String Object ID returned in the last SOAP response * received from the WSA. *
* @param A null return value indicates that the last response did not * return an Object ID. */ public String lastResponseObjectID() { String returnID = null; SOAPHeaderElement idElement = (SOAPHeaderElement)this.get(RESPONSE_ID_ELEMENT); if (null != idElement) { // if we have an element, do the XML parser thing to extract // the id. returnID = extractID(idElement); } return(returnID); } /* * Get the current state of the handler debug mode. *
* @return boolean true when debug mode is ON. */ public boolean getDebugMode() { if (null == this.get(DEBUG)) { return(false); } else { return(true); } } /* * Set the current state of the handler debug mode. *
* @param boolean which when true turns debug mode ON. */ public void setDebugMode(boolean debugMode) { if (debugMode) { this.put(DEBUG, ""); } else { this.remove(DEBUG); } } /* * Export the raw SOAPHeaderElement object that holds the Object ID * information for the given Proxy Object name. *
* @param objectName is the String Proxy object name to return the * SOAPHeaderElement for *
* @return Object holding the SOAPHeaderElement. If null, it indicates * that no Object ID is stored for the given Proxy object name */ public Object exportObjectID(String objectName) { Object returnID = null; Hashtable ids = (Hashtable)this.get(REQUEST_ID_STORE); if (null != ids) { returnID = (Object)ids.get(objectName + "ID"); } return(returnID); } /* * Import the raw SOAPHeaderElement object that holds the Object ID * for the specified Proxy object name. The Object ID will be stored * for use, and if a Proxy object name is not set to send on the next * Web Service request, the named Proxy object name will be inserted. *
* @param objectName is the name of the Proxy object to import. It must * already be listed in the list of handled proxys. * @param rawObjectID is the SOAPHeaderElement object to store for the * object. *
* @exception NullPointerException if either the objectName or rawObjectID * parameters are null */ public void importObjectID(String objectName, Object rawObjectID) throws Exception { if (null != objectName && null != rawObjectID) { String targetName = objectName + "ID"; String matchName = null; String[] names = (String[])this.get(OBJECT_IDS); // Lookup the name to make sure a valid, registered, proxy // object name is present. // for (int i = 0; i < names.length; i++) { if (names[i].equals(targetName)) { matchName = targetName; break; } } // If no match, this is an exceptional condition. // if (null == matchName) { throw new Exception("The object name " + objectName + " is not registered."); } // Store the raw object id. // Hashtable store = (Hashtable)this.get(REQUEST_ID_STORE); store.put(matchName, rawObjectID); // If a name isn't already registered to send out an Object ID // for, register one now. // if (null == this.get(REQUEST_ID_NAME)) { this.put(REQUEST_ID_NAME, matchName); } } else { throw new Exception("Neither the objectName or rawObjecID parameters may be null."); } } /* * Private method to extract the character node Object ID string from * inside the UUID element that is nested inside the element holding * the Proxy Object ID name. * */ private String extractID(SOAPHeaderElement header) { String returnID = "NO_UUID_FOUND"; Iterator uuidList = header.getChildElements(); if (null != uuidList) { while (uuidList.hasNext()) { SOAPElement uuidElement = (SOAPElement)uuidList.next(); if (uuidElement.getElementName().getLocalName().equals("UUID")) { returnID = uuidElement.getValue(); break; } } } return(returnID); } }