[jboss-svn-commits] JBL Code SVN: r23350 - in labs/jbossesb/workspace/skeagh: osgi and 14 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Oct 7 10:28:16 EDT 2008


Author: beve
Date: 2008-10-07 10:28:15 -0400 (Tue, 07 Oct 2008)
New Revision: 23350

Added:
   labs/jbossesb/workspace/skeagh/osgi/
   labs/jbossesb/workspace/skeagh/osgi/osgi.bnd
   labs/jbossesb/workspace/skeagh/osgi/pom.xml
   labs/jbossesb/workspace/skeagh/osgi/src/
   labs/jbossesb/workspace/skeagh/osgi/src/main/
   labs/jbossesb/workspace/skeagh/osgi/src/main/java/
   labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/
   labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/
   labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/
   labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/
   labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java
   labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceActivator.java
   labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java
   labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceFactory.java
   labs/jbossesb/workspace/skeagh/osgi/src/main/resources/
   labs/jbossesb/workspace/skeagh/osgi/src/test/
   labs/jbossesb/workspace/skeagh/osgi/src/test/java/
   labs/jbossesb/workspace/skeagh/osgi/src/test/java/org/
   labs/jbossesb/workspace/skeagh/osgi/src/test/java/org/jboss/
   labs/jbossesb/workspace/skeagh/osgi/src/test/java/org/jboss/esb/
   labs/jbossesb/workspace/skeagh/osgi/src/test/java/org/jboss/esb/osgi/
   labs/jbossesb/workspace/skeagh/osgi/src/test/java/org/jboss/esb/osgi/EsbServiceFactoryTest.java
   labs/jbossesb/workspace/skeagh/osgi/src/test/resources/
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DefaultResourceLocator.java
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/IDeploymentRuntime.java
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/ResourceLocator.java
Modified:
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DeploymentRuntime.java
Log:
Added the osgi module. this is in a prototyp status.
Updated the runtime with a suggestion for solving the resources issue.


Added: labs/jbossesb/workspace/skeagh/osgi/osgi.bnd
===================================================================
--- labs/jbossesb/workspace/skeagh/osgi/osgi.bnd	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/osgi/osgi.bnd	2008-10-07 14:28:15 UTC (rev 23350)
@@ -0,0 +1,10 @@
+#-----------------------------------------------------------------
+# Use this file to add customized Bnd instructions for the bundle
+#-----------------------------------------------------------------
+Export-Package: org.jboss.esb.osgi.*
+Bundle-Activator: org.jboss.esb.osgi.EsbServiceDeploymentActivator
+Import-Package: *;resolution:=optional
+
+Embed-Dependency: *;scope=compile|runtime;artifactId=!xercesImpl|jbossesb-api-service|jbossesb-api-routing|jbossesb-commons|log4j;inline=false
+Embed-Transitive: true
+

Added: labs/jbossesb/workspace/skeagh/osgi/pom.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/osgi/pom.xml	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/osgi/pom.xml	2008-10-07 14:28:15 UTC (rev 23350)
@@ -0,0 +1,30 @@
+<?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">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>jboss.jbossesb</groupId>
+        <artifactId>jbossesb</artifactId>
+        <version>5.0-SNAPSHOT</version>
+    </parent>
+    <groupId>jboss.jbossesb</groupId>
+    <artifactId>jbossesb-osgi</artifactId>
+    <packaging>bundle</packaging>
+    <version>5.0-SNAPSHOT</version>
+    <name>Jboss ESB OSGi</name>
+    <url>http://www.jboss.org/jbossesb/</url>
+
+    <dependencies>
+        <dependency>
+            <groupId>jboss.jbossesb</groupId>
+            <artifactId>jbossesb-rt</artifactId>
+            <version>${jboss.esb.version}</version>
+        </dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>osgi_R4_core</artifactId>
+			<version>1.0</version>
+		</dependency>
+    </dependencies>
+
+</project>

