You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2009/02/20 14:29:08 UTC

svn commit: r746231 [1/2] - in /servicemix/smx4/nmr/trunk/jbi/deployer/src: main/java/org/apache/servicemix/jbi/deployer/ main/java/org/apache/servicemix/jbi/deployer/artifacts/ main/java/org/apache/servicemix/jbi/deployer/classloader/ main/java/org/ap...

Author: gnodet
Date: Fri Feb 20 13:29:07 2009
New Revision: 746231

URL: http://svn.apache.org/viewvc?rev=746231&view=rev
Log:
SMX4NMR-99, SMX4NMR-100 + big refactoring of the deployer

Removed:
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/classloader/
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/utils/QueryUtils.java
Modified:
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceUnit.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/AbstractLifecycleJbiArtifact.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ComponentImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceUnitImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/SharedLibraryImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Connection.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Parser.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/URLHandler.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractInstaller.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminCommandsImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminService.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentInstaller.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/DeploymentService.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationService.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryInstaller.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/utils/ManagementSupport.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml
    servicemix/smx4/nmr/trunk/jbi/deployer/src/test/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImplTest.java

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java Fri Feb 20 13:29:07 2009
@@ -40,6 +40,13 @@
     String getDescription();
 
     /**
+     * Retrieve the JBI descriptor for this service assembly
+     *
+     * @return the JBI descriptor
+     */
+    String getDescriptor();
+
+    /**
      * Return the type of this component (service-engine or binding-component)
      *
      * @return the type
@@ -59,6 +66,11 @@
     ServiceUnit[] getServiceUnits();
 
     /**
+     * Retrieve the Shared Libraries used by this component
+     */
+    SharedLibrary[] getSharedLibraries();
+
+    /**
      * Force a shutdown of this component
      *
      * @throws javax.jbi.JBIException

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceUnit.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceUnit.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceUnit.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceUnit.java Fri Feb 20 13:29:07 2009
@@ -37,6 +37,13 @@
     String getDescription();
 
     /**
+     * Retrieve the JBI descriptor for this service assembly
+     *
+     * @return the JBI descriptor
+     */
+    String getDescriptor();
+
+    /**
      * Get the ServiceAssembly to which this ServiceUnit belongs
      *
      * @return

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java Fri Feb 20 13:29:07 2009
@@ -37,6 +37,13 @@
     String getDescription();
 
     /**
+     * Retrieve the JBI descriptor for this service assembly
+     *
+     * @return the JBI descriptor
+     */
+    String getDescriptor();
+
+    /**
      * Retrieves the version of this shared library
      *
      * @return the version
@@ -50,4 +57,11 @@
      */
     ClassLoader getClassLoader();
 
+    /**
+     * Retrieve a list of components using this shared library
+     *
+     * @return
+     */
+    Component[] getComponents();
+
 }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/AbstractLifecycleJbiArtifact.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/AbstractLifecycleJbiArtifact.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/AbstractLifecycleJbiArtifact.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/AbstractLifecycleJbiArtifact.java Fri Feb 20 13:29:07 2009
