[jbpm-commits] JBoss JBPM SVN: r2362 - in jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/client: internal and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Sep 24 12:30:08 EDT 2008


Author: thomas.diesler at jboss.com
Date: 2008-09-24 12:30:08 -0400 (Wed, 24 Sep 2008)
New Revision: 2362

Added:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/client/MicrocontainerEngineProvider.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/client/internal/
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/client/internal/EmbeddedBeansDeployer.java
Log:
Add MC engine provider

Added: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/client/MicrocontainerEngineProvider.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/client/MicrocontainerEngineProvider.java	                        (rev 0)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/client/MicrocontainerEngineProvider.java	2008-09-24 16:30:08 UTC (rev 2362)
@@ -0,0 +1,88 @@
+/*
+ * 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.jbpm.api.client;
+
+//$Id$
+
+import java.net.URL;
+
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.util.KernelLocator;
+import org.jboss.kernel.spi.registry.KernelRegistryEntry;
+import org.jboss.kernel.spi.registry.KernelRegistryEntryNotFoundException;
+import org.jbpm.api.client.internal.EmbeddedBeansDeployer;
+
+/**
+ * The ProcessEngineProvider provides a ProcessEngine through a given configuration method
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 18-Jun-2008
+ */
+public class MicrocontainerEngineProvider implements ProcessEngineProvider
+{
+  /** The process engine bean name - jBPMEngine */
+  public static final String BEAN_NAME = "jBPMProcessEngine";
+  /** The default bean config: jbpm-cfg-beans.xml */
+  public static final String JBPM_ENGINE_CONFIG = "jbpm-cfg-beans.xml";
+
+  /**
+   * Get the ProcessEngine from this provider
+   * 
+   * @return The configured instance of a process engine
+   */
+  @SuppressWarnings("deprecation")
+  public ProcessEngine getProcessEngine()
+  {
+    KernelRegistryEntry entry = null;
+    Kernel kernel = KernelLocator.getKernel();
+    if (kernel == null)
+    {
+      deployEngineConfiguration();
+      kernel = KernelLocator.getKernel();
+      entry = kernel.getRegistry().getEntry(BEAN_NAME);
+    }
+    else
+    {
+      try
+      {
+        entry = kernel.getRegistry().getEntry(BEAN_NAME);
+      }
+      catch (KernelRegistryEntryNotFoundException ex)
+      {
+        deployEngineConfiguration();
+        entry = kernel.getRegistry().getEntry(BEAN_NAME);
+      }
+    }
+
+    ProcessEngine engine = (ProcessEngine)entry.getTarget();
+    return engine;
+  }
+
+  private void deployEngineConfiguration()
+  {
+    URL url = Thread.currentThread().getContextClassLoader().getResource(JBPM_ENGINE_CONFIG);
+    if (url == null)
+      throw new IllegalStateException("Cannot find resource: " + JBPM_ENGINE_CONFIG);
+
+    new EmbeddedBeansDeployer().deploy(url);
+  }
+}
\ No newline at end of file


Property changes on: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/client/MicrocontainerEngineProvider.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/client/internal/EmbeddedBeansDeployer.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/client/internal/EmbeddedBeansDeployer.java	                        (rev 0)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/client/internal/EmbeddedBeansDeployer.java	2008-09-24 16:30:08 UTC (rev 2362)
@@ -0,0 +1,108 @@
+/*
+ * 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.jbpm.api.client.internal;
+
+// $Id$
+
+import java.net.URL;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
+import org.jboss.kernel.plugins.util.KernelLocator;
+
+/**
+ * Boostrap the Microcontainer
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-Jun-2008
+ */
+public class EmbeddedBeansDeployer extends BasicBootstrap
+{
+  // provide logging
+  private static final Log log = LogFactory.getLog(EmbeddedBeansDeployer.class);
+
+  private Kernel kernel;
+  private BasicXMLDeployer deployer;
+
+  public EmbeddedBeansDeployer()
+  {
+    // Get or bootstrap the kernel
+    kernel = KernelLocator.getKernel();
+    if (kernel == null)
+    {
+      try
+      {
+        super.bootstrap();
+        kernel = super.getKernel();
+        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.debug("deploy: " + url);
+    
+    // Deploy the beans
+    try
+    {
+      deployer.deploy(url);
+      deployer.validate();
+
+      // The KernelLocator is expected to get deployed as a bean
+      if (KernelLocator.getKernel() == null)
+        throw new IllegalStateException("KernelLocator not deployed as MC bean");
+
+    }
+    catch (Throwable e)
+    {
+      throw new IllegalStateException("Cannot deploy beans from: " + url, e);
+    }
+  }
+
+  /**
+   * Undeploy MC beans from URL
+   */
+  public void undeploy(URL url)
+  {
+    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


Property changes on: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/client/internal/EmbeddedBeansDeployer.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jbpm-commits mailing list