Added: labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java
===================================================================
--- labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/BundleResourceLocator.java	2008-10-07 14:28:15 UTC (rev 23350)
@@ -0,0 +1,114 @@
+/*
+ * 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.deploy.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 context - the OSGi BundleContext.
+     */
+    public BundleResourceLocator(final Bundle context)
+    {
+        this.bundle = context;
+    }
+
+    /**
+     * Load the specified class using the passed in class's classloader.
+     *
+     * @param className The name of the class to load.
+     * @param caller    The class of the caller.
+     * @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
+    {
+        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 classpath.
+     *
+     * @param resourceName - the name of the resource to be retrieved.
+     * @return InputStream - the InputStream for the resource.
+     * @throws IOException - if an IOExcpetion occurs while trying to access the resource.
+     */
+    public final InputStream getResourceAsStream(final String resourceName) throws IOException
+    {
+        final URL entry = bundle.getEntry(resourceName);
+        if (entry == null)
+        {
+            return null;
+        }
+
+        return entry.openStream();
+    }
+
+    /**
+     * 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.
+     * @throws IOException - if an IOExcpetion occurs while trying to access the resource.
+     */
+    public final InputStream getResourceAsStream(final String resourceName, final Class<?> caller) throws IOException
+    {
+        return caller.getClassLoader().getResourceAsStream(resourceName);
+    }
+
+}

Added: labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceActivator.java
===================================================================
--- labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceActivator.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceActivator.java	2008-10-07 14:28:15 UTC (rev 23350)
@@ -0,0 +1,85 @@
+/*
+ * 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.jboss.esb.deploy.IDeploymentRuntime;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * EsbServiceActivator is an OSGi Activator that takes care
+ * of deploying the ESB configuration for this bundle.
+ * <p>
+ *
+ * This is intended to be used by users bundles. Users package
+ * their transformers/routers/services/configuration properties in a
+ * bundle and specify the following OSGi header: <br>
+ * <pre>{@code
+ * Bundle-Activator: org.jboss.esb.osgi.EsbServiceActivator
+ * }</pre>
+ * <p>
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ */
+public class EsbServiceActivator implements BundleActivator
+{
+    /**
+     * OSGi ServiceTracker.
+     */
+    private ServiceTracker esbServiceTracker;
+
+    /**
+     * Deploy the ESB Service.
+     *
+     * @param context - the OSGi bunlde context.
+     * @throws Exception if an exception occurs.
+     */
+    public final void start(final BundleContext context) throws Exception
+    {
+        esbServiceTracker = new ServiceTracker(context, IDeploymentRuntime.class.getName(), null);
+        esbServiceTracker.open();
+
+        final IDeploymentRuntime runtime = (IDeploymentRuntime)esbServiceTracker.getService();
+        if (runtime != null)
+        {
+            runtime.deploy();
+        }
+    }
+
+    /**
+     * Undeploy the ESB service.
+     *
+     * @param context - the OSGi bunlde context.
+     * @throws Exception if an exception occurs.
+     */
+    public final void stop(final BundleContext context) throws Exception
+    {
+        final IDeploymentRuntime runtime = (IDeploymentRuntime)esbServiceTracker.getService();
+        if (runtime != null)
+        {
+            runtime.undeploy();
+        }
+
+        esbServiceTracker.close();
+    }
+
+}

Added: labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java
===================================================================
--- labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceDeploymentActivator.java	2008-10-07 14:28:15 UTC (rev 23350)
@@ -0,0 +1,60 @@
+/*
+ * 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.jboss.esb.deploy.IDeploymentRuntime;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * EsbServiceDeploymentActivator is an OSGi Activator that takes care
+ * registering the EsbServiceDeployer service.
+ * <p>
+ * It actually registers an instance of {@link EsbServiceFactory} using
+ * the FQN of {@link IDeploymentRuntime}.
+ *
+ * @see EsbServiceFactory
+ * @see EsbServiceActivator
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ */
+public class EsbServiceDeploymentActivator implements BundleActivator
+{
+    /**
+     * Start the deployer.
+     *
+     * @param context - the OSGi bundle context.
+     * @throws Exception if an exception occurs.
+     */
+    public final void start(final BundleContext context) throws Exception
+    {
+        final EsbServiceFactory esbService = new EsbServiceFactory();
+        context.registerService(IDeploymentRuntime.class.getName(), esbService, null);
+    }
+
+    /**
+     * @param context - the OSGi bunlde context.
+     * @throws Exception if an exception occurs.
+     */
+    public final void stop(final BundleContext context) throws Exception
+    {
+    }
+}