@@ -29,7 +29,6 @@
 
     public enum State {
         Unknown,
-        Initialized,
         Started,
         Stopped,
         Shutdown,
@@ -51,7 +50,6 @@
                 return LifeCycleMBean.STARTED;
             case Stopped:
                 return LifeCycleMBean.STOPPED;
-            case Initialized:
             case Shutdown:
                 return LifeCycleMBean.SHUTDOWN;
             default:

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ComponentImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ComponentImpl.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ComponentImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ComponentImpl.java Fri Feb 20 13:29:07 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.servicemix.jbi.deployer.artifacts;
 
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -34,31 +35,39 @@
 
 import org.apache.servicemix.jbi.deployer.Component;
 import org.apache.servicemix.jbi.deployer.ServiceUnit;
+import org.apache.servicemix.jbi.deployer.SharedLibrary;
 import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
-import org.apache.servicemix.jbi.deployer.descriptor.SharedLibraryList;
+import org.apache.servicemix.jbi.deployer.descriptor.DescriptorFactory;
 import org.apache.servicemix.jbi.runtime.ComponentWrapper;
+import org.osgi.framework.Bundle;
 import org.osgi.service.prefs.Preferences;
 
 /**
  */
 public class ComponentImpl extends AbstractLifecycleJbiArtifact implements Component, ComponentWrapper {
 
+    private Bundle bundle;
     private ComponentDesc componentDesc;
     private javax.jbi.component.Component component;
     private List<ServiceUnitImpl> serviceUnits;
     private Runnable callback;
+    private SharedLibrary[] sharedLibraries;
 
-    public ComponentImpl(ComponentDesc componentDesc,
+    public ComponentImpl(Bundle bundle,
+                         ComponentDesc componentDesc,
                          javax.jbi.component.Component component,
                          Preferences prefs,
                          boolean autoStart,
-                         Runnable callback) {
+                         Runnable callback,
+                         SharedLibrary[] sharedLibraries) {
+        this.bundle = bundle;
         this.componentDesc = componentDesc;
         this.component = new ComponentWrapper(component);
         this.prefs = prefs;
         this.runningState = State.valueOf(this.prefs.get(STATE, (autoStart ? State.Started : State.Shutdown).name()));
         this.callback = callback;
         this.serviceUnits = new ArrayList<ServiceUnitImpl>();
+        this.sharedLibraries = sharedLibraries;
     }
 
     public void addServiceUnit(ServiceUnitImpl serviceUnit) {
@@ -69,6 +78,10 @@
         serviceUnits.remove(serviceUnit);
     }
 
+    public Bundle getBundle() {
+        return bundle;
+    }
+
     public ServiceUnit[] getServiceUnits() {
         return serviceUnits.toArray(new ServiceUnit[serviceUnits.size()]);
     }
@@ -81,6 +94,11 @@
         return componentDesc.getIdentification().getDescription();
     }
 
+    public String getDescriptor() {
+        URL url = bundle.getResource(DescriptorFactory.DESCRIPTOR_FILE);
+        return DescriptorFactory.getDescriptorAsText(url);
+    }
+
     public String getType() {
         return componentDesc.getType();
     }
@@ -123,8 +141,8 @@
         return sas;
     }
 
-    public SharedLibraryList[] getSharedLibraries() {
-        return componentDesc.getSharedLibraries();
+    public SharedLibrary[] getSharedLibraries() {
+        return sharedLibraries;
     }
 
     public void stop(boolean saveState) throws JBIException {
@@ -161,8 +179,7 @@
         if (state == State.Stopped) {
             // Shutdown deployed SAs
             for (ServiceAssemblyImpl sa : getServiceAssemblies()) {
-                if (sa.getState() == ServiceAssemblyImpl.State.Stopped
-                        || sa.getState() == ServiceAssemblyImpl.State.Initialized) {
+                if (sa.getState() == ServiceAssemblyImpl.State.Stopped) {
                     sa.shutDown(false, force);
                 }
             }
@@ -226,20 +243,13 @@
             try {
                 Thread.currentThread().setContextClassLoader(component.getClass().getClassLoader());
                 if (runningState != State.Unknown) {
-                    if (runningState == State.Initialized) {
-                        LOGGER.warn("Illegal running state: 'Initialized'.  Defaulting to 'Shutdown'.");
-                        runningState = State.Shutdown;
-                    }
                     if (runningState == State.Started) {
                         lifeCycle.init(context);
-                        state = State.Initialized;
                         start();
                         state = State.Started;
                     } else if (runningState == State.Stopped) {
                         lifeCycle.init(context);
-                        state = State.Initialized;
                         start();
-                        state = State.Started;
                         stop();
                         state = State.Stopped;
                     } else if (runningState == State.Shutdown) {
@@ -248,7 +258,7 @@
                     runningState = State.Unknown;
                 } else {
                     lifeCycle.init(context);
-                    state = State.Initialized;
+                    state = State.Shutdown;
                 }
                 if (callback != null) {
                     callback.run();

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImpl.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImpl.java Fri Feb 20 13:29:07 2009
@@ -43,6 +43,28 @@
  */
 public class ServiceAssemblyImpl extends AbstractLifecycleJbiArtifact implements ServiceAssembly {
 
+    private enum Action {
+        Init,
+        Start,
+        Stop,
+        Shutdown;
+
+        public Action reverse() {
+            switch (this) {
+                case Init:
+                    return Shutdown;
+                case Start:
+                    return Stop;
+                case Stop:
+                    return Start;
+                case Shutdown:
+                    return Init;
+                default:
+                    throw new IllegalStateException();
+            }
+        }
+    }
+
     private final Bundle bundle;
 
     private final ServiceAssemblyDesc serviceAssemblyDesc;
@@ -62,12 +84,16 @@
         this.serviceUnits = serviceUnits;
         this.prefs = prefs;
         this.listener = listener;
-        this.runningState = State.valueOf(this.prefs.get(STATE, (autoStart ? State.Started : State.Initialized).name()));
+        this.runningState = State.valueOf(this.prefs.get(STATE, (autoStart ? State.Started : State.Shutdown).name()));
         for (ServiceUnitImpl su : serviceUnits) {
             su.setServiceAssemblyImpl(this);
         }
     }
 
+    public Bundle getBundle() {
+        return bundle;
+    }
+
     public String getName() {
         return serviceAssemblyDesc.getIdentification().getName();
     }
@@ -88,12 +114,13 @@
     public synchronized void init() throws JBIException {
         listener.setAssembly(this);
         try {
-            transition(State.Initialized);
             if (runningState == State.Started) {
-                transition(State.Started);
+                transition(Action.Init, State.Stopped);
+                transition(Action.Start, State.Started);
             } else if (runningState == State.Stopped) {
-                transition(State.Started);
-                transition(State.Stopped);
+                transition(Action.Init, State.Stopped);
+            } else if (runningState == State.Shutdown) {
+                state = State.Shutdown;
             }
         } finally {
             listener.setAssembly(null);
@@ -111,10 +138,10 @@
                 return;
             }
             if (state == State.Shutdown) {
-                transition(State.Initialized);
+                transition(Action.Init, State.Stopped);
             }
             startConnections();
-            transition(State.Started);
+            transition(Action.Start, State.Started);
             if (persist) {
                 saveState();
             }
@@ -134,10 +161,10 @@
                 return;
             }
             if (state == State.Shutdown) {
-                transition(State.Initialized);
+                transition(Action.Init, State.Stopped);
             }
             if (state == State.Started) {
-                transition(State.Stopped);
+                transition(Action.Stop,  State.Stopped);
             }
             stopConnections();
             if (persist) {
@@ -163,7 +190,7 @@
                 return;
             }
             if (state == State.Started) {
-                transition(State.Stopped);
+                transition(Action.Stop, State.Stopped);
             }
             if (!force) {
                 for (; ;) {
@@ -174,7 +201,7 @@
                     }
                 }
             }
-            transition(State.Shutdown);
+            transition(Action.Shutdown, State.Shutdown);
             if (persist) {
                 saveState();
             }
@@ -184,19 +211,19 @@
         }
     }
 
-    protected void transition(State to) throws JBIException {
+    protected void transition(Action action, State to) throws JBIException {
         LOGGER.info("Changing SA state to " + to);
         State from = state;
         List<ServiceUnitImpl> success = new ArrayList<ServiceUnitImpl>();
         for (ServiceUnitImpl su : serviceUnits) {
             try {
-                changeState(su, to);
+                changeState(su, action);
                 success.add(su);
             } catch (JBIException e) {
                 if (from != State.Unknown) {
                     for (ServiceUnitImpl su2 : success) {
                         try {
-                            changeState(su2, from);
+                            changeState(su2, action.reverse());
                         } catch (JBIException e2) {
                             // Ignore
                         }
@@ -208,15 +235,15 @@
         state = to;
     }
 
-    protected void changeState(ServiceUnitImpl su, State state) throws JBIException {
-        switch (state) {
-            case Initialized:
+    protected void changeState(ServiceUnitImpl su, Action action) throws JBIException {
+        switch (action) {
+            case Init:
                 su.init();
                 break;
-            case Started:
+            case Start:
                 su.start();
                 break;
-            case Stopped:
+            case Stop:
                 su.stop();
                 break;
             case Shutdown:
@@ -249,6 +276,6 @@
     }
     
     protected void unregisterWire(Wire wire, Map<String, ?> from) {
-        
+        // TODO
     }
 }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceUnitImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceUnitImpl.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceUnitImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceUnitImpl.java Fri Feb 20 13:29:07 2009
@@ -60,6 +60,11 @@
         return serviceUnitDesc.getIdentification().getDescription();
     }
 
+    public String getDescriptor() {
+        // TODO: implement this
+        throw new UnsupportedOperationException();
+    }
+
     public String getComponentName() {
         return serviceUnitDesc.getTarget().getComponentName();
     }
@@ -85,31 +90,67 @@
     }
 
     public void deploy() throws JBIException {
-        component.getComponent().getServiceUnitManager().deploy(getName(), getRootDir() != null ? getRootDir().getAbsolutePath() : null);
+        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(component.getComponent().getClass().getClassLoader());
+            component.getComponent().getServiceUnitManager().deploy(getName(), getRootDir() != null ? getRootDir().getAbsolutePath() : null);
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldCl);
+        }
         component.addServiceUnit(this);
     }
 
     public void init() throws JBIException {
-        component.getComponent().getServiceUnitManager().init(getName(), getRootDir() != null ? getRootDir().getAbsolutePath() : null);
+        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(component.getComponent().getClass().getClassLoader());
+            component.getComponent().getServiceUnitManager().init(getName(), getRootDir() != null ? getRootDir().getAbsolutePath() : null);
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldCl);
+        }
     }
 
     public void start() throws JBIException {
         checkComponentStarted("start");
-        component.getComponent().getServiceUnitManager().start(getName());
+        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(component.getComponent().getClass().getClassLoader());
+            component.getComponent().getServiceUnitManager().start(getName());
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldCl);
+        }
     }
 
     public void stop() throws JBIException {
         checkComponentStarted("stop");
-        component.getComponent().getServiceUnitManager().stop(getName());
+        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(component.getComponent().getClass().getClassLoader());
+            component.getComponent().getServiceUnitManager().stop(getName());
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldCl);
+        }
     }
 
     public void shutdown() throws JBIException {
         checkComponentStartedOrStopped("shutDown");
-        component.getComponent().getServiceUnitManager().shutDown(getName());
+        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(component.getComponent().getClass().getClassLoader());
+            component.getComponent().getServiceUnitManager().shutDown(getName());
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldCl);
+        }
     }
 
     public void undeploy() throws JBIException {
-        component.getComponent().getServiceUnitManager().undeploy(getName(), getRootDir() != null ? getRootDir().getAbsolutePath() : null);
+        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(component.getComponent().getClass().getClassLoader());
+            component.getComponent().getServiceUnitManager().undeploy(getName(), getRootDir() != null ? getRootDir().getAbsolutePath() : null);
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldCl);
+        }
         component.removeServiceUnit(this);
     }
 

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/SharedLibraryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/SharedLibraryImpl.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/SharedLibraryImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/SharedLibraryImpl.java Fri Feb 20 13:29:07 2009
@@ -16,20 +16,17 @@
  */
 package org.apache.servicemix.jbi.deployer.artifacts;
 
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Enumeration;
 import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.deployer.Component;
 import org.apache.servicemix.jbi.deployer.SharedLibrary;
-import org.apache.servicemix.jbi.deployer.classloader.OsgiMultiParentClassLoader;
-import org.apache.servicemix.jbi.deployer.descriptor.ClassPath;
+import org.apache.servicemix.jbi.deployer.descriptor.DescriptorFactory;
 import org.apache.servicemix.jbi.deployer.descriptor.SharedLibraryDesc;
 import org.osgi.framework.Bundle;
