[jboss-svn-commits] JBL Code SVN: r23441 - in labs/jbossesb/workspace/skeagh: commons/src/main/java/org/jboss/esb/classpath and 13 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Oct 13 09:42:12 EDT 2008


Author: beve
Date: 2008-10-13 09:42:12 -0400 (Mon, 13 Oct 2008)
New Revision: 23441

Added:
   labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java
   labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/DeploymentRegistry.java
   labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java
   labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/package.html
Removed:
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/DeploymentRegistry.java
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java
Modified:
   labs/jbossesb/workspace/skeagh/commons/osgi.bnd
   labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/classpath/ClassUtil.java
   labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/util/JNDIUtil.java
   labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/xml/XsdDOMValidator.java
   labs/jbossesb/workspace/skeagh/container/osgi/osgi.bnd
   labs/jbossesb/workspace/skeagh/container/osgi/pom.xml
   labs/jbossesb/workspace/skeagh/examples/helloworld/osgi.bnd
   labs/jbossesb/workspace/skeagh/examples/helloworld/pom.xml
   labs/jbossesb/workspace/skeagh/examples/helloworld/src/main/java/org/jboss/esb/examples/helloworld/MyTestService.java
   labs/jbossesb/workspace/skeagh/examples/helloworld/src/main/resources/jboss-esb.xml
   labs/jbossesb/workspace/skeagh/routing/jms/osgi.bnd
   labs/jbossesb/workspace/skeagh/routing/jms/pom.xml
   labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java
   labs/jbossesb/workspace/skeagh/runtime/osgi.bnd
   labs/jbossesb/workspace/skeagh/runtime/pom.xml
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/DefaultConfigurationDigester.java
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/jms/JMSBus.java
Log:
added container/osgi that houses the jbossesb osgi bundle.

Modified: labs/jbossesb/workspace/skeagh/commons/osgi.bnd
===================================================================
--- labs/jbossesb/workspace/skeagh/commons/osgi.bnd	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/commons/osgi.bnd	2008-10-13 13:42:12 UTC (rev 23441)
@@ -1,11 +1,14 @@
 
 # Use this file to add customized Bnd instructions for the bundle
 #-----------------------------------------------------------------
+# This file is currently not in use as commons is not a bundle.
+# This might change and I'm keeping the file in svn for the time being. /Daniel 
+#
 
-Export-Package: org.jboss.esb.classpath,\
-org.jboss.esb.jms;include:="AbstractMessageHandler,AbstractMessageListener,JMSSession,MessageSender,MockMessageListener,StreamMessageInputStream",\
-org.jboss.esb.lifecycle,\
-org.jboss.esb.properties,\
-org.jboss.esb.util,\
-org.jboss.esb.xml
+#Export-Package: org.jboss.esb.classpath,\
+#org.jboss.esb.jms;include:="AbstractMessageHandler,AbstractMessageListener,JMSSession,MessageSender,MockMessageListener,StreamMessageInputStream",\
+#org.jboss.esb.lifecycle,\
+#org.jboss.esb.properties,\
+#org.jboss.esb.util,\
+#org.jboss.esb.xml
 

Modified: labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/classpath/ClassUtil.java
===================================================================
--- labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/classpath/ClassUtil.java	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/classpath/ClassUtil.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -21,11 +21,13 @@
  */
 package org.jboss.esb.classpath;
 
-import org.apache.log4j.Logger;
-
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
-import java.lang.reflect.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
 
 /**
  * Utility methods to aid in class/resource loading.
@@ -35,11 +37,6 @@
 public abstract class ClassUtil
 {
     /**
-     * Logger.
-     */
-    private static Logger logger = Logger.getLogger(ClassUtil.class);
-
-    /**
      * Private default constructor.
      */
     private ClassUtil()
@@ -54,7 +51,7 @@
      * @return The specified class.
      * @throws ClassNotFoundException If the class cannot be found.
      */