Added: labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceFactory.java
===================================================================
--- labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceFactory.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/osgi/src/main/java/org/jboss/esb/osgi/EsbServiceFactory.java	2008-10-07 14:28:15 UTC (rev 23350)
@@ -0,0 +1,69 @@
+/*
+ * 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.jboss.esb.deploy.DeploymentRuntime;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * EsbServiceFactory is a ServiceFactory implementation that creates a
+ * {@link DeploymentRuntime} and passing a newly created instance of
+ * {@link BundleResourceLocator}.
+ * <p>
+ * When a bundle looks up a service an instance of a ServiceFactory
+ * can be bound instead and this particular factory will create
+ * a DeploymentRuntime with a BundleResourceLocator specific to the
+ * current bundle.
+ * <p>
+ *
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ */
+public class EsbServiceFactory implements ServiceFactory
+{
+    /**
+     * Creates a DeploymentRuntime and passes it a newly created BundleResourceLocator
+     * specific to the bundle calling getService().
+     *
+     * @param bundle - the OSGi bundle that is calling this method.
+     * @param registration - the service registration.
+     * @return Object - the service.
+     */
+    public final Object getService(final Bundle bundle, final ServiceRegistration registration)
+    {
+        BundleResourceLocator bundleResourceLocator = new BundleResourceLocator(bundle);
+        return new DeploymentRuntime(bundleResourceLocator);
+    }
+
+    /**
+     * Unget the service.
+     *
+     * @param bundle - the OSGi bundle that is calling this method.
+     * @param registration - the service registration.
+     * @param service - the service to unget.
+     */
+    public final void ungetService(final Bundle bundle, final ServiceRegistration registration, final Object service)
+    {
+        // NoOp
+    }
+
+}

