[jboss-cvs] JBossAS SVN: r59512 - in trunk: embedded/src/main/java/org/jboss/embedded and 13 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 11 02:01:28 EST 2007


Author: bill.burke at jboss.com
Date: 2007-01-11 02:01:21 -0500 (Thu, 11 Jan 2007)
New Revision: 59512

Added:
   trunk/embedded/src/main/java/org/jboss/embedded/DeploymentGroup.java
   trunk/embedded/src/main/java/org/jboss/embedded/DeploymentGroupBean.java
   trunk/embedded/src/main/java/org/jboss/embedded/WebInfLibScanner.java
   trunk/embedded/src/main/java/org/jboss/embedded/jndi/
   trunk/embedded/src/main/java/org/jboss/embedded/jndi/BridgeContext.java
   trunk/embedded/src/main/java/org/jboss/embedded/jndi/DelegatingContextFactory.java
   trunk/embedded/src/main/java/org/jboss/embedded/jndi/KernelInitializingContextFactory.java
   trunk/embedded/src/main/java/org/jboss/embedded/jndi/WrappingContext.java
   trunk/embedded/src/main/java/org/jboss/embedded/tomcat/
   trunk/embedded/src/main/java/org/jboss/embedded/tomcat/EmbeddedJBossBootstrapListener.java
   trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/
   trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/ENCFactory.java
   trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/KernelInitializingContextFactory.java
   trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/TomcatBridgeContextFactory.java
   trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/java/
   trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/java/javaURLContextFactory.java
   trunk/embedded/src/main/java/org/jboss/embedded/url/
   trunk/embedded/src/main/java/org/jboss/embedded/url/BridgeHandlerFactory.java
   trunk/embedded/src/main/java/org/jboss/embedded/url/HandlerFactoryHack.java
   trunk/embedded/src/main/java/org/jboss/embedded/url/JavaProtocolHandlerPkgs.java
   trunk/embedded/src/main/resources/tomcat-jndi.properties
   trunk/embedded/src/test/java/org/jboss/embedded/test/jndibootstrap/
   trunk/embedded/src/test/java/org/jboss/embedded/test/jndibootstrap/unit/
   trunk/embedded/src/test/java/org/jboss/embedded/test/jndibootstrap/unit/BootstrapTestCase.java
Removed:
   trunk/embedded/src/main/java/org/jboss/embedded/Test.java
Modified:
   trunk/embedded/build-test.xml
   trunk/embedded/build.xml
   trunk/embedded/src/main/java/org/jboss/embedded/Bootstrap.java
   trunk/embedded/src/main/java/org/jboss/embedded/ClasspathResourceScanner.java
   trunk/embedded/src/main/java/org/jboss/embedded/JMXKernel.java
   trunk/embedded/src/main/java/org/jboss/embedded/ServerConfig.java
   trunk/embedded/src/main/resources/javase/conf/bootstrap-beans.xml
   trunk/embedded/src/main/resources/javase/conf/jboss-service.xml
   trunk/embedded/src/main/resources/javase/log4j.xml
   trunk/embedded/src/test/java/org/jboss/embedded/test/ejb/unit/EjbTestCase.java
   trunk/server/src/main/org/jboss/naming/ENCFactory.java
   trunk/server/src/main/org/jboss/naming/JavaCompInitializer.java
Log:
more refactoring

Modified: trunk/embedded/build-test.xml
===================================================================
--- trunk/embedded/build-test.xml	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/build-test.xml	2007-01-11 07:01:21 UTC (rev 59512)
@@ -158,6 +158,7 @@
       <jar jarfile="${build.lib}/bootstrap-test.jar">
          <fileset dir="${build.classes}">
             <include name="org/jboss/embedded/test/bootstrap/**/*.class"/>
+            <include name="org/jboss/embedded/test/jndibootstrap/**/*.class"/>
          </fileset>
       </jar>
       <jar jarfile="${build.lib}/ejb-test.jar">

Modified: trunk/embedded/build.xml
===================================================================
--- trunk/embedded/build.xml	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/build.xml	2007-01-11 07:01:21 UTC (rev 59512)
@@ -93,6 +93,7 @@
          <path refid="quartz.quartz.classpath"/>
          <path refid="jboss.jbossws.classpath"/>
          <path refid="jboss.jbossxb.classpath"/>
+         <path refid="jboss.web.classpath"/>
          <path refid="jacorb.jacorb.classpath"/>
          <!-- FIXME: temporary for EJBTHREE-485 -->
          <path refid="cglib.classpath"/>
@@ -278,9 +279,16 @@
          </fileset>
       </copy>
 
+      <jar jarfile="${build.lib}/embedded-jboss/lib/jboss-embedded-tomcat-bootstrap.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/embedded/tomcat/EmbeddedJBossBootstrapListener.class"/>
+         </fileset>
+      </jar>
+
       <jar jarfile="${build.lib}/embedded-jboss/lib/jboss-embedded-all.jar">
          <fileset dir="${build.classes}">
             <include name="org/jboss/**"/>
+            <exclude name="org/jboss/embedded/tomcat/EmbeddedJBossBootstrapListener.class"/>
          </fileset>
          <fileset dir="../ejb3/src/resources">
             <include name="META-INF/persistence.properties"/>

Modified: trunk/embedded/src/main/java/org/jboss/embedded/Bootstrap.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/Bootstrap.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/Bootstrap.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -21,22 +21,23 @@
 */
 package org.jboss.embedded;
 
-import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
-import org.jboss.kernel.plugins.deployment.xml.BeanXMLDeployer;
-import org.jboss.kernel.Kernel;
-import org.jboss.deployers.spi.deployment.MainDeployer;
-import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.deployers.plugins.structure.AbstractDeploymentContext;
 import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.IncompleteDeploymentException;
 import org.jboss.deployers.spi.IncompleteDeployments;
 import org.jboss.deployers.spi.IncompleteDeploymentsBuilder;
-import org.jboss.deployers.spi.IncompleteDeploymentException;
-import org.jboss.deployers.plugins.structure.AbstractDeploymentContext;
-import org.jboss.virtual.VirtualFile;
+import org.jboss.deployers.spi.deployment.MainDeployer;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.deployment.xml.BeanXMLDeployer;
 import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
 
