geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1127333 - /geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/osgi/ConfigRegistryImpl.java
Date Tue, 24 May 2011 23:35:42 GMT
Author: gawor
Date: Tue May 24 23:35:41 2011
New Revision: 1127333

URL: http://svn.apache.org/viewvc?rev=1127333&view=rev
Log:
GERONIMO-5938: refactor the code a bit

Modified:
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/osgi/ConfigRegistryImpl.java

Modified: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/osgi/ConfigRegistryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/osgi/ConfigRegistryImpl.java?rev=1127333&r1=1127332&r2=1127333&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/osgi/ConfigRegistryImpl.java
(original)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/osgi/ConfigRegistryImpl.java
Tue May 24 23:35:41 2011
@@ -22,8 +22,8 @@ package org.apache.geronimo.myfaces.conf
 import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Enumeration;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -122,73 +122,61 @@ public class ConfigRegistryImpl implemen
         bundleIdFaceletsConfigResourcesMap.remove(removeBundleId);
     }
 
-    public List<FacesConfig> getDependentFacesConfigs(Long bundleId) {
-        BundleContext bundleContext = activator.getBundleContext();
-        ServiceReference serviceReference = null;
-        try {
-            serviceReference = bundleContext.getServiceReference(DependencyManager.class.getName());
-            if (serviceReference == null) {
-                return Collections.<FacesConfig> emptyList();
-            }
-            DependencyManager dependencyManager = (DependencyManager) bundleContext.getService(serviceReference);
-            Set<Bundle> dependentBundles = dependencyManager.getFullDependentBundles(bundleId);
-            addWiredBundles(bundleId, dependentBundles);
-            List<FacesConfig> dependentFacesConfigs = new ArrayList<FacesConfig>();
-            for (Bundle dependentBundle : dependentBundles) {
-                List<FacesConfig> facesConfigs = bundleIdFacesConfigsMap.get(dependentBundle.getBundleId());
-                if (facesConfigs != null) {
-                    dependentFacesConfigs.addAll(facesConfigs);
-                }
-            }
-            return dependentFacesConfigs;
-        } finally {
-            if (serviceReference != null) {
-                bundleContext.ungetService(serviceReference);
-            }
-        }
-    }
-
-    @Override
-    public List<URL> getDependentFaceletsConfigResources(Long bundleId) {
+    private Set<Bundle> getDependentBundles(Long bundleId) {
         BundleContext bundleContext = activator.getBundleContext();
-        ServiceReference serviceReference = null;
-        try {
-            serviceReference = bundleContext.getServiceReference(DependencyManager.class.getName());
-            if (serviceReference == null) {
-                return Collections.<URL> emptyList();
-            }
+        
+        Set<Bundle> dependentBundles = null;
+        
+        // add in bundles from dependency manager
+        ServiceReference serviceReference = bundleContext.getServiceReference(DependencyManager.class.getName());
+        if (serviceReference != null) {
             DependencyManager dependencyManager = (DependencyManager) bundleContext.getService(serviceReference);
-            Set<Bundle> dependentBundles = dependencyManager.getFullDependentBundles(bundleId);
-            addWiredBundles(bundleId, dependentBundles);
-            List<URL> faceletsConfigResources = new ArrayList<URL>();
-            for (Bundle dependentBundle : dependentBundles) {
-                List<URL> faceletConfigResources = bundleIdFaceletsConfigResourcesMap.get(dependentBundle.getBundleId());
-                if (faceletConfigResources != null) {
-                    faceletsConfigResources.addAll(faceletConfigResources);
-                }
-            }
-            return faceletsConfigResources;
-        } finally {
-            if (serviceReference != null) {
+            try {
+                dependentBundles = dependencyManager.getFullDependentBundles(bundleId);
+            } finally {
                 bundleContext.ungetService(serviceReference);
             }
+        } else {
+            dependentBundles = new HashSet<Bundle>();
         }
-    }
-
-    /*
-     * Add any wired bundles if the bundle is a Web Application Bundle.
-     */
-    private void addWiredBundles(Long bundleId, Set<Bundle> dependentBundles) {
-        BundleContext bundleContext = activator.getBundleContext();
+        
+        // add in wired bundles if WAB        
         Bundle bundle = bundleContext.getBundle(bundleId);
         String contextPath = (String) bundle.getHeaders().get("Web-ContextPath");
         if (contextPath != null) {
             Set<Bundle> wiredBundles = BundleUtils.getWiredBundles(bundle);
             dependentBundles.addAll(wiredBundles);
         }
+
+        return dependentBundles;
+    }
+    
+    public List<FacesConfig> getDependentFacesConfigs(Long bundleId) {
+        Set<Bundle> dependentBundles = getDependentBundles(bundleId);
+        List<FacesConfig> dependentFacesConfigs = new ArrayList<FacesConfig>();
+        for (Bundle dependentBundle : dependentBundles) {
+            List<FacesConfig> facesConfigs = bundleIdFacesConfigsMap.get(dependentBundle.getBundleId());
+            if (facesConfigs != null) {
+                dependentFacesConfigs.addAll(facesConfigs);
+            }
+        }
+        return dependentFacesConfigs;
     }
 
     @Override
+    public List<URL> getDependentFaceletsConfigResources(Long bundleId) {
+        Set<Bundle> dependentBundles = getDependentBundles(bundleId);
+        List<URL> faceletsConfigResources = new ArrayList<URL>();
+        for (Bundle dependentBundle : dependentBundles) {
+            List<URL> faceletConfigResources = bundleIdFaceletsConfigResourcesMap.get(dependentBundle.getBundleId());
+            if (faceletConfigResources != null) {
+                faceletsConfigResources.addAll(faceletConfigResources);
+            }
+        }
+        return faceletsConfigResources;
+    }
+    
+    @Override
     public Set<Long> getFacesConfigsBundleIds() {
         return bundleIdFacesConfigsMap.keySet();
     }



Mime
View raw message