-import org.springframework.osgi.util.BundleDelegatingClassLoader;
 
 /**
  * SharedLibrary object
@@ -41,10 +38,17 @@
     private SharedLibraryDesc library;
     private Bundle bundle;
     private ClassLoader classLoader;
+    private List<Component> components;
 
-    public SharedLibraryImpl(SharedLibraryDesc library, Bundle bundle) {
-        this.library = library;
+    public SharedLibraryImpl(Bundle bundle, SharedLibraryDesc library, ClassLoader classLoader) {
         this.bundle = bundle;
+        this.library = library;
+        this.classLoader = classLoader;
+        this.components = new ArrayList<Component>();
+    }
+
+    public Bundle getBundle() {
+        return bundle;
     }
 
     public String getName() {
@@ -55,44 +59,31 @@
         return library.getIdentification().getDescription();
     }
 
+    public String getDescriptor() {
+        URL url = bundle.getResource(DescriptorFactory.DESCRIPTOR_FILE);
+        return DescriptorFactory.getDescriptorAsText(url);
+    }
+
     public String getVersion() {
         return library.getVersion();
     }
 
     public ClassLoader getClassLoader() {
         if (classLoader == null) {
-            // Make the current ClassLoader the parent
-            ClassLoader parent = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle, getClass().getClassLoader());
-            boolean parentFirst = library.isParentFirstClassLoaderDelegation();
-            ClassPath cp = library.getSharedLibraryClassPath();
-            String[] classPathNames = cp.getPathElements();
-            List<URL> urls = new ArrayList<URL>();
-            for (String classPathName : classPathNames) {
-                if (!".".equals(classPathName)) {
-                    URL url = bundle.getResource(classPathName);
-                    if (url == null) {
-                        throw new IllegalArgumentException("SharedLibrary classpath entry not found: '" + classPathName + "'");
-                    }
-                    Enumeration en = bundle.findEntries(classPathName, null, false);
-                    if (en != null && en.hasMoreElements()) {
-                        try {
-                            url = new URL(url.toString() + "/");
-                        } catch (MalformedURLException e) {
-                            // Ignore
-                        }
-                    }
-                    urls.add(url);
-                }
-            }
-            classLoader = new OsgiMultiParentClassLoader(
-                    bundle,
-                    library.getIdentification().getName(),
-                    urls.toArray(new URL[urls.size()]),
-                    parent,
-                    !parentFirst,
-                    new String[0],
-                    new String[]{"java.", "javax."});
         }
         return classLoader;
     }
+
+    public Component[] getComponents() {
+        return components.toArray(new Component[components.size()]);
+    }
+
+    public void addComponent(Component component) {
+        components.add(component);
+    }
+
+    public void removeComponent(Component component) {
+        components.remove(component);
+    }
+
 }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Connection.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Connection.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Connection.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Connection.java Fri Feb 20 13:29:07 2009
@@ -22,9 +22,9 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
-import java.net.MalformedURLException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Parser.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Parser.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Parser.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Parser.java Fri Feb 20 13:29:07 2009
@@ -16,15 +16,15 @@
  */
 package org.apache.servicemix.jbi.deployer.handler;
 
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-import java.util.Properties;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLDecoder;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * Parser for jbi: protocol URL.

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java Fri Feb 20 13:29:07 2009
@@ -22,13 +22,13 @@
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.Properties;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
-import java.util.Properties;
-import java.util.Enumeration;
 
 import org.apache.servicemix.jbi.deployer.descriptor.Descriptor;
 import org.apache.servicemix.jbi.deployer.descriptor.DescriptorFactory;

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/URLHandler.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/URLHandler.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/URLHandler.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/URLHandler.java Fri Feb 20 13:29:07 2009
@@ -18,12 +18,9 @@
 package org.apache.servicemix.jbi.deployer.handler;
 
 import java.io.IOException;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.osgi.service.url.AbstractURLStreamHandlerService;
 
 /**

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractInstaller.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractInstaller.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractInstaller.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractInstaller.java Fri Feb 20 13:29:07 2009
@@ -19,16 +19,24 @@
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Enumeration;
+
+import javax.jbi.JBIException;
+import javax.management.ObjectName;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.jbi.deployer.artifacts.AbstractLifecycleJbiArtifact;
+import org.apache.servicemix.jbi.deployer.descriptor.Descriptor;
 import org.apache.servicemix.jbi.deployer.handler.Transformer;
+import org.apache.servicemix.jbi.deployer.utils.FileUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
+import org.osgi.framework.BundleException;
 import org.osgi.service.prefs.BackingStoreException;
 import org.osgi.service.prefs.Preferences;
 import org.osgi.service.prefs.PreferencesService;
@@ -37,9 +45,19 @@
 
     protected final Log LOGGER = LogFactory.getLog(getClass());
 
-    protected BundleContext bundleContext;
+    protected Deployer deployer;
+    protected Descriptor descriptor;
     protected Bundle bundle;
-    private boolean autoStart = false;
+    protected boolean autoStart = false;
+    protected File jbiArtifact;
+    protected File installRoot;
+    protected boolean uninstallFromOsgi;
+
+    protected AbstractInstaller(Deployer deployer, Descriptor descriptor, File jbiArtifact) {
+        this.deployer = deployer;
+        this.descriptor = descriptor;
+        this.jbiArtifact = jbiArtifact;
+    }
 
     public void setBundle(Bundle bundle) {
         this.bundle = bundle;
@@ -49,25 +67,30 @@
         return bundle;
     }
 
-    public void setBundleContext(BundleContext bundleContext) {
-        this.bundleContext = bundleContext;
+    protected BundleContext getBundleContext() {
+        return deployer.getBundleContext();
     }
 
-    public BundleContext getBundleContext() {
-        return bundleContext;
+    public abstract String getName();
+
+    public void init() throws Exception {
+        extractBundle(installRoot, getBundle(), "/");
     }
 
-    public abstract String getName();
+    public abstract ObjectName install() throws JBIException;
+
+    public abstract void uninstall(boolean force) throws Exception;
 
-    public synchronized void deployFile(String filename) {
+    public void installBundle() throws Exception {
         InputStream is = null;
         try {
-            File artifact = new File(filename);
+            deployer.setJmxManaged(this);
+            File artifact = new File(jbiArtifact.getCanonicalPath());
             String bundleName = artifact.getName().substring(0, artifact.getName().length() - 4) + ".jar";
             File osgi = new File(getGenerateDir(), bundleName);
             Transformer.transformToOSGiBundle(artifact, osgi);
             is = new BufferedInputStream(new FileInputStream(osgi));
-            bundle = bundleContext.installBundle(artifact.getCanonicalFile().toURI().toString(), is);
+            bundle = getBundleContext().installBundle(artifact.getCanonicalFile().toURI().toString(), is);
             bundle.start();
         } catch (Exception e) {
             if (is != null) {
@@ -77,7 +100,20 @@
                     LOGGER.info("Failed to close stream. " + io, io);
                 }
             }
-            LOGGER.info("Failed to process: " + filename + ". Reason: " + e, e);
+            throw e;
+        } finally {
+            deployer.setJmxManaged(null);
+        }
+    }
+
+    protected void uninstallBundle() throws BundleException {
+        if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && !uninstallFromOsgi) {
+            try {
+                deployer.setJmxManaged(this);
+                bundle.uninstall();
+            } finally {
+                deployer.setJmxManaged(null);
+            }
         }
     }
 
@@ -87,7 +123,7 @@
     }
 
     protected void initializePreferences() throws BackingStoreException {
-        PreferencesService preferencesService = getPreferencesService();
+        PreferencesService preferencesService = deployer.getPreferencesService();
         Preferences prefs = preferencesService.getUserPreferences(getName());
         prefs.put(AbstractLifecycleJbiArtifact.STATE, isAutoStart()
                         ? AbstractLifecycleJbiArtifact.State.Started.name()
@@ -96,21 +132,12 @@
     }
 
     protected void deletePreferences() throws BackingStoreException {
-        PreferencesService preferencesService = getPreferencesService();
+        PreferencesService preferencesService = deployer.getPreferencesService();
         Preferences prefs = preferencesService.getUserPreferences(getName());
         prefs.clear();
         prefs.flush();
     }
 
-    private PreferencesService getPreferencesService() throws BackingStoreException {
-        ServiceReference ref = getBundleContext().getServiceReference(PreferencesService.class.getName());
-        PreferencesService preferencesService = (PreferencesService) getBundleContext().getService(ref);
-        if (preferencesService == null) {
-            throw new BackingStoreException("Unable to find bundle 'org.apache.servicemix.jbi.deployer'");
-        }
-        return preferencesService;
-    }
-
     public boolean isAutoStart() {
         return autoStart;
     }
@@ -118,4 +145,34 @@
     public void setAutoStart(boolean autoStart) {
         this.autoStart = autoStart;
     }
+
+    public boolean isUninstallFromOsgi() {
+        return uninstallFromOsgi;
+    }
+
+    public void setUninstallFromOsgi(boolean uninstallFromOsgi) {
+        this.uninstallFromOsgi = uninstallFromOsgi;
+    }
+
+    protected void extractBundle(File installRoot, Bundle bundle, String path) throws IOException {
+        Enumeration e = bundle.getEntryPaths(path);
+        while (e != null && e.hasMoreElements()) {
+            String entry = (String) e.nextElement();
+            File fout = new File(installRoot, entry);
+            if (entry.endsWith("/")) {
+                fout.mkdirs();
+                extractBundle(installRoot, bundle, entry);
+            } else {
+                InputStream in = bundle.getEntry(entry).openStream();
+                OutputStream out = new FileOutputStream(fout);
+                try {
+                    FileUtil.copyInputStream(in, out);
+                } finally {
+                    in.close();
+                    out.close();
+                }
+            }
+        }
+    }
+
 }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminCommandsImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminCommandsImpl.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminCommandsImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminCommandsImpl.java Fri Feb 20 13:29:07 2009
@@ -23,7 +23,6 @@
 import java.util.Properties;
 import java.util.Set;
 
-import javax.jbi.JBIException;
 import javax.jbi.management.LifeCycleMBean;
 import javax.management.StandardMBean;
 
@@ -32,51 +31,32 @@
 import org.apache.servicemix.jbi.deployer.ServiceAssembly;
 import org.apache.servicemix.jbi.deployer.ServiceUnit;
 import org.apache.servicemix.jbi.deployer.SharedLibrary;
-import org.apache.servicemix.jbi.deployer.artifacts.ComponentImpl;
-import org.apache.servicemix.jbi.deployer.artifacts.ServiceAssemblyImpl;
-import org.apache.servicemix.jbi.deployer.descriptor.SharedLibraryList;
 import org.apache.servicemix.jbi.deployer.utils.ManagementSupport;
-import org.apache.servicemix.jbi.deployer.utils.QueryUtils;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.springframework.osgi.context.BundleContextAware;
-import org.springframework.util.StringUtils;
+import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.InitializingBean;
+import org.springframework.util.StringUtils;
 
-public class AdminCommandsImpl implements AdminCommands, BundleContextAware, InitializingBean {
+public class AdminCommandsImpl implements AdminCommands, InitializingBean, DisposableBean {
 
     private Deployer deployer;
     private InstallationService installationService;
-    private BundleContext bundleContext;
     private DeploymentService deploymentService;
 
 
-    protected interface ComponentCallback {
-        void doWithComponent(Component component) throws JBIException;
-    }
-
-    protected void executeWithComponent(String name, ComponentCallback callback) throws JBIException {
-        Component component = QueryUtils.getComponent(bundleContext, name);
-        if (component == null) {
-            throw new JBIException("Component '" + name + "' not found");
-        }
-        callback.doWithComponent(component);
-    }
-
     /**
      * Install a JBI component (a Service Engine or Binding Component)
      *
-     * @param fileName jbi component archive to install
+     * @param file jbi component archive to install
      * @param props    installation properties
      * @return
      */
