[jboss-osgi-commits] JBoss-OSGI SVN: r90464 - projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Fri Jun 19 03:55:30 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-06-19 03:55:30 -0400 (Fri, 19 Jun 2009)
New Revision: 90464

Added:
   projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedKernelBootstrap.java
   projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedSchemaResolverFactory.java
   projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java
Removed:
   projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeansDeployer.java
Modified:
   projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
Log:
[JBOSGI-107] Use embedded schema resolver

Deleted: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeansDeployer.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeansDeployer.java	2009-06-19 07:46:03 UTC (rev 90463)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeansDeployer.java	2009-06-19 07:55:30 UTC (rev 90464)
@@ -1,103 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, 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.osgi.microcontainer.internal;
-
-// $Id$
-
-import java.net.URL;
-
-import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
-import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
-import org.jboss.osgi.common.log.LogServiceTracker;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogService;
-
-/**
- * Boostrap the Microcontainer
- * 
- * @author thomas.diesler at jboss.com
- * @since 27-Jun-2008
- */
-public class EmbeddedBeansDeployer extends BasicBootstrap
-{
-   private LogService log;
-   private BasicXMLDeployer deployer;
-
-   public EmbeddedBeansDeployer(BundleContext context)
-   {
-      this.log = new LogServiceTracker(context);
-      
-      // Get or bootstrap the kernel
-      if (kernel == null)
-      {
-         try
-         {
-            super.bootstrap();
-            log.log(LogService.LOG_DEBUG, "bootstrap kernel: " + kernel);
-         }
-         catch (Throwable e)
-         {
-            throw new IllegalStateException("Cannot bootstrap kernel", e);
-         }
-      }
-      deployer = new BasicXMLDeployer(kernel);
-   }
-
-   /** 
-    * Deploy MC beans from URL
-    */
-   public void deploy(URL url)
-   {
-      log.log(LogService.LOG_DEBUG, "deploy: " + url);
-      ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
-      try
-      {
-         Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-         deployer.deploy(url);
-         deployer.validate();
-      }
-      catch (Throwable e)
-      {
-         throw new IllegalStateException("Cannot deploy beans from: " + url, e);
-      }
-      finally
-      {
-         Thread.currentThread().setContextClassLoader(ctxLoader);
-      }
-   }
-
-   /**
-    * Undeploy MC beans from URL
-    */
-   public void undeploy(URL url)
-   {
-      log.log(LogService.LOG_DEBUG, "undeploy: " + url);
-      try
-      {
-         deployer.undeploy(url);
-      }
-      catch (Throwable e)
-      {
-         throw new IllegalStateException("Cannot undeploy beans from: " + url, e);
-      }
-   }
-}
\ No newline at end of file