-import java.net.URL;
-import java.io.IOException;
 import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.StringTokenizer;
 
 /**
@@ -47,11 +48,28 @@
  */
 public class Bootstrap
 {
-   private String bootstrap = "conf/bootstrap-beans.xml";
+   public static final String BOOTSTRAP_RESOURCE_PATH="jboss.embedded.bootstrap.resource.path";
+   public static final String BOOTSTRAP_RESOURCE_FILE="conf/bootstrap-beans.xml";
+
    private Kernel kernel;
    private ClassLoader loader = Thread.currentThread().getContextClassLoader();
    private MainDeployer mainDeployer;
 
+
+
+   private static Bootstrap instance;
+
+   /**
+    * For those applications that need a singelton Bootstrap instance
+    *
+    * @return
+    */
+   public static synchronized Bootstrap getInstance()
+   {
+      if (instance == null) instance = new Bootstrap();
+      return instance;
+   }
+
    public Bootstrap()
    {
       kernel = createKernel();
@@ -63,16 +81,15 @@
       this.kernel = kernel;
    }
 
-
-   public String getBootstrap()
+   public DeploymentGroup createDeploymentGroup()
    {
-      return bootstrap;
+      DeploymentGroup group = new DeploymentGroup();
+      group.setClassLoader(loader);
+      group.setMainDeployer(mainDeployer);
+      group.setKernel(kernel);
+      return group;
    }
 
-   public void setBootstrap(String bootstrap)
-   {
-      this.bootstrap = bootstrap;
-   }
 
    public Kernel getKernel()
    {
@@ -94,6 +111,7 @@
       this.loader = loader;
    }
 
+
    private static Kernel createKernel()
    {
       BasicBootstrap bootstrap1 = new BasicBootstrap();
@@ -113,13 +131,10 @@
          throw new IncompleteDeploymentException(incomplete);
    }
 
-
-   
-   public void bootstrap() throws DeploymentException
+   protected void bootstrapURL(URL url) throws DeploymentException
    {
       try
       {
-         URL url = loader.getResource(bootstrap);
          BeanXMLDeployer deployer = new BeanXMLDeployer(kernel);
          deployer.deploy(url);
          deployer.validate();
@@ -130,116 +145,56 @@
          throw new RuntimeException("Unable to bootstrap: ", throwable);
       }
       checkIncomplete();
-   }
 
-   public void shutdown()
-   {
-      mainDeployer.shutdown();
    }
 
    /**
-    * Deploy a file based on its URL
     *
-    * @param url
-    * @throws DeploymentException
-    */
-   public void deploy(URL url) throws DeploymentException
-   {
-      VirtualFile file = null;
-      try
-      {
-         file = VFS.getRoot(url);
-      }
-      catch (IOException e)
-      {
-         throw new DeploymentException("Unable to get VirtualFile for url: " + url, e);
-      }
-      DeploymentContext deployment = new AbstractDeploymentContext(file);
-      mainDeployer.addDeploymentContext(deployment);
-      mainDeployer.process();
-   }
+    * Specify top classpath resource directory where base JBoss Embedded directory structure is.
 
-   /**
-    * Scan all paths/jars in Java CLasspath (found with java.class.path System Property)
+    * The Embedded JBoss directory structure is determined by extrapolating a directory from a base
+    * classpath resource.
+
+    * The absolute directory will be determined by doing
+    *   classloader.getResource(bootstrapResourcePath + "conf/bootstrap-beans.xml")
     *
     *
+    * @param bootstrapResourcePath
     * @throws DeploymentException
     */
-   public void scanClasspath() throws DeploymentException
+   public void bootstrap(String bootstrapResourcePath) throws DeploymentException
    {
-      String classpath = System.getProperty("java.class.path");
-      StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
-
-      while (tokenizer.hasMoreTokens())
+      if (bootstrapResourcePath == null)
       {
-         String path = tokenizer.nextToken();
-         File fp = new File(path);
-         if (!fp.exists()) throw new DeploymentException("File in java.class.path does not exist: " + fp);
-         VirtualFile file = null;
-         try
-         {
-            URL url = fp.toURL();
-            file = VFS.getRoot(url);
-         }
-         catch (Exception e)
-         {
-            throw new DeploymentException("Unable to get VirtualFile for file: " + fp, e);
-         }
-         DeploymentContext deployment = new AbstractDeploymentContext(file);
-         mainDeployer.addDeploymentContext(deployment);
+         bootstrapResourcePath = "";
       }
-      mainDeployer.process();
+      else if (!bootstrapResourcePath.equals("") && !bootstrapResourcePath.endsWith("/"))
+      {
+         bootstrapResourcePath += "/";
+      }
+      System.setProperty(BOOTSTRAP_RESOURCE_PATH, bootstrapResourcePath);
+      bootstrapResourcePath += BOOTSTRAP_RESOURCE_FILE;
+      URL url = loader.getResource(bootstrapResourcePath);
+      if (url == null) throw new DeploymentException("Unable to find bootstrap file: " + bootstrapResourcePath + " in classpath");
+      bootstrapURL(url);
    }
 
 
    /**
-    * Scan Java Classpath (found with java.class.path)
-    * for a specified list of files you want to deploy
+    * Will obtain resource path from jboss.embedded.bootstrap.resource.path System Property.
+    * Otherwise it just invoked bootstrap(String bootstrapResourcePath) with ""
     *
-    * The files listed should be only the filename.  Do not put relative or absolute paths in filenames.
-    * i.e. "myejbs.jar, my-beans.xml"
-    *
-    * @param paths comma delimited list of files
     * @throws DeploymentException
     */
-   public void scanClasspath(String paths) throws DeploymentException
+   public void bootstrap() throws DeploymentException
    {
-      String classpath = System.getProperty("java.class.path");
-      StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
-      String[] split = paths.split(",");
-      for (int i = 0; i < split.length; i++)
-      {
-         split[i] = split[i].trim();
-      }
+      String path = System.getProperty(BOOTSTRAP_RESOURCE_PATH, "");
+      bootstrap(path);
+   }
 
-      while (tokenizer.hasMoreTokens())
-      {
-         String path = tokenizer.nextToken().trim();
-         boolean found = false;
-         for (String wantedPath : split)
-         {
-            if (path.endsWith(System.getProperty("file.separator") + wantedPath))
-            {
-               found = true;
-               break;
-            }
-         }
-         if (!found) continue;
-         File fp = new File(path);
-         if (!fp.exists()) throw new DeploymentException("File in java.class.path does not exists: " + fp);
-         VirtualFile file = null;
-         try
-         {
-            URL url = fp.toURL();
-            file = VFS.getRoot(url);
-         }
-         catch (Exception e)
-         {
-            throw new DeploymentException("Unable to get VirtualFile for file: " + fp, e);
-         }
-         DeploymentContext deployment = new AbstractDeploymentContext(file);
-         mainDeployer.addDeploymentContext(deployment);
-      }
-      mainDeployer.process();
+   public void shutdown()
+   {
+      mainDeployer.shutdown();
    }
-}
+
+ }
\ No newline at end of file

Modified: trunk/embedded/src/main/java/org/jboss/embedded/ClasspathResourceScanner.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/ClasspathResourceScanner.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/ClasspathResourceScanner.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -21,17 +21,17 @@
 */
 package org.jboss.embedded;
 
+import org.jboss.deployers.plugins.structure.AbstractDeploymentContext;
 import org.jboss.deployers.spi.deployment.MainDeployer;
 import org.jboss.deployers.spi.structure.DeploymentContext;
-import org.jboss.deployers.plugins.structure.AbstractDeploymentContext;
-import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.VirtualFileFilter;
 