Added: labs/jbossesb/workspace/skeagh/osgi/src/test/java/org/jboss/esb/osgi/EsbServiceFactoryTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/osgi/src/test/java/org/jboss/esb/osgi/EsbServiceFactoryTest.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/osgi/src/test/java/org/jboss/esb/osgi/EsbServiceFactoryTest.java	2008-10-07 14:28:15 UTC (rev 23350)
@@ -0,0 +1,39 @@
+/*
+ * 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.junit.Test;
+
+/**
+ * Test for {@link EsbServiceFactory}.
+ *
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class EsbServiceFactoryTest
+{
+    @Test
+    public void getService()
+    {
+       EsbServiceFactory serviceFactory = new EsbServiceFactory();
+    }
+
+}

Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DefaultResourceLocator.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DefaultResourceLocator.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DefaultResourceLocator.java	2008-10-07 14:28:15 UTC (rev 23350)
@@ -0,0 +1,94 @@
+/*
+ * 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.deploy;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.jboss.esb.classpath.ClassUtil;
+
+/**
+ * Default resource locator works like you would expect a traditional
+ * Java resource locator.
+ * <p/>
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class DefaultResourceLocator implements ResourceLocator
+{
+
+    /**
+     * Simply delegates to {@link ClassUtil#forName(String, Class)} and passes this
+     * classes class as the second argument.
+     *
+     * @param className - the class to load.
+     * @return Class - the loaded class.
+     * @throws ClassNotFoundException - if the class could not be found.
+     */
+    public final Class<?> forName(final String className) throws ClassNotFoundException
+    {
+        return ClassUtil.forName(className, getClass());
+    }
+
+    /**
+     * Simply delegates to {@link ClassUtil#forName(String, Class)} and passes this
+     * classes class as the second argument.
+     *
+     * @param className - the class to load.
+     * @return Class - the loaded class.
+     * @param caller - the class which should be used as the callers class.
+     * @throws ClassNotFoundException - if the class could not be found.
+     */
+    public final Class<?> forName(final String className, final Class<?> caller) throws ClassNotFoundException
+    {
+       return ClassUtil.forName(className, caller);
+    }
+
+    /**
+     * Simply delegates to {@link ClassUtil#getResourceAsStream(String, Class)} and passes this
+     * classes class as the second argument.
+     *
+     * @param resourceName - the name of the resource to locate.
+     * @return InputStream - the input stream for the resource.
+     * @throws IOException - if the resource could not be located.
+     */
+    public final InputStream getResourceAsStream(final String resourceName) throws IOException
+    {
+        return ClassUtil.getResourceAsStream(resourceName, getClass());
+    }
+
+    /**
+     * Simply delegates to {@link ClassUtil#getResourceAsStream(String, Class)}.
+     * classes class as the second argument.
+     *
+     * @param resourceName - the name of the resource to locate.
+     * @param caller - the class which should be used as the callers class.
+     * @return InputStream - the input stream for the resource.
+     * @throws IOException - if the resource could not be located.
+     *
+     */
+    public final InputStream getResourceAsStream(final String resourceName, final Class<?> caller) throws IOException
+    {
+        return ClassUtil.getResourceAsStream(resourceName, caller);
+    }
+
+}

Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DeploymentRuntime.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DeploymentRuntime.java	2008-10-07 14:16:03 UTC (rev 23349)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DeploymentRuntime.java	2008-10-07 14:28:15 UTC (rev 23350)
@@ -69,7 +69,7 @@
  *
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */
-public class DeploymentRuntime
+public class DeploymentRuntime implements IDeploymentRuntime
 {
     /**
      * Class logger.
@@ -135,6 +135,31 @@
     private DeploymentCoordinator deploymentCoordinator;
 
     /**
+     * ResourceLocator that will be used by this instance.
+     */
+    private ResourceLocator resourceLocator;
+
+    /**
+     * Constructs a DeploymentRuntime and sets its {@link ResourceLocator}
+     * to {@link DefaultResourceLocator}.
+     */
+    public DeploymentRuntime()
+    {
+        resourceLocator = new DefaultResourceLocator();
+    }
+
+    /**
+     * Constructs a DeploymentRuntime and sets its {@link ResourceLocator}
+     * to the passed in resource locator instance.
+     *
+     * @param resourceLocator - the resource locator to be used.
+     */
+    public DeploymentRuntime(final ResourceLocator resourceLocator)
+    {
+        this.resourceLocator = resourceLocator;
+    }
+
+    /**
      * Get the deployment name.
      *
      * @return The deployment name.

Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/IDeploymentRuntime.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/IDeploymentRuntime.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/IDeploymentRuntime.java	2008-10-07 14:28:15 UTC (rev 23350)
@@ -0,0 +1,23 @@
+package org.jboss.esb.deploy;
+
+/**
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public interface IDeploymentRuntime
+{
+    /**
+     * Deploy an Esb Service.
+     *
+     * @throws DeploymentException if error occurs during deployment
+     */
+    void deploy() throws DeploymentException;
+
+    /**
+     * Undeploy an Esb Service.
+     *
+     * @throws DeploymentException if error occurs during undeployment
+     */
+    void undeploy() throws DeploymentException;
+}

Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/ResourceLocator.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/ResourceLocator.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/ResourceLocator.java	2008-10-07 14:28:15 UTC (rev 23350)
@@ -0,0 +1,75 @@
+/*
+ * 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.deploy;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * A ResourceLocator is intended to be used by any code in the ESB
+ * that needs to access resources from a deployment.
+ * <p/>
+ * Different implementations can use different means to retreive
+ * the resources.
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public interface ResourceLocator
+{
+    /**
+     * Load the specified class.
+     *
+     * @param className The name of the class to load.
+     * @return The specified class.
+     * @throws ClassNotFoundException If the class cannot be found.
+     */
+    Class<?> forName(final String className) throws ClassNotFoundException;
+
+    /**
+     * Load the specified class using the passed in class's classloader.
+     *
+     * @param className The name of the class to load.
+     * @param caller    The class of the caller.
+     * @return The specified class.
+     * @throws ClassNotFoundException If the class cannot be found.
+     */
+    Class<?> forName(final String className, final Class<?> caller) throws ClassNotFoundException;
+
+    /**
+     * Get a resource from classpath.
+     *
+     * @param resourceName - the name of the resource to be retrieved.
+     * @return InputStream - the InputStream for the resource.
+     * @throws IOException - if an IOExcpetion occurs while trying to access the resource.
+     */
+    InputStream getResourceAsStream(final String resourceName) throws IOException;
+
+    /**
+     * 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.
+     * @throws IOException - if an IOExcpetion occurs while trying to access the resource.
+     */
+    InputStream getResourceAsStream(final String resourceName, final Class<?> caller) throws IOException;
+}




More information about the jboss-svn-commits mailing list