servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r608566 - in /servicemix/smx4/nmr/trunk: jbi/ jbi/commands/ jbi/commands/src/ jbi/commands/src/main/ jbi/commands/src/main/java/ jbi/commands/src/main/java/org/ jbi/commands/src/main/java/org/apache/ jbi/commands/src/main/java/org/apache/se...
Date Thu, 03 Jan 2008 17:19:56 GMT
Author: gnodet
Date: Thu Jan  3 09:19:53 2008
New Revision: 608566

URL: http://svn.apache.org/viewvc?rev=608566&view=rev
Log:
Add commands for NMR and JBI (mainly placeholders right now)

Added:
    servicemix/smx4/nmr/trunk/jbi/commands/   (with props)
    servicemix/smx4/nmr/trunk/jbi/commands/pom.xml
    servicemix/smx4/nmr/trunk/jbi/commands/src/
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandSupport.java
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiLifeCycleCommandSupport.java
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ListCommand.java
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ShutdownCommand.java
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/StartCommand.java
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/StopCommand.java
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/META-INF/
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/META-INF/spring/
    servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/META-INF/spring/servicemix-jbi-commands.xml
    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/impl/AbstractBundleWatcher.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java
    servicemix/smx4/nmr/trunk/nmr/commands/   (with props)
    servicemix/smx4/nmr/trunk/nmr/commands/pom.xml
    servicemix/smx4/nmr/trunk/nmr/commands/src/
    servicemix/smx4/nmr/trunk/nmr/commands/src/main/
    servicemix/smx4/nmr/trunk/nmr/commands/src/main/java/
    servicemix/smx4/nmr/trunk/nmr/commands/src/main/java/org/
    servicemix/smx4/nmr/trunk/nmr/commands/src/main/java/org/apache/
    servicemix/smx4/nmr/trunk/nmr/commands/src/main/java/org/apache/servicemix/
    servicemix/smx4/nmr/trunk/nmr/commands/src/main/java/org/apache/servicemix/nmr/
    servicemix/smx4/nmr/trunk/nmr/commands/src/main/java/org/apache/servicemix/nmr/commands/
    servicemix/smx4/nmr/trunk/nmr/commands/src/main/java/org/apache/servicemix/nmr/commands/NmrCommandSupport.java
    servicemix/smx4/nmr/trunk/nmr/commands/src/main/resources/
    servicemix/smx4/nmr/trunk/nmr/commands/src/main/resources/META-INF/
    servicemix/smx4/nmr/trunk/nmr/commands/src/main/resources/META-INF/spring/
    servicemix/smx4/nmr/trunk/nmr/commands/src/main/resources/META-INF/spring/servicemix-nmr-commands.xml
Modified:
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceAssembly.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/impl/Deployer.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java
    servicemix/smx4/nmr/trunk/jbi/pom.xml
    servicemix/smx4/nmr/trunk/nmr/pom.xml

Propchange: servicemix/smx4/nmr/trunk/jbi/commands/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jan  3 09:19:53 2008
@@ -0,0 +1,7 @@
+target
+*.iml
+*.ipr
+*.iws
+.classpath
+.project
+.settings