+import java.io.IOException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
-import java.net.URL;
-import java.io.IOException;
 
 /**
  * comment
@@ -150,89 +150,6 @@
    }
 
 
-   /**
-    * Find the directory that contains a given resource.
-    * <p/>
-    * The '.' character can be used to specify the current directory.
-    * The '..' string can be used to specify a higher relative path
-    * <p/>
-    * i.e.
-    * <p/>
-    * getDirFromResource(loader, "org/jboss/Test.class")
-    * file:/<root>/org/jboss/
-    * <p/>
-    * getDirFromResource(loader, "org/jboss/Test.class/..")
-    * file:/<root>/org/
-    * <p/>
-    * getDirFromResource(loader, "org/jboss/Test.class/../acme")
-    * file:/<root>/org/acme/
-    * <p/>
-    * getDirFromResource(loader, "org/jboss/Test.class/./embedded")
-    * file:/<root>/org/jboss/embedded/
-    *
-    * @param loader
-    * @param resource
-    * @return
-    * @throws Exception
-    */
-   public static URL getDirFromResource(ClassLoader loader, String resource) throws Exception
-   {
-      int idx = resource.indexOf("/.");
-      String base = resource;
-      String relative = null;
-      if (idx != -1)
-      {
-         base = resource.substring(0, idx);
-         relative = resource.substring(idx + 1);
-      }
-      URL url = loader.getResource(base);
-      if (url == null) return null;
-      String urlAsString = url.toString();
-      String[] paths = urlAsString.split("/");
-      int last = paths.length - 2;
-      if (relative != null)
-      {
-         String[] relativePaths = relative.split("/");
-         int relativeStart = 0;
-         for (String relativePath : relativePaths)
-         {
-            if (relativePath.equals(".."))
-            {
-               last--;
-               relativeStart++;
-            }
-            else if (relativePath.equals("."))
-            {
-               relativeStart++;
-            }
-            else
-            {
-               break;
-            }
-         }
-         urlAsString = "";
-         for (int i = 0; i <= last; i++)
-         {
-            urlAsString += paths[i] + "/";
-         }
-         for (int i = relativeStart; i < relativePaths.length; i++)
-         {
-            urlAsString += relativePaths[i] + "/";
-         }
-      }
-      else
-      {
-         urlAsString = "";
-         for (int i = 0; i <= last; i++)
-         {
-            urlAsString += paths[i] + "/";
-         }
-
-      }
-      url = new URL(urlAsString);
-      return url;
-   }
-
    public void start() throws Exception
    {
       if (classLoader == null) classLoader = Thread.currentThread().getContextClassLoader();
@@ -259,7 +176,7 @@
       {
          for (String deployDir : deployDirsByResource)
          {
-            URL url = getDirFromResource(classLoader, deployDir);
+            URL url = DeploymentGroupBean.getDirFromResource(classLoader, deployDir);
             if (url == null)
             {
                throw new Exception("Unable to find deployDir from resource: " + deployDir);

Added: trunk/embedded/src/main/java/org/jboss/embedded/DeploymentGroup.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/DeploymentGroup.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/DeploymentGroup.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,530 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded;
+
+import org.jboss.deployers.spi.deployment.MainDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.IncompleteDeployments;
+import org.jboss.deployers.spi.IncompleteDeploymentsBuilder;
+import org.jboss.deployers.spi.IncompleteDeploymentException;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.deployers.plugins.structure.AbstractDeploymentContext;
+import org.jboss.kernel.Kernel;
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFS;
+
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.Enumeration;
+import java.util.ArrayList;
+import java.io.IOException;
+import java.io.File;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeploymentGroup
+{
+   private ArrayList<DeploymentContext> deployments = new ArrayList<DeploymentContext>();
+   protected MainDeployer mainDeployer;
+   protected Kernel kernel;
+   private VirtualFileFilter filter;
+   private ClassLoader classLoader;
+
+   public void setMainDeployer(MainDeployer mainDeployer)
+   {
+      this.mainDeployer = mainDeployer;
+   }
+
+   public void setKernel(Kernel kernel)
+   {
+      this.kernel = kernel;
+   }
+
+
+   /**
+    *
+    * File filter that will be used when scanning a directory
+    *
+    * @param filter
+    */
+   public void setFilter(VirtualFileFilter filter)
+   {
+      this.filter = filter;
+   }
+
+   public void setClassLoader(ClassLoader classLoader)
+   {
+      this.classLoader = classLoader;
+   }
+
+   /**
+    * A helper to find all deployments under a directory vf
+    * and add them to the supplied list.
+    *
+    * We may recurse.
+    */
+   private void addDeployments(List<VirtualFile> list, VirtualFile root, boolean recurse)
+      throws IOException
+   {
+      List<VirtualFile> components = root.getChildren();
+
+      for (VirtualFile component : components)
+      {
+         // Filter the component regardless of its type
+         if( filter != null && filter.accepts(component) == false)
+            continue;
+         if (component.isLeaf())
+         {
+            list.add(component);
+         }
+         // TODO replace . in the name with isArchive() == false?
+         else if (component.getName().indexOf('.') == -1 && recurse)
+         {
+            // recurse if not '.' in name and recursive search is enabled
+            addDeployments(list, component, true);
+         }
+         else
+         {
+            list.add(component);
+         }
+      }
+   }
+
+   /**
+    * Ask the mainDeployer to process the set of files you added to the group
+    * this will also check the processing
+    *
+    * @throws org.jboss.deployers.spi.DeploymentException
+    */
+   public void process() throws DeploymentException
+   {
+      mainDeployer.process();
+      checkIncomplete();
+   }
+
+   /**
+    *  Ask the mainDeployer to undeploy the set of files in the group
+    *
+    * @throws org.jboss.deployers.spi.DeploymentException
+    */
+   public void undeploy() throws DeploymentException
+   {
+      for (DeploymentContext ctx : deployments)
+      {
+         mainDeployer.removeDeploymentContext(ctx.getName());
+      }
+      process();
+   }
+
+   protected void checkIncomplete() throws DeploymentException
+   {
+      IncompleteDeployments incomplete = IncompleteDeploymentsBuilder.build(mainDeployer, kernel.getController());
+      if (incomplete.isIncomplete())
+         throw new IncompleteDeploymentException(incomplete);
+   }
+
+   /**
+    * Schedule a VirtualFile to be deployed
+    *
+    * @param vf
+    * @throws DeploymentException
+    */
+   public void add(VirtualFile vf) throws DeploymentException
+   {
+      DeploymentContext deployment = new AbstractDeploymentContext(vf);
+      mainDeployer.addDeploymentContext(deployment);
+      deployments.add(deployment);
+   }
+
+   /**
+    * convenience function adds and processes.
+    *
+    * @param url
+    * @throws DeploymentException
+    */
+   public void deploy(URL url) throws DeploymentException
+   {
+      add(url);
+      process();
+   }
+
+   /**
+    * schedules a URL to be deployed
+    *
+    * @param url
+    * @throws DeploymentException
+    */
+   public void add(URL url) throws DeploymentException
+   {
+      VirtualFile file = null;
+      try
+      {
+         file = VFS.getRoot(url);
+      }
+      catch (IOException e)
+      {
+         throw new DeploymentException("Unable to get VirtualFile for url: " + url, e);
+      }
+      add(file);
+   }
+
+   /**
+    * schedules a list of virtual files to be deployed
+    *
+    * @param vfs
+    * @throws DeploymentException
+    */
+   public void addVirtualFiles(List<VirtualFile> vfs) throws DeploymentException
+   {
+      for (VirtualFile vf : vfs)
+      {
+         add(vf);
+      }
+   }
+
+   /**
+    * schedules a list of urls to be deployed
+    *
+    * @param urls
+    * @throws DeploymentException
+    */
+   public void addUrls(List<URL> urls) throws DeploymentException
+   {
+      for (URL url : urls)
+      {
+         add(url);
+      }
+   }
+
+   /**
+    * Scan all paths/jars in Java CLasspath (found with java.class.path System Property)
+    * schedule these jars to be deployed
+    *
+    * @throws org.jboss.deployers.spi.DeploymentException
+    */
+   public void addClasspath() throws DeploymentException
+   {
+      String classpath = System.getProperty("java.class.path");
+      StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
+
+      while (tokenizer.hasMoreTokens())
+      {
+         String path = tokenizer.nextToken();
+         File fp = new File(path);
+         if (!fp.exists()) throw new DeploymentException("File in java.class.path does not exist: " + fp);
+         try
+         {
+            add(fp.toURL());
+         }
+         catch (MalformedURLException e)
+         {
+            throw new DeploymentException(e);
+         }
+      }
+   }
+
+   /**
+    *  convience function.  Same as addClasspath() but it processes deployments
+    *
+    * @throws DeploymentException
+    */
+   public void scanClasspath() throws DeploymentException
+   {
+      addClasspath();
+      process();
+   }
+
+   /**
+    * Scan Java Classpath (found with java.class.path)
+    * for a specified list of files you want to deploy
+    *
+    * The files listed should be only the filename.  Do not put relative or absolute paths in filenames.
+    * i.e. "myejbs.jar, my-beans.xml"
+    *
+    * @param paths comma delimited list of files
+    * @throws org.jboss.deployers.spi.DeploymentException
+    */
+   public void addClasspath(String paths) throws DeploymentException
+   {
+      String classpath = System.getProperty("java.class.path");
+      StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
+      String[] split = paths.split(",");
+      for (int i = 0; i < split.length; i++)
+      {
+         split[i] = split[i].trim();
+      }
+
+      while (tokenizer.hasMoreTokens())
+      {
+         String path = tokenizer.nextToken().trim();
+         boolean found = false;
+         for (String wantedPath : split)
+         {
+            if (path.endsWith(System.getProperty("file.separator") + wantedPath))
+            {
+               found = true;
+               break;
+            }
+         }
+         if (!found) continue;
+         File fp = new File(path);
+         if (!fp.exists()) throw new DeploymentException("File in java.class.path does not exists: " + fp);
+         try
+         {
+            add(fp.toURL());
+         }
+         catch (MalformedURLException e)
+         {
+            throw new DeploymentException(e);
+         }
+      }
+   }
+
+   /**
+    * convenience  function.  Same as addClasspath(String) but processes deployments too
+    *
+    * @param paths
+    * @throws DeploymentException
+    */
+   public void scanClasspath(String paths) throws DeploymentException
+   {
+      addClasspath(paths);
+      process();
+   }
+
+   /**
+    * Search for the resource using the group's configured classloader
+    * if no classloader, then Thread.currentThread().getContextClassLoader() is used.
+    *    classLoader.getResource(String resource)
+    *
+    * Schedule the resource to be deployed.
+    *
+    * @param resource
+    * @throws DeploymentException
+    * @throws NullPointerException
+    */
+   public void addResource(String resource) throws DeploymentException, NullPointerException
+   {
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      if (classLoader != null) loader = classLoader;
+      URL url = loader.getResource(resource);
+      if (url == null) throw new NullPointerException("Resource was null: " + resource);
+      add(url);
+   }
+
+   /**
+    * convenience function.  Same as addResource(String) but processes deployments too
+    *
+    * @param resource
+    * @throws DeploymentException
+    * @throws NullPointerException
+    */
+   public void deployResource(String resource)  throws DeploymentException, NullPointerException
+   {
+      addResource(resource);
+      process();
+   }
+
+
+   /**
+    * Search for resources using the group's configured classloader
+    * if no classloader, then Thread.currentThread().getContextClassLoader() is used.
+    *    classLoader.getResources(String resource)
+    *
+    * Schedule the resource to be deployed.
+    *
+    * @param resource
+    * @throws DeploymentException
+    * @throws IOException
+    */
+   public void addMultipleResources(String resource) throws DeploymentException, IOException
+   {
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      if (classLoader != null) loader = classLoader;
+      Enumeration<URL> urls = loader.getResources(resource);
+      while (urls.hasMoreElements())
+      {
+         add(urls.nextElement());
+      }
+   }
+
+   /**
+    *
+    * convenience function.  Same as addMultipleResources(String) but processes deployments too
+    *
+    * @param resource
+    * @throws DeploymentException
+    * @throws IOException
+    */
+   public void deployMultipleResrouces(String resource) throws DeploymentException, IOException
+   {
+      addMultipleResources(resource);
+      process();
+   }
+
+
+   /**
+    * Searches for a directory as described in the  getDirFromResource() method of this class.
+    *
+    * schedules all possible files in directory to be deployed
+    *
+    *
+    * @param resource
+    * @param recurse whether or not to recurse child directories
+    * @throws DeploymentException
+    * @throws IOException
+    */
+   public void addDirectoryByResource(String resource, boolean recurse) throws DeploymentException, IOException
+   {
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      if (classLoader != null) loader = classLoader;
+      URL url = getDirFromResource(loader, resource);
+      if (url == null)
+      {
+         throw new DeploymentException("Unable to find deployDir from resource: " + resource);
+      }
+      VirtualFile file = null;
+      try
+      {
+         file = VFS.getRoot(url);
+      }
+      catch (Exception e)
+      {
+         throw new DeploymentException("Unable to find deployDir from resource: " + resource, e);
+      }
+      List<VirtualFile> files = new ArrayList<VirtualFile>();
+      addDeployments(files, file, recurse);
+      addVirtualFiles(files);
+   }
+
+   /**
+    * convenience function.  Same as deployDirectoryByResource(String, boolean) but processes deployments too
+    *
+    * @param resource
+    * @param recurse
+    * @throws DeploymentException
+    * @throws IOException
+    */
+   public void deployDirectoryByResource(String resource, boolean recurse) throws DeploymentException, IOException
+   {
+      addDirectoryByResource(resource, recurse);
+      process();
+   }
+
+
+   /**
+    * Find the directory that contains a given resource.
+    * <p/>
+    * The '.' character can be used to specify the current directory.
+    * The '..' string can be used to specify a higher relative path
+    * <p/>
+    * i.e.
+    * <p/>
+    * getDirFromResource(loader, "org/jboss/Test.class")
+    * file:/<root>/org/jboss/
+    * <p/>
+    * getDirFromResource(loader, "org/jboss/Test.class/..")
+    * file:/<root>/org/
+    * <p/>
+    * getDirFromResource(loader, "org/jboss/Test.class/../acme")
+    * file:/<root>/org/acme/
+    * <p/>
+    * getDirFromResource(loader, "org/jboss/Test.class/./embedded")
+    * file:/<root>/org/jboss/embedded/
+    *
+    * @param loader
+    * @param resource
+    * @return
+    * @throws Exception
+    */
+   public static URL getDirFromResource(ClassLoader loader, String resource)
+   {
+      int idx = resource.indexOf("/.");
+      String base = resource;
+      String relative = null;
+      if (idx != -1)
+      {
+         base = resource.substring(0, idx);
+         relative = resource.substring(idx + 1);
+      }
+      URL url = loader.getResource(base);
+      if (url == null) return null;
+      String urlAsString = url.toString();
+      String[] paths = urlAsString.split("/");
+      int last = paths.length - 2;
+      if (relative != null)
+      {
+         String[] relativePaths = relative.split("/");
+         int relativeStart = 0;
+         for (String relativePath : relativePaths)
+         {
+            if (relativePath.equals(".."))
+            {
+               last--;
+               relativeStart++;
+            }
+            else if (relativePath.equals("."))
+            {
+               relativeStart++;
+            }
+            else
+            {
+               break;
+            }
+         }
+         urlAsString = "";
+         for (int i = 0; i <= last; i++)
+         {
+            urlAsString += paths[i] + "/";
+         }
+         for (int i = relativeStart; i < relativePaths.length; i++)
+         {
+            urlAsString += relativePaths[i] + "/";
+         }
+      }
+      else
+      {
+         urlAsString = "";
+         for (int i = 0; i <= last; i++)
+         {
+            urlAsString += paths[i] + "/";
+         }
+
+      }
+      try
+      {
+         url = new URL(urlAsString);
+      }
+      catch (MalformedURLException e)
+      {
+         throw new RuntimeException(e);
+      }
+      return url;
+   }
+}

Added: trunk/embedded/src/main/java/org/jboss/embedded/DeploymentGroupBean.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/DeploymentGroupBean.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/DeploymentGroupBean.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,115 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.deployers.spi.deployment.MainDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.IncompleteDeployments;
+import org.jboss.deployers.spi.IncompleteDeploymentsBuilder;
+import org.jboss.deployers.spi.IncompleteDeploymentException;
+import org.jboss.deployers.plugins.structure.AbstractDeploymentContext;
+import org.jboss.kernel.Kernel;
+import org.jboss.logging.Logger;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.Enumeration;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.io.IOException;
+import java.io.File;
+
+/**
+ * Bean so that you can create a DeploymentGroup from the Microcontainer
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeploymentGroupBean extends DeploymentGroup
+{
+   private static final Logger log = Logger.getLogger(DeploymentGroupBean.class);
+   private List<URL> urls;
+   private List<String> resources;
+   private List<String> multiple;
+   private List<String> dirs;
+
+   public void setUrls(List<URL> urls) throws DeploymentException
+   {
+      this.urls = urls;
+   }
+
+
+   public void setResources(List<String> resources) throws DeploymentException, NullPointerException
+   {
+      this.resources = resources;
+   }
+
+
+   public void setMultipleResources(List<String> resources) throws DeploymentException, IOException
+   {
+      this.multiple = resources;
+   }
+
+
+   public void setDirectoriesByResource(List<String> resources) throws DeploymentException, IOException
+   {
+      dirs = resources;
+   }
+
+   public void start() throws Exception
+   {
+      if (urls != null) addUrls(urls);
+      if (resources != null)
+      {
+         for (String resource : resources)
+         {
+            addResource(resource);
+         }
+      }
+      if (multiple != null)
+      {
+         for (String resource : multiple)
+         {
+            addMultipleResources(resource);
+         }
+      }
+      if (dirs != null)
+      {
+         for (String resource : dirs)
+         {
+            addDirectoryByResource(resource, true);
+         }
+      }
+      mainDeployer.process();
+   }
+
+   public void stop() throws DeploymentException
+   {
+      undeploy();
+   }
+
+}

Modified: trunk/embedded/src/main/java/org/jboss/embedded/JMXKernel.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/JMXKernel.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/JMXKernel.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -28,9 +28,9 @@
 import org.jboss.system.ServiceController;
 import org.jboss.system.ServiceControllerMBean;
 import org.jboss.system.deployers.ServiceDeployer;
-import org.jboss.system.server.ServerImplMBean;
 import org.jboss.system.server.ServerConfigImpl;
 import org.jboss.system.server.ServerConfigImplMBean;
+import org.jboss.system.server.ServerImplMBean;
 import org.jboss.util.JBossObject;
 
 import javax.management.JMRuntimeException;
@@ -65,6 +65,7 @@
    private MBeanServerBuilder builder = new MBeanServerBuilderImpl();
    private ServiceController controller;
    private Kernel kernel;
+   private ServerConfig serverConfig;
    private NotificationBroadcasterSupport broadcasterSupport = new NotificationBroadcasterSupport();
    private boolean started;
 
@@ -89,6 +90,17 @@
       this.builder = builder;
    }
 
+
+   public ServerConfig getServerConfig()
+   {
+      return serverConfig;
+   }
+
+   public void setServerConfig(ServerConfig serverConfig)
+   {
+      this.serverConfig = serverConfig;
+   }
+
    /**
     * We don't want to override platforms default mechanism for creating MBeanServer so lets just do it ourselves
     *
@@ -118,7 +130,7 @@
 
    }
 
-   private static void setupUrlHandlers()
+   public static void setupUrlHandlers()
    {
       String pkgs = System.getProperty("java.protocol.handler.pkgs");
       if (pkgs == null || pkgs.trim().length() == 0)
@@ -131,6 +143,8 @@
          pkgs += "|org.jboss.net.protocol";
          System.setProperty("java.protocol.handler.pkgs", pkgs);
       }
+      //Field field = URL.class.getDeclaredField("")
+      //URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory());
 
    }
 
@@ -148,7 +162,7 @@
       mbeanServer.registerMBean(controller, new ObjectName("jboss.system:service=ServiceController"));
       // Register mbeanServer components
       mbeanServer.registerMBean(this, ServerImplMBean.OBJECT_NAME);
-      mbeanServer.registerMBean(new ServerConfigImpl(new ServerConfig()), ServerConfigImplMBean.OBJECT_NAME);
+      mbeanServer.registerMBean(new ServerConfigImpl(serverConfig), ServerConfigImplMBean.OBJECT_NAME);
       started = true;
    }
 

Modified: trunk/embedded/src/main/java/org/jboss/embedded/ServerConfig.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/ServerConfig.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/ServerConfig.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -24,7 +24,9 @@
 import org.jboss.system.server.BaseServerConfig;
 
 import java.io.File;
+import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Properties;
 
 /**
  * comment
@@ -34,141 +36,209 @@
  */
 public class ServerConfig implements org.jboss.system.server.ServerConfig
 {
-   private String tempDir = System.getProperty("java.io.tmpdir");
+   protected BaseServerConfig config;
+   protected Properties props;
 
+   public void start() throws Exception
+   {
+      props = new Properties(System.getProperties());
 
-   public String getTempDir()
+      String homeDir = System.getProperty(HOME_DIR);
+
+      // if HOME_DIR property is null, then try to figure it out
+      if (homeDir == null)
+      {
+
+         String path = System.getProperty(Bootstrap.BOOTSTRAP_RESOURCE_PATH);
+         if (path == null) throw new Exception("${jboss.embedded.bootstrap.resource.path} is null");
+
+
+         path += Bootstrap.BOOTSTRAP_RESOURCE_FILE;
+
+         URL url = Thread.currentThread().getContextClassLoader().getResource(path);
+         if (url.toString().startsWith("file:"))
+         {
+            initializeByFile(path);
+         }
+         else
+         {
+            // we do not know the protocol
+            initializeByUnknown();
+         }
+      }
+      else
+      {
+         props.put(SERVER_HOME_DIR, homeDir);
+      }
+      config = new BaseServerConfig(props);
+      config.initURLs();
+
+      // create tmp and data directories
+
+      if (!config.getServerTempDir().exists())
+      {
+         config.getServerTempDir().mkdir();
+      }
+      if (!config.getServerDataDir().exists())
+      {
+         config.getServerDataDir().mkdir();
+      }
+   }
+
+   protected void initializeByFile(String path) throws Exception
    {
-      return tempDir;
+      URL homeDirUrl = DeploymentGroupBean.getDirFromResource(Thread.currentThread().getContextClassLoader(), path + "/..");
+      File homeDir = new File(homeDirUrl.toURI());
+      props.put(HOME_DIR, homeDir.toString());
+      props.put(SERVER_HOME_DIR, homeDir.toString());
    }
 
-   public void setTempDir(String tempDir)
+   /**
+    * Creates base JBoss Embedded directory structure under java.io.tmpdir
+    *
+    * @throws Exception
+    */
+   protected void initializeByUnknown() throws Exception
    {
-      this.tempDir = tempDir;
+      String temp = System.getProperty("java.io.tmpdir");
+      File fp = new File(temp, "embedded-jboss");
+      if (!fp.exists())
+      {
+         fp.mkdir();
+      }
+      props.put(HOME_DIR, fp.toString());
+      props.put(SERVER_HOME_DIR, fp.toString());
    }
 
+
+   public void initURLs()
+           throws MalformedURLException
+   {
+      config.initURLs();
+   }
+
    public File getHomeDir()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getHomeDir();
    }
 
    public URL getHomeURL()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getHomeURL();
    }
 
    public URL getLibraryURL()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getLibraryURL();
    }
 
    public URL getPatchURL()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getPatchURL();
    }
 
    public String getServerName()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getServerName();
    }
 
    public File getServerBaseDir()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getServerBaseDir();
    }
 
    public File getServerHomeDir()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getServerHomeDir();
    }
 
    public File getServerLogDir()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getServerLogDir();
    }
 
    public File getServerTempDir()
    {
-      return new File(tempDir);
+      return config.getServerTempDir();
    }
 
    public File getServerDataDir()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getServerDataDir();
    }
 
