Author: scheu
Date: Sat Jul  3 11:16:36 2010
New Revision: 960201

URL: http://svn.apache.org/viewvc?rev=960201&view=rev
Log:
AXIS2-4708
Contributor:Rich Scheuerle
Small change to enhance lookup of JAXBContext objects

Modified:
    
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
    
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionImpl.java

Modified: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java?rev=960201&r1=960200&r2=960201&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
 Sat Jul  3 11:16:36 2010
@@ -22,6 +22,7 @@ package org.apache.axis2.jaxws.message.d
 import org.apache.axis2.java.security.AccessController;
 import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.message.databinding.JAXBUtilsMonitor;
 import org.apache.axis2.jaxws.message.factory.ClassFinderFactory;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
 import org.apache.axis2.jaxws.utility.ClassUtils;
@@ -208,7 +209,7 @@ public class JAXBUtils {
                 log.debug(pkg);
             }
         }
-        JAXBUtilsMonitor.addPackageKey(key);
+        JAXBUtilsMonitor.addPackageKey(contextPackages.toString());
 
         // Get or Create The InnerMap using the package key
         ConcurrentHashMap<ClassLoader, JAXBContextValue> innerMap = null;

Modified: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionImpl.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionImpl.java?rev=960201&r1=960200&r2=960201&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionImpl.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionImpl.java
 Sat Jul  3 11:16:36 2010
@@ -90,7 +90,7 @@ public class MarshalServiceRuntimeDescri
 
     void setPackages(TreeSet<String> packages) {
         this.packages = packages;
-        this.packagesKey = packages.toString();  // Unique key for searches
+        this.packagesKey = getObjectIdentity(packages);  // Unique key for 
searches
     }
 
     public AnnotationDesc getAnnotationDesc(Class cls) {
@@ -266,5 +266,39 @@ public class MarshalServiceRuntimeDescri
     public MessageFactory getMessageFactory() {
         return messageFactory;
     }
+    
+    /**
+     * Java does not provide a way to uniquely identify an object.  This makes
+     * it difficult to distinguish one object from another in a trace.  The
+     * default Object.toString() produces a string of the form:
+     * 
+     *      obj.getClass().getName() + "@" + 
Integer.toHexString(obj.hashCode())
+     * 
+     * This is "as-good-as-it-gets".  If 'hashCode' has been overridden, it 
gets
+     * worse. Specifically, if hashCode has been overriden such that:
+     * 
+     *      obj1.equals(obj2)  ==> obj1.hashCode() == obj2.hashCode()
+     * 
+     * then it becomes impossible to distinguish between obj1 and obj2 in a 
trace:
+     * - dumping values is (almost) guaranteed to reveal that both have same 
content.
+     * - dumping hashCode (see Object.toString() comment above) gives same 
hashCode.
+     * 
+     * [For example, JNDI Reference objects exhibit this behavior]
+     * 
+     * The purpose of getObjectIdentity is to attempt to duplicate the 
"original"
+     * behavior of Object.toString().  On some JVMs, the 'original' hashCode
+     * corresponds to a memory reference to the object - which is unique.
+     * 
+     * This is NOT guaranteed to work on all JVMs.  But again, this seems to be
+     * "as-good-as-it-gets".
+     *  
+     * @return obj.getClass().getName() + "@" + 
Integer.toHexString(System.identityHashCode(obj));
+     */
+    private static String getObjectIdentity(Object obj) {
+        if (obj == null) {
+            return "null";
+        }
+        return obj.getClass().getName() + "@" + 
Integer.toHexString(System.identityHashCode(obj));
+    }
 
 }


Reply via email to