You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jo...@apache.org on 2012/02/27 08:30:10 UTC

svn commit: r1294047 - /geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java

Author: johnxiao
Date: Mon Feb 27 07:30:09 2012
New Revision: 1294047

URL: http://svn.apache.org/viewvc?rev=1294047&view=rev
Log:
GERONIMO-6224 NPE while accessing the system modules portlet

Modified:
    geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java

Modified: geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java?rev=1294047&r1=1294046&r2=1294047&view=diff
==============================================================================
--- geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java (original)
+++ geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java Mon Feb 27 07:30:09 2012
@@ -425,7 +425,7 @@ public class SimpleConfigurationManager 
         return configuration;
     }
 
-    protected List<Configuration> buildAllServiceParents(Map<Artifact, Configuration> loadedConfigurations, DependencyNode dependencyNode) throws InvalidConfigException {
+    protected List<Configuration> buildAllServiceParents(Map<Artifact, Configuration> loadedConfigurations, DependencyNode dependencyNode) throws InvalidConfigException, MissingDependencyException {
         List<Configuration> allServiceParents = new ArrayList<Configuration>();
         for (Artifact parentId : dependencyNode.getServiceParents()) {
             addDepthFirstServiceParents(parentId, allServiceParents, new HashSet<Artifact>(), loadedConfigurations);
@@ -439,9 +439,14 @@ public class SimpleConfigurationManager 
         return dependencyNode;
     }
 
-    private void addDepthFirstServiceParents(Artifact id, List<Configuration> ancestors, Set<Artifact> ids, Map<Artifact, Configuration> loadedConfigurations) throws InvalidConfigException {
+    private void addDepthFirstServiceParents(Artifact id, List<Configuration> ancestors, Set<Artifact> ids, Map<Artifact, Configuration> loadedConfigurations) throws InvalidConfigException, MissingDependencyException {
         if (!ids.contains(id)) {
-            Configuration configuration = getConfiguration(id, loadedConfigurations);
+        	Configuration configuration = null;
+        	try {
+        		configuration = getConfiguration(id, loadedConfigurations);
+        	} catch (InvalidConfigException e) {
+        		throw new MissingDependencyException(id);
+        	}
             ancestors.add(configuration);
             ids.add(id);
             for (Artifact parentId : configuration.getDependencyNode().getServiceParents()) {
@@ -851,7 +856,9 @@ public class SimpleConfigurationManager 
         LifecycleResults results = new LifecycleResults();
         for (Artifact configurationId : unloadList) {
             Configuration configuration = getConfiguration(configurationId);
-
+            
+            if(configuration == null) throw new NoSuchConfigException(configurationId);
+            
             // first make sure it is stopped
             if (started.contains(configurationId)) {
                 monitor.stopping(configurationId);
@@ -874,6 +881,11 @@ public class SimpleConfigurationManager 
 
             try {
                 Bundle bundle = bundles.remove(configurationId);
+                if(bundle == null) {
+                	// Attempt to get the bundle from framework directly
+					bundle = attemptGetBundleByLocation(configurationId, monitor);
+                }
+                
                 if (bundle != null) {
                     if (BundleUtils.canStop(bundle)) {
                         bundle.stop(Bundle.STOP_TRANSIENT);
@@ -890,7 +902,34 @@ public class SimpleConfigurationManager 
         monitor.finished();
         return results;
     }
-
+    /**
+     * Attempt to get the bundle by searching the bundle's location in all bundles in framework 
+     * 
+     * @param artifact
+     * @param monitor
+     * @return 
+     * @throws NoSuchConfigException
+     * @throws IOException
+     * @throws InvalidConfigException
+     */
+    protected Bundle attemptGetBundleByLocation(Artifact artifact, LifecycleMonitor monitor) {
+    	String artifactLoc = "";
+    	try {
+    		artifactLoc = locateBundle(artifact, monitor);
+    	} catch (Exception e) {
+    		// Because just attempt to get, so ignore
+    		return null;
+    	}
+    	 
+    	Bundle[] bundles = this.bundleContext.getBundles();
+    	
+    	for(Bundle bundle : bundles) {
+    		if(artifactLoc.equals(bundle.getLocation())) return bundle;
+    	}
+    	
+    	return null;
+    }
+    
     protected void removeConfigurationFromModel(Artifact configurationId) throws NoSuchConfigException {
         if (configurationModel.containsConfiguration(configurationId)) {
             configurationModel.removeConfiguration(configurationId);