+   public File getServerNativeDir()
+   {
+      return config.getServerNativeDir();
+   }
+
+   public File getServerTempDeployDir()
+   {
+      return config.getServerTempDeployDir();
+   }
+
    public URL getServerBaseURL()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getServerBaseURL();
    }
 
    public URL getServerHomeURL()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getServerHomeURL();
    }
 
    public URL getServerLibraryURL()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getServerLibraryURL();
    }
 
    public URL getServerConfigURL()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getServerConfigURL();
    }
 
    public boolean getPlatformMBeanServer()
    {
-      return false;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getPlatformMBeanServer();
    }
 
    public void setExitOnShutdown(boolean flag)
    {
-      //To change body of implemented methods use File | Settings | File Templates.
+      config.setExitOnShutdown(flag);
    }
 
    public boolean getExitOnShutdown()
    {
-      return false;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getExitOnShutdown();
    }
 
-   public boolean getBlockingShutdown()
+   public void setBlockingShutdown(boolean flag)
    {
-      return false;  //To change body of implemented methods use File | Settings | File Templates.
+      config.setBlockingShutdown(flag);
    }
 
-   public void setBlockingShutdown(boolean blockingShutdown)
+   public boolean getBlockingShutdown()
    {
-      //To change body of implemented methods use File | Settings | File Templates.
+      return config.getBlockingShutdown();
    }
 
