Maintain the order that extensions are discovered/added and use that order when 
searching to allow some level of predictability and controlability.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/eecaebb4
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/eecaebb4
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/eecaebb4

Branch: refs/heads/3.0.x-fixes
Commit: eecaebb4b0ea89fc2aa94acb6464f0e913b8b223
Parents: 8453007
Author: Daniel Kulp <dk...@apache.org>
Authored: Thu Nov 13 11:37:53 2014 -0500
Committer: Daniel Kulp <dk...@apache.org>
Committed: Fri Nov 14 11:27:25 2014 -0500

----------------------------------------------------------------------
 .../cxf/bus/extension/ExtensionManagerImpl.java | 28 +++++++++++++-------
 1 file changed, 19 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/eecaebb4/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java 
b/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
index 1a5ee00..62d1944 100644
--- a/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
+++ b/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
@@ -32,6 +32,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
@@ -56,6 +57,7 @@ public class ExtensionManagerImpl implements 
ExtensionManager, ConfiguredBeanLoc
     private final ClassLoader loader;
     private ResourceManager resourceManager;
     private Map<String, Extension> all = new ConcurrentHashMap<String, 
Extension>();
+    private List<Extension> ordered = new CopyOnWriteArrayList<Extension>();
     private final Map<Class<?>, Object> activated;
     private final Bus bus;
 
@@ -91,6 +93,7 @@ public class ExtensionManagerImpl implements 
ExtensionManager, ConfiguredBeanLoc
         for (Map.Entry<String, Extension> ext : 
ExtensionRegistry.getRegisteredExtensions().entrySet()) {
             if (!all.containsKey(ext.getKey())) {
                 all.put(ext.getKey(), ext.getValue());
+                ordered.add(ext.getValue());
             }
         }
     }
@@ -109,10 +112,11 @@ public class ExtensionManagerImpl implements 
ExtensionManager, ConfiguredBeanLoc
     }
     public void add(Extension ex) {
         all.put(ex.getName(), ex);
+        ordered.add(ex);
     }
     
     public void initialize() {
-        for (Extension e : all.values()) {
+        for (Extension e : ordered) {
             if (!e.isDeferred() && e.getLoadedObject() == null) {
                 loadAndRegister(e);
             }
@@ -121,18 +125,21 @@ public class ExtensionManagerImpl implements 
ExtensionManager, ConfiguredBeanLoc
 
     public void removeBeansOfNames(List<String> names) {
         for (String s : names) {
-            all.remove(s);
+            Extension ex = all.remove(s);
+            if (ex != null) {
+                ordered.remove(ex);
+            }
         }
     }
     public void activateAll() {
-        for (Extension e : all.values()) {
+        for (Extension e : ordered) {
             if (e.getLoadedObject() == null) {
                 loadAndRegister(e);
             }
         }        
     }
     public <T> void activateAllByType(Class<T> type) {
-        for (Extension e : all.values()) {
+        for (Extension e : ordered) {
             if (e.getLoadedObject() == null) {
                 Class<?> cls = e.getClassObject(loader);
                 if (cls != null && type.isAssignableFrom(cls)) {
@@ -178,6 +185,7 @@ public class ExtensionManagerImpl implements 
ExtensionManager, ConfiguredBeanLoc
                     }
                     if (!all.containsKey(e.getName())) {
                         all.put(e.getName(), e);
+                        ordered.add(e);
                     }
                 }
             } finally {
@@ -292,7 +300,7 @@ public class ExtensionManagerImpl implements 
ExtensionManager, ConfiguredBeanLoc
     }
     public List<String> getBeanNamesOfType(Class<?> type) {
         List<String> ret = new LinkedList<String>();
-        for (Extension ex : all.values()) {
+        for (Extension ex : ordered) {
             Class<?> cls = ex.getClassObject(loader);
             if (cls != null && type.isAssignableFrom(cls)) {
                 synchronized (ex) {
@@ -325,11 +333,13 @@ public class ExtensionManagerImpl implements 
ExtensionManager, ConfiguredBeanLoc
                     if (ext.getLoadedObject() == null) {
                         loadAndRegister(ext);
                     }
-                    ret.add(type.cast(ext.getLoadedObject()));
+                    if (ext.getLoadedObject() != null) {
+                        ret.add(type.cast(ext.getLoadedObject()));
+                    }
                 }                
             }
         }
-        for (Extension ex : all.values()) {
+        for (Extension ex : ordered) {
             if (ex != ext) {
                 Class<?> cls = ex.getClassObject(loader);
                 if (cls != null && type.isAssignableFrom(cls)) {
@@ -348,7 +358,7 @@ public class ExtensionManagerImpl implements 
ExtensionManager, ConfiguredBeanLoc
     }
     public <T> boolean loadBeansOfType(Class<T> type, BeanLoaderListener<T> 
listener) {
         boolean loaded = false;
-        for (Extension ex : all.values()) {
+        for (Extension ex : ordered) {
             Class<?> cls = ex.getClassObject(loader);
             if (cls != null 
                 && type.isAssignableFrom(cls)) {
@@ -376,7 +386,7 @@ public class ExtensionManagerImpl implements 
ExtensionManager, ConfiguredBeanLoc
             && ex.getNamespaces().contains(value);
     }
     public void destroyBeans() {
-        for (Extension ex : all.values()) {
+        for (Extension ex : ordered) {
             if (ex.getLoadedObject() != null) {
                 ResourceInjector injector = new 
ResourceInjector(resourceManager);
                 injector.destroy(ex.getLoadedObject());

Reply via email to