ws-wsif-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject cvs commit: xml-axis-wsif/java/src/org/apache/wsif/providers/java WSIFPort_Java.java WSIFOperation_Java.java
Date Fri, 31 Jan 2003 17:25:37 GMT
antelder    2003/01/31 09:25:37

  Modified:    java/src/org/apache/wsif/providers/java WSIFPort_Java.java
                        WSIFOperation_Java.java
  Log:
  Start the Java provider tidyup so I can soon start make the real changes I want ...
  
  WSIFPort_Java
  1 - fix Bugzilla Bug 16586 WSIF Java provider target object must have no agrs constructor

  2 - add instance variables for service object constructors and methods so shared amoung
operations
  3 - javadoc all methods
  4 - changed deep to use a stringbuffer
  5 - format all the code
  
  WSIFOperation_Java
  6 - change to use above new WSIFPort_Java methods
  7 - add wsdlOperation instance variable so creating this is only done once
  
  Changes 2, 6 and 7 seem to make a significant performance improvement from the tests I did
  
  Revision  Changes    Path
  1.13      +284 -110  xml-axis-wsif/java/src/org/apache/wsif/providers/java/WSIFPort_Java.java
  
  Index: WSIFPort_Java.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/java/WSIFPort_Java.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- WSIFPort_Java.java	7 Dec 2002 12:33:59 -0000	1.12
  +++ WSIFPort_Java.java	31 Jan 2003 17:25:35 -0000	1.13
  @@ -58,6 +58,8 @@
   package org.apache.wsif.providers.java;
   
   import java.io.Serializable;
  +import java.lang.reflect.Constructor;
  +import java.lang.reflect.Method;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
  @@ -81,39 +83,64 @@
   
   /**
    * Java WSIF Port.
  + * 
  + * This implements the WSDL Java binding allowing a Java object
  + * to be used as a WSDL described service. The Class of the 
  + * target service object is identified by the WSDL java:address
  + * element. Each instance of a WSIFPort_Java will instantiate 
  + * a new instance of the target service class, and this instance
  + * will be shared by all WSIFOperations created from the WSIFPort.  
  + *  
    * @author <a href="mailto:gpfau@de.ibm.com">Gerhard Pfau</a>
  - * Partially based on WSIFPort_ApacheSOAP from Alekander Slominski, 
  - * Paul Fremantle, Sanjiva Weerawarana and Matthew J. Duftler
    * @author Owen Burroughs <owenb@apache.org>
    * @author Jeremy Hughes <hughesj@apache.org>
  + * @author <a href="mailto:ant.elder@uk.ibm.com">Ant Elder</a>
    */
   public class WSIFPort_Java extends WSIFDefaultPort implements Serializable {
  -	
  -	private static final long serialVersionUID = 1L;
  -	
  -    private javax.wsdl.Definition fieldDefinition = null;
  -    private javax.wsdl.Port fieldPortModel = null;
  -    private java.lang.Object fieldObjectReference = null; // 'physical connection'
  -    private Map fieldTypeMaps = new HashMap();
   
  -    protected Map operationInstances = new HashMap();
  +    private static final long serialVersionUID = 1L;
   
  +    private Definition fieldDefinition;
  +    private Port fieldPortModel;
  +
  +    transient private Class serviceObjectClass;
  +    transient private Method[] serviceObjectMethods;
  +    transient private Constructor[] serviceObjectConstructors;
  +
  +    private java.lang.Object fieldObjectReference; // 'physical connection'
  +
  +    private Map fieldTypeMaps;
  +    protected Map operationInstances;
  +
  +    /**
  +     * Construct a new instance of WSIFPort_Java
  +     * 
  +     * @param def   the WSDL4J Definintion object   
  +     * @param port   the WSDL4J Port this WSIFPort_Java represents   
  +     * @param typeMap   the WSIF type mappings (TODO: not used)
  +     */
       public WSIFPort_Java(Definition def, Port port, WSIFDynamicTypeMap typeMap)
           throws WSIFException {
           Trc.entry(this, def, port, typeMap);
  +
           fieldDefinition = def;
           fieldPortModel = port;
  +
  +        operationInstances = new HashMap();
  +
           buildTypeMap();
  -        if (Trc.ON)
  -            Trc.exit(deep());
  -    }
   
  -    public Definition getDefinition() {
  -        Trc.entry(this);
  -        Trc.exit(fieldDefinition);
  -        return fieldDefinition;
  +        if (Trc.ON) {
  +            Trc.exit(deep());
  +        }
       }
   
  +    /**
  +     * Creates a WSIFOperation for the given operation name
  +     * @return WSIFOperation   the WSIFOperation
  +     * @see WSIFOperation#createOperation(opName) 
  +     * @throws WSIFException  if there is an exception creating the WSIFOperation
  +     */
       public WSIFOperation createOperation(String operationName)
           throws WSIFException {
           Trc.entry(this);
  @@ -122,6 +149,12 @@
           return wo;
       }
   
  +    /**
  +     * Creates a WSIFOperation for the given operation name
  +     * @return WSIFOperation   the WSIFOperation_ApacheAxis
  +     * @see WSIFOperation#createOperation(opName, inName, outName) 
  +     * @throws WSIFException  if there is an exception creating the WSIFOperation
  +     */
       public WSIFOperation createOperation(
           String operationName,
           String inputName,
  @@ -145,6 +178,12 @@
           return wo;
       }
   
  +    /**
  +     * Gets a WSIFOperation_Java instance for given names.
  +     * If an instance has already been created and exists in the 
  +     * operationInstances cache return that, otherwise construct
  +     * a new instance, and add it to the operationInstances cache.  
  +     */
       protected WSIFOperation_Java getDynamicWSIFOperation(
           String name,
           String inputName,
  @@ -158,8 +197,11 @@
   
           if (operation == null) {
               BindingOperation bindingOperationModel =
  -            WSIFUtils.getBindingOperation( 
  -               fieldPortModel.getBinding(), name, inputName, outputName );
  +                WSIFUtils.getBindingOperation(
  +                    fieldPortModel.getBinding(),
  +                    name,
  +                    inputName,
  +                    outputName);
   
               if (bindingOperationModel != null) {
                   operation =
  @@ -175,91 +217,150 @@
           return operation;
       }
   
  -    public java.lang.Object getObjectReference() throws WSIFException {
  +    /**
  +     * Add a WSIFOperation_Java instance to the cache
  +     */
  +    protected void setDynamicWSIFOperation(
  +        String name,
  +        String inputName,
  +        String outputName,
  +        WSIFOperation_Java value) {
  +        Trc.entry(this, name, inputName, outputName, value);
  +        operationInstances.put(getKey(name, inputName, outputName), value);
  +        Trc.exit();
  +    }
  +
  +    /**
  +     * Gets the Java class of the service object
  +     * @return Class   the class of the service object
  +     */
  +    Class getServiceObjectClass() throws WSIFException {
  +        // no method access modifier as it used by WSIFOperation_Java
           Trc.entry(this);
  -        if (fieldObjectReference == null) {
  -            JavaAddress address = null;
  +        if (serviceObjectClass == null) {
   
  -            try {
  -                ExtensibilityElement portExtension =
  -                    (ExtensibilityElement) fieldPortModel.getExtensibilityElements().get(0);
  +            ExtensibilityElement portExtension =
  +                (ExtensibilityElement) fieldPortModel.getExtensibilityElements().get(
  +                    0);
   
  -                if (portExtension == null) {
  -                    throw new WSIFException("missing port extension");
  -                }
  +            if (portExtension == null) {
  +                throw new WSIFException("missing port extension");
  +            }
   
  -                address = (JavaAddress) portExtension;
  +            JavaAddress address = (JavaAddress) portExtension;
   
  -                fieldObjectReference =
  -                    Class
  -                        .forName(
  -                            address.getClassName(),
  -                            true,
  -                            Thread.currentThread().getContextClassLoader())
  -                        .newInstance();
  -            } catch (Exception ex) {
  -            	Trc.exception(ex);
  +            try {
  +                serviceObjectClass =
  +                    Class.forName(
  +                        address.getClassName(),
  +                        true,
  +                        Thread.currentThread().getContextClassLoader());
  +            } catch (Throwable ex) {
  +                Trc.exception(ex);
                   throw new WSIFException(
  -                    "Could not create object of class '" + address.getClassName() + "'",
  +                    "Exception getting target object class '"
  +                        + address.getClassName()
  +                        + "'",
                       ex);
               }
           }
  -        Trc.exit(fieldObjectReference);
  -        return fieldObjectReference;
  +        Trc.exit(serviceObjectClass);
  +        return serviceObjectClass;
       }
   
  -    public Port getPortModel() {
  +    /**
  +     * Gets the constructors of the service object
  +     * @return Constructor[]   the constructors of the service object
  +     */
  +    Constructor[] getServiceObjectConstructors() throws WSIFException {
  +        // no method access modifier as it used by WSIFOperation_Java
           Trc.entry(this);
  -        Trc.exit(fieldPortModel);
  -        return fieldPortModel;
  +        if (serviceObjectConstructors == null) {
  +            Class c = getServiceObjectClass();
  +            serviceObjectConstructors = c.getConstructors();
  +        }
  +        Trc.exit(serviceObjectConstructors);
  +        return serviceObjectConstructors;
       }
   
  -    public void setDefinition(Definition value) {
  -        Trc.entry(this, value);
  -        fieldDefinition = value;
  -        Trc.exit();
  +    /**
  +     * Gets the methods of the service object
  +     * @return Method[]   the methods of the service object
  +     */
  +    Method[] getServiceObjectMethods() throws WSIFException {
  +        // no method access modifier as it used by WSIFOperation_Java
  +        Trc.entry(this);
  +        if (serviceObjectMethods == null) {
  +            Class c = getServiceObjectClass();
  +            serviceObjectMethods = c.getMethods();
  +        }
  +        Trc.exit(serviceObjectMethods);
  +        return serviceObjectMethods;
       }
   
  -    // WSIF: keep list of operations available in this port
  -    public void setDynamicWSIFOperation(
  -        String name,
  -        String inputName,
  -        String outputName,
  -        WSIFOperation_Java value) {
  -        Trc.entry(this, name, inputName, outputName, value);
  -        operationInstances.put(getKey(name, inputName, outputName), value);
  -        Trc.exit();
  +    /**
  +     * Gets the service object.
  +     * @return Object   the service object instance
  +     */
  +    public Object getObjectReference() throws WSIFException {
  +        Trc.entry(this);
  +        if (fieldObjectReference == null) {
  +            Class c = getServiceObjectClass();
  +            try {
  +                fieldObjectReference = c.newInstance();
  +            } catch (Exception ex) {
  +                Trc.exception(ex);
  +                throw new WSIFException(
  +                    "Could not instantiate target object of class '"
  +                        + c.getName()
  +                        + "'",
  +                    ex);
  +            }
  +        }
  +        Trc.exit(fieldObjectReference);
  +        return fieldObjectReference;
       }
   
  -    public void setObjectReference(java.lang.Object newObjectReference) {
  +    /**
  +     * Sets a new instance of the target service object
  +     * Used by WSIFOperation_Java when it runs a Constructor
  +     * instead of an instance method. 
  +     */
  +    void setObjectReference(java.lang.Object newObjectReference) {
  +        /* no method access modifier as this is called by WSIFOperation_Java
  +         * I don't think this should be made public */
           Trc.entry(this, newObjectReference);
           fieldObjectReference = newObjectReference;
           Trc.exit();
       }
   
  -    public void setPortModel(Port value) {
  -        Trc.entry(this, value);
  -        fieldPortModel = value;
  -        Trc.exit();
  -    }
  -
  +    /**
  +     * Builds the type map from the WSDL format binding.
  +     * The fieldTypeMaps is a HashTable with the key
  +     * a type QName, and the value a String class name.
  +     * The format binding has the form:
  +     * <format:typeMapping style="uri" encoding="..."/>?
  +     *    <format:typeMap typeName="qname"|elementName="qname" formatType="nmtoken"/>*
  +     * </format:typeMapping> 
  +     */
       private void buildTypeMap() throws WSIFException {
  -    	Trc.entry(this);
  +        Trc.entry(this);
           TypeMapping typeMapping = null;
   
           // Get the TypeMappings from the binding
           Iterator bindingIterator =
               this.fieldPortModel.getBinding().getExtensibilityElements().iterator();
  -            
  +
           // Choose the first typeMap that has encoding=Java and style=Java. 
           // Ignore any other typeMap's that have other encodings and styles.
           while (bindingIterator.hasNext()) {
               Object next = bindingIterator.next();
               if (next instanceof TypeMapping) {
                   typeMapping = (TypeMapping) next;
  -                if ("Java".equals(typeMapping.getEncoding()) &&
  -                    "Java".equals(typeMapping.getStyle()))
  +                if ("Java".equals(typeMapping.getEncoding())
  +                    && "Java".equals(typeMapping.getStyle())) {
                       break;
  +                }
                   typeMapping = null;
               }
           }
  @@ -272,24 +373,27 @@
                       + " does not contain a typeMap with encoding=Java and style=Java");
           }
   
  -        // Build the hashmap 
  +        // Build the formatTypeMaps hashmap 
  +        fieldTypeMaps = new HashMap();
           bindingIterator = typeMapping.getMaps().iterator();
           while (bindingIterator.hasNext()) {
               TypeMap typeMap = (TypeMap) bindingIterator.next();
               ///////////////////////////////////
               QName typeName = typeMap.getTypeName();
  -            if (typeName == null) typeName = typeMap.getElementName();
  +            if (typeName == null) {
  +                typeName = typeMap.getElementName();
  +            }
               String type = typeMap.getFormatType();
               if (typeName != null && type != null) {
                   if (fieldTypeMaps.containsKey(typeName)) {
  -                	Vector v = null;
  -                	Object obj = fieldTypeMaps.get(typeName);                	
  -                	if (obj instanceof Vector) {
  -                		v = (Vector) obj;
  -                	} else {
  -                		v = new Vector();
  -	                    v.addElement(obj);
  -                	}                	                    
  +                    Vector v = null;
  +                    Object obj = fieldTypeMaps.get(typeName);
  +                    if (obj instanceof Vector) {
  +                        v = (Vector) obj;
  +                    } else {
  +                        v = new Vector();
  +                        v.addElement(obj);
  +                    }
                       v.addElement(type);
                       this.fieldTypeMaps.put(typeName, v);
                   } else {
  @@ -302,41 +406,111 @@
           Trc.exit();
       }
   
  +    /**
  +     * Gets the WSDL4J Definition asscociated with this WSIFPort
  +     * @return Definition   the WSDL4J Definition object
  +     */
  +    public Definition getDefinition() {
  +        Trc.entry(this);
  +        Trc.exit(fieldDefinition);
  +        return fieldDefinition;
  +    }
  +
  +    /**
  +     * Gets the WSDL4J Port asscociated with this WSIFPort
  +     * @return Port   the WSDL4J Port object
  +     */
  +    public Port getPortModel() {
  +        Trc.entry(this);
  +        Trc.exit(fieldPortModel);
  +        return fieldPortModel;
  +    }
  +
  +    /**
  +     * Used by WSIF Trc
  +     */
       public String deep() {
  -        String buff = "";
  -        try {
  -            buff = new String(super.toString() + ":\n");
  -
  -            buff += "definition:" + fieldDefinition == null
  -                ? "null"
  -                : fieldDefinition.getQName() == null
  -                ? "unknown"
  -                : fieldDefinition.getQName().toString();
  -            buff += " portModel:" + fieldPortModel == null
  -                ? "null"
  -                : fieldPortModel.getName() == null
  -                ? "unknown"
  -                : fieldPortModel.getName().toString();
  -            buff += " objectReference:" + fieldObjectReference;
  -
  -            buff += " operationInstances:";
  -            if (operationInstances == null)
  -                buff += "null";
  -            else {
  -                buff += " size:" + operationInstances.size();
  -                Iterator it = operationInstances.keySet().iterator();
  -                int i = 0;
  -                while (it.hasNext()) {
  -                    String key = (String) it.next();
  -                    WSIFOperation_Java woj = (WSIFOperation_Java) operationInstances.get(key);
  -                    buff += "\noperationInstances[" + i + "]:" + key + " " + woj + " ";
  -                    i++;
  -                }
  +        StringBuffer buff = new StringBuffer();
  +
  +        buff.append(super.toString()).append(":\n");
  +
  +        buff.append("definition:");
  +        if (fieldDefinition == null) {
  +            buff.append("null");
  +        } else {
  +            if (fieldDefinition.getQName() == null) {
  +                buff.append("unknown");
  +            } else {
  +                buff.append(fieldDefinition.getQName().toString());
  +            }
  +        }
  +
  +        buff.append(" portModel:");
  +        if (fieldPortModel == null) {
  +            buff.append("null");
  +        } else {
  +            if (fieldPortModel.getName() == null) {
  +                buff.append("unknown");
  +            } else {
  +                buff.append(fieldPortModel.getName().toString());
  +            }
  +        }
  +
  +        buff.append(" serviceObjectReference:").append(fieldObjectReference);
  +
  +        buff.append(" serviceObjectClass: ").append(serviceObjectClass);
  +
  +        buff.append(" serviceObjectConstructors: ");
  +        if (serviceObjectConstructors == null) {
  +            buff.append("null");
  +        } else {
  +            buff.append(serviceObjectConstructors);
  +            buff.append(" size:").append(serviceObjectConstructors.length);
  +        }
  +
  +        buff.append(" serviceObjectMethods: ");
  +        if (serviceObjectMethods == null) {
  +            buff.append("null");
  +        } else {
  +            buff.append(serviceObjectMethods);
  +            buff.append(" size:").append(serviceObjectMethods.length);
  +        }
  +
  +        buff.append(" formatTypeMaps: ");
  +        if (fieldTypeMaps == null) {
  +            buff.append("null");
  +        } else {
  +            buff.append(" size:").append(fieldTypeMaps.size());
  +            int i = 0;
  +            for (Iterator it = fieldTypeMaps.keySet().iterator();
  +                it.hasNext();
  +                ) {
  +                QName type = (QName) it.next();
  +                Object value = fieldTypeMaps.get(type);
  +                buff.append("\nformatTypeMaps[").append(i++).append("]:");
  +                buff.append(type).append(", ").append(value);
  +            }
  +            buff.append("\n");
  +        }
  +
  +        buff.append(" operationInstances:");
  +        if (operationInstances == null) {
  +            buff.append("null");
  +        } else {
  +            buff.append(" size:").append(operationInstances.size());
  +            int i = 0;
  +            for (Iterator it = operationInstances.keySet().iterator();
  +                it.hasNext();
  +                ) {
  +                String key = (String) it.next();
  +                WSIFOperation_Java woj =
  +                    (WSIFOperation_Java) operationInstances.get(key);
  +                buff.append("\noperationInstances[").append(i++).append("]:");
  +                buff.append(key).append(" ").append(woj).append(" ");
               }
  -        } catch (Exception e) {
  -            Trc.exceptionInTrace(e);
  +            buff.append("\n");
           }
   
  -        return buff;
  +        return buff.toString();
       }
   }
  
  
  
  1.30      +32 -23    xml-axis-wsif/java/src/org/apache/wsif/providers/java/WSIFOperation_Java.java
  
  Index: WSIFOperation_Java.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/java/WSIFOperation_Java.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- WSIFOperation_Java.java	13 Jan 2003 20:40:21 -0000	1.29
  +++ WSIFOperation_Java.java	31 Jan 2003 17:25:36 -0000	1.30
  @@ -105,6 +105,7 @@
       protected WSIFPort_Java fieldPort;
       protected javax.wsdl.BindingOperation fieldBindingOperationModel;
       protected JavaOperation fieldJavaOperationModel;
  +    protected Operation wsdlOperation;
       
       protected String[] fieldInParameterNames = null;
       protected String[] fieldOutParameterNames = null;
  @@ -135,14 +136,13 @@
           WSIFPort_Java port,
           Map typeMaps)
           throws WSIFException {
  -
           Trc.entry(this, portModel, bindingOperationModel, port, typeMaps);
   
           fieldPortModel = portModel;
           fieldBindingOperationModel = bindingOperationModel;
           fieldPort = port;
           fieldTypeMaps = typeMaps;
  -        Method[] allMethods = fieldPort.getObjectReference().getClass().getMethods();
  +        Method[] allMethods = fieldPort.getServiceObjectMethods();
   
           try {
               fieldJavaOperationModel =
  @@ -168,6 +168,7 @@
           }
   
           fieldConstructors = getConstructors();
  +
           fieldMethods = getMethods(allMethods);
   
           if (Trc.ON)
  @@ -243,6 +244,9 @@
                   fieldIsStatic,
                   fieldIsConstructor,
                   fieldTypeMaps);
  +
  +        woj.wsdlOperation = wsdlOperation;
  +
           Trc.exit(woj);
           return woj;
       }
  @@ -297,7 +301,7 @@
           Constructor[] candidates;
           // Get the possible constructors with the argument classes we've found.
           Constructor[] constructors =
  -            fieldPort.getObjectReference().getClass().getConstructors();
  +            fieldPort.getServiceObjectConstructors();
           Object[] args = getMethodArgumentClasses();
           Vector possibles = new Vector();
           for (int i = 0; i < constructors.length; i++) {
  @@ -504,27 +508,32 @@
   
       protected Operation getOperation() throws Exception {
       	Trc.entry(this);
  -        Operation operation = null;
   
  -        // <input> and <output> tags in binding operations are not mandatory
  -        // so deal with null BindingInputs or BindingOutputs
  -        String inputName = null;
  -        if (fieldBindingOperationModel.getBindingInput()!=null)
  -            inputName = fieldBindingOperationModel.getBindingInput().getName();
  -
  -        String outputName = null;
  -        if (fieldBindingOperationModel.getBindingOutput()!=null)
  -            outputName = fieldBindingOperationModel.getBindingOutput().getName();
  -
  -        // Build the parts list
  -        //this.fieldBindingOperationModel.getBindingInput().getName(),
  -        operation =
  -            this.fieldPortModel.getBinding().getPortType().getOperation(
  -                this.fieldBindingOperationModel.getName(),
  -                inputName,
  -                outputName);
  -        Trc.exit(operation);
  -        return operation;
  +        if (wsdlOperation == null) {
  +
  +            // <input> and <output> tags in binding operations are not mandatory
  +            // so deal with null BindingInputs or BindingOutputs
  +            String inputName = null;
  +            if (fieldBindingOperationModel.getBindingInput()!=null) {
  +                inputName = fieldBindingOperationModel.getBindingInput().getName();
  +            }
  +
  +            String outputName = null;
  +            if (fieldBindingOperationModel.getBindingOutput()!=null) {
  +                outputName = fieldBindingOperationModel.getBindingOutput().getName();
  +            }
  +
  +            // Build the parts list
  +            //this.fieldBindingOperationModel.getBindingInput().getName(),
  +            wsdlOperation =
  +                this.fieldPortModel.getBinding().getPortType().getOperation(
  +                    this.fieldBindingOperationModel.getName(),
  +                    inputName,
  +                    outputName);
  +        }
  +
  +        Trc.exit(wsdlOperation);
  +        return wsdlOperation;
       }
   
       protected Object getMethodReturnClass() throws WSIFException {
  
  
  

Mime
View raw message