-   public boolean getRequireJBossURLStreamHandlerFactory()
+   public void setRequireJBossURLStreamHandlerFactory(boolean flag)
    {
-      return false;  //To change body of implemented methods use File | Settings | File Templates.
+      config.setRequireJBossURLStreamHandlerFactory(flag);
    }
 
-   public void setRequireJBossURLStreamHandlerFactory(boolean requireJBossURLStreamHandlerFactory)
+   public boolean getRequireJBossURLStreamHandlerFactory()
    {
-      //To change body of implemented methods use File | Settings | File Templates.
+      return config.getRequireJBossURLStreamHandlerFactory();
    }
 
    public void setRootDeploymentFilename(String filename)
    {
-      //To change body of implemented methods use File | Settings | File Templates.
+      config.setRootDeploymentFilename(filename);
    }
 
    public String getRootDeploymentFilename()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return config.getRootDeploymentFilename();
    }
-
-   public File getServerNativeDir()
-   {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
-   }
-
-   public File getServerTempDeployDir()
-   {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
-   }
-}
+}
\ No newline at end of file

Deleted: trunk/embedded/src/main/java/org/jboss/embedded/Test.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/Test.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/Test.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -1,120 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* 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.embedded;
-
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VFS;
-
-import java.net.URL;
-
-/**
- * comment
- *
- * @author <a href="bill at jboss.com">Bill Burke</a>
- * @version $Revision: 1.1 $
- */
-public class Test
-{
-
-   private static VirtualFile getFile(ClassLoader classLoader, String resource)
-   {
-      URL url = classLoader.getResource(resource);
-      VirtualFile file = null;
-      try
-      {
-         file = VFS.getRoot(url);
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException("Unable to find resource: " + resource, e);
-      }
-      return file;
-
-   }
-   private static URL getDirFromResource(ClassLoader loader, String resource) throws Exception
-   {
-      int idx = resource.indexOf("/.");
-      String base = resource;
-      String relative = null;
-      if (idx != -1)
-      {
-         base = resource.substring(0, idx);
-         relative = resource.substring(idx + 1);
-      }
-      URL url = loader.getResource(base);
-      String urlAsString = url.toString();
-      String[] paths = urlAsString.split("/");
-      int last = paths.length - 2;
-      if (relative != null)
-      {
-         String[] relativePaths = relative.split("/");
-         int relativeStart = 0;
-         for (String relativePath : relativePaths)
-         {
-            if (relativePath.equals(".."))
-            {
-               last--;
-               relativeStart++;
-            }
-            else if (relativePath.equals("."))
-            {
-               relativeStart++;
-            }
-            else
-            {
-               break;
-            }
-         }
-         urlAsString = "";
-         for (int i = 0; i <= last; i++)
-         {
-            urlAsString += paths[i] + "/";
-         }
-         for (int i = relativeStart; i < relativePaths.length; i++)
-         {
-            urlAsString += relativePaths[i] + "/";
-         }
-      }
-      else
-      {
-         urlAsString = "";
-         for (int i = 0; i <= last; i++)
-         {
-            urlAsString += paths[i] + "/";
-         }
-
-      }
-      url = new URL(urlAsString);
-      return url;
-   }
-
-   public static void main(String[] args) throws Exception
-   {
-      System.out.println(getFile(Thread.currentThread().getContextClassLoader(), "org/jboss/embedded/Test.class").toURL());
-      System.out.println("url: " + getDirFromResource(Thread.currentThread().getContextClassLoader(), "org/jboss/embedded/Test.class/../../.."));
-      System.out.println("url: " + getDirFromResource(Thread.currentThread().getContextClassLoader(), "org/jboss/embedded/Test.class/../../../javax/ejb"));
-      System.out.println("url: " + getDirFromResource(Thread.currentThread().getContextClassLoader(), "org/jboss/embedded/Test.class"));
-      System.out.println("url: " + getDirFromResource(Thread.currentThread().getContextClassLoader(), "org/jboss/embedded/Test.class/./javax/ejb"));
-
-   }
-
-}

Added: trunk/embedded/src/main/java/org/jboss/embedded/WebInfLibScanner.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/WebInfLibScanner.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/WebInfLibScanner.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,67 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded;
+
+import org.jboss.logging.Logger;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 44597 $
+ */
+public class WebInfLibScanner implements ServletContextListener
+{
+   private static final Logger log = Logger.getLogger(WebInfLibScanner.class);
+
+   private List<URL> jars = new ArrayList<URL>();
+
+   public void contextInitialized(ServletContextEvent servletContextEvent)
+   {
+      try
+      {
+         ServletContext servletContext = servletContextEvent.getServletContext();
+         Set libJars = servletContext.getResourcePaths("/WEB-INF/lib");
+         for (Object jar : libJars)
+         {
+            URL archive = servletContext.getResource((String)jar);
+         }
+      }
+      catch (Exception e)
+      {
+         log.error("failed to deploy from ServletListenerDeployer", e);
+         throw new RuntimeException(e);
+      }
+   }
+
+   public void contextDestroyed(ServletContextEvent servletContextEvent)
+   {
+   }
+}

Added: trunk/embedded/src/main/java/org/jboss/embedded/jndi/BridgeContext.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/jndi/BridgeContext.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/jndi/BridgeContext.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,91 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.jndi;
+
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+/** This class is the Context interface handler and performs the
+    failed lookup delegation from the primary to secondary naming
+    Context.
+*/
+public class BridgeContext implements InvocationHandler
+{
+   private Context primaryCtx;
+   private Context secondaryCtx;
+
+   public static Context createBridge(Context primaryCtx, Context secondaryCtx)
+   {
+      BridgeContext h = new BridgeContext(primaryCtx, secondaryCtx);
+      Class[] interfaces = {Context.class};
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      return (Context) Proxy.newProxyInstance(loader, interfaces, h);
+   }
+
+   BridgeContext(Context primaryCtx, Context secondaryCtx)
+   {
+      this.primaryCtx = primaryCtx;
+      this.secondaryCtx = secondaryCtx;
+   }
+
+   public Object invoke(Object proxy, Method method, Object[] args)
+         throws Throwable
+   {
+      Object value = null;
+      // First try the primary context
+      try
+      {
+         value = method.invoke(primaryCtx, args);
+      }
+      catch(InvocationTargetException e)
+      {
+         Throwable t = e.getTargetException();
+         // Try the secondary if this is a failed lookup
+         if( t instanceof NameNotFoundException && method.getName().startsWith("lookup") )
+         {
+            try
+            {
+               value = method.invoke(secondaryCtx, args);
+            }
+            catch (InvocationTargetException e1)
+            {
+               throw e1.getTargetException();
+            }
+         }
+         else
+         {
+            throw t;
+         }
+      }
+      return value;
+   }
+}