-    public String installComponent(String fileName, Properties props, boolean deferException) throws Exception {
+    public String installComponent(String file, Properties props, boolean deferException) throws Exception {
         // TODO: handle deferException
         try {
-            getInstallationService().install(fileName, props, false);
-            return ManagementSupport.createSuccessMessage("installComponent", fileName);
+            getInstallationService().install(file, props, false);
+            return ManagementSupport.createSuccessMessage("installComponent", file);
         } catch (Exception e) {
-            throw ManagementSupport.failure("installComponent", fileName, e);
+            throw ManagementSupport.failure("installComponent", file, e);
         }
     }
 
@@ -90,30 +70,11 @@
      */
     public String uninstallComponent(final String name) throws Exception {
         try {
-            executeWithComponent(name, new ComponentCallback() {
-                public void doWithComponent(Component comp) throws JBIException {
-                    try {
-                        if (comp == null) {
-                            throw ManagementSupport.failure("uninstallComponent", "Component '" + name + "' is not installed.");
-                        }
-                        if (!comp.getCurrentState().equals(LifeCycleMBean.SHUTDOWN)) {
-                            throw ManagementSupport.failure("uninstallComponent", "Component '" + name + "' is not shut down.");
-                        }
-                        boolean success = installationService.unloadInstaller(name, true);
-                        if (!success) {
-                            throw new RuntimeException();
-                        }
-                    } catch (Exception e) {
-                        throw new JBIException(e);
-                    }
-
-                }
-            });
+            installationService.unloadInstaller(name, true);
+            return ManagementSupport.createSuccessMessage("uninstallComponent", name);
         } catch (Exception e) {
             throw ManagementSupport.failure("uninstallComponent", name, e);
         }
-        return ManagementSupport.createSuccessMessage("uninstallComponent",
-                name);
     }
 
     /**
@@ -125,7 +86,8 @@
     public String installSharedLibrary(String file, boolean deferException) throws Exception {
         // TODO: handle deferException
         try {
-            return installationService.installSharedLibrary(file);
+            installationService.installSharedLibrary(file);
+            return ManagementSupport.createSuccessMessage("installSharedLibrary", file);
         } catch (Exception e) {
             throw ManagementSupport.failure("installSharedLibrary", file, e);
         }
@@ -139,34 +101,8 @@
      */
     public String uninstallSharedLibrary(String name) throws Exception {
         try {
-            //Check that the library is installed
-            boolean isInstalled = getDeployer().getInstalledSharedLibararies().contains(name);
-            if (!isInstalled) {
-                throw ManagementSupport.failure("uninstallSharedLibrary", "Shared library '" + name + "' is not installed.");
-            }
-            // Check that it is not used by a running component
-            ServiceReference[] refs = QueryUtils.getComponentsServiceReferences(bundleContext, null);
-
-            for (ServiceReference ref : refs) {
-                ComponentImpl component = (ComponentImpl) getBundleContext().getService(ref);
-                if (!component.getCurrentState().equalsIgnoreCase(LifeCycleMBean.SHUTDOWN)) {
-                    SharedLibraryList[] sls = component.getSharedLibraries();
-                    if (sls != null) {
-                        for (SharedLibraryList sl : sls) {
-                            if (name.equals(sl.getName())) {
-                                throw ManagementSupport.failure("uninstallSharedLibrary", "Shared library '" + name
-                                        + "' is used by component '" + component.getName() + "'.");
-                            }
-                        }
-                    }
-                }
-            }
-            boolean success = getInstallationService().uninstallSharedLibrary(name);
-            if (success) {
-                return ManagementSupport.createSuccessMessage("uninstallSharedLibrary", name);
-            } else {
-                throw ManagementSupport.failure("uninstallSharedLibrary", name);
-            }
+            getInstallationService().doUninstallSharedLibrary(name);
+            return ManagementSupport.createSuccessMessage("uninstallSharedLibrary", name);
         } catch (Throwable e) {
             throw ManagementSupport.failure("uninstallSharedLibrary", name, e);
         }
@@ -179,13 +115,13 @@
      * @return
      */
     public String startComponent(String name) throws Exception {
+        Component component = deployer.getComponent(name);
+        if (component == null) {
+            throw ManagementSupport.failure("start", "Component does not exist: " + name);
+        }
         try {
-            executeWithComponent(name, new ComponentCallback() {
-                public void doWithComponent(Component component) throws JBIException {
-                    component.start();
-                }
-            });
-            return ManagementSupport.createSuccessMessage("startComponent", name);
+            component.start();
+            return ManagementSupport.createSuccessMessage("Component started", name);
         } catch (Throwable e) {
             throw ManagementSupport.failure("startComponent", name, e);
         }
@@ -198,13 +134,13 @@
      * @return
      */
     public String stopComponent(String name) throws Exception {
+        Component component = deployer.getComponent(name);
+        if (component == null) {
+            throw ManagementSupport.failure("stop", "Component does not exist: " + name);
+        }
         try {
-            executeWithComponent(name, new ComponentCallback() {
-                public void doWithComponent(Component component) throws JBIException {
-                    component.stop();
-                }
-            });
-            return ManagementSupport.createSuccessMessage("stopComponent", name);
+            component.stop();
+            return ManagementSupport.createSuccessMessage("Component stopped", name);
         } catch (Throwable e) {
             throw ManagementSupport.failure("stopComponent", name, e);
         }
@@ -217,13 +153,13 @@
      * @return
      */
     public String shutdownComponent(String name) throws Exception {
+        Component component = deployer.getComponent(name);
+        if (component == null) {
+            throw ManagementSupport.failure("shutdown", "Component does not exist: " + name);
+        }
         try {
-            executeWithComponent(name, new ComponentCallback() {
-                public void doWithComponent(Component component) throws JBIException {
-                    component.shutDown();
-                }
-            });
-            return ManagementSupport.createSuccessMessage("shutdownComponent", name);
+            component.shutDown();
+            return ManagementSupport.createSuccessMessage("Component shut down", name);
         } catch (Throwable e) {
             throw ManagementSupport.failure("shutdownComponent", name, e);
         }
@@ -252,7 +188,12 @@
      * @return
      */
     public String undeployServiceAssembly(String name) throws Exception {
+        ServiceAssembly sa = deployer.getServiceAssembly(name);
+        if (sa == null) {
+            throw ManagementSupport.failure("start", "Service assembly does not exist: " + name);
+        }
         try {
+            // TODO: refactor
             return getDeploymentService().undeploy(name);
         } catch (Throwable e) {
             throw ManagementSupport.failure("undeployServiceAssembly", name, e);
@@ -266,8 +207,13 @@
      * @return
      */
     public String startServiceAssembly(String name) throws Exception {
+        ServiceAssembly sa = deployer.getServiceAssembly(name);
+        if (sa == null) {
+            throw ManagementSupport.failure("start", "Service assembly does not exist: " + name);
+        }
         try {
-            return getDeploymentService().start(name);
+            sa.start();
+            return ManagementSupport.createSuccessMessage("Service assembly started", name);
         } catch (Throwable e) {
             throw ManagementSupport.failure("startServiceAssembly", name, e);
         }
@@ -280,8 +226,13 @@
      * @return
      */
     public String stopServiceAssembly(String name) throws Exception {
+        ServiceAssembly sa = deployer.getServiceAssembly(name);
+        if (sa == null) {
+            throw ManagementSupport.failure("stop", "Service assembly does not exist: " + name);
+        }
         try {
-            return getDeploymentService().stop(name);
+            sa.stop();
+            return ManagementSupport.createSuccessMessage("Service assembly stopped", name);
         } catch (Throwable e) {
             throw ManagementSupport.failure("stopServiceAssembly", name, e);
         }
@@ -294,8 +245,13 @@
      * @return
      */
     public String shutdownServiceAssembly(String name) throws Exception {
+        ServiceAssembly sa = deployer.getServiceAssembly(name);
+        if (sa == null) {
+            throw ManagementSupport.failure("shutdown", "Service assembly does not exist: " + name);
+        }
         try {
-            return getDeploymentService().shutDown(name);
+            sa.shutDown();
+            return ManagementSupport.createSuccessMessage("Service assembly shut down", name);
         } catch (Throwable e) {
             throw ManagementSupport.failure("shutdownServiceAssembly", name, e);
         }
@@ -328,43 +284,43 @@
             throw ManagementSupport.failure("listComponents", "Required state '" + requiredState + "' is not a valid state.");
         }
         // Get components
-        String filter = null;
-        if (excludeSEs && !excludeBCs) {
-            filter = "(" + Deployer.TYPE + "=" + Deployer.TYPE_BINDING_COMPONENT + ")";
-        }
-        if (excludeBCs && !excludeSEs) {
-            filter = "(" + Deployer.TYPE + "=" + Deployer.TYPE_SERVICE_ENGINE + ")";
-        }
-        ServiceReference[] refs = QueryUtils.getComponentsServiceReferences(bundleContext, filter);
-        if (excludeBCs && excludeSEs) {
-            refs = new ServiceReference[0];
-        }
         List<Component> components = new ArrayList<Component>();
-        for (ServiceReference ref : refs) {
-            Component component = (Component) getBundleContext().getService(ref);
-
+        for (Component component : deployer.getComponents().values()) {
+            // Check type
+            if (excludeSEs && Deployer.TYPE_SERVICE_ENGINE.equals(component.getType())) {
+                continue;
+            }
+            // Check type
+            if (excludeBCs && Deployer.TYPE_BINDING_COMPONENT.equals(component.getType())) {
+                continue;
+            }
             // Check status
             if (requiredState != null && requiredState.length() > 0 && !requiredState.equalsIgnoreCase(component.getCurrentState())) {
                 continue;
             }
             // Check shared library
-            // TODO: check component dependency on SL
-            if (sharedLibraryName != null && sharedLibraryName.length() > 0
-                    && !getInstallationService().containsSharedLibrary(sharedLibraryName)) {
-                continue;
+            if (StringUtils.hasLength(sharedLibraryName)) {
+                boolean match = false;
+                for (SharedLibrary lib : component.getSharedLibraries()) {
+                    if (sharedLibraryName.equals(lib.getName())) {
+                        match = true;
+                        break;
+                    }
+                }
+                if (!match) {
+                    continue;
+                }
             }
             // Check deployed service assembly
-            if (serviceAssemblyName != null && serviceAssemblyName.length() > 0) {
-                ComponentImpl compImpl = (ComponentImpl) component;
-                Set<ServiceAssemblyImpl> saImpls = compImpl.getServiceAssemblies();
-                boolean found = false;
-                for (ServiceAssemblyImpl sa : saImpls) {
-                    if (serviceAssemblyName.equals(sa.getName())) {
-                        found = true;
+            if (StringUtils.hasLength(serviceAssemblyName)) {
+                boolean match = false;
+                for (ServiceUnit su : component.getServiceUnits()) {
+                    if (serviceAssemblyName.equals(su.getServiceAssembly().getName())) {
+                        match = true;
                         break;
                     }
                 }
-                if (!found) {
+                if (!match) {
                     continue;
                 }
             }
@@ -399,43 +355,28 @@
      * @return
      */
     public String listSharedLibraries(String componentName, String sharedLibraryName) throws Exception {
-        Set<String> libs = new HashSet<String>();
+        Set<SharedLibrary> libs = new HashSet<SharedLibrary>();
         if (sharedLibraryName != null && sharedLibraryName.length() > 0) {
-            if (getDeployer().getInstalledSharedLibararies().contains(sharedLibraryName)) {
-                libs.add(sharedLibraryName);
+            SharedLibrary lib = getDeployer().getSharedLibrary(sharedLibraryName);
+            if (lib != null) {
+                libs.add(lib);
             }
         } else if (componentName != null && componentName.length() > 0) {
-            ServiceReference ref = QueryUtils.getComponentServiceReference(bundleContext, "(" + Deployer.NAME + "=" + componentName + ")");
-            if (ref == null) {
-                throw new JBIException("Component '" + componentName + "' not found");
-            }
-            ComponentImpl component = (ComponentImpl) bundleContext.getService(ref);
-            for (SharedLibraryList sl : component.getSharedLibraries()) {
-                libs.add(sl.getName());
+            Component component = deployer.getComponent(componentName);
+            if (component != null) {
+                for (SharedLibrary lib : component.getSharedLibraries()) {
+                    libs.add(lib);
+                }
             }
         } else {
-            libs = getDeployer().getInstalledSharedLibararies();
+            libs.addAll(getDeployer().getSharedLibraries().values());
         }
         StringBuffer buffer = new StringBuffer();
         buffer.append("<?xml version='1.0'?>\n");
         buffer.append("<component-info-list xmlns='http://java.sun.com/xml/ns/jbi/component-info-list' version='1.0'>\n");
-        for (String sl : libs) {
-            buffer.append("  <component-info type='shared-library' name='").append(sl).append("' state='Started'>");
-            buffer.append("    <description>");
-
-            String desc = null;
-            ServiceReference ref = QueryUtils.getSharedLibraryServiceReference(bundleContext, "(" + Deployer.NAME + "=" + sl + ")");
-            if (ref != null) {
-                SharedLibrary sharedLib = (SharedLibrary) getBundleContext().getService(ref);
-                if (sharedLib != null) {
-                    desc = sharedLib.getDescription();
-                    getBundleContext().ungetService(ref);
-                }
-            }
-            if (desc != null) {
-                buffer.append(desc);
-            }
-            buffer.append("</description>\n");
+        for (SharedLibrary sl : libs) {
+            buffer.append("  <component-info type='shared-library' name='").append(sl.getName()).append("' state='Started'>\n");
+            buffer.append("    <description>").append(sl.getDescription()).append("</description>\n");
             buffer.append("  </component-info>\n");
         }
         buffer.append("</component-info-list>");
@@ -454,10 +395,9 @@
         List<ServiceAssembly> assemblies = new ArrayList<ServiceAssembly>();
         Component component = null;
         if (StringUtils.hasLength(componentName)) {
-            component = QueryUtils.getComponent(bundleContext, componentName);
+            component = deployer.getComponent(componentName);
         }
-        for (ServiceReference ref : QueryUtils.getServiceAssembliesServiceReferences(bundleContext, null)) {
-            ServiceAssembly sa = (ServiceAssembly) bundleContext.getService(ref);
+        for (ServiceAssembly sa : deployer.getServiceAssemblies().values()) {
             boolean match = true;
             if (StringUtils.hasLength(serviceAssemblyName)) {
                 match = serviceAssemblyName.equals(sa.getName());
@@ -508,12 +448,8 @@
                                                deployer.getNamingStrategy().getObjectName(this));
     }
 
-    public void setBundleContext(BundleContext bundleContext) {
-        this.bundleContext = bundleContext;
-    }
-
-    public BundleContext getBundleContext() {
-        return bundleContext;
+    public void destroy() throws Exception {
+        deployer.getManagementAgent().unregister(deployer.getNamingStrategy().getObjectName(this));
     }
 
     public void setInstallationService(InstallationService installationService) {

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminService.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminService.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminService.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminService.java Fri Feb 20 13:29:07 2009
@@ -24,16 +24,10 @@
 import javax.management.ObjectName;
 
 import org.apache.servicemix.jbi.deployer.Component;
-import org.apache.servicemix.jbi.deployer.ServiceAssembly;
-import org.apache.servicemix.jbi.deployer.ServiceUnit;
-import org.apache.servicemix.jbi.deployer.utils.QueryUtils;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.springframework.osgi.context.BundleContextAware;
 
 /**
  */
-public class AdminService implements AdminServiceMBean, BundleContextAware {
+public class AdminService implements AdminServiceMBean {
 
     public static final String DEFAULT_NAME = "ServiceMix4";
 
@@ -43,18 +37,17 @@
 
     public static final int DEFAULT_CONNECTOR_PORT = 1099;
 
-    private BundleContext bundleContext;
+    private Deployer deployer;
     private DefaultNamingStrategy namingStrategy;
 
-    public BundleContext getBundleContext() {
-        return bundleContext;
+    public Deployer getDeployer() {
+        return deployer;
     }
 
-    public void setBundleContext(BundleContext bundleContext) {
-        this.bundleContext = bundleContext;
+    public void setDeployer(Deployer deployer) {
+        this.deployer = deployer;
     }
 
-
     public void setNamingStrategy(DefaultNamingStrategy namingStrategy) {
         this.namingStrategy = namingStrategy;
     }
@@ -64,38 +57,40 @@
     }
 
     public ObjectName[] getBindingComponents() {
-        String filter = "(" + Deployer.TYPE + "=" + Deployer.TYPE_BINDING_COMPONENT + ")";
-        Component[] components = QueryUtils.getComponents(getBundleContext(), filter);
-        ObjectName[] names = new ObjectName[components.length];
-        for (int i = 0; i < components.length; i++) {
-            try {
-                names[i] = namingStrategy.getObjectName(components[i]);
-            } catch (MalformedObjectNameException e) {
+        Set<ObjectName> names = new HashSet<ObjectName>();
+        for (Component component : deployer.getComponents().values()) {
+            if (Deployer.TYPE_BINDING_COMPONENT.equals(component.getType())) {
+                try {
+                    names.add(namingStrategy.getObjectName(component));
+                } catch (MalformedObjectNameException e) {
+                }
             }
         }
-        return names;
+        return names.toArray(new ObjectName[names.size()]);
     }
 
     public ObjectName getComponentByName(String name) {
-        Component component = QueryUtils.getComponent(bundleContext, name);
-        try {
-            return namingStrategy.getObjectName(component);
-        } catch (MalformedObjectNameException e) {
-            return null;
+        Component component = deployer.getComponent(name);
+        if (component != null) {
+            try {
+                return namingStrategy.getObjectName(component);
+            } catch (MalformedObjectNameException e) {
+            }
         }
+        return null;
     }
 
     public ObjectName[] getEngineComponents() {
-        String filter = "(" + Deployer.TYPE + "=" + Deployer.TYPE_SERVICE_ENGINE + ")";
-        Component[] components = QueryUtils.getComponents(getBundleContext(), filter);
-        ObjectName[] names = new ObjectName[components.length];
-        for (int i = 0; i < components.length; i++) {
-            try {
-                names[i] = namingStrategy.getObjectName(components[i]);
-            } catch (MalformedObjectNameException e) {
+        Set<ObjectName> names = new HashSet<ObjectName>();
+        for (Component component : deployer.getComponents().values()) {
+            if (Deployer.TYPE_SERVICE_ENGINE.equals(component.getType())) {
+                try {
+                    names.add(namingStrategy.getObjectName(component));
+                } catch (MalformedObjectNameException e) {
+                }
             }
         }
-        return names;
+        return names.toArray(new ObjectName[names.size()]);
     }
 
     public String getSystemInfo() {
@@ -103,104 +98,23 @@
     }
 
     public ObjectName getSystemService(String serviceName) {
+        // TODO
         return null;
     }
 
     public ObjectName[] getSystemServices() {
+        // TODO
         return new ObjectName[0];
     }
 
     public boolean isBinding(String componentName) {
-        return QueryUtils.isBinding(getBundleContext(), componentName);
+        Component component = deployer.getComponent(componentName);
+        return component != null && Deployer.TYPE_BINDING_COMPONENT.equals(component.getType());
     }
 
     public boolean isEngine(String componentName) {
-        return QueryUtils.isEngine(getBundleContext(), componentName);
-    }
-
-    /**
-     * Returns a list of Service Assemblies that contain SUs for the given component.
-     *
-     * @param componentName name of the component.
-     * @return list of Service Assembly names.
-     */
-    public String[] getDeployedServiceAssembliesForComponent(String componentName) {
-        String[] result;
-        // iterate through the service assemblies
-        Set<String> tmpList = new HashSet<String>();
-        ServiceReference[] serviceRefs = QueryUtils.getServiceAssembliesServiceReferences(getBundleContext(), null);
-        for (ServiceReference ref : serviceRefs) {
-            ServiceAssembly sa = (ServiceAssembly) getBundleContext().getService(ref);
-            for (ServiceUnit su : sa.getServiceUnits()) {
-                if (su.getComponent().getName().equals(componentName)) {
-                    tmpList.add(sa.getName());
-                }
-            }
-        }
-        result = new String[tmpList.size()];
-        tmpList.toArray(result);
-        return result;
-    }
-
-    public String[] getDeployedServiceUnitsForComponent(String componentName) {
-        String[] result;
-        // iterate through the service assembiliessalc
-        Set<String> tmpList = new HashSet<String>();
-        ServiceReference[] serviceRefs = QueryUtils.getServiceAssembliesServiceReferences(getBundleContext(), null);
-        for (ServiceReference ref : serviceRefs) {
-            ServiceAssembly sa = (ServiceAssembly) getBundleContext().getService(ref);
-            for (ServiceUnit su : sa.getServiceUnits()) {
-                if (su.getComponent().getName().equals(componentName)) {
-                    tmpList.add(su.getName());
-                }
-            }
-        }
-        result = new String[tmpList.size()];
-        tmpList.toArray(result);
-        return result;
-    }
-
-    public String[] getComponentsForDeployedServiceAssembly(String saName) {
-        String[] result;
-        // iterate through the service assembiliessalc
-        Set<String> tmpList = new HashSet<String>();
-        ServiceAssembly sa = QueryUtils.getServiceAssembly(getBundleContext(), saName);
-        if (sa != null) {
-            for (ServiceUnit su : sa.getServiceUnits()) {
-                if (su.getComponent().getName().equals(saName)) {
-                    tmpList.add(su.getComponent().getName());
-                }
-            }
-        }
-        result = new String[tmpList.size()];
-        tmpList.toArray(result);
-        return result;
-    }
-
-    /**
-     * Returns a boolean value indicating whether the SU is currently deployed.
-     *
-     * @param componentName - name of component.
-     * @param suName        - name of the Service Unit.
-     * @return boolean value indicating whether the SU is currently deployed.
-     */
-    public boolean isDeployedServiceUnit(String componentName, String suName) {
-        boolean result = false;
-        ServiceReference[] serviceRefs = QueryUtils.getServiceAssembliesServiceReferences(getBundleContext(), null);
-        for (ServiceReference ref : serviceRefs) {
-            ServiceAssembly sa = (ServiceAssembly) getBundleContext().getService(ref);
-            ServiceUnit[] sus = sa.getServiceUnits();
-            if (sus != null) {
-                for (int i = 0; i < sus.length; i++) {
-                    if (sus[i].getComponent().getName().equals(componentName)
-                            && sus[i].getName().equals(suName)) {
-                        result = true;
-                        break;
-                    }
-                }
-            }
-        }
-        return result;
+        Component component = deployer.getComponent(componentName);
+        return component != null && Deployer.TYPE_SERVICE_ENGINE.equals(component.getType());
     }
 
 }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentInstaller.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentInstaller.java?rev=746231&r1=746230&r2=746231&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentInstaller.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentInstaller.java Fri Feb 20 13:29:07 2009
@@ -17,56 +17,52 @@
 package org.apache.servicemix.jbi.deployer.impl;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.Enumeration;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
 
 import javax.jbi.JBIException;
 import javax.jbi.component.Bootstrap;
 import javax.jbi.management.DeploymentException;
 import javax.jbi.management.InstallerMBean;
+import javax.jbi.management.LifeCycleMBean;
+import javax.management.Attribute;
 import javax.management.JMException;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.management.StandardMBean;
 
 import org.apache.servicemix.jbi.deployer.Component;
 import org.apache.servicemix.jbi.deployer.SharedLibrary;
-import org.apache.servicemix.jbi.deployer.classloader.OsgiMultiParentClassLoader;
 import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
+import org.apache.servicemix.jbi.deployer.descriptor.Descriptor;
 import org.apache.servicemix.jbi.deployer.descriptor.SharedLibraryList;
 import org.apache.servicemix.jbi.deployer.utils.FileUtil;
-import org.apache.servicemix.jbi.deployer.utils.QueryUtils;
+import org.apache.servicemix.jbi.deployer.utils.ManagementSupport;
 import org.apache.xbean.classloader.MultiParentClassLoader;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
 import org.osgi.service.prefs.BackingStoreException;
 import org.springframework.osgi.util.BundleDelegatingClassLoader;
 
 public class ComponentInstaller extends AbstractInstaller implements InstallerMBean {
 
-    private final Deployer deployer;
-    private final InstallationContextImpl installationContext;
-    private final File jbiArtifact;
-    private final File installRoot;
+    private InstallationContextImpl installationContext;
     private ObjectName objectName;
     private ObjectName extensionMBeanName;
-
     private boolean initialized;
     private Bootstrap bootstrap;
 
 
-    public ComponentInstaller(Deployer deployer, ComponentDesc componentDesc, File jbiArtifact) throws Exception {
-        this.deployer = deployer;
-        this.bundleContext = deployer.getBundleContext();
-        this.installationContext = new InstallationContextImpl(componentDesc, deployer.getEnvironment(),
+    public ComponentInstaller(Deployer deployer, Descriptor descriptor, File jbiArtifact) throws Exception {
+        super(deployer, descriptor, jbiArtifact);
+        this.installRoot = new File(System.getProperty("servicemix.base"), "data/jbi/" + getName() + "/install");
+        this.installRoot.mkdirs();
+        this.installationContext = new InstallationContextImpl(descriptor.getComponent(), deployer.getEnvironment(),
                                                                deployer.getNamingStrategy(), deployer.getManagementAgent());
-        this.jbiArtifact = jbiArtifact;
-        installRoot = new File(System.getProperty("servicemix.base"), "data/jbi/" + installationContext.getComponentName() + "/install");
-        installRoot.mkdirs();
         this.installationContext.setInstallRoot(installRoot);
     }
 
@@ -87,10 +83,22 @@
         deployer.getManagementAgent().unregister(getObjectName());
     }
 
+    public String getName() {
+        return descriptor.getComponent().getIdentification().getName();
+    }
+
     public void init() throws Exception {
-        // Extract component (needed to feed the installRoot)
-        // Few components actually use this, but Ode is one of them
-        extractBundle(installRoot, getBundle(), "/");
+        // Check requirements
+        if (descriptor.getComponent().getSharedLibraries() != null) {
+            for (SharedLibraryList sl : descriptor.getComponent().getSharedLibraries()) {
+                if (deployer.getSharedLibrary(sl.getName()) == null) {
+                    throw new PendingException(bundle, "SharedLibrary not installed: " + sl.getName());
+                }
+            }
+        }
+        // Extract bundle
+        super.init();
+        // Init bootstrap
         initBootstrap();
     }
 
@@ -112,7 +120,7 @@
                 try {
                     initializePreferences();
                 } catch (BackingStoreException e) {
-                    LOGGER.warn("Error initializing persistent state for component: " + installationContext.getComponentName(), e);
+                    LOGGER.warn("Error initializing persistent state for component: " + getName(), e);
                 }
                 ObjectName name = initComponent();
                 cleanUpBootstrap();
@@ -128,10 +136,6 @@
         }
     }
 
-    public void deployBundle() throws Exception {
-        deployFile(jbiArtifact.getCanonicalPath());
-    }
-
 
     /**
      * Determine whether or not the component is installed.
@@ -148,31 +152,57 @@
      * @throws javax.jbi.JBIException if the uninstallation fails.
      */
     public void uninstall() throws javax.jbi.JBIException {
-        // TODO: check component status
-        // TODO: we should always uninstall the bundle
-        // the component must not be started and not have any SUs deployed
-        if (!isInstalled()) {
-            throw new DeploymentException("Component is not installed");
-        }
-        String componentName = installationContext.getComponentName();
         try {
-            Bundle bundle = getBundle();
+            uninstall(false);
+        } catch (JBIException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new JBIException(e);
+        }
+    }
 
-            if (bundle == null) {
-                LOGGER.warn("Could not find Bundle for component: " + componentName);
-            } else {
-                bundle.stop();
-                bundle.uninstall();
-                try {
-                    deletePreferences();
-                } catch (BackingStoreException e) {
-                    LOGGER.warn("Error cleaning persistent state for component: " + componentName, e);
-                }
+    public void uninstall(boolean force) throws Exception {
+        Component comp = deployer.getComponent(getName());
+        if (comp == null && !force) {
+            throw ManagementSupport.failure("uninstallComponent", "Component '" + getName() + "' is not installed.");
+        }
+        // Check component state is shutdown
+        if (comp != null && !LifeCycleMBean.SHUTDOWN.equals(comp.getCurrentState())) {
+            if (!force) {
+                throw ManagementSupport.failure("uninstallComponent", "Component '" + getName() + "' is not shut down.");
             }
-        } catch (BundleException e) {
-            LOGGER.error("failed to uninstall component: " + componentName, e);
-            throw new JBIException(e);
+            if (LifeCycleMBean.STARTED.equals(comp.getCurrentState())) {
+                comp.stop();
+            }
+            if (LifeCycleMBean.STOPPED.equals(comp.getCurrentState())) {
+                comp.shutDown();
+            }
+        }
+        // TODO: if there is any SA deployed onto this component, undeploy the SA and put it in a pending state
+        // Bootstrap stuff
+        try {
+            initBootstrap();
+            bootstrap.init(this.installationContext);
+            bootstrap.getExtensionMBeanName();
+            bootstrap.onUninstall();
+            cleanUpBootstrap();
+            installationContext.setInstall(true);
+        } catch (Exception e) {
+            cleanUpBootstrap();
+            throw e;
         }
+        // Unregister component
+        deployer.unregisterComponent(comp);
+        // Remove preferences
+        try {
+            deletePreferences();
+        } catch (BackingStoreException e) {
+            LOGGER.warn("Error cleaning persistent state for component: " + getName(), e);
+        }
+        // Uninstall bundle
+        uninstallBundle();
+        // Remove files
+        FileUtil.deleteFile(installRoot);
     }
 
     /**
@@ -202,17 +232,13 @@
         this.objectName = objectName;
     }
 
-    public String getName() {
-        return installationContext.getComponentName();
-    }
-
-    protected ClassLoader createClassLoader(Bundle bundle, String name, String[] classPathNames, boolean parentFirst, SharedLibraryList[] sharedLibs) {
+    protected ClassLoader createClassLoader(Bundle bundle, String name, String[] classPathNames, boolean parentFirst, SharedLibrary[] sharedLibs) {
         // Create parents classloaders
         ClassLoader[] parents;
         if (sharedLibs != null) {
             parents = new ClassLoader[sharedLibs.length + 2];
             for (int i = 0; i < sharedLibs.length; i++) {
-                parents[i] = getSharedLibraryClassLoader(sharedLibs[i].getName());
+                parents[i] = sharedLibs[i].getClassLoader();
             }
         } else {
             parents = new ClassLoader[2];
@@ -221,14 +247,14 @@
         parents[parents.length - 1] = BundleDelegatingClassLoader.createBundleClassLoaderFor(getBundleContext().getBundle(0));
 
         // Create urls
-        URL[] urls = new URL[classPathNames.length];
+        List<URL> urls = new ArrayList<URL>();
         for (int i = 0; i < classPathNames.length; i++) {
             File f = new File(installRoot, classPathNames[i]);
             if (!f.exists()) {
-                throw new IllegalArgumentException("Component classpath entry not found: '" + classPathNames[i] + "'");
+                LOGGER.warn("Component classpath entry not found: '" + classPathNames[i] + "'");
             }
             try {
-                urls[i] = f.getCanonicalFile().toURL();
+                urls.add(f.getCanonicalFile().toURL());
             } catch (IOException e) {
                 throw new IllegalArgumentException("Component classpath entry not found: '" + classPathNames[i] + "'");
             }
@@ -237,21 +263,13 @@
         // Create classloader
         return new MultiParentClassLoader(
                 name,
-                urls,
+                urls.toArray(new URL[urls.size()]),
                 parents,
                 !parentFirst,
                 new String[0],
                 new String[]{"java.", "javax."});
     }
 
-    private ClassLoader getSharedLibraryClassLoader(String name) {
-        SharedLibrary sa = QueryUtils.getSharedLibrary(getBundleContext(), name);
-        if (sa != null) {
-            return sa.getClassLoader();
-        }
-        throw new IllegalStateException("Unable to retrieve class loader for shared library: " + name);
-    }
-
     private void initBootstrap() throws DeploymentException {
         try {
             if (!initialized) {
@@ -329,43 +347,52 @@
         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
         try {
             ComponentDesc componentDesc = installationContext.getDescriptor();
+            Set<SharedLibrary> libs = new HashSet<SharedLibrary>();
+            if (componentDesc.getSharedLibraries() != null) {
+                for (SharedLibraryList sll : componentDesc.getSharedLibraries()) {
+                    SharedLibrary lib = deployer.getSharedLibrary(sll.getName());
+                    if (lib == null) {
+                        // TODO: throw exception here
+                    } else {
+                        libs.add(lib);
+                    }
+                }
+            }
+            SharedLibrary[] aLibs = libs.toArray(new SharedLibrary[libs.size()]);
+
             ClassLoader classLoader = createClassLoader(
                     getBundle(),
                     componentDesc.getIdentification().getName(),
                     (String[]) installationContext.getClassPathElements().toArray(new String[installationContext.getClassPathElements().size()]),
                     componentDesc.isComponentClassLoaderDelegationParentFirst(),
-                    componentDesc.getSharedLibraries());
+                    aLibs);
             Thread.currentThread().setContextClassLoader(classLoader);
             Class clazz = classLoader.loadClass(componentDesc.getComponentClassName());
             javax.jbi.component.Component innerComponent = (javax.jbi.component.Component) clazz.newInstance();
-            Component component = deployer.registerComponent(getBundle(), componentDesc, innerComponent);
-            ObjectName name = deployer.getNamingStrategy().getObjectName(component);
-            deployer.getManagementAgent().register(new StandardMBean(component, Component.class), name, true);
-            return name;
+            Component component = deployer.registerComponent(getBundle(), componentDesc, innerComponent, aLibs);
+            return deployer.getNamingStrategy().getObjectName(component);
         } finally {
             Thread.currentThread().setContextClassLoader(oldCl);
         }
     }
 
-    private void extractBundle(File installRoot, Bundle bundle, String path) throws IOException {
-        Enumeration e = bundle.getEntryPaths(path);
-        while (e != null && e.hasMoreElements()) {
-            String entry = (String) e.nextElement();
-            File fout = new File(installRoot, entry);
-            if (entry.endsWith("/")) {
-                fout.mkdirs();
-                extractBundle(installRoot, bundle, entry);
+    public void configure(Properties props) throws Exception {
+        if (props != null && props.size() > 0) {
+            ObjectName on = getInstallerConfigurationMBean();
+            if (on == null) {
+                LOGGER.warn("Could not find installation configuration MBean. Installation properties will be ignored.");
             } else {
-                InputStream in = bundle.getEntry(entry).openStream();
-                OutputStream out = new FileOutputStream(fout);
-                try {
-                    FileUtil.copyInputStream(in, out);
-                } finally {
-                    in.close();
-                    out.close();
+                MBeanServer mbs = deployer.getManagementAgent().getMbeanServer();
+                for (Object o : props.keySet()) {
+                    String key = (String) o;
+                    String val = props.getProperty(key);
+                    try {
+                        mbs.setAttribute(on, new Attribute(key, val));
+                    } catch (JMException e) {
+                        throw new DeploymentException("Could not set installation property: (" + key + " = " + val, e);
+                    }
                 }
             }
         }
     }
-
 }