You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ow...@apache.org on 2002/09/17 16:33:16 UTC

cvs commit: xml-axis-wsif/java/src/org/apache/wsif/providers WSIFDynamicTypeMap.java

owenb       2002/09/17 07:33:14

  Modified:    java/src/org/apache/wsif/base WSIFServiceImpl.java
                        WSIFServiceFactoryImpl.java
               java/src/org/apache/wsif/providers WSIFDynamicTypeMap.java
  Log:
  Improvements to service caching code to help make thread safe:
  - Use Hashtable rather than HashMap in WSIFServiceFactoryImpl
  - Improve copyInitializedService method in WSIFServiceImpl
  - Add copy method to WSIFDynamicTypeMap
  - Add checks to avoid duplicate mappings in WSIFDynamicTypeMap
  
  Revision  Changes    Path
  1.27      +7 -3      xml-axis-wsif/java/src/org/apache/wsif/base/WSIFServiceImpl.java
  
  Index: WSIFServiceImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/base/WSIFServiceImpl.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- WSIFServiceImpl.java	29 Aug 2002 12:20:24 -0000	1.26
  +++ WSIFServiceImpl.java	17 Sep 2002 14:33:14 -0000	1.27
  @@ -302,13 +302,17 @@
               Trc.exit(deep());
       }
   
  +	/**
  +	 * Copy the "read-only" parts of an initialized WSIFServiceImpl
  +	 */
   	private void copyInitializedService(WSIFServiceImpl svc) {
   		this.def = svc.def;
           this.service = svc.service;
           this.portType = svc.portType;
  -        this.myPortsArr = svc.myPortsArr;
  -        this.myPortsMap = svc.myPortsMap;
  -        this.typeMap = svc.typeMap;
  +		this.myPortsArr = new Port[svc.myPortsArr.length];
  +		System.arraycopy(svc.myPortsArr, 0, this.myPortsArr, 0, svc.myPortsArr.length);
  +        this.myPortsMap = (Map) ((Hashtable) svc.myPortsMap).clone();
  +		this.typeMap = svc.typeMap.copy();
   	}
   
       /**
  
  
  
  1.8       +2 -2      xml-axis-wsif/java/src/org/apache/wsif/base/WSIFServiceFactoryImpl.java
  
  Index: WSIFServiceFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/base/WSIFServiceFactoryImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WSIFServiceFactoryImpl.java	29 Aug 2002 14:49:55 -0000	1.7
  +++ WSIFServiceFactoryImpl.java	17 Sep 2002 14:33:14 -0000	1.8
  @@ -57,7 +57,7 @@
   
   package org.apache.wsif.base;
   
  -import java.util.HashMap;
  +import java.util.Hashtable;
   import java.util.Map;
   
   import javax.wsdl.Definition;
  @@ -79,7 +79,7 @@
   public class WSIFServiceFactoryImpl extends WSIFServiceFactory {
   
       private boolean useCache = false;
  -    private Map cache = new HashMap();
  +    private Map cache = new Hashtable();
   
       /**
        * Create a WSIFService from WSDL document URL.
  
  
  
  1.6       +46 -5     xml-axis-wsif/java/src/org/apache/wsif/providers/WSIFDynamicTypeMap.java
  
  Index: WSIFDynamicTypeMap.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/WSIFDynamicTypeMap.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WSIFDynamicTypeMap.java	1 Aug 2002 13:08:33 -0000	1.5
  +++ WSIFDynamicTypeMap.java	17 Sep 2002 14:33:14 -0000	1.6
  @@ -107,8 +107,15 @@
        */
       public void mapType(QName xmlType, Class javaType) {
           Trc.entry(this, xmlType, javaType);
  -        typeMapList.add(new WSIFDynamicTypeMapping(xmlType, javaType));
  -        xmlTypes.add(xmlType);
  +        int i = xmlTypes.indexOf(xmlType);
  +        if (i == -1) {
  +        	// No mapping for this type exists so create one.        	
  +        	typeMapList.add(new WSIFDynamicTypeMapping(xmlType, javaType));
  +        	xmlTypes.add(xmlType);
  +        } else {
  +        	// Mapping for this type already exists so replace it.
  +        	typeMapList.setElementAt(new WSIFDynamicTypeMapping(xmlType, javaType), i);        	
  +        }
           Trc.exit();
       }
   
  @@ -121,9 +128,18 @@
        */
       public void mapType(QName xmlType, Class javaType, boolean force) {
           Trc.entry(this, xmlType, javaType);
  -        if (force || !xmlTypes.contains(xmlType)) {
  -            typeMapList.add(new WSIFDynamicTypeMapping(xmlType, javaType));
  -            xmlTypes.add(xmlType);
  +        int i = xmlTypes.indexOf(xmlType);
  +        // Only add mapping if no mapping yet exists for this type
  +        // or if force is set to true
  +        if (force || (i == -1)) {        	
  +            if (i == -1) {
  +            	// No mapping for this type exists so create one.        	
  +            	typeMapList.add(new WSIFDynamicTypeMapping(xmlType, javaType));
  +            	xmlTypes.add(xmlType);
  +            } else {
  +            	// Mapping for this type already exists so replace it.
  +            	typeMapList.setElementAt(new WSIFDynamicTypeMapping(xmlType, javaType), i);        	
  +            }
           }
           Trc.exit();
       }
  @@ -182,5 +198,30 @@
           Trc.entry(this);
           Trc.exit();
           return typeMapList.iterator();
  +    }
  +    
  +    /**
  +     * Produce a copy of the WSIFDynamicTypeMap. This is not a clone;
  +     * the copy will contain references to the same WSIFDynamicTypeMappings.
  +     * This method contains synchronized code so that the type map cannot
  +     * be altered whilst the copy takes place.
  +     * @return The copy of the WSIFDynamicTypeMap
  +     */
  +    public WSIFDynamicTypeMap copy() {
  +    	// Obtain a lock on the hash map
  +        synchronized (typeMapList) {
  +        	WSIFDynamicTypeMap tm = new WSIFDynamicTypeMap();
  +        	synchronized (allTypes) {
  +        		tm.setAllTypes((ArrayList) allTypes.clone());
  +        	}            
  +            Iterator it = typeMapList.iterator();
  +            // Copy the mappings
  +            while (it.hasNext()) {
  +                WSIFDynamicTypeMapping temp =
  +                    (WSIFDynamicTypeMapping) it.next();
  +                tm.mapType(temp.getXmlType(), temp.getJavaType());
  +            }
  +            return tm;
  +        }
       }
   }