Added: trunk/embedded/src/main/java/org/jboss/embedded/jndi/DelegatingContextFactory.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/jndi/DelegatingContextFactory.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/jndi/DelegatingContextFactory.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,71 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.jndi;
+
+import org.jnp.interfaces.NamingContextFactory;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+import java.util.Hashtable;
+
+/**
+ * abstract class that delegates to a different initial context factory
+ * Allows you to reuse other JBoss context factories like the security one.
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class DelegatingContextFactory implements InitialContextFactory
+{
+   public static final String INITIAL_CONTEXT_FACTORY_DELEGATE = "jboss.embedded.initial.context.factory.delegate";
+   public static final String INITIAL_CONTEXT_FACTORY_DEFAULT = "org.jnp.interfaces.NamingContextFactory";
+   private NamingContextFactory delegate;
+
+   protected synchronized NamingContextFactory getDelegate(Hashtable env) throws NamingException
+   {
+      if (delegate != null) return delegate;
+      String factoryName = (String) env.get(INITIAL_CONTEXT_FACTORY_DELEGATE);
+      if (factoryName != null)
+      {
+         try
+         {
+            Class clazz = Thread.currentThread().getContextClassLoader().loadClass(factoryName);
+            delegate = (NamingContextFactory)clazz.newInstance();
+         }
+         catch (Exception e)
+         {
+            throw new RuntimeException("Unable to initialize InitialContextFactory", e);
+         }
+      }
+      else
+      {
+         delegate = new NamingContextFactory();
+      }
+      return delegate;
+   }
+
+   public Context getInitialContext(Hashtable env) throws NamingException
+   {
+      return getDelegate(env).getInitialContext(env);
+   }
+}

Added: trunk/embedded/src/main/java/org/jboss/embedded/jndi/KernelInitializingContextFactory.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/jndi/KernelInitializingContextFactory.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/jndi/KernelInitializingContextFactory.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,75 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.jndi;
+
+import org.jboss.embedded.Bootstrap;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import java.util.Hashtable;
+
+/**
+ * InitialContextFactory that will bootstrap embedded jboss.
+ *
+ * This factory also delegates to a org.jnp.interfaces.NamingContextFactory.  You can change the delegate
+ * by setting the jboss.embeddded.initial.context.factory.delegate jndi property.
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class KernelInitializingContextFactory extends DelegatingContextFactory
+{
+   public static boolean initialized = false;
+   public static final String BOOTSTRAP_RESOURCE_PATH = "jboss.embedded.resource.path";
+
+   public static synchronized void bootstrapEmbeddedKernel(Hashtable env)
+   {
+      if (initialized == false)
+      {
+         initialized = true;
+         String bootstrapResourcePath = (String) env.get(BOOTSTRAP_RESOURCE_PATH);
+         try
+         {
+            if (bootstrapResourcePath != null)
+            {
+               Bootstrap.getInstance().bootstrap(bootstrapResourcePath);
+            }
+            else
+            {
+               Bootstrap.getInstance().bootstrap();
+            }
+         }
+         catch (Exception e)
+         {
+            throw new RuntimeException("Unable to bootstrap JBoss kernel", e);
+         }
+      }
+   }
+
+   // InitialContextFactory implementation --------------------------
+   public Context getInitialContext(Hashtable env) throws NamingException
+   {
+      KernelInitializingContextFactory.bootstrapEmbeddedKernel(env);
+      return super.getInitialContext(env);
+   }
+
+}

Added: trunk/embedded/src/main/java/org/jboss/embedded/jndi/WrappingContext.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/jndi/WrappingContext.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/jndi/WrappingContext.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,228 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.jndi;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import java.util.Hashtable;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class WrappingContext implements Context
+{
+   private Context namingContext;
+
+
+   public WrappingContext(Context namingContext)
+   {
+      this.namingContext = namingContext;
+   }
+
+   public Object lookup(Name name)
+           throws NamingException
+   {
+      return getNamingContext().lookup(name);
+   }
+
+   public Object lookup(String name)
+           throws NamingException
+   {
+      return getNamingContext().lookup(name);
+   }
+
+   public void bind(Name name, Object obj)
+           throws NamingException
+   {
+      getNamingContext().bind(name, obj);
+   }
+
+   public void bind(String name, Object obj)
+           throws NamingException
+   {
+      getNamingContext().bind(name, obj);
+   }
+
+   public void rebind(Name name, Object obj)
+           throws NamingException
+   {
+      getNamingContext().rebind(name, obj);
+   }
+
+   public void rebind(String name, Object obj)
+           throws NamingException
+   {
+      getNamingContext().rebind(name, obj);
+   }
+
+   public void unbind(Name name)
+           throws NamingException
+   {
+      getNamingContext().unbind(name);
+   }
+
+   public void unbind(String name)
+           throws NamingException
+   {
+      getNamingContext().unbind(name);
+   }
+
+   public void rename(Name oldName, Name newName)
+           throws NamingException
+   {
+      getNamingContext().rename(oldName, newName);
+   }
+
+   public void rename(String oldName, String newName)
+           throws NamingException
+   {
+      getNamingContext().rename(oldName, newName);
+   }
+
+   public NamingEnumeration<NameClassPair> list(Name name)
+           throws NamingException
+   {
+      return getNamingContext().list(name);
+   }
+
+   public NamingEnumeration<NameClassPair> list(String name)
+           throws NamingException
+   {
+      return getNamingContext().list(name);
+   }
+
+   public NamingEnumeration<Binding> listBindings(Name name)
+           throws NamingException
+   {
+      return getNamingContext().listBindings(name);
+   }
+
+   public NamingEnumeration<Binding> listBindings(String name)
+           throws NamingException
+   {
+      return getNamingContext().listBindings(name);
+   }
+
+   public void destroySubcontext(Name name)
+           throws NamingException
+   {
+      getNamingContext().destroySubcontext(name);
+   }
+
+   public void destroySubcontext(String name)
+           throws NamingException
+   {
+      getNamingContext().destroySubcontext(name);
+   }
+
+   public Context createSubcontext(Name name)
+           throws NamingException
+   {
+      return getNamingContext().createSubcontext(name);
+   }
+
+   public Context createSubcontext(String name)
+           throws NamingException
+   {
+      return getNamingContext().createSubcontext(name);
+   }
+
+   public Object lookupLink(Name name)
+           throws NamingException
+   {
+      return getNamingContext().lookupLink(name);
+   }
+
+   public Object lookupLink(String name)
+           throws NamingException
+   {
+      return getNamingContext().lookupLink(name);
+   }
+
+   public NameParser getNameParser(Name name)
+           throws NamingException
+   {
+      return getNamingContext().getNameParser(name);
+   }
+
+   public NameParser getNameParser(String name)
+           throws NamingException
+   {
+      return getNamingContext().getNameParser(name);
+   }
+
+   public Name composeName(Name name, Name prefix)
+           throws NamingException
+   {
+      return getNamingContext().composeName(name, prefix);
+   }
+
+   public String composeName(String name, String prefix)
+           throws NamingException
+   {
+      return getNamingContext().composeName(name, prefix);
+   }
+
+   public Object addToEnvironment(String propName, Object propVal)
+           throws NamingException
+   {
+      return getNamingContext().addToEnvironment(propName, propVal);
+   }
+
+   public Object removeFromEnvironment(String propName)
+           throws NamingException
+   {
+      return getNamingContext().removeFromEnvironment(propName);
+   }
+
+   public Hashtable<?, ?> getEnvironment()
+           throws NamingException
+   {
+      return getNamingContext().getEnvironment();
+   }
+
+   public void close()
+           throws NamingException
+   {
+      getNamingContext().close();
+   }
+
+   public String getNameInNamespace()
+           throws NamingException
+   {
+      return getNamingContext().getNameInNamespace();
+   }
+
+   protected Context getNamingContext()
+   {
+      return namingContext;
+   }
+
+}

Added: trunk/embedded/src/main/java/org/jboss/embedded/tomcat/EmbeddedJBossBootstrapListener.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/tomcat/EmbeddedJBossBootstrapListener.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/tomcat/EmbeddedJBossBootstrapListener.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,90 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.tomcat;
+
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.jboss.embedded.Bootstrap;
+import org.jboss.embedded.tomcat.jndi.ENCFactory;
+import org.jboss.embedded.tomcat.jndi.TomcatBridgeContextFactory;
+import org.jboss.embedded.url.JavaProtocolHandlerPkgs;
+import org.jboss.net.protocol.URLStreamHandlerFactory;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.net.URL;
+
+/**
+ * Tomcat Listener that initializes embedded jboss.
+ *
+ * It resets the JNDI context factory as well as URL_PKG_PREFIXES
+ *
+ * It sets up URL.setURLStreamHandlerFactory to be a jboss supplied one but
+ * it does append org.apache.naming.resources to the pkgs.
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class EmbeddedJBossBootstrapListener implements LifecycleListener
+{
+
+   public void lifecycleEvent(LifecycleEvent event)
+   {
+      if (Lifecycle.START_EVENT.equals(event.getType()))
+      {                                                                                            
+         innerStart();
+      }
+      else if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType()))
+      {
+         innerStop();
+      }
+
+   }
+
+   protected void innerStart()
+   {
+      System.setProperty(Context.INITIAL_CONTEXT_FACTORY, TomcatBridgeContextFactory.class.getName());
+      System.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming");
+
+      String[] protocolPkgs = {
+              "org.apache.naming.resources"
+      };
+      JavaProtocolHandlerPkgs.setupHandlerPkgs(protocolPkgs);
+      URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory());
+      try
+      {
+         Bootstrap.getInstance().bootstrap();
+         InitialContext ctx = new InitialContext();
+         ENCFactory.rebindComp(ctx);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   protected void innerStop()
+   {
+      Bootstrap.getInstance().shutdown();
+   }
+}

Added: trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/ENCFactory.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/ENCFactory.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/ENCFactory.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,74 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.tomcat.jndi;
+
+import org.apache.naming.SelectorContext;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import java.util.Hashtable;
+
+/**
+ * We look to see if a threadlocal tag is set, if so, just use JBoss java:comp resolving.
+ * If it is not set, then obtain a reference to "java:" and lookup "comp"
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class ENCFactory extends org.jboss.naming.ENCFactory
+{
+   private static boolean initialized;
+
+   /**
+    * Convience function.  Rebinds java:comp to this class just in case an existing
+    * jboss configuration already bound java:comp.  This is so we don't have to have
+    * multiple copies of jboss configuration files.
+    *
+    * @param jbossContext
+    * @throws NamingException
+    */
+   public static synchronized void rebindComp(Context jbossContext) throws NamingException
+   {
+      if (initialized)return;
+      initialized = true;
+      RefAddr refAddr = new StringRefAddr("nns", "ENC");
+      Reference envRef = new Reference("javax.naming.Context", refAddr, ENCFactory.class.getName(), null);
+      Context ctx = (Context)jbossContext.lookup("java:");
+      ctx.rebind("comp", envRef);
+   }
+
+
+   @Override
+   public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception
+   {
+      if (getCurrentId() != null)
+      {
+         return super.getObjectInstance(obj, name, nameCtx, environment);
+      }
+      return new SelectorContext(environment).lookup("comp");
+   }
+
+}