Added: servicemix/smx4/nmr/trunk/jbi/commands/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/commands/pom.xml?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/commands/pom.xml (added)
+++ servicemix/smx4/nmr/trunk/jbi/commands/pom.xml Thu Jan  3 09:19:53 2008
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.servicemix.jbi</groupId>
+        <artifactId>jbi</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.apache.servicemix.jbi</groupId>
+    <artifactId>org.apache.servicemix.jbi.commands</artifactId>
+    <packaging>bundle</packaging>
+    <name>ServiceMix JBI Commands</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.servicemix.jbi</groupId>
+            <artifactId>org.apache.servicemix.jbi.deployer</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.runtime.gshell</groupId>
+            <artifactId>org.apache.servicemix.runtime.gshell.core</artifactId>
+            <version>${smx.runtime.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>${pom.artifactId}*</Export-Package>
+                        <DynamicImport-Package>*</DynamicImport-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

Added: servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandSupport.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandSupport.java?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandSupport.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandSupport.java Thu Jan  3 09:19:53 2008
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.commands;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.geronimo.gshell.support.OsgiCommandSupport;
+import org.apache.servicemix.jbi.deployer.Component;
+import org.apache.servicemix.jbi.deployer.ServiceAssembly;
+import org.apache.servicemix.jbi.deployer.SharedLibrary;
+import org.apache.servicemix.jbi.deployer.impl.Deployer;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Base class for JBI related commands
+ */
+public abstract class JbiCommandSupport extends OsgiCommandSupport {
+
+    protected List<ServiceReference> usedReferences;
+
+    protected List<SharedLibrary> getSharedLibraries() throws Exception {
+        return getAllServices(SharedLibrary.class, null);
+    }
+
+    protected List<Component> getComponents() throws Exception {
+        return getAllServices(Component.class, null);
+    }
+
+    protected List<ServiceAssembly> getServiceAssemblies() throws Exception {
+        return getAllServices(ServiceAssembly.class, null);
+    }
+
+    protected Component getComponent(String name) throws Exception {
+        List<Component> components = getAllServices(Component.class, "(" + Deployer.NAME + "=" + name + ")");
+        if (components != null && components.size() == 1) {
+            return components.get(0);
+        }
+        return null;
+    }
+
+    protected ServiceAssembly getServiceAssembly(String name) throws Exception {
+        List<ServiceAssembly> assemblies = getAllServices(ServiceAssembly.class, "(" + Deployer.NAME + "=" + name + ")");
+        if (assemblies != null && assemblies.size() == 1) {
+            return assemblies.get(0);
+        }
+        return null;
+    }
+
+    public Object doExecute(final Object... args) throws Exception {
+        try {
+            return super.doExecute(args);
+        } finally {
+            ungetServices();
+        }
+    }
+
+    protected <T> List<T> getAllServices(Class<T> clazz, String filter) throws Exception {
+        ServiceReference[] references = getBundleContext().getAllServiceReferences(clazz.getName(), filter);
+        if (references == null) {
+            return null;
+        }
+        List<T> services = new ArrayList<T>();
+        for (ServiceReference ref : references) {
+            T t = getService(clazz, ref);
+            services.add(t);
+        }
+        return services;
+    }
+
+    protected <T> T getService(Class<T> clazz, ServiceReference reference) {
+        T t = (T) getBundleContext().getService(reference);
+        if (t != null) {
+            if (usedReferences == null) {
+                usedReferences = new ArrayList<ServiceReference>();
+            }
+            usedReferences.add(reference);
+        }
+        return t;
+    }
+
+    protected void ungetServices() {
+        if (usedReferences != null) {
+            for (ServiceReference ref : usedReferences) {
+                getBundleContext().ungetService(ref);
+            }
+        }
+    }
+
+}

Added: servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiLifeCycleCommandSupport.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiLifeCycleCommandSupport.java?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiLifeCycleCommandSupport.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiLifeCycleCommandSupport.java Thu Jan  3 09:19:53 2008
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.commands;
+
+import java.util.List;
+
+import javax.jbi.management.LifeCycleMBean;
+
+import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.clp.Option;
+import org.apache.servicemix.jbi.deployer.Component;
+import org.apache.servicemix.jbi.deployer.ServiceAssembly;
+
+/**
+ * JBI artifact lifecycle command
+ */
+public abstract class JbiLifeCycleCommandSupport extends JbiCommandSupport {
+
+    @Option(name = "-c", aliases = "--component", description = "a component")
+    boolean isComponent;
+
+    @Option(name = "-a", aliases = "--service-assembly", description = "a service assembly")
+    boolean isAssembly;
+
+    @Argument(required = true, multiValued = true)
+    List<String> artifacts;
+
+    protected Object doExecute() throws Exception {
+        if (isComponent && isAssembly) {
+            throw new IllegalArgumentException("Can not specify options -c and -a at the same time!");
+        }
+        for (String artifact : artifacts) {
+            try {
+                if ((!isComponent && !isAssembly) || isComponent) {
+                    Component component = getComponent(artifact);
+                    if (component != null) {
+                        handle(component);
+                        continue;
+                    }
+                }
+                if ((!isComponent && !isAssembly) || isAssembly) {
+                    ServiceAssembly assembly = getServiceAssembly(artifact);
+                    if (assembly != null) {
+                        handle(assembly);
+                        continue;
+                    }
+                }
+                io.out.println("Artifact " + artifact + " not found");
+            }
+            catch (Exception e) {
+                io.out.println("Error processing " + artifact + ": " + e);
+            }
+        }
+        return null;
+    }
+
+    protected abstract void handle(LifeCycleMBean artifact) throws Exception;
+
+}

Added: servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ListCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ListCommand.java?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ListCommand.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ListCommand.java Thu Jan  3 09:19:53 2008
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.commands;
+
+import java.util.List;
+
+import org.apache.servicemix.jbi.deployer.Component;
+import org.apache.servicemix.jbi.deployer.ServiceAssembly;
+import org.apache.servicemix.jbi.deployer.SharedLibrary;
+
+/**
+ * List JBI artifacts
+ */
+@org.apache.geronimo.gshell.command.annotation.CommandComponent(id = "jbi:list", description = "List deployed JBI artifacts")
+public class ListCommand extends JbiCommandSupport {
+
+    protected Object doExecute() throws Exception {
+        List<SharedLibrary> libraries = getSharedLibraries();
+        if (libraries != null && !libraries.isEmpty()) {
+            io.out.println("Shared Libraries");
+            io.out.println("----------------");
+            for (SharedLibrary library : libraries) {
+                io.out.println(library.getName() + " - " + library.getVersion() + " - " + library.getDescription());
+            }
+            io.out.println();
+        }
+
+        List<Component> components = getComponents();
+        if (components != null && !components.isEmpty()) {
+            io.out.println("Components");
+            io.out.println("----------");
+            for (Component component : components) {
+                io.out.println(component.getName() + " - " + component.getCurrentState() + " - " + component.getDescription());
+            }
+        }
+
+        List<ServiceAssembly> assemblies = getServiceAssemblies();
+        if (assemblies != null && !assemblies.isEmpty()) {
+            io.out.println("Service Assemblies");
+            io.out.println("------------------");
+            for (ServiceAssembly assembly : assemblies) {
+                io.out.println(assembly.getName() + " - " + assembly.getCurrentState() + " - " + assembly.getDescription());
+            }
+        }
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+}

Added: servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ShutdownCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ShutdownCommand.java?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ShutdownCommand.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ShutdownCommand.java Thu Jan  3 09:19:53 2008
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.commands;
+
+import javax.jbi.JBIException;
+import javax.jbi.management.LifeCycleMBean;
+
+/**
+ * Shutdown a JBI artifact
+ */
+@org.apache.geronimo.gshell.command.annotation.CommandComponent(id = "jbi:shutdown", description = "Shutdown a JBI artifact")
+public class ShutdownCommand extends JbiLifeCycleCommandSupport {
+
+    protected void handle(LifeCycleMBean artifact) throws JBIException {
+        artifact.shutDown();
+    }
+}
\ No newline at end of file

Added: servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/StartCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/StartCommand.java?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/StartCommand.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/StartCommand.java Thu Jan  3 09:19:53 2008
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.commands;
+
+import javax.jbi.JBIException;
+import javax.jbi.management.LifeCycleMBean;
+
+/**
+ * Start a JBI artifact
+ */
+@org.apache.geronimo.gshell.command.annotation.CommandComponent(id = "jbi:start", description = "Start a JBI artifact")
+public class StartCommand extends JbiLifeCycleCommandSupport {
+
+    protected void handle(LifeCycleMBean artifact) throws JBIException {
+        artifact.start();
+    }
+}

Added: servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/StopCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/StopCommand.java?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/StopCommand.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/StopCommand.java Thu Jan  3 09:19:53 2008
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.commands;
+
+import javax.jbi.JBIException;
+import javax.jbi.management.LifeCycleMBean;
+
+/**
+ * Stop a JBI artifact
+ */
+@org.apache.geronimo.gshell.command.annotation.CommandComponent(id = "jbi:stop", description = "Stop a JBI artifact")
+public class StopCommand extends JbiLifeCycleCommandSupport {
+
+    protected void handle(LifeCycleMBean artifact) throws JBIException {
+        artifact.stop();
+    }
+}
\ No newline at end of file

Added: servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/META-INF/spring/servicemix-jbi-commands.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/META-INF/spring/servicemix-jbi-commands.xml?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/META-INF/spring/servicemix-jbi-commands.xml (added)
+++ servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/META-INF/spring/servicemix-jbi-commands.xml Thu Jan  3 09:19:53 2008
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:osgi="http://www.springframework.org/schema/osgi"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="
+  http://www.springframework.org/schema/beans
+  http://www.springframework.org/schema/beans/spring-beans.xsd
+  http://www.springframework.org/schema/util
+  http://www.springframework.org/schema/util/spring-util.xsd
+  http://www.springframework.org/schema/osgi
+  http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+    <bean id="list" class="org.apache.servicemix.jbi.commands.ListCommand" />
+
+    <bean id="start" class="org.apache.servicemix.jbi.commands.StartCommand" />
+
+    <bean id="stop" class="org.apache.servicemix.jbi.commands.StopCommand" />
+
+    <bean id="shutdown" class="org.apache.servicemix.jbi.commands.ShutdownCommand" />
+
+    <osgi:service ref="list" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="jbi"/>
+        <entry key="alias" value="ls"/>
+      </osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="start" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="jbi"/>
+      </osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="stop" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="jbi"/>
+      </osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="shutdown" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="jbi"/>
+      </osgi:service-properties>
+    </osgi:service>
+
+
+</beans>
\ No newline at end of file

Added: 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=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java Thu Jan  3 09:19:53 2008
@@ -0,0 +1,26 @@
+package org.apache.servicemix.jbi.deployer;
+
+import javax.jbi.management.ComponentLifeCycleMBean;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Jan 3, 2008
+ * Time: 3:44:17 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface Component extends ComponentLifeCycleMBean {
+
+    /**
+     * Retrieves the name of this service assembly
+     * @return the name
+     */
+    String getName();
+
+    /**
+     * Retrieves the description of this service assembly
+     * @return the description
+     */
+    String getDescription();
+
+}

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceAssembly.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceAssembly.java?rev=608566&r1=608565&r2=608566&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceAssembly.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceAssembly.java Thu Jan  3 09:19:53 2008
@@ -17,12 +17,13 @@
 package org.apache.servicemix.jbi.deployer;
 
 import javax.jbi.JBIException;
+import javax.jbi.management.LifeCycleMBean;
 
 /**
  * This interface represents a JBI Service Assembly and will be registered
  * in the OSGi registry
  */
-public interface ServiceAssembly {
+public interface ServiceAssembly extends LifeCycleMBean {
 
     /**
      * Retrieves the name of this service assembly
@@ -41,13 +42,5 @@
      * @return
      */
     ServiceUnit[] getServiceUnits();
-
-	void init() throws JBIException;
-
-	void start() throws JBIException;
-
-	void stop() throws JBIException;
-
-	void shutdown() throws JBIException;
 
 }

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=608566&r1=608565&r2=608566&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 Thu Jan  3 09:19:53 2008
@@ -44,6 +44,6 @@
      * Create a classloader for this shared library
      * @return a new classloader
      */
-    ClassLoader createClassLoader();
+    //ClassLoader createClassLoader();
     
 }

Added: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java Thu Jan  3 09:19:53 2008
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.deployer.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.SynchronousBundleListener;
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.osgi.context.BundleContextAware;
+
+/**
+ */
+public abstract class AbstractBundleWatcher implements BundleContextAware, InitializingBean, DisposableBean {
+
+    private BundleContext bundleContext;
+    private SynchronousBundleListener bundleListener;
+    private List<Bundle> bundles = new ArrayList<Bundle>();
+
+    public void setBundleContext(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+    }
+
+    public BundleContext getBundleContext() {
+        return bundleContext;
+    }
+
+    public void afterPropertiesSet() throws Exception {
+        bundleContext.addBundleListener(bundleListener = new SynchronousBundleListener() {
+            public void bundleChanged(BundleEvent event) {
+                switch (event.getType()) {
+                    case BundleEvent.STARTED:
+                        onBundleStarted(event.getBundle());
+                        break;
+                    case BundleEvent.STOPPED:
+                        onBundleStopped(event.getBundle());
+                        break;
+                }
+            }
+        });
+        Bundle[] bundles = bundleContext.getBundles();
+        if (bundles != null) {
+            for (Bundle bundle : bundles) {
+                onBundleStarted(bundle);
+            }
+        }
+    }
+
+    public void destroy() throws Exception {
+        bundleContext.removeBundleListener(bundleListener);
+        for (Bundle bundle : bundles.toArray(new Bundle[bundles.size()])) {
+            if (bundle.getState() == Bundle.ACTIVE) {
+                onBundleStopped(bundle);
+            }
+        }
+    }
+
+    private void onBundleStarted(Bundle bundle) {
+        if (match(bundle)) {
+            register(bundle);
+            bundles.add(bundle);
+        }
+    }
+
+    private void onBundleStopped(Bundle bundle) {
+        if (bundles.remove(bundle)) {
+            unregister(bundle);
+        }
+    }
+
+    protected boolean match(Bundle bundle) {
+        return true;
+    }
+
+    protected abstract void register(Bundle bundle);
+
+    protected abstract void unregister(Bundle bundle);
+
+}

Added: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java Thu Jan  3 09:19:53 2008
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.deployer.impl;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.jbi.component.ComponentLifeCycle;
+import javax.jbi.component.ServiceUnitManager;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.management.LifeCycleMBean;
+import javax.management.ObjectName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+
+import org.apache.servicemix.jbi.deployer.Component;
+import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Jan 3, 2008
+ * Time: 5:15:57 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class ComponentImpl implements Component {
+
+    protected enum State {
+        Unknown,
+        Initialized,
+        Started,
+        Stopped,
+        Shutdown,
+    }
+
+    private ComponentDesc componentDesc;
+    private javax.jbi.component.Component component;
+
+    private State state = State.Unknown;
+
+    public ComponentImpl(ComponentDesc componentDesc, javax.jbi.component.Component component) {
+        this.componentDesc = componentDesc;
+        this.component = component;
+    }
+
+    public String getName() {
+        return componentDesc.getIdentification().getName();
+    }
+
+    public String getDescription() {
+        return componentDesc.getIdentification().getDescription();
+    }
+
+    public ObjectName getExtensionMBeanName() throws JBIException {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public javax.jbi.component.Component getComponent() {
+        return component;
+    }
+
+    public void start() throws JBIException {
+        component.getLifeCycle().start();
+        state = State.Started;
+    }
+
+    public void stop() throws JBIException {
+        if (state == State.Started) {
+            component.getLifeCycle().stop();
+            state = State.Stopped;
+        }
+    }
+
+    public void shutDown() throws JBIException {
+        if (state == State.Started) {
+            stop();
+        }
+        if (state == State.Stopped) {
+            component.getLifeCycle().shutDown();
+            state = State.Shutdown;
+        }
+    }
+
+    public String getCurrentState() {
+        switch (state) {
+            case Started:
+                return LifeCycleMBean.STARTED;
+            case Stopped:
+                return LifeCycleMBean.STOPPED;
+            case Initialized:
+            case Shutdown:
+                return LifeCycleMBean.SHUTDOWN;
+            default:
+                return LifeCycleMBean.UNKNOWN;
+        }
+    }
+
+    protected class ComponentWrapper implements javax.jbi.component.Component, ComponentLifeCycle {
+        private javax.jbi.component.Component component;
+        private ComponentLifeCycle lifeCycle;
+
+        public ComponentWrapper(javax.jbi.component.Component component) {
+            this.component = component;
+        }
+
+        public ComponentLifeCycle getLifeCycle() {
+            if (lifeCycle == null) {
+                lifeCycle = component.getLifeCycle();
+            }
+            return this;
+        }
+
+        public ServiceUnitManager getServiceUnitManager() {
+            return component.getServiceUnitManager();
+        }
+
+        public Document getServiceDescription(ServiceEndpoint endpoint) {
+            return component.getServiceDescription(endpoint);
+        }
+
+        public boolean isExchangeWithConsumerOkay(ServiceEndpoint endpoint, MessageExchange exchange) {
+            return component.isExchangeWithConsumerOkay(endpoint, exchange);
+        }
+
+        public boolean isExchangeWithProviderOkay(ServiceEndpoint endpoint, MessageExchange exchange) {
+            return component.isExchangeWithProviderOkay(endpoint, exchange);
+        }
+
+        public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) {
+            return component.resolveEndpointReference(epr);
+        }
+
+        public ObjectName getExtensionMBeanName() {
+            return lifeCycle.getExtensionMBeanName();
+        }
+
+        public void init(ComponentContext context) throws JBIException {
+            lifeCycle.init(context);
+            state = State.Initialized;
+        }
+
+        public void shutDown() throws JBIException {
+            lifeCycle.shutDown();
+        }
+
+        public void start() throws JBIException {
+            lifeCycle.start();
+        }
+
+        public void stop() throws JBIException {
+            lifeCycle.stop();
+        }
+    }
+
+}

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java?rev=608566&r1=608565&r2=608566&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java Thu Jan  3 09:19:53 2008
@@ -27,10 +27,10 @@
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.jbi.JBIException;
-import javax.jbi.component.Component;
 
 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.ServiceAssembly;
 import org.apache.servicemix.jbi.deployer.SharedLibrary;
 import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
@@ -43,12 +43,8 @@
 import org.apache.xbean.classloader.MultiParentClassLoader;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
 import org.osgi.framework.ServiceReference;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.osgi.context.BundleContextAware;
+import org.osgi.framework.ServiceRegistration;
 import org.springframework.osgi.util.BundleDelegatingClassLoader;
 import org.springframework.osgi.util.OsgiServiceReferenceUtils;
 import org.springframework.osgi.util.OsgiServiceUtils;
@@ -58,7 +54,7 @@
  * Deployer for JBI artifacts
  *
  */
-public class Deployer implements BundleListener, BundleContextAware, InitializingBean, DisposableBean {
+public class Deployer extends AbstractBundleWatcher {
 
     public static final String NAME = "NAME";
     public static final String TYPE = "TYPE";
@@ -67,83 +63,77 @@
 
     private static final String JBI_DESCRIPTOR = "META-INF/jbi.xml";
 
-    private BundleContext context;
+    private Map<String, SharedLibraryImpl> sharedLibraries;
 
-    private Map<String, SharedLibrary> sharedLibraries;
+    private Map<String, ServiceAssemblyImpl> serviceAssemblies;
 
-    private Map<String, ServiceAssembly> serviceAssemblies;
+    private Map<Bundle, List<ServiceRegistration>> services;
 
     private File jbiRootDir;
 
     public Deployer() throws JBIException{
-        sharedLibraries = new ConcurrentHashMap<String, SharedLibrary>();
-        serviceAssemblies = new ConcurrentHashMap<String, ServiceAssembly>();
+        sharedLibraries = new ConcurrentHashMap<String, SharedLibraryImpl>();
+        serviceAssemblies = new ConcurrentHashMap<String, ServiceAssemblyImpl>();
+        services = new ConcurrentHashMap<Bundle, List<ServiceRegistration>>();
         // TODO: control that using properties
         jbiRootDir = new File(System.getProperty("servicemix.base"), "jbi");
         jbiRootDir.mkdirs();
     }
 
-    public void setBundleContext(BundleContext context) {
-        this.context = context;
-    }
-
-    public void afterPropertiesSet() throws Exception {
-        this.context.addBundleListener(this);
-        for (Bundle bundle : this.context.getBundles()) {
-            checkInstalledBundle(bundle);
+    @Override
+    protected boolean match(Bundle bundle) {
+        LOGGER.debug("Checking bundle: '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "'");
+        URL url = bundle.getResource(JBI_DESCRIPTOR);
+        if (url == null) {
+            LOGGER.debug("Bundle '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "' does not contain any JBI descriptor.");
+            return false;
         }
+        return true;
     }
 
-    public void destroy() throws Exception {
-        this.context.removeBundleListener(this);
-    }
-
-    public void bundleChanged(BundleEvent event) {
-            if (event.getType() == BundleEvent.INSTALLED) {
-                checkInstalledBundle(event.getBundle());
-            } else if (event.getType() == BundleEvent.UNINSTALLED) {
-            	//TODO: uninstall the bundle.
-            }
-    }
-
-    private void checkInstalledBundle(Bundle bundle) {
+    @Override
+    protected void register(Bundle bundle) {
         try {
-            LOGGER.debug("Checking bundle: '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "'");
             URL url = bundle.getResource(JBI_DESCRIPTOR);
-            if (url == null) {
-                LOGGER.debug("Bundle '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "' does not contain any JBI descriptor.");
-                return;
-            }
             Descriptor descriptor = DescriptorFactory.buildDescriptor(url);
             DescriptorFactory.checkDescriptor(descriptor);
             if (descriptor.getComponent() != null) {
                 installComponent(descriptor.getComponent(), bundle);
             } else if (descriptor.getServiceAssembly() != null) {
                 deployServiceAssembly(descriptor.getServiceAssembly(), bundle);
-            } else if (descriptor.getSharedLibrary() != null) {
-                installSharedLibrary(descriptor.getSharedLibrary(), bundle);
             } else {
-                // WARN: unhandled JBI artifact
+                installSharedLibrary(descriptor.getSharedLibrary(), bundle);
             }
         } catch (Exception e) {
             LOGGER.error("Error handling bundle event", e);
         }
     }
 
+    @Override
+    protected void unregister(Bundle bundle) {
+        List<ServiceRegistration> registrations = services.remove(bundle);
+        for (ServiceRegistration reg : registrations) {
+            reg.unregister();
+        }
+    }
+
     protected void installComponent(ComponentDesc componentDesc, Bundle bundle) throws Exception {
         LOGGER.debug("Bundle '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "' is a JBI component");
         // Create component class loader
         ClassLoader classLoader = createComponentClassLoader(componentDesc, bundle);
+        Thread.currentThread().setContextClassLoader(classLoader);
         // Instanciate component
         Class clazz = classLoader.loadClass(componentDesc.getComponentClassName());
-        Component component = (Component) clazz.newInstance();
+        javax.jbi.component.Component innerComponent = (javax.jbi.component.Component) clazz.newInstance();
+        ComponentImpl component = new ComponentImpl(componentDesc, innerComponent);
         // populate props from the component meta-data
         Dictionary<String, String> props = new Hashtable<String, String>();
         props.put(NAME, componentDesc.getIdentification().getName());
         props.put(TYPE, componentDesc.getType());
         // register the component in the OSGi registry
         LOGGER.debug("Registering JBI component");
-        bundle.getBundleContext().registerService(Component.class.getName(), component, props);
+        registerService(bundle, Component.class.getName(), component, props);
+        registerService(bundle, javax.jbi.component.Component.class.getName(), component.getComponent(), props);
     }
 
     protected void deployServiceAssembly(ServiceAssemblyDesc serviceAssembyDesc, Bundle bundle) throws Exception {
@@ -164,7 +154,7 @@
             FileUtil.unpackArchive(zipUrl, suRootDir);
             // Find component
             String componentName = sud.getTarget().getComponentName();
-            Component component = getComponent(componentName);
+            javax.jbi.component.Component component = getComponent(componentName);
             // Create service unit object
             ServiceUnitImpl su = new ServiceUnitImpl(sud, suRootDir, component);
             su.deploy();
@@ -179,7 +169,7 @@
         props.put(NAME, serviceAssembyDesc.getIdentification().getName());
         // register the service assembly in the OSGi registry
         LOGGER.debug("Registering JBI service assembly");
-        bundle.getBundleContext().registerService(ServiceAssembly.class.getName(), sa, props);
+        registerService(bundle, ServiceAssembly.class.getName(), sa, props);
     }
 
     protected void installSharedLibrary(SharedLibraryDesc sharedLibraryDesc, Bundle bundle) {
@@ -190,13 +180,25 @@
         // populate props from the library meta-data
         props.put(NAME, sharedLibraryDesc.getIdentification().getName());
         LOGGER.debug("Registering JBI Shared Library");
-        bundle.getBundleContext().registerService(SharedLibrary.class.getName(), sl, props);
+        registerService(bundle, SharedLibrary.class.getName(), sl, props);
+    }
+
+    protected void registerService(Bundle bundle, String clazz, Object service, Dictionary props) {
+        BundleContext context = bundle.getBundleContext() != null ? bundle.getBundleContext() : getBundleContext();
+        ServiceRegistration reg = context.registerService(clazz, service, props);
+        List<ServiceRegistration> registrations = services.get(bundle);
+        if (registrations == null) {
+            registrations = new ArrayList<ServiceRegistration>();
+            services.put(bundle, registrations);
+        }
+        registrations.add(reg);
     }
 
-    protected Component getComponent(String name) {
-        String filter = "(" + NAME + "=" + name + ")"; 
-        ServiceReference reference = OsgiServiceReferenceUtils.getServiceReference(context, Component.class.getName(), filter);
-        return (Component) OsgiServiceUtils.getService(context, reference);
+    protected javax.jbi.component.Component getComponent(String name) {
+        String filter = "(" + NAME + "=" + name + ")";
+        BundleContext context = getBundleContext();
+        ServiceReference reference = OsgiServiceReferenceUtils.getServiceReference(context, javax.jbi.component.Component.class.getName(), filter);
+        return (javax.jbi.component.Component) OsgiServiceUtils.getService(context, reference);
     }
 
     protected ClassLoader createComponentClassLoader(ComponentDesc component, Bundle bundle) {
@@ -233,7 +235,7 @@
     }
 
     protected ClassLoader getSharedLibraryClassLoader(SharedLibraryList sharedLibraryList) {
-        SharedLibrary sl = sharedLibraries.get(sharedLibraryList.getName());
+        SharedLibraryImpl sl = sharedLibraries.get(sharedLibraryList.getName());
         if (sl != null) {
             return sl.createClassLoader();
         } else {

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java?rev=608566&r1=608565&r2=608566&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java Thu Jan  3 09:19:53 2008
@@ -20,13 +20,13 @@
 import java.util.List;
 
 import javax.jbi.JBIException;
+import javax.jbi.management.LifeCycleMBean;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.jbi.deployer.ServiceAssembly;
 import org.apache.servicemix.jbi.deployer.ServiceUnit;
 import org.apache.servicemix.jbi.deployer.descriptor.ServiceAssemblyDesc;
-import org.osgi.framework.BundleContext;
 
 /**
  * ServiceAssembly object
@@ -66,11 +66,25 @@
 		return serviceUnits.toArray(new ServiceUnit[serviceUnits.size()]);
 	}
 
-	public void init() throws JBIException {
+    public String getCurrentState() {
+        switch (state) {
+            case Started:
+                return LifeCycleMBean.STARTED;
+            case Stopped:
+                return LifeCycleMBean.STOPPED;
+            case Initialized:
+            case Shutdown:
+                return LifeCycleMBean.SHUTDOWN;
+            default:
+                return LifeCycleMBean.UNKNOWN;
+        }
+    }
+
+    public void init() throws JBIException {
         transition(State.Initialized);
 	}
 
-	public void shutdown() throws JBIException {
+	public void shutDown() throws JBIException {
         transition(State.Shutdown);
 	}
 

Modified: servicemix/smx4/nmr/trunk/jbi/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/pom.xml?rev=608566&r1=608565&r2=608566&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/pom.xml Thu Jan  3 09:19:53 2008
@@ -40,6 +40,7 @@
         <module>deployer</module>
         <module>osgi</module>
         <module>offline</module>
+        <module>commands</module>
         <module>itests</module>
     </modules>
 

Propchange: servicemix/smx4/nmr/trunk/nmr/commands/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jan  3 09:19:53 2008
@@ -0,0 +1,7 @@
+target
+*.iml
+*.ipr
+*.iws
+.classpath
+.project
+.settings

Added: servicemix/smx4/nmr/trunk/nmr/commands/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/commands/pom.xml?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/commands/pom.xml (added)
+++ servicemix/smx4/nmr/trunk/nmr/commands/pom.xml Thu Jan  3 09:19:53 2008
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.servicemix.nmr</groupId>
+        <artifactId>nmr</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.apache.servicemix.nmr</groupId>
+    <artifactId>org.apache.servicemix.nmr.commands</artifactId>
+    <packaging>bundle</packaging>
+    <name>ServiceMix NMR Commands</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.servicemix.nmr</groupId>
+            <artifactId>org.apache.servicemix.nmr.core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.runtime.gshell</groupId>
+            <artifactId>org.apache.servicemix.runtime.gshell.core</artifactId>
+            <version>${smx.runtime.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>${pom.artifactId}</Export-Package>
+                        <DynamicImport-Package>*</DynamicImport-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

Added: servicemix/smx4/nmr/trunk/nmr/commands/src/main/java/org/apache/servicemix/nmr/commands/NmrCommandSupport.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/commands/src/main/java/org/apache/servicemix/nmr/commands/NmrCommandSupport.java?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/commands/src/main/java/org/apache/servicemix/nmr/commands/NmrCommandSupport.java (added)
+++ servicemix/smx4/nmr/trunk/nmr/commands/src/main/java/org/apache/servicemix/nmr/commands/NmrCommandSupport.java Thu Jan  3 09:19:53 2008
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.nmr.commands;
+
+import org.apache.geronimo.gshell.support.OsgiCommandSupport;
+
+/**
+ * Base class for NMR related commands
+ */
+public abstract class NmrCommandSupport extends OsgiCommandSupport {
+}

Added: servicemix/smx4/nmr/trunk/nmr/commands/src/main/resources/META-INF/spring/servicemix-nmr-commands.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/commands/src/main/resources/META-INF/spring/servicemix-nmr-commands.xml?rev=608566&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/commands/src/main/resources/META-INF/spring/servicemix-nmr-commands.xml (added)
+++ servicemix/smx4/nmr/trunk/nmr/commands/src/main/resources/META-INF/spring/servicemix-nmr-commands.xml Thu Jan  3 09:19:53 2008
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:osgi="http://www.springframework.org/schema/osgi"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="
+  http://www.springframework.org/schema/beans
+  http://www.springframework.org/schema/beans/spring-beans.xsd
+  http://www.springframework.org/schema/util
+  http://www.springframework.org/schema/util/spring-util.xsd
+  http://www.springframework.org/schema/osgi
+  http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+
+</beans>                                                                                                                                                                                                   
\ No newline at end of file

Modified: servicemix/smx4/nmr/trunk/nmr/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/pom.xml?rev=608566&r1=608565&r2=608566&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/nmr/pom.xml Thu Jan  3 09:19:53 2008
@@ -38,6 +38,7 @@
         <module>core</module>
         <module>spring</module>
         <module>osgi</module>
+        <module>commands</module>
     </modules>
 
 </project>



Mime
View raw message