-    public static Class forName(final String className, final Class caller)
+    public static Class<?> forName(final String className, final Class<?> caller)
             throws ClassNotFoundException
     {
         final ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader();
@@ -100,7 +97,7 @@
      * @return The specified proxy class.
      * @throws ClassNotFoundException If the class cannot be found.
      */
-    public static Class resolveProxy(final String[] interfaces, final Class caller)
+    public static Class<?> resolveProxy(final String[] interfaces, final Class<?> caller)
             throws ClassNotFoundException
     {
         final int numInterfaces = (interfaces == null ? 0 : interfaces.length);
@@ -109,7 +106,7 @@
             throw new ClassNotFoundException("Cannot generate proxy with no interfaces");
         }
 
-        final Class[] interfaceClasses = new Class[numInterfaces];
+        final Class<?>[] interfaceClasses = new Class[numInterfaces];
         for (int count = 0; count < numInterfaces; count++)
         {
             interfaceClasses[count] = forName(interfaces[count], caller);
@@ -142,7 +139,7 @@
      * @param caller       The class of the caller.
      * @return The input stream for the resource or null if not found.
      */
-    public static InputStream getResourceAsStream(final String resourceName, final Class caller)
+    public static InputStream getResourceAsStream(final String resourceName, final Class<?> caller)
     {
         final String resource;
         if (resourceName.startsWith("/"))
@@ -227,7 +224,7 @@
      */
     private static void execAnnotatedMethod(final Object objectInstance, final Class<? extends Object> hierarchyClass, final Class<? extends Annotation> annotation) throws InvocationTargetException, IllegalAccessException
     {
-        Class superClass = hierarchyClass.getSuperclass();
+        Class<?> superClass = hierarchyClass.getSuperclass();
 
         // Work our way up to the root of the class inheritance hierarchy....
         if (superClass != null)
@@ -274,7 +271,7 @@
             return searchClass;
         }
 
-        Class superClass = searchClass.getSuperclass();
+        Class<?> superClass = searchClass.getSuperclass();
         if (superClass != null)
         {
             return findExecutingHierarchyClass(method, superClass);
@@ -306,8 +303,8 @@
                     }
 
                     /* Avoid unnecessary cloning */
-                    Class[] params1 = classMethod.getParameterTypes();
-                    Class[] params2 = method.getParameterTypes();
+                    Class<?>[] params1 = classMethod.getParameterTypes();
+                    Class<?>[] params2 = method.getParameterTypes();
                     if (params1.length == params2.length)
                     {
                         for (int i = 0; i < params1.length; i++)
@@ -401,7 +398,7 @@
      * @param hierarchyClass The class hierarchy on which to check for fields.
      * @throws IllegalAccessException Unable to access the object field.
      */
-    private static void setFieldValue(final Object targetObject, final String fieldName, final Object value, final Class hierarchyClass) throws IllegalAccessException
+    private static void setFieldValue(final Object targetObject, final String fieldName, final Object value, final Class<?> hierarchyClass) throws IllegalAccessException
     {
         // Check all the fields declared at the hierarchyClass level in
         // the inheritance tree...
@@ -415,7 +412,7 @@
         }
 
         // Iterate up the inheritance hierarchy...
-        Class superClass = hierarchyClass.getSuperclass();
+        Class<?> superClass = hierarchyClass.getSuperclass();
         if (superClass != null)
         {
             setFieldValue(targetObject, fieldName, value, superClass);

Modified: labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/util/JNDIUtil.java
===================================================================
--- labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/util/JNDIUtil.java	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/util/JNDIUtil.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -59,33 +59,19 @@
     public static Context getNamingContext(final Properties jndiProperties) throws JMSException
     {
         Context context;
-        /*
-         * Storing the context classloader which will be reset after usage.
-         * This was needed to force our current impl to work nicely with OSGi.
-         * TODO: Revisit and update when our OSGi strategy has been set/Dan
-         */
-        ClassLoader loader = Thread.currentThread().getContextClassLoader();
         try
         {
-            Thread.currentThread().setContextClassLoader(JNDIUtil.class.getClassLoader());
-            try
-            {
-                context = jndiProperties.isEmpty() ? new InitialContext() : new InitialContext(jndiProperties);
-            }
-            catch (NamingException e)
-            {
-                log.error("NamingException while try to create initialContext. jndiProperties are " + jndiProperties, e);
-                throw new JMSException("Failed to load InitialContext: " + jndiProperties);
-            }
-            if (context == null)
-            {
-                throw new JMSException("Failed to create JNDI context.  Check that '" + Context.PROVIDER_URL + "', '" + Context.INITIAL_CONTEXT_FACTORY + "', '" + Context.URL_PKG_PREFIXES + "' are correctly configured in the supplied JNDI properties.");
-            }
+            context = jndiProperties.isEmpty() ? new InitialContext() : new InitialContext(jndiProperties);
         }
-        finally
+        catch (NamingException e)
         {
-            Thread.currentThread().setContextClassLoader(loader);
+            log.error("NamingException while try to create initialContext. jndiProperties are " + jndiProperties, e);
+            throw new JMSException("Failed to load InitialContext: " + jndiProperties);
         }
+        if (context == null)
+        {
+            throw new JMSException("Failed to create JNDI context.  Check that '" + Context.PROVIDER_URL + "', '" + Context.INITIAL_CONTEXT_FACTORY + "', '" + Context.URL_PKG_PREFIXES + "' are correctly configured in the supplied JNDI properties.");
+        }
 
         return context;
     }

Modified: labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/xml/XsdDOMValidator.java
===================================================================
--- labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/xml/XsdDOMValidator.java	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/xml/XsdDOMValidator.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -185,6 +185,7 @@
         String resourcePath = "/META-INF" + namespace.getPath();
         InputStream xsdStream = resourceLocator.getResourceAsStream(resourcePath, getClass());
 
+
         if (xsdStream == null)
         {
             throw new SAXException("Failed to locate XSD resource '" + resourcePath + "' on classpath. Namespace: '" + namespace + "'.");

Modified: labs/jbossesb/workspace/skeagh/container/osgi/osgi.bnd
===================================================================
--- labs/jbossesb/workspace/skeagh/container/osgi/osgi.bnd	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/container/osgi/osgi.bnd	2008-10-13 13:42:12 UTC (rev 23441)
@@ -1,7 +1,47 @@
 #-----------------------------------------------------------------
 # Use this file to add customized Bnd instructions for the bundle
 #-----------------------------------------------------------------
-Export-Package: org.jboss.esb.osgi.*
+Export-Package: org.jboss.esb.deploy.*,\
+org.jboss.esb.dispatch.*,\
+org.jboss.esb.failure.*,\
+org.jboss.esb.federate.*,\
+org.jboss.esb.filter.*,\
+org.jboss.esb.history.*,\
+org.jboss.esb.routing.*,\
+org.jboss.esb.schedule.*,\
+org.jboss.esb.serialization.*,\
+org.jboss.esb.test.*,\
+org.jboss.esb.osgi.*,\
+org.jboss.esb.util.*,\
+org.jboss.esb.classpath.*,\
+org.jboss.esb.xml.*,\
+org.jboss.esb.properties.*,\
+org.jboss.esb.annotations.*,\
+org.jboss.esb.context.*,\
+org.jboss.esb.exception.*,\
+org.jboss.esb.service.*,\
+org.jboss.esb.message.*
+
+Import-Package: *;resolution:=optional, javax.jms;version="1.1.0", org.apache.activemq.*;version="0.0.0";resolution:=optional, *;resolution:=optional
+
 Bundle-Activator: org.jboss.esb.osgi.EsbServiceDeploymentActivator
-Import-Package: *;resolution:=optional
 
+Embed-Dependency: quartz,\
+xpp3_min, \
+xstream, \
+freemarker,\
+hsqldb, \
+jbossesb-rt, \
+mvel, \
+milyn-commons, \
+milyn-smooks-core, \
+milyn-smooks-javabean, \
+backport, \
+commons-lang, \
+commons-logging, \
+geronimo-j2ee-management, \
+geronimo-jms_1.1_spec-1.1.1.jar;scope=compile|runtime;artifactId=!xercesImpl|log4j|jbossesb-api-routing|jbossesb-api-service|jbossesb-routing|jbossesb-routing-jms|jbossesb-commons|activemq-core;inline=false
+
+Embed-Transitive: true
+
+

Modified: labs/jbossesb/workspace/skeagh/container/osgi/pom.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/container/osgi/pom.xml	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/container/osgi/pom.xml	2008-10-13 13:42:12 UTC (rev 23441)
@@ -19,8 +19,18 @@
 			<groupId>org.osgi</groupId>
 			<artifactId>osgi_R4_core</artifactId>
 			<version>1.0</version>
-			<scope>compile</scope>
+			<scope>provided</scope>
 		</dependency>
+		<dependency>
+			<groupId>jboss.jbossesb</groupId>
+			<artifactId>jbossesb-routing-jms</artifactId>
+			<version>${jboss.esb.version}</version>
+		</dependency>
+		<dependency>
+            <groupId>javax.jms</groupId>
+            <artifactId>jms</artifactId>
+            <version>1.1</version>
+        </dependency>
     </dependencies>
 
 </project>

Copied: labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java (from rev 23418, labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java)
===================================================================
--- labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.esb.osgi;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.esb.classpath.ClassUtil;
+import org.jboss.esb.classpath.ResourceLocator;
+import org.osgi.framework.Bundle;
+
+/**
+ * BundleResourceLocator is an OSGi implementation of ResourceLocator.
+ * <p/>
+ * This locator will look for and load resources by first looking in
+ * the bundles classpath. Does this violate the OSGi classloading?
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class BundleResourceLocator implements ResourceLocator
+{
+    /**
+     * The OSGi BundleContext instance.
+     */
+    private final Bundle bundle;
+
+    /**
+     * Creates and instance and stores the passed-in BundleContext.
+     *
+     * @param bundle - the OSGi Bundle.
+     */
+    public BundleResourceLocator(final Bundle bundle)
+    {
+        this.bundle = bundle;
+    }
+
+    /**
+     * Load the specified class. Ignores the callers classloader.
+     *
+     * @param className The name of the class to load.
+     * @param caller    The class of the caller. Ignored
+     * @return Class The specified class.
+     * @throws ClassNotFoundException If the class cannot be found.
+     */
+    public final Class<?> forName(final String className, final Class<?> caller) throws ClassNotFoundException
+    {
+        try
+        {
+            return forName(className);
+        }
+        catch (final ClassNotFoundException e)
+        {
+            // fallback to normal classloading
+            return ClassUtil.forName(className, caller);
+        }
+    }
+
+    /**
+     * Load the specified class.
+     *
+     * @param className The name of the class to load.
+     * @return Class The specified class.
+     * @throws ClassNotFoundException If the class cannot be found.
+     */
+    public final Class<?> forName(final String className) throws ClassNotFoundException
+    {
+        return bundle.loadClass(className);
+    }
+
+    /**
+     * Get a resource from the callers classpath.
+     *
+     * @param resourceName - the name of the resource to be retrieved.
+     * @param caller - the class of the caller. The classes classloader will be used to search for the resource.
+     *
+     * @return InputStream - the InputStream for the resource.
+     */
+    public final InputStream getResourceAsStream(final String resourceName, final Class<?> caller)
+    {
+        final URL entry = bundle.getEntry(resourceName);
+        if (entry != null)
+        {
+            try
+            {
+                return entry.openStream();
+            }
+            catch (final IOException ignore)
+            {
+                ignore.printStackTrace();
+                // ignore. Will fallback to normal classloading
+            }
+        }
+        return ClassUtil.getResourceAsStream(resourceName, caller);
+    }
+
+}

Copied: labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/DeploymentRegistry.java (from rev 23419, labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/DeploymentRegistry.java)
===================================================================
--- labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/DeploymentRegistry.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/DeploymentRegistry.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -0,0 +1,180 @@
+package org.jboss.esb.osgi;
+
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Set;
+
+import org.jboss.esb.deploy.DeploymentException;
+import org.jboss.esb.deploy.DeploymentRuntime;
+import org.jboss.esb.deploy.DeploymentUtil;
+import org.osgi.framework.Bundle;
+
+/**
+ * DeploymentRegistry keeps tracks of deployed runtimes.
+ * <p/>
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class DeploymentRegistry
+{
+    /**
+     * Default name of the config file.
+     */
+    private static final String DEFAULT_CONFIG_FILENAME = "/jboss-esb.xml";
+
+    /**
+     * Header that can be placed in the MANIFEST.MF file to
+     * specify a different config file name then the default one.
+     */
+    private static final String CONFIG_FILE_HEADER = "JBossESB-ConfigFile";
+
+    /**
+     * Header that can be placed in the MANIFEST.MF file to
+     * specify a different deployment name then the default, which
+     * is the bundle name.
+     */
+    private static final String DEPLOYMENT_NAME_HEADER = "JBossESB-DeploymentName";
+
+    /**
+     * Set of activated deployments.
+     */
+    private HashMap<Bundle,DeploymentRuntime> activated = new HashMap<Bundle,DeploymentRuntime>();
+
+    /**
+     * Unregisters the DeploymentRuntime.
+     *
+     * @param bundle The bundle to register.
+     */
+    public final void register(final Bundle bundle)
+    {
+        synchronized (activated)
+        {
+            if (activated.containsKey(bundle))
+            {
+                // already registered. Don't need to do anything
+                return;
+            }
+        }
+
+        final URL configUrl = getEsbConfigFile(bundle);
+        if (configUrl == null)
+        {
+            return;
+        }
+
+        try
+        {
+            //TODO: Use logging service
+            System.out.println("Found config : " + configUrl + " for bundle : " + bundle);
+            DeploymentRuntime runtime = DeploymentUtil.createRuntime(configUrl.openStream(), new BundleResourceLocator(bundle));
+            runtime.setDeploymentName(getDeploymentName(bundle));
+            runtime.deploy();
+
+            synchronized (activated)
+            {
+                activated.put(bundle, runtime);
+            }
+        }
+        catch (final Throwable t)
+        {
+            //TODO: add exception handling.
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * Unregisters the DeploymentRuntime.
+     *
+     * @param bundle the bundle.
+     */
+    public final void unregister(final Bundle bundle)
+    {
+        //TODO: Use logging service
+        System.out.println("unregister bundle: " + bundle);
+        synchronized (activated)
+        {
+            if (!activated.containsKey(bundle))
+            {
+                return;
+            }
+
+            final DeploymentRuntime deploymentRuntime = activated.get(bundle);
+            try
+            {
+                deploymentRuntime.undeploy();
+            }
+            catch (DeploymentException e)
+            {
+                //TODO: Handle exception.
+                e.printStackTrace();
+            }
+            finally
+            {
+                activated.remove(bundle);
+            }
+        }
+    }
+
+    /**
+     * Gets the Esb configuration file from the bundle.
+     *
+     * @param bundle The Bundle being activated.
+     * @return URL URL to the configuration file.
+     *
+     */
+    private URL getEsbConfigFile(final Bundle bundle)
+    {
+        String configFileName = (String) getHeader(bundle, CONFIG_FILE_HEADER);
+        if (configFileName == null)
+        {
+            configFileName = DEFAULT_CONFIG_FILENAME;
+        }
+        return bundle.getEntry(configFileName);
+    }
+
+    /**
+     * Get the deployment name from the MANIFEST header {@link DeploymentRegistry#DEPLOYMENT_NAME_HEADER}.
+     * If that header has not been set the deployment name will be set to the bundles sympolic name.
+     *
+     * @param bundle The current bundle
+     * @return String   The name of the deployment. Either the value of the deployement header or the bundles sympolic name
+     */
+    private String getDeploymentName(final Bundle bundle)
+    {
+        String deploymentName = (String) getHeader(bundle, DEPLOYMENT_NAME_HEADER);
+        if (deploymentName == null)
+        {
+            deploymentName = bundle.getSymbolicName();
+        }
+        return deploymentName;
+    }
+
+    /**
+     * Get the the specified header from the passed in bundle.
+     *
+     * @param from  The Bundle to retrieve the header from.
+     * @param headerName The header name
+     * @return String   The value of the header of null if the header has not been set.
+     */
+    private String getHeader(final Bundle from, final String headerName)
+    {
+        final Dictionary<?,?> headers = from.getHeaders();
+        return (String) headers.get(headerName);
+    }
+
+    /**
+     * Close this registry.
+     */
+    public final void close()
+    {
+        Set<Bundle> keySet = activated.keySet();
+        for (Bundle bundle : keySet)
+        {
+            unregister(bundle);
+        }
+    }
+}
+
+

Copied: labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java (from rev 23418, labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java)
===================================================================
--- labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.esb.osgi;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.log.LogService;
+
+/**
+ * EsbServiceDeploymentActivator is an OSGi Activator that takes care
+ * registering the EsbServiceDeployer service.
+ * <p>
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ */
+public class EsbServiceDeploymentActivator implements BundleActivator, BundleListener
+{
+    /**
+     * The BundleContext for this listener.
+     */
+    private BundleContext bundleContext;
+
+    /**
+     * Registry that hold the DeploymentRuntimes.
+     */
+    private DeploymentRegistry registry = new DeploymentRegistry();
+
+    /**
+     * Log service.
+     */
+    private LogService  log;
+
+    /**
+     * Activation method that will be called by the Service Component Runtime.
+     * @param cc The ComponentContext.
+     */
+    public final void activate(final ComponentContext cc)
+    {
+        System.out.println("activate...ContextClassLoader : " + Thread.currentThread().getContextClassLoader());
+        this.bundleContext = cc.getBundleContext();
+        System.out.println("activate...bundleClassLoader : " + getClass().getClassLoader());
+        log.log(LogService.LOG_DEBUG, "activate....");
+
+        bundleContext.addBundleListener(this);
+
+        // get all the currently installed bundles.
+        final Bundle[] bundles = bundleContext.getBundles();
+        for (Bundle bundle : bundles)
+        {
+            if ((bundle.getState() & (Bundle.STARTING | Bundle.ACTIVE)) != 0)
+            {
+                // register the bundles that are esb bundles.
+                registry.register(bundle);
+            }
+        }
+    }
+
+    /**
+     * Called when the OSGi Component Runtime notifies about
+     * changed bundles.
+     *
+     * @param event The event that occured. This method only handles STARTED and STOPPED events.
+     */
+    public final void bundleChanged(final BundleEvent event)
+    {
+        switch (event.getType())
+        {
+            case BundleEvent.STARTED:
+                registry.register(event.getBundle());
+                break;
+
+            case BundleEvent.STOPPED:
+                registry.unregister(event.getBundle());
+                break;
+
+            default:
+                break;
+        }
+    }
+
+    /**
+     * Starts the bundle.
+     * Will add this instance as a bundle listener, and register any bundles
+     * containing an esb configuration file.
+     *
+     * @param context The bundle context.
+     * @throws Exception If an exception occurs during startup.
+     */
+    public final void start(final BundleContext context) throws Exception
+    {
+        this.bundleContext = context;
+
+        context.addBundleListener(this);
+
+        // get all the currently installed bundles.
+        final Bundle[] bundles = context.getBundles();
+        for (final Bundle bundle : bundles)
+        {
+            if ((bundle.getState() & (Bundle.STARTING | Bundle.ACTIVE)) != 0)
+            {
+                // register and deploy the bundles that are esb bundles.
+                registry.register(bundle);
+            }
+        }
+    }
+
+    /**
+     * Stops this bundle.
+     * Will close the underlying registry of DeploymentRuntime, going
+     * through them and undeploying them.
+     *
+     * @param unused The bundle context.
+     * @throws Exception If an exception occurs during startup.
+     */
+    public final void stop(final BundleContext unused) throws Exception
+    {
+        registry.close();
+    }
+}

Added: labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/package.html
===================================================================
--- labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/package.html	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/container/osgi/src/main/java/org/jboss/esb/osgi/package.html	2008-10-13 13:42:12 UTC (rev 23441)
@@ -0,0 +1,8 @@
+<html>
+<head></head>
+<body>
+OSGi Handling.
+
+<h2>Package Specification</h2>
+</body>
+</html>
\ No newline at end of file

Modified: labs/jbossesb/workspace/skeagh/examples/helloworld/osgi.bnd
===================================================================
--- labs/jbossesb/workspace/skeagh/examples/helloworld/osgi.bnd	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/examples/helloworld/osgi.bnd	2008-10-13 13:42:12 UTC (rev 23441)
@@ -3,16 +3,14 @@
 #-----------------------------------------------------------------
 
 # Need to export all classes that this bundle uses
-Export-Package: org.jboss.esb.examples.helloworld.*, org.apache.activemq.*, org.apache.log4j.*, javax.jms.*, edu.emory.*, org.apache.commons.logging.*, javax.management.j2ee.*
+Export-Package: org.jboss.esb.examples.helloworld.*, org.apache.log4j.*, edu.emory.*, org.apache.commons.logging.*, javax.management.j2ee.*
 
 # Explicit imports
-Import-Package: org.jboss.esb.*, *;resolution:=optional,*
+Import-Package: org.jboss.esb.*, *;resolution:=optional
 
 # Dependencies that need to be included into the bundle.
 # This can be any no-osgi bundle that your bundle needs.
 Embed-Dependency: log4j;scope=compile|runtime, \
-activemq-core;scope=compile|runtime, \
-jms;scope=compile|runtime, \
 mx4j;scope=compile|runtime, \ 
 mx4j-tools, \
 backport-util-concurrent;scope=compile|runtime, \ 
@@ -25,5 +23,7 @@
 # default configuration file name.
 JBossESB-ConfigFile = /jboss-esb.xml
 
+JBossESB-DeploymentName=TestDeploymentName
 
 
+

Modified: labs/jbossesb/workspace/skeagh/examples/helloworld/pom.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/examples/helloworld/pom.xml	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/examples/helloworld/pom.xml	2008-10-13 13:42:12 UTC (rev 23441)
@@ -90,31 +90,20 @@
 			<version>1.0-M1</version>
 		</dependency> 
 
+		<!-- JBossESB OSGi bundle -->
 		<dependency>
 			<groupId>jboss.jbossesb</groupId>
-			<artifactId>jbossesb-routing-jms</artifactId>
+			<artifactId>jbossesb-container-osgi</artifactId>
 			<version>${jboss.esb.version}</version>
 		</dependency>
 
+		<!-- JBossESB JMS Souting bundle -->
 		<dependency>
 			<groupId>jboss.jbossesb</groupId>
-			<artifactId>jbossesb-api-service</artifactId>
+			<artifactId>jbossesb-routing-jms</artifactId>
 			<version>${jboss.esb.version}</version>
 		</dependency>
 
-		<dependency>
-			<groupId>jboss.jbossesb</groupId>
-			<artifactId>jbossesb-api-routing</artifactId>
-			<version>${jboss.esb.version}</version>
-		</dependency>
-
-		<!--
-        <dependency>
-            <groupId>jboss.jbossesb</groupId>
-            <artifactId>jbossesb-osgi</artifactId>
-			<version>${jboss.esb.version}</version>
-		</dependency>
-		-->
 	</dependencies>
 	
 </project>

Modified: labs/jbossesb/workspace/skeagh/examples/helloworld/src/main/java/org/jboss/esb/examples/helloworld/MyTestService.java
===================================================================
--- labs/jbossesb/workspace/skeagh/examples/helloworld/src/main/java/org/jboss/esb/examples/helloworld/MyTestService.java	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/examples/helloworld/src/main/java/org/jboss/esb/examples/helloworld/MyTestService.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -19,7 +19,6 @@
  */
 package org.jboss.esb.examples.helloworld;
 
-import org.jboss.esb.annotations.Initialize;
 import org.jboss.esb.message.Message;
 import org.jboss.esb.service.Service;
 import org.jboss.esb.service.ServiceException;
@@ -32,15 +31,6 @@
 public final class MyTestService implements Service
 {
     /**
-     * Just an example of an initialize method.
-     */
-    @Initialize
-    public void init()
-    {
-        System.out.println("Init in MyTestService");
-    }
-
-    /**
      * Processes the message.
      * @param msg - the esb message object instance.
      * @return Messsage - the esb message object instance.

Modified: labs/jbossesb/workspace/skeagh/examples/helloworld/src/main/resources/jboss-esb.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/examples/helloworld/src/main/resources/jboss-esb.xml	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/examples/helloworld/src/main/resources/jboss-esb.xml	2008-10-13 13:42:12 UTC (rev 23441)
@@ -4,7 +4,7 @@
             <inRouter name="inrouter1" class="org.jboss.esb.jms.JmsInboundRouter">
                 <property name="java.naming.provider.url">tcp://localhost:61717</property>
                 <property name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</property>
-                <property name="jmsDestination">jbossesb.TestQueue</property>
+                <property name="jmsDestination">dynamicQueues/jbossesb.TestQueue</property>
                 <!--property name="queue.jbossesb.TestQueue">jbossesb.TestQueue</property-->
             </inRouter>
         </service>

Modified: labs/jbossesb/workspace/skeagh/routing/jms/osgi.bnd
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/osgi.bnd	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/routing/jms/osgi.bnd	2008-10-13 13:42:12 UTC (rev 23441)
@@ -2,5 +2,21 @@
 # Use this file to add customized Bnd instructions for the bundle
 #-----------------------------------------------------------------
 
-Export-Package: org.jboss.esb.jms.*
+# *	Need to make javax.jms available as it is needed by our runtime. As we are using a JMSBus the bus impl 
+# 	exits in the runtime and not in the jms routing module. The JMSBus will configure a queue and a topic for
+#	internal bus communication and needs to be able to have access the javax.jms package and also the jms providers
+# 	classess(which are loaded via jndi). The provider in this case is activemq.
+#
+# As I see it have have the following options of packaging this bundle:
+# 1. Include the JMSProviders jars in this bundle and make them accessible by exporting them.
+# 2. Installing the jms provider as a bundle and importing it in this bundle. This would mean that
+#	 this bundles manifest must be updated with the providers packages as users will have different jms
+#	 providers. 
+# 3. Using dynamic imports for the jms provider classes.
+#
+Export-Package: org.jboss.esb.jms.*, javax.jms;version="1.1", org.apache.activemq.*
 Import-Package: *;resolution:=optional
+
+Embed-Dependency: jms;scope=compile|runtime,jbossesb-commons;scope=compile|runtime;inline=false, activemq-core
+Embed-Transitive: true
+

Modified: labs/jbossesb/workspace/skeagh/routing/jms/pom.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/pom.xml	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/routing/jms/pom.xml	2008-10-13 13:42:12 UTC (rev 23441)
@@ -28,7 +28,7 @@
             <groupId>org.apache.activemq</groupId>
             <artifactId>activemq-core</artifactId>
             <version>4.1.2</version>
-            <scope>test</scope>
+            <scope>compile</scope>
         </dependency>
 
         <dependency>

Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -110,24 +110,48 @@
     @Initialize
     public final void initialize() throws JMSException
     {
+        Destination jmsDestination = null;
+        /*
+         * Need to set the context classloader due to the current OSGi packaging.
+         * The jbossesb-routing-jms bundle needs to set the context classloader as
+         * it uses classes that in turn use jndi to lookup a destination. JNDI uses
+         * the thread context classloader which is not set by an osgi bundle. We are
+         * currently setting the context classloader to this bundles classloader, hence
+         * we are saying that the bundle that this class is packaged in will provide the
+         * classes needed to by the installed JMS provider. This does not mean that the
+         * JMS providers classes must physically exist in this bundle. It can also mean
+         * that this bundle imports the packages needed. All we are saying is that the
+         * bundles classloader will have access to the classes. /Daniel 2008-10-13
+         */
+        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
         try
         {
-            final Destination jmsDestination = AbstractMessageHandler.lookupDestination(destination, jmsProperties);
+            // set the context class loader to this classes classloader.
+            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            jmsDestination = AbstractMessageHandler.lookupDestination(destination, jmsProperties);
+
             jmsSession = new JMSSession(jmsDestination.getClass(), jmsProperties);
             jmsSession.connect();
-            messageListener = new JmsMessageListener(destination, jmsSession, jmsProperties, dispatcher);
-            messageListener.connect();
+            try
+            {
+                messageListener = new JmsMessageListener(destination, jmsSession, jmsProperties, dispatcher);
+                messageListener.connect();
+            }
+            catch (final JMSException e)
+            {
+                jmsSession.close();
+                throw e;
+            }
+            catch (final Throwable t)
+            {
+                jmsSession.close();
+                throw (JMSException) (new JMSException("Unexpected exception while connecting JmsMesssageListener.").initCause(t));
+            }
         }
-        catch (final JMSException e)
+        finally
         {
-            jmsSession.close();
-            throw e;
+            Thread.currentThread().setContextClassLoader(contextClassLoader);
         }
-        catch (final Throwable t)
-        {
-            jmsSession.close();
-            throw (JMSException) (new JMSException("Unexpected exception while connecting JmsMesssageListener.").initCause(t));
-        }
     }
 
     /**
@@ -246,7 +270,7 @@
             try
             {
                 final Message esbMessage = JmsInformationExtractor.extractPayload(jmsMessage);
-                log.info(esbMessage);
+                log.info("Extracted Jms Payload -> " + esbMessage);
 
                 final InvocationContext context = new InvocationContext();
                 if (extractProperties)

Modified: labs/jbossesb/workspace/skeagh/runtime/osgi.bnd
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/osgi.bnd	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/runtime/osgi.bnd	2008-10-13 13:42:12 UTC (rev 23441)
@@ -11,21 +11,14 @@
 org.jboss.esb.schedule.*,\
 org.jboss.esb.serialization.*,\
 org.jboss.esb.test.*,\
-org.jboss.esb.osgi.*,\
-org.jboss.esb.util.*,\
-org.jboss.esb.classpath.*,\
-org.jboss.esb.jms.*,\
-org.jboss.esb.xml.*,\
-org.jboss.esb.properties.*,\
 org.jboss.esb.annotations.*,\
 org.jboss.esb.context.*,\
 org.jboss.esb.exception.*,\
 org.jboss.esb.service.*,\
 org.jboss.esb.message.*
 
-Import-Package: *;resolution:=optional
+#Import-Package: *;resolution:=optional,javax.jms.*;resolution:=optional
+#Import-Package: *;resolution:=optional
 
-Bundle-Activator: org.jboss.esb.osgi.EsbServiceDeploymentActivator
-
-Embed-Dependency: *;scope=compile|runtime;artifactId=!xercesImpl|log4j;inline=false
+Embed-Dependency: jbossesb-commons,jbossesb-api-services,jbossesb-api-routing,*;scope=compile|runtime;artifactId=!xercesImpl|log4j;inline=false,
 Embed-Transitive: true

Modified: labs/jbossesb/workspace/skeagh/runtime/pom.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/pom.xml	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/runtime/pom.xml	2008-10-13 13:42:12 UTC (rev 23441)
@@ -52,12 +52,6 @@
 			<artifactId>log4j</artifactId>
 			<version>1.2.14</version>
 		</dependency> 
-		 <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>osgi_R4_core</artifactId>
-            <version>1.0</version>
-            <scope>provided</scope>
-        </dependency>
 
         <!--
             Test dependencies...

Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/DefaultConfigurationDigester.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/DefaultConfigurationDigester.java	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/DefaultConfigurationDigester.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -293,7 +293,7 @@
                 Map<String, Object> outRoutersObjects = DigestUtil.digestElement(outRoutersElement, resourceLocator);
                 List<OutboundRouterConfig> outRouters = (List<OutboundRouterConfig>) outRoutersObjects.get("outRouters");
 
-                if(!outRouters.isEmpty())
+                if (!outRouters.isEmpty())
                 {
                     ServiceName serviceName = outRouters.get(0).getServiceName();
 

Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/jms/JMSBus.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/jms/JMSBus.java	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/jms/JMSBus.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -177,48 +177,64 @@
             throw new IllegalStateException("'properties' not set on Bus.");
         }
 
-        connectJMSSessions(properties);
+        /*
+         * Need to set the context classloader to this classes classloader. When deployed/included
+         * as an osgi bundle this calls make by this class will involve jndi which uses
+         * the thread context classloader. The application classloader will the the context classloader
+         * for the bundle and will not have the ability to use the bundles classloader to find the
+         * resources is needs.
+         */
+        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+        try
+        {
+            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            connectJMSSessions(properties);
 
-        if (topicSession != null && queueSession != null)
-        {
-            try
+            if (topicSession != null && queueSession != null)
             {
-                connectCoordinationListener(properties);
-                connectCoordintationSender(properties);
-                connectBusListener(properties);
-                connectBusSender(properties);
-            }
-            catch (DeploymentException e)
-            {
                 try
                 {
-                    if (jmsCoordinationListener == null && jmsCoordinationSender == null && jmsBusListener == null && jmsBusSender == null)
+                    connectCoordinationListener(properties);
+                    connectCoordintationSender(properties);
+                    connectBusListener(properties);
+                    connectBusSender(properties);
+                }
+                catch (DeploymentException e)
+                {
+                    try
                     {
-                        if (!logger.isDebugEnabled())
+                        if (jmsCoordinationListener == null && jmsCoordinationSender == null && jmsBusListener == null && jmsBusSender == null)
                         {
-                            logger.info("Deployment '" + deploymentName + "' is not being coordinated with any other local deployment.  Turn on deug logging for more details.");
+                            if (!logger.isDebugEnabled())
+                            {
+                                logger.info("Deployment '" + deploymentName + "' is not being coordinated with any other local deployment.  Turn on deug logging for more details.");
+                            }
+                            else
+                            {
+                                logger.debug("Deployment '" + deploymentName + "' is not being coordinated with any other local deployment.", e);
+                            }
                         }
                         else
                         {
-                            logger.debug("Deployment '" + deploymentName + "' is not being coordinated with any other local deployment.", e);
+                            throw e;
                         }
                     }
-                    else
+                    finally
                     {
-                        throw e;
+                        closeJMSSessions();
                     }
                 }
-                finally
+                catch (Throwable t)
                 {
                     closeJMSSessions();
+                    throw new DeploymentException("Failed to connect coordination listener", t);
                 }
             }
-            catch (Throwable t)
-            {
-                closeJMSSessions();
-                throw new DeploymentException("Failed to connect coordination listener", t);
-            }
         }
+        finally
+        {
+            Thread.currentThread().setContextClassLoader(contextClassLoader);
+        }
     }
 
     /**

Deleted: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -1,116 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
- * LLC, and individual contributors by the @authors tag. See the copyright.txt
- * in the distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- *
- * This software is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this software; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
- * site: http://www.fsf.org.
- */
-package org.jboss.esb.osgi;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-
-import org.jboss.esb.classpath.ClassUtil;
-import org.jboss.esb.classpath.ResourceLocator;
-import org.osgi.framework.Bundle;
-
-/**
- * BundleResourceLocator is an OSGi implementation of ResourceLocator.
- * <p/>
- * This locator will look for and load resources by first looking in
- * the bundles classpath. Does this violate the OSGi classloading?
- *
- * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
- *
- */
-public class BundleResourceLocator implements ResourceLocator
-{
-    /**
-     * The OSGi BundleContext instance.
-     */
-    private final Bundle bundle;
-
-    /**
-     * Creates and instance and stores the passed-in BundleContext.
-     *
-     * @param bundle - the OSGi Bundle.
-     */
-    public BundleResourceLocator(final Bundle bundle)
-    {
-        this.bundle = bundle;
-    }
-
-    /**
-     * Load the specified class. Ignores the callers classloader.
-     *
-     * @param className The name of the class to load.
-     * @param caller    The class of the caller. Ignored
-     * @return Class The specified class.
-     * @throws ClassNotFoundException If the class cannot be found.
-     */
-    public final Class<?> forName(final String className, final Class<?> caller) throws ClassNotFoundException
-    {
-        try
-        {
-            return forName(className);
-        }
-        catch (final ClassNotFoundException e)
-        {
-            // fallback to normal classloading
-            return ClassUtil.forName(className, caller);
-        }
-    }
-
-    /**
-     * Load the specified class.
-     *
-     * @param className The name of the class to load.
-     * @return Class The specified class.
-     * @throws ClassNotFoundException If the class cannot be found.
-     */
-    public final Class<?> forName(final String className) throws ClassNotFoundException
-    {
-        return bundle.loadClass(className);
-    }
-
-    /**
-     * Get a resource from the callers classpath.
-     *
-     * @param resourceName - the name of the resource to be retrieved.
-     * @param caller - the class of the caller. The classes classloader will be used to search for the resource.
-     *
-     * @return InputStream - the InputStream for the resource.
-     */
-    public final InputStream getResourceAsStream(final String resourceName, final Class<?> caller)
-    {
-        final URL entry = bundle.getEntry(resourceName);
-        if (entry != null)
-        {
-            try
-            {
-                return entry.openStream();
-            }
-            catch (final IOException ignore)
-            {
-                ignore.printStackTrace();
-                // ignore. Will fallback to normal classloading
-            }
-        }
-        return ClassUtil.getResourceAsStream(resourceName, caller);
-    }
-
-}

Deleted: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/DeploymentRegistry.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/DeploymentRegistry.java	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/DeploymentRegistry.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -1,162 +0,0 @@
-package org.jboss.esb.osgi;
-
-import java.net.URL;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Set;
-
-import org.jboss.esb.deploy.DeploymentException;
-import org.jboss.esb.deploy.DeploymentRuntime;
-import org.jboss.esb.deploy.DeploymentUtil;
-import org.osgi.framework.Bundle;
-
-/**
- * DeploymentRegistry keeps tracks of deployed runtimes.
- * <p/>
- *
- * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
- *
- */
-public class DeploymentRegistry
-{
-    /**
-     * Default name of the config file.
-     */
-    private static final String DEFAULT_CONFIG_FILENAME = "/jboss-esb.xml";
-
-    /**
-     * Header that can be placed in the MANIFEST.MF file to
-     * specify a different config file name then the default one.
-     */
-    private static final String CONFIG_FILE_HEADER = "JBossESB-ConfigFile";
-
-    /**
-     * Header that can be placed in the MANIFEST.MF file to
-     * specify a different deployment name then the default, which
-     * is the bundle name.
-     */
-    private static final String DEPLOYMENT_NAME_HEADER = "JBossESB-DeploymentName";
-
-    /**
-     * Set of activated deployments.
-     */
-    private HashMap<Bundle,DeploymentRuntime> activated = new HashMap<Bundle,DeploymentRuntime>();
-
-    /**
-     * Unregisters the DeploymentRuntime.
-     *
-     * @param bundle The bundle to register.
-     */
-    public final void register(final Bundle bundle)
-    {
-        synchronized (activated)
-        {
-            if (activated.containsKey(bundle))
-            {
-                // already registered. Don't need to do anything
-                return;
-            }
-        }
-
-        final URL configUrl = getEsbConfigFile(bundle);
-        if (configUrl == null)
-        {
-            return;
-        }
-
-        try
-        {
-            //TODO: Use logging service
-            System.out.println("Found config : " + configUrl + " for bundle : " + bundle);
-            DeploymentRuntime runtime = DeploymentUtil.createRuntime(configUrl.openStream(), new BundleResourceLocator(bundle));
-            runtime.setDeploymentName(getDeploymentName(bundle));
-            runtime.deploy();
-
-            synchronized (activated)
-            {
-                activated.put(bundle, runtime);
-            }
-        }
-        catch (final Throwable t)
-        {
-            //TODO: add exception handling.
-            t.printStackTrace();
-        }
-    }
-
-    /**
-     * Unregisters the DeploymentRuntime.
-     *
-     * @param bundle the bundle.
-     */
-    public final void unregister(final Bundle bundle)
-    {
-        //TODO: Use logging service
-        System.out.println("unregister bundle: " + bundle);
-        synchronized (activated)
-        {
-            if (!activated.containsKey(bundle))
-            {
-                return;
-            }
-
-            final DeploymentRuntime deploymentRuntime = activated.get(bundle);
-            try
-            {
-                deploymentRuntime.undeploy();
-            }
-            catch (DeploymentException e)
-            {
-                //TODO: Handle exception.
-                e.printStackTrace();
-            }
-            finally
-            {
-                activated.remove(bundle);
-            }
-        }
-    }
-
-    /**
-     * Gets the Esb configuration file from the bundle.
-     *
-     * @param bundle The Bundle being activated.
-     * @return URL URL to the configuration file.
-     *
-     */
-    private URL getEsbConfigFile(final Bundle bundle)
-    {
-        final Dictionary headers = bundle.getHeaders();
-        String configFileName = (String)headers.get(CONFIG_FILE_HEADER);
-        if (configFileName == null)
-        {
-            configFileName = DEFAULT_CONFIG_FILENAME;
-        }
-        return bundle.getEntry(configFileName);
-    }
-
-    private String getDeploymentName(final Bundle bundle)
-    {
-        final Dictionary headers = bundle.getHeaders();
-        String deploymentName = (String)headers.get(DEPLOYMENT_NAME_HEADER);
-        if (deploymentName == null)
-        {
-            deploymentName = bundle.getSymbolicName();
-        }
-        return deploymentName;
-    }
-
-    /**
-     * Close this registry.
-     */
-    public final void close()
-    {
-        Set<Bundle> keySet = activated.keySet();
-        for (Bundle bundle : keySet)
-        {
-            unregister(bundle);
-        }
-    }
-}
-
-

Deleted: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java	2008-10-13 12:59:22 UTC (rev 23440)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java	2008-10-13 13:42:12 UTC (rev 23441)
@@ -1,141 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
- * LLC, and individual contributors by the @authors tag. See the copyright.txt
- * in the distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- *
- * This software is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this software; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
- * site: http://www.fsf.org.
- */
-package org.jboss.esb.osgi;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
-import org.osgi.service.component.ComponentContext;
-import org.osgi.service.log.LogService;
-
-/**
- * EsbServiceDeploymentActivator is an OSGi Activator that takes care
- * registering the EsbServiceDeployer service.
- * <p>
- *
- * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
- */
-public class EsbServiceDeploymentActivator implements BundleActivator, BundleListener
-{
-    /**
-     * The BundleContext for this listener.
-     */
-    private BundleContext bundleContext;
-
-    /**
-     * Registry that hold the DeploymentRuntimes.
-     */
-    private DeploymentRegistry registry = new DeploymentRegistry();
-
-    /**
-     * Log service.
-     */
-    private LogService  log;
-
-    /**
-     * Activation method that will be called by the Service Component Runtime.
-     * @param cc The ComponentContext.
-     */
-    public final void activate(final ComponentContext cc)
-    {
-        System.out.println("activate...");
-        this.bundleContext = cc.getBundleContext();
-        log.log(LogService.LOG_DEBUG, "activate....");
-
-        bundleContext.addBundleListener(this);
-
-        // get all the currently installed bundles.
-        final Bundle[] bundles = bundleContext.getBundles();
-        for (Bundle bundle : bundles)
-        {
-            if ((bundle.getState() & (Bundle.STARTING | Bundle.ACTIVE)) != 0)
-            {
-                // register the bundles that are esb bundles.
-                registry.register(bundle);
-            }
-        }
-    }
-
-    /**
-     * Called when the OSGi Component Runtime notifies about
-     * changed bundles.
-     *
-     * @param event The event that occured. This method only handles STARTED and STOPPED events.
-     */
-    public final void bundleChanged(final BundleEvent event)
-    {
-        switch (event.getType())
-        {
-            case BundleEvent.STARTED:
-                registry.register(event.getBundle());
-                break;
-
-            case BundleEvent.STOPPED:
-                registry.unregister(event.getBundle());
-                break;
-
-            default:
-                break;
-        }
-    }
-
-    /**
-     * Starts the bundle.
-     * Will add this instance as a bundle listener, and register any bundles
-     * containing an esb configuration file.
-     *
-     * @param context The bundle context.
-     * @throws Exception If an exception occurs during startup.
-     */
-    public final void start(final BundleContext context) throws Exception
-    {
-        System.out.println("activate...");
-        this.bundleContext = context;
-
-        context.addBundleListener(this);
-
-        // get all the currently installed bundles.
-        final Bundle[] bundles = context.getBundles();
-        for (final Bundle bundle : bundles)
-        {
-            if ((bundle.getState() & (Bundle.STARTING | Bundle.ACTIVE)) != 0)
-            {
-                // register and deploy the bundles that are esb bundles.
-                registry.register(bundle);
-            }
-        }
-    }
-
-    /**
-     * Stops this bundle.
-     * Will close the underlying registry of DeploymentRuntime, going
-     * through them and undeploying them.
-     *
-     * @param unused The bundle context.
-     * @throws Exception If an exception occurs during startup.
-     */
-    public final void stop(final BundleContext unused) throws Exception
-    {
-        registry.close();
-    }
-}




More information about the jboss-svn-commits mailing list