Added: trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/KernelInitializingContextFactory.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/KernelInitializingContextFactory.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/KernelInitializingContextFactory.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,52 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.tomcat.jndi;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import java.util.Hashtable;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class KernelInitializingContextFactory extends TomcatBridgeContextFactory
+{
+   /**
+    * Get a new (writable) initial context.
+    */
+   @Override
+   public Context getInitialContext(Hashtable environment)
+           throws NamingException
+   {
+      System.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.embedded.tomcat.jndi");
+      org.jboss.embedded.jndi.KernelInitializingContextFactory.bootstrapEmbeddedKernel(environment);
+      Context jbossContext = super.getInitialContext(environment);
+      // reinitialize java:comp so that we don't have to have two copies of embedded configuration
+      ENCFactory.rebindComp(jbossContext);
+
+      return jbossContext;
+   }
+
+}

Added: trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/TomcatBridgeContextFactory.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/TomcatBridgeContextFactory.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/TomcatBridgeContextFactory.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,54 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.tomcat.jndi;
+
+import org.apache.naming.java.javaURLContextFactory;
+import org.jboss.embedded.jndi.BridgeContext;
+import org.jboss.embedded.jndi.DelegatingContextFactory;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import java.util.Hashtable;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class TomcatBridgeContextFactory extends DelegatingContextFactory
+{
+   private javaURLContextFactory apache = new javaURLContextFactory();
+
+   /**
+    * Get a new (writable) initial context.
+    */
+   @Override
+   public Context getInitialContext(Hashtable environment)
+           throws NamingException
+   {
+      Context jbossContext = super.getInitialContext(environment);
+      Context apacheContext = apache.getInitialContext(environment);
+      return BridgeContext.createBridge(jbossContext, apacheContext);
+   }
+
+}

Added: trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/java/javaURLContextFactory.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/java/javaURLContextFactory.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/tomcat/jndi/java/javaURLContextFactory.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,52 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.tomcat.jndi.java;
+
+import org.jboss.embedded.jndi.BridgeContext;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.spi.ObjectFactory;
+import java.util.Hashtable;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class javaURLContextFactory implements ObjectFactory
+{
+   private org.jboss.naming.java.javaURLContextFactory jboss = new org.jboss.naming.java.javaURLContextFactory();
+   private org.apache.naming.java.javaURLContextFactory apache = new org.apache.naming.java.javaURLContextFactory();
+
+   public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception
+   {
+      Context jbossContext = (Context)jboss.getObjectInstance(obj, name, nameCtx, environment);
+      Context apacheContext = (Context)apache.getObjectInstance(obj, name, nameCtx, environment);
+      return BridgeContext.createBridge(jbossContext, apacheContext);
+   }
+
+
+
+}
+

Added: trunk/embedded/src/main/java/org/jboss/embedded/url/BridgeHandlerFactory.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/url/BridgeHandlerFactory.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/url/BridgeHandlerFactory.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,55 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.url;
+
+import java.net.URLStreamHandler;
+import java.net.URLStreamHandlerFactory;
+import java.util.List;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class BridgeHandlerFactory implements URLStreamHandlerFactory
+{
+   private List<URLStreamHandlerFactory> list;
+
+
+   public BridgeHandlerFactory(List<URLStreamHandlerFactory> list)
+   {
+      this.list = list;
+   }
+
+   public URLStreamHandler createURLStreamHandler(String protocol)
+   {
+      URLStreamHandler result = null;
+      for (URLStreamHandlerFactory factory : list)
+      {
+         
+         result = factory.createURLStreamHandler(protocol);
+         if (result != null) return result;
+      }
+      return null;
+   }
+}

