geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r908295 - /geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/XBeanNamespaceHandler.java
Date Wed, 10 Feb 2010 00:32:13 GMT
Author: djencks
Date: Wed Feb 10 00:32:13 2010
New Revision: 908295

URL: http://svn.apache.org/viewvc?rev=908295&view=rev
Log:
XBEAN-142 Do our own key equality comparisons for maps

Modified:
    geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/XBeanNamespaceHandler.java

Modified: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/XBeanNamespaceHandler.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/XBeanNamespaceHandler.java?rev=908295&r1=908294&r2=908295&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/XBeanNamespaceHandler.java
(original)
+++ geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/XBeanNamespaceHandler.java
Wed Feb 10 00:32:13 2010
@@ -57,6 +57,10 @@
 import org.osgi.service.blueprint.reflect.Metadata;
 import org.osgi.service.blueprint.reflect.NonNullMetadata;
 import org.osgi.service.blueprint.reflect.NullMetadata;
+import org.osgi.service.blueprint.reflect.RefMetadata;
+import org.osgi.service.blueprint.reflect.ReferenceMetadata;
+import org.osgi.service.blueprint.reflect.ServiceReferenceMetadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Attr;
@@ -143,7 +147,7 @@
                     managedClasses.add(beanClass);
                     findAnnotations(key, beanClass, methods);
                 } catch (NoClassDefFoundError e) {
-                    LOGGER.warn("Could not load class: {} due to {}",className, e.getMessage());
+                    LOGGER.warn("Could not load class: {} due to {}", className, e.getMessage());
                 } catch (ClassNotFoundException e) {
                     LOGGER.warn("Could not load class: {}", className);
                 }
@@ -165,7 +169,7 @@
                     managedClasses.add(beanClass);
                     findAnnotations(key, beanClass, methods);
                 } catch (NoClassDefFoundError e) {
-                    LOGGER.warn("Could not load class: {} due to {}",className, e.getMessage());
+                    LOGGER.warn("Could not load class: {} due to {}", className, e.getMessage());
                 } catch (ClassNotFoundException e) {
                     LOGGER.warn("Could not load class: {}", className);
                 }
@@ -176,9 +180,9 @@
     }
 
     private static void findAnnotations(String key, Class<?> beanClass, Properties
methods) {
-        for (Method m: beanClass.getMethods()) {
+        for (Method m : beanClass.getMethods()) {
             if (m.isAnnotationPresent(PostConstruct.class)) {
-                methods.put(key  + ".initMethod", m.getName());
+                methods.put(key + ".initMethod", m.getName());
             }
             if (m.isAnnotationPresent(PreDestroy.class)) {
                 methods.put(key + ".destroyMethod", m.getName());
@@ -190,7 +194,7 @@
         Map<String, Class<? extends PropertyEditor>> propertyEditors = new HashMap<String,
Class<? extends PropertyEditor>>();
         for (Map.Entry entry : properties.entrySet()) {
             String key = (String) entry.getKey();
-            if (key.endsWith(".propertyEditor") ) {
+            if (key.endsWith(".propertyEditor")) {
                 String className = (String) entry.getValue();
                 Class<? extends PropertyEditor> clazz = bundle.loadClass(className).asSubclass(PropertyEditor.class);
                 propertyEditors.put(className, clazz);
@@ -198,11 +202,12 @@
         }
         return propertyEditors;
     }
+
     private Map<String, Class<? extends PropertyEditor>> propertyEditorsFromProperties(ClassLoader
classLoader, Properties properties) throws ClassNotFoundException, IllegalAccessException,
InstantiationException {
         Map<String, Class<? extends PropertyEditor>> propertyEditors = new HashMap<String,
Class<? extends PropertyEditor>>();
         for (Map.Entry entry : properties.entrySet()) {
             String key = (String) entry.getKey();
-            if (key.endsWith(".propertyEditor") ) {
+            if (key.endsWith(".propertyEditor")) {
                 String className = (String) entry.getValue();
                 Class<? extends PropertyEditor> clazz = classLoader.loadClass(className).asSubclass(PropertyEditor.class);
                 propertyEditors.put(className, clazz);
@@ -613,13 +618,44 @@
 
     private Metadata get(MutableMapMetadata map, NonNullMetadata keyValue) {
         for (MapEntry entry : map.getEntries()) {
-            if (entry.getKey().equals(keyValue)) {
+            if (equals(entry.getKey(), keyValue)) {
                 return entry.getValue();
             }
         }
         return null;
     }
 
+    private boolean equals(NonNullMetadata key1, NonNullMetadata key2) {
+        if (key1 == key2) return true;
+        if (key1.getClass() != key2.getClass()) return false;
+        if (key1 instanceof RefMetadata) return ((RefMetadata) key1).getComponentId().equals(((RefMetadata)
key2).getComponentId());
+        if (key1 instanceof ReferenceMetadata) {
+            if (((ReferenceMetadata) key1).getTimeout() != ((ReferenceMetadata) key2).getTimeout())
return false;
+        }
+        if (key1 instanceof ServiceReferenceMetadata) {
+            ServiceReferenceMetadata sr1 = (ServiceReferenceMetadata) key1;
+            ServiceReferenceMetadata sr2 = (ServiceReferenceMetadata) key2;
+            return sr1.getAvailability() == sr2.getAvailability()
+                    && sr1.getInterface().equals(sr2.getInterface())
+                    && sr1.getComponentName().equals(sr2.getComponentName())
+                    && sr1.getFilter().equals(sr2.getFilter())
+                    && sr1.getReferenceListeners().equals(sr2.getReferenceListeners())
+
+                    && sr1.getId().equals(sr2.getId())
+                    && sr1.getActivation() == sr2.getActivation()
+                    && sr1.getDependsOn().equals(sr2.getDependsOn());
+        }
+        if (key1 instanceof ValueMetadata) {
+            ValueMetadata v1 = (ValueMetadata) key1;
+            ValueMetadata v2 = (ValueMetadata) key2;
+            if (v1.getStringValue() != null ? v1.getStringValue().equals(v2.getStringValue())
: v2.getStringValue() == null
+                    && v1.getType() != null ? v1.getType().equals(v2.getType()) :
v2.getType() == null) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private boolean hasKey(MutableMapMetadata map, NonNullMetadata keyValue) {
         return get(map, keyValue) != null;
     }



Mime
View raw message