Copied: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedKernelBootstrap.java (from rev 90458, projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeansDeployer.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedKernelBootstrap.java	                        (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedKernelBootstrap.java	2009-06-19 07:55:30 UTC (rev 90464)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.osgi.microcontainer.internal;
+
+// $Id$
+
+import java.net.URL;
+
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.osgi.common.log.LogServiceTracker;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+/**
+ * Boostrap the Microcontainer
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-Jun-2008
+ */
+public class EmbeddedKernelBootstrap extends BasicBootstrap
+{
+   private LogService log;
+   private EmbeddedXMLDeployer deployer;
+
+   public EmbeddedKernelBootstrap(BundleContext context)
+   {
+      this.log = new LogServiceTracker(context);
+      
+      // Get or bootstrap the kernel
+      if (kernel == null)
+      {
+         try
+         {
+            super.bootstrap();
+            log.log(LogService.LOG_DEBUG, "bootstrap kernel: " + kernel);
+         }
+         catch (Throwable e)
+         {
+            throw new IllegalStateException("Cannot bootstrap kernel", e);
+         }
+      }
+      deployer = new EmbeddedXMLDeployer(kernel);
+   }
+
+   /** 
+    * Deploy MC beans from URL
+    */
+   public void deploy(URL url)
+   {
+      log.log(LogService.LOG_DEBUG, "deploy: " + url);
+      ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+      try
+      {
+         Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+         deployer.deploy(url);
+         deployer.validate();
+      }
+      catch (Throwable e)
+      {
+         throw new IllegalStateException("Cannot deploy beans from: " + url, e);
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(ctxLoader);
+      }
+   }
+
+   /**
+    * Undeploy MC beans from URL
+    */
+   public void undeploy(URL url)
+   {
+      log.log(LogService.LOG_DEBUG, "undeploy: " + url);
+      try
+      {
+         deployer.undeploy(url);
+      }
+      catch (Throwable e)
+      {
+         throw new IllegalStateException("Cannot undeploy beans from: " + url, e);
+      }
+   }
+}
\ No newline at end of file

Added: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedSchemaResolverFactory.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedSchemaResolverFactory.java	                        (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedSchemaResolverFactory.java	2009-06-19 07:55:30 UTC (rev 90464)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.osgi.microcontainer.internal;
+
+// $Id$
+
+import org.jboss.logging.Logger;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaResolverFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
+
+/**
+ * A {@link SchemaResolverFactory} that unlike the {@link SingletonSchemaResolverFactory} 
+ * does not cache classes in static singletons.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-Jun-2008
+ */
+public class EmbeddedSchemaResolverFactory implements SchemaResolverFactory
+{
+   /** The log */
+   private static final Logger log = Logger.getLogger(EmbeddedSchemaResolverFactory.class);
+
+   /** The resolver */
+   private final DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+
+   /**
+    * Create a new SingletonSchemaResolverFactory.
+    */
+   private EmbeddedSchemaResolverFactory()
+   {
+      addJaxbSchema("urn:jboss:aop-beans:1.0", "org.jboss.aop.microcontainer.beans.metadata.AOPDeployment");
+      addJaxbSchema("urn:jboss:bean-deployer", "org.jboss.kernel.plugins.deployment.AbstractKernelDeployment10");
+      addJaxbSchema("urn:jboss:bean-deployer:2.0", "org.jboss.kernel.plugins.deployment.AbstractKernelDeployment");
+      addJaxbSchema("urn:jboss:javabean:1.0", "org.jboss.javabean.plugins.jaxb.JavaBean10");
+      addJaxbSchema("urn:jboss:javabean:2.0", "org.jboss.javabean.plugins.jaxb.JavaBean20");
+      addJaxbSchema("urn:jboss:policy:1.0", "org.jboss.beans.metadata.plugins.policy.AbstractPolicyMetaData");
+      addJaxbSchema("urn:jboss:classloading:1.0", "org.jboss.classloading.spi.metadata.ClassLoadingMetaData10");
+      addJaxbSchema("urn:jboss:classloader:1.0", "org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory10");
+      addJaxbSchema("urn:jboss:deployers:2.0", "org.jboss.deployers.vfs.plugins.xb.SchemaResolverDeployerMetaData");
+   }
+
+   public static SchemaResolverFactory getInstance()
+   {
+      return new EmbeddedSchemaResolverFactory();
+   }
+   
+   public SchemaBindingResolver getSchemaBindingResolver()
+   {
+      return resolver;
+   }
+
+   /**
+    * Set the parse annotations for a schema
+    * 
+    * @param namespace the namespace
+    * @param parseAnnotations whether to parse annotations
+    */
+   protected void setParseAnnotations(String namespace, Boolean parseAnnotations)
+   {
+      resolver.addSchemaParseAnnotations(namespace, parseAnnotations);
+      if (log.isTraceEnabled())
+         log.trace("Parse annotations '" + namespace + "' set to '" + parseAnnotations + "'");
+   }
+
+   /**
+    * Add a schema.
+    * 
+    * @param namespace the namespace
+    * @param reference the schema reference class
+    * @return true when added
+    */
+   public boolean addJaxbSchema(String namespace, String reference)
+   {
+      try
+      {
+         resolver.addClassBinding(namespace, reference);
+         if (log.isTraceEnabled())
+            log.trace("Mapped '" + namespace + "' to '" + reference + "'");
+         
+         return true;
+      }
+      catch (Exception ignored)
+      {
+         if (log.isTraceEnabled())
+            log.trace("Ignored: ", ignored);
+         
+         return false;
+      }
+   }
+}


Property changes on: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedSchemaResolverFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java	2009-06-19 07:55:30 UTC (rev 90464)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.osgi.microcontainer.internal;
+
+// $Id$
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.deployment.BasicKernelDeployer;
+import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+import org.jboss.logging.Logger;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+
+/**
+ * An XML deployer that unlike the {@link BasicXMLDeployer} does not cache
+ * classes in static singletons.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-Jun-2008
+ */
+public class EmbeddedXMLDeployer extends BasicKernelDeployer
+{
+   /** The log */
+   private static final Logger log = Logger.getLogger(EmbeddedXMLDeployer.class);
+
+   /** Unmarshaller factory */
+   private UnmarshallerFactory factory = UnmarshallerFactory.newInstance();
+
+   /** The resolver */
+   private SchemaBindingResolver resolver = EmbeddedSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+
+   /** The deployments by url or name */
+   private Map<String, KernelDeployment> deploymentsByName = new ConcurrentHashMap<String, KernelDeployment>();
+
+   /**
+    * Create a new XML deployer
+    * 
+    * @param kernel the kernel
+    */
+   public EmbeddedXMLDeployer(Kernel kernel)
+   {
+      super(kernel, null);
+   }
+
+   public Collection<String> getDeploymentNames()
+   {
+      return deploymentsByName.keySet();
+   }
+
+   public void deploy(KernelDeployment deployment) throws Throwable
+   {
+      super.deploy(deployment);
+      deploymentsByName.put(deployment.getName(), deployment);
+   }
+
+   public void undeploy(KernelDeployment deployment)
+   {
+      deploymentsByName.remove(deployment.getName());
+      super.undeploy(deployment);
+   }
+
+   /**
+    * Undeploy a url
+    * 
+    * @param url the url to undeploy
+    * @throws IllegalStateException if the url is unknown
+    */
+   public void undeploy(final URL url)
+   {
+      if (url == null)
+         throw new IllegalArgumentException("Null url");
+
+      undeploy(url.toString());
+   }
+
+   /**
+    * Undeploy a name deployment
+    * 
+    * @param name the name of the deployment to undeploy
+    * @throws IllegalStateException if the name is unknown
+    */
+   public void undeploy(final String name)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+
+      KernelDeployment deployment = deploymentsByName.remove(name);
+      if (deployment == null)
+         throw new IllegalStateException("Unknown deployment " + name);
+
+      undeploy(deployment);
+   }
+
+   /**
+    * Deploy a url
+    * 
+    * @param url the url to deploy
+    * @return the kernel deployment
+    * @throws Throwable for any error
+    */
+   public KernelDeployment deploy(final URL url) throws Throwable
+   {
+      final boolean trace = log.isTraceEnabled();
+
+      if (url == null)
+         throw new IllegalArgumentException("Null url");
+
+      if (trace)
+         log.trace("Parsing " + url);
+
+      long start = System.currentTimeMillis();
+
+      Unmarshaller unmarshaller = factory.newUnmarshaller();
+      KernelDeployment deployment = (KernelDeployment)unmarshaller.unmarshal(url.toString(), resolver);
+      if (deployment == null)
+         throw new RuntimeException("The xml " + url + " is not well formed!");
+
+      deployment.setName(url.toString());
+
+      if (trace)
+      {
+         long now = System.currentTimeMillis();
+         log.trace("Parsing " + url + " took " + (now - start) + " milliseconds");
+      }
+
+      deploy(deployment);
+
+      if (trace)
+      {
+         long now = System.currentTimeMillis();
+         log.trace("Deploying " + url + " took " + (now - start) + " milliseconds");
+      }
+
+      return deployment;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java	2009-06-19 07:46:03 UTC (rev 90463)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java	2009-06-19 07:55:30 UTC (rev 90464)
@@ -58,7 +58,7 @@
 public class MicrocontainerServiceImpl extends AbstractMicrocontainerService implements MicrocontainerServiceMBean
 {
    private BundleContext context;
-   private EmbeddedBeansDeployer deployer;
+   private EmbeddedKernelBootstrap deployer;
    private LogService log;
 
    public MicrocontainerServiceImpl(BundleContext context)
@@ -68,7 +68,7 @@
 
       VFS.init();
 
-      deployer = new EmbeddedBeansDeployer(context);
+      deployer = new EmbeddedKernelBootstrap(context);
    }
 
    public Kernel getKernel()




More information about the jboss-osgi-commits mailing list