Added: trunk/embedded/src/main/java/org/jboss/embedded/url/HandlerFactoryHack.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/url/HandlerFactoryHack.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/url/HandlerFactoryHack.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,88 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.url;
+
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.net.URLStreamHandlerFactory;
+import java.util.List;
+
+/**
+ * Tries to set URL.setURLStreamHandlerFactory() with the provided factory.
+ * If it fails, it tries to reset handler by creating a BridgeHandlerFactory
+ * and hacking the JDK to overcome URL.setURLStreamHandlerFactory()'s limitation
+ * of only being able to be set up once.
+ *
+ * If there is already an existing handler factory then this factory will be added to the bridge list
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class HandlerFactoryHack
+{
+   private List<URLStreamHandlerFactory> factories;
+
+   public List<URLStreamHandlerFactory> getFactories()
+   {
+      return factories;
+   }
+
+   public void setFactories(List<URLStreamHandlerFactory> factories)
+   {
+      this.factories = factories;
+   }
+
+   public void start() throws Exception
+   {
+      hack();
+   }
+
+   protected void hack() throws Exception
+   {
+      BridgeHandlerFactory bridge = new BridgeHandlerFactory(factories);
+      try
+      {
+         URL.setURLStreamHandlerFactory(bridge);
+         return;
+      }
+      catch (Error ignored)
+      {
+         // already set
+      }
+      try
+      {
+         Field factoryField = URL.class.getDeclaredField("factory");
+         factoryField.setAccessible(true);
+         URLStreamHandlerFactory old = (URLStreamHandlerFactory)factoryField.get(null);
+         if (old != null) factories.add(0, old);
+         factoryField.set(null, bridge);
+      }
+      catch (Exception e)
+      {
+         throw e;
+      }
+
+
+   }
+
+
+}

Added: trunk/embedded/src/main/java/org/jboss/embedded/url/JavaProtocolHandlerPkgs.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/url/JavaProtocolHandlerPkgs.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/java/org/jboss/embedded/url/JavaProtocolHandlerPkgs.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,77 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.url;
+
+/**
+ * Adds handler string to current System.getProperty("java.protocol.handler.pkgs")
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class JavaProtocolHandlerPkgs
+{
+   private String pkgs;
+
+
+   public String getPkgs()
+   {
+      return pkgs;
+   }
+
+   public void setPkgs(String pkgs)
+   {
+      this.pkgs = pkgs;
+   }
+
+   public void start()
+   {
+      setupHandlerPkgs(pkgs);
+   }
+
+   public static void setupHandlerPkgs(String pkgs)
+   {
+      setupHandlerPkgs(pkgs.split("|"));
+   }
+
+   public static void setupHandlerPkgs(String[] additionalPkgs)
+   {
+      String pkgs = System.getProperty("java.protocol.handler.pkgs");
+      if (pkgs == null || pkgs.trim().length() == 0)
+      {
+         pkgs = "";
+         for (int i = 0; i < additionalPkgs.length; i++)
+         {
+            pkgs += additionalPkgs[i];
+            if (i + 1 < additionalPkgs.length) pkgs += "|";
+         }
+         System.setProperty("java.protocol.handler.pkgs", pkgs);
+      }
+      else
+      {
+         for (String pkg : additionalPkgs)
+         {
+            pkgs += "|" + pkg;
+         }
+         System.setProperty("java.protocol.handler.pkgs", pkgs);
+      }
+   }
+}

Modified: trunk/embedded/src/main/resources/javase/conf/bootstrap-beans.xml
===================================================================
--- trunk/embedded/src/main/resources/javase/conf/bootstrap-beans.xml	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/resources/javase/conf/bootstrap-beans.xml	2007-01-11 07:01:21 UTC (rev 59512)
@@ -5,11 +5,16 @@
 -->
 <deployment xmlns="urn:jboss:bean-deployer:2.0">
 
+   <bean name="ServerConfig" class="org.jboss.embedded.ServerConfig"/>
+
    <!-- The legacy JMX kernel -->
    <bean name="JMXKernel" class="org.jboss.embedded.JMXKernel">
       <property name="kernel">
          <inject bean="jboss.kernel:service=Kernel"/>
       </property>
+      <property name="serverConfig">
+         <inject bean="ServerConfig"/>
+      </property>
    </bean>
 
    <!-- The MainDeployer -->
@@ -123,21 +128,47 @@
         setup deployers
         setup deploy/ directory
      -->
-   <bean name="ResourcesToDeploy" class="org.jboss.embedded.ClasspathResourceScanner">
+   <bean name="ResourcesToDeploy" class="org.jboss.embedded.DeploymentGroupBean">
       <property name="filter"><inject bean="DeploymentFilter"/></property>
       <property name="mainDeployer">
          <inject bean="MainDeployer"/>
       </property>
+      <property name="kernel">
+         <inject bean="jboss.kernel:service=Kernel"/>
+      </property>
       <property name="resources">
          <list elementClass="java.lang.String">
-            <value>conf/jboss-service.xml</value>
+            <value>${jboss.embedded.bootstrap.resource.path}conf/jboss-service.xml</value>
          </list>
       </property>
-      <property name="deployDirsByResource">
+   </bean>
+
+   <bean name="ResourcesToDeploy2" class="org.jboss.embedded.DeploymentGroupBean">
+      <property name="filter"><inject bean="DeploymentFilter"/></property>
+      <property name="mainDeployer">
+         <inject bean="MainDeployer"/>
+      </property>
+      <property name="kernel">
+         <inject bean="jboss.kernel:service=Kernel"/>
+      </property>
+      <property name="directoriesByResource">
          <list elementClass="java.lang.String">
-            <value>conf/jboss-service.xml/../deployers</value>
-            <value>conf/jboss-service.xml/../deploy</value>
+            <value>${jboss.embedded.bootstrap.resource.path}conf/jboss-service.xml/../deployers</value>
          </list>
       </property>
    </bean>
+   <bean name="ResourcesToDeploy3" class="org.jboss.embedded.DeploymentGroupBean">
+      <property name="filter"><inject bean="DeploymentFilter"/></property>
+      <property name="mainDeployer">
+         <inject bean="MainDeployer"/>
+      </property>
+      <property name="kernel">
+         <inject bean="jboss.kernel:service=Kernel"/>
+      </property>
+      <property name="directoriesByResource">
+         <list elementClass="java.lang.String">
+            <value>${jboss.embedded.bootstrap.resource.path}conf/jboss-service.xml/../deploy</value>
+         </list>
+      </property>
+   </bean>
 </deployment>

Modified: trunk/embedded/src/main/resources/javase/conf/jboss-service.xml
===================================================================
--- trunk/embedded/src/main/resources/javase/conf/jboss-service.xml	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/resources/javase/conf/jboss-service.xml	2007-01-11 07:01:21 UTC (rev 59512)
@@ -36,7 +36,7 @@
    </mbean>
    <mbean code="org.jboss.security.auth.login.XMLLoginConfig"
       name="jboss.security:service=XMLLoginConfig">
-      <attribute name="ConfigResource">conf/login-config.xml</attribute>
+      <attribute name="ConfigResource">${jboss.embedded.bootstrap.resource.path}conf/login-config.xml</attribute>
    </mbean>
 
    <!-- JAAS security manager and realm mapping -->

Modified: trunk/embedded/src/main/resources/javase/log4j.xml
===================================================================
--- trunk/embedded/src/main/resources/javase/log4j.xml	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/resources/javase/log4j.xml	2007-01-11 07:01:21 UTC (rev 59512)
@@ -19,7 +19,7 @@
 <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
       <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
       <param name="Target" value="System.out"/>
-      <param name="Threshold" value="INFO"/>
+      <param name="Threshold" value="WARN"/>
 
       <layout class="org.apache.log4j.PatternLayout">
          <!-- The default pattern: Date Priority [Category] Messagen -->

Added: trunk/embedded/src/main/resources/tomcat-jndi.properties
===================================================================
--- trunk/embedded/src/main/resources/tomcat-jndi.properties	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/main/resources/tomcat-jndi.properties	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,4 @@
+# DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
+#
+java.naming.factory.initial=org.jboss.embedded.KernelInitializingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Modified: trunk/embedded/src/test/java/org/jboss/embedded/test/ejb/unit/EjbTestCase.java
===================================================================
--- trunk/embedded/src/test/java/org/jboss/embedded/test/ejb/unit/EjbTestCase.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/test/java/org/jboss/embedded/test/ejb/unit/EjbTestCase.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -27,6 +27,7 @@
 import junit.extensions.TestSetup;
 import org.jboss.embedded.Bootstrap;
 import org.jboss.embedded.JMXKernel;
+import org.jboss.embedded.DeploymentGroup;
 import org.jboss.embedded.test.bootstrap.unit.BootstrapTestCase;
 import org.jboss.embedded.test.ejb.DAO;
 import org.jboss.embedded.test.ejb.Customer;
@@ -124,7 +125,9 @@
 
    public void testSimpleEjb() throws Exception
    {
-      bootstrap.scanClasspath("ejb-test.jar");
+      DeploymentGroup group = bootstrap.createDeploymentGroup();
+      group.scanClasspath("ejb-test.jar");
+
       outputJNDI();
       InitialContext ctx = new InitialContext();
       DAO dao = (DAO)ctx.lookup("DAOBean/local");
@@ -132,6 +135,10 @@
       cust = dao.findCustomer("Bill");
       assert cust != null;
       assert cust.getName().equals("Bill");
+
+      group.undeploy();
+
+
    }
 
 }

Added: trunk/embedded/src/test/java/org/jboss/embedded/test/jndibootstrap/unit/BootstrapTestCase.java
===================================================================
--- trunk/embedded/src/test/java/org/jboss/embedded/test/jndibootstrap/unit/BootstrapTestCase.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/embedded/src/test/java/org/jboss/embedded/test/jndibootstrap/unit/BootstrapTestCase.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -0,0 +1,93 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.embedded.test.jndibootstrap.unit;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.jboss.embedded.Bootstrap;
+import org.jboss.embedded.JMXKernel;
+import org.jboss.embedded.jndi.KernelInitializingContextFactory;
+
+import javax.naming.InitialContext;
+import javax.naming.Context;
+import javax.sql.DataSource;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.ReflectionException;
+import javax.management.MalformedObjectNameException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.sql.Connection;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 42757 $
+ */
+public class BootstrapTestCase extends TestCase
+{
+   public BootstrapTestCase()
+   {
+      super("BootstrapTestCase");
+   }
+
+   public static Test suite() throws Exception
+   {
+      TestSuite suite = new TestSuite();
+      suite.addTestSuite(BootstrapTestCase.class);
+
+      return suite;
+   }
+
+   public void testDefaultDS() throws Exception
+   {
+      System.setProperty(Context.INITIAL_CONTEXT_FACTORY, KernelInitializingContextFactory.class.getName());
+      System.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
+      InitialContext ctx = new InitialContext();
+      outputJNDI();
+      DataSource ds = (DataSource)ctx.lookup("java:/DefaultDS");
+      Connection conn = ds.getConnection();
+      conn.close();
+   }
+
+   public void testTwo() throws Exception
+   {
+      assert KernelInitializingContextFactory.initialized == true;
+   }
+
+   private void outputJNDI()
+           throws InstanceNotFoundException, MBeanException, ReflectionException, MalformedObjectNameException
+   {
+      MBeanServer server = getMBeanServer();
+      String xml = (String)server.invoke(new ObjectName("jboss:service=JNDIView"), "listXML", null, null);
+      System.out.println(xml);
+   }
+
+   private static MBeanServer getMBeanServer()
+   {
+      JMXKernel jmxKernel = (JMXKernel) Bootstrap.getInstance().getKernel().getRegistry().getEntry("JMXKernel").getTarget();
+      MBeanServer server = jmxKernel.getMbeanServer();
+      return server;
+   }
+}

Modified: trunk/server/src/main/org/jboss/naming/ENCFactory.java
===================================================================
--- trunk/server/src/main/org/jboss/naming/ENCFactory.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/server/src/main/org/jboss/naming/ENCFactory.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -30,6 +30,7 @@
 import java.security.AccessController;
 import javax.naming.Context;
 import javax.naming.Name;
+import javax.naming.NamingException;
 import javax.naming.spi.ObjectFactory;
 
 import org.jnp.server.NamingServer;
@@ -75,6 +76,11 @@
       return encIdStack.pop();
    }
 
+   public static Object getCurrentId()
+   {
+      return encIdStack.get();
+   }
+
    // Static --------------------------------------------------------
    public static void setTopClassLoader(ClassLoader topLoader)
    {
@@ -86,8 +92,11 @@
    }
 
 
+
+
    // Constructors --------------------------------------------------
 
+
    // Public --------------------------------------------------------
 
    // ObjectFactory implementation ----------------------------------
@@ -101,8 +110,7 @@
          Context compCtx = encById.get(currentId);
          if (compCtx == null)
          {
-            NamingServer srv = new NamingServer();
-            compCtx = new NamingContext(environment, null, srv);
+            compCtx = createContext(environment);
             encById.put(currentId, compCtx);
          }
          return compCtx;
@@ -128,8 +136,7 @@
             // If we did not find an ENC create it
             if( compCtx == null )
             {
-               NamingServer srv = new NamingServer();
-               compCtx = new NamingContext(environment, null, srv);
+               compCtx = createContext(environment);
                classloaderKeyedEncs.put(ctxClassLoader, compCtx);
             }
          }
@@ -137,6 +144,15 @@
       }
    }
 
+   protected Context createContext(Hashtable environment)
+           throws NamingException
+   {
+      Context compCtx;
+      NamingServer srv = new NamingServer();
+      compCtx = new NamingContext(environment, null, srv);
+      return compCtx;
+   }
+
    private static class GetTCLAction implements PrivilegedAction
    {
       static PrivilegedAction ACTION = new GetTCLAction();

Modified: trunk/server/src/main/org/jboss/naming/JavaCompInitializer.java
===================================================================
--- trunk/server/src/main/org/jboss/naming/JavaCompInitializer.java	2007-01-11 06:37:05 UTC (rev 59511)
+++ trunk/server/src/main/org/jboss/naming/JavaCompInitializer.java	2007-01-11 07:01:21 UTC (rev 59512)
@@ -40,7 +40,6 @@
    private InitialContext iniCtx;
    private Hashtable initialContextProperties;
 
-
    public Hashtable getInitialContextProperties()
    {
       return initialContextProperties;
@@ -83,6 +82,5 @@
       Reference envRef = new Reference("javax.naming.Context", refAddr, ENCFactory.class.getName(), null);
       Context ctx = (Context)iniCtx.lookup("java:");
       ctx.rebind("comp", envRef);
-
    }
 }




More information about the jboss-cvs-commits mailing list