[jbpm-commits] JBoss JBPM SVN: r3147 - in jbpm3/trunk/modules: integration/jboss42/src/main/etc and 4 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Nov 28 08:54:21 EST 2008
Author: thomas.diesler at jboss.com
Date: 2008-11-28 08:54:21 -0500 (Fri, 28 Nov 2008)
New Revision: 3147
Added:
jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/
jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/AbstractDeployment.java
jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/PARDeployment.java
jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/XMLDeployment.java
jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/service/DeploymentServiceImpl.java
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/par/ProcessArchive.java
jbpm3/trunk/modules/integration/jboss42/src/main/etc/jboss-beans.xml
jbpm3/trunk/modules/integration/jboss42/src/main/java/org/jbpm/integration/jboss42/PARSubDeployer.java
Log:
Add deployment service
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/par/ProcessArchive.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/par/ProcessArchive.java 2008-11-28 13:50:24 UTC (rev 3146)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/par/ProcessArchive.java 2008-11-28 13:54:21 UTC (rev 3147)
@@ -44,100 +44,125 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-public class ProcessArchive implements ProblemListener {
-
+public class ProcessArchive implements ProblemListener
+{
+
private static final long serialVersionUID = 1L;
static List processArchiveParsers = getProcessArchiveParsers();
-
+
// fields ///////////////////////////////////////////////////////////////////
String name = "";
// maps entry-names (String) to byte-arrays (byte[])
Map entries = new HashMap();
- List problems = new ArrayList();
+ List problems = new ArrayList();
// constructors /////////////////////////////////////////////////////////////
- public ProcessArchive(ZipInputStream zipInputStream) throws IOException {
+ public ProcessArchive(ZipInputStream zipInputStream) throws IOException
+ {
ZipEntry zipEntry = zipInputStream.getNextEntry();
- while(zipEntry!=null) {
+ while (zipEntry != null)
+ {
String entryName = zipEntry.getName();
byte[] bytes = IoUtil.readBytes(zipInputStream);
- if (bytes!=null) {
+ if (bytes != null)
+ {
entries.put(entryName, bytes);
}
zipEntry = zipInputStream.getNextEntry();
}
}
-
+
// parse the process definition from the contents ///////////////////////////
- public ProcessDefinition parseProcessDefinition() {
+ public ProcessDefinition parseProcessDefinition()
+ {
ProcessDefinition processDefinition = ProcessDefinition.createNewProcessDefinition();
Iterator iter = processArchiveParsers.iterator();
- while (iter.hasNext()) {
- ProcessArchiveParser processArchiveParser = (ProcessArchiveParser) iter.next();
+ while (iter.hasNext())
+ {
+ ProcessArchiveParser processArchiveParser = (ProcessArchiveParser)iter.next();
processDefinition = processArchiveParser.readFromArchive(this, processDefinition);
}
- if (Problem.containsProblemsOfLevel(problems, Problem.LEVEL_ERROR)) {
+ if (Problem.containsProblemsOfLevel(problems, Problem.LEVEL_ERROR))
+ {
throw new JpdlException(problems);
}
return processDefinition;
}
-
+
// methods for the process archive parsers //////////////////////////////////
- public String toString() {
- return "process-archive("+name+")";
+ public String toString()
+ {
+ return "process-archive(" + name + ")";
}
-
- public Map getEntries() {
+
+ public Map getEntries()
+ {
return entries;
}
-
- public byte[] getEntry(String entryName) {
- return (byte[]) entries.get(entryName);
+
+ public byte[] getEntry(String entryName)
+ {
+ return (byte[])entries.get(entryName);
}
- public InputStream getEntryInputStream(String entryName) {
+ public InputStream getEntryInputStream(String entryName)
+ {
return new ByteArrayInputStream(getEntry(entryName));
}
- public byte[] removeEntry(String entryName) {
- return (byte[]) entries.remove(entryName);
+ public byte[] removeEntry(String entryName)
+ {
+ return (byte[])entries.remove(entryName);
}
- public InputStream removeEntryInputStream(String entryName) {
+ public InputStream removeEntryInputStream(String entryName)
+ {
return new ByteArrayInputStream(removeEntry(entryName));
}
- public void addProblem(Problem problem) {
+
+ public void addProblem(Problem problem)
+ {
problems.add(problem);
}
- public List getProblems() {
+
+ public List getProblems()
+ {
return problems;
}
- public void resetProblems() {
+
+ public void resetProblems()
+ {
problems = new ArrayList();
}
- static List getProcessArchiveParsers() {
+ static List getProcessArchiveParsers()
+ {
List processArchiveParsers = new ArrayList();
- try {
+ try
+ {
String resource = JbpmConfiguration.Configs.getString("resource.parsers");
InputStream parsersStream = ClassLoaderUtil.getStream(resource);
Document document = XmlUtil.parseXmlInputStream(parsersStream);
Iterator iter = XmlUtil.elementIterator(document.getDocumentElement(), "parser");
- while (iter.hasNext()) {
- Element element = (Element) iter.next();
+ while (iter.hasNext())
+ {
+ Element element = (Element)iter.next();
String className = element.getAttribute("class");
- ProcessArchiveParser processArchiveParser= (ProcessArchiveParser) ClassLoaderUtil.loadClass(className).newInstance();
- if (processArchiveParser instanceof ConfigurableParser) {
+ ProcessArchiveParser processArchiveParser = (ProcessArchiveParser)ClassLoaderUtil.loadClass(className).newInstance();
+ if (processArchiveParser instanceof ConfigurableParser)
+ {
((ConfigurableParser)processArchiveParser).configure(element);
}
processArchiveParsers.add(processArchiveParser);
}
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new JbpmException("couldn't parse process archive parsers (jbpm.parsers.xml)", e);
}
return processArchiveParsers;
Modified: jbpm3/trunk/modules/integration/jboss42/src/main/etc/jboss-beans.xml
===================================================================
--- jbpm3/trunk/modules/integration/jboss42/src/main/etc/jboss-beans.xml 2008-11-28 13:50:24 UTC (rev 3146)
+++ jbpm3/trunk/modules/integration/jboss42/src/main/etc/jboss-beans.xml 2008-11-28 13:54:21 UTC (rev 3147)
@@ -13,6 +13,7 @@
<bean name="BPMProcessEngine" class="org.jbpm.integration.client.ProcessEngineImpl">
<property name="services">
<set elementClass="org.jboss.bpm.api.service.Service">
+ <inject bean="BPMDeploymentService"/>
<inject bean="BPMDialectHandlerService"/>
<inject bean="BPMExecutionService"/>
<inject bean="BPMIdentityService"/>
@@ -49,6 +50,7 @@
<bean name="BPMDialectHandlerJPDL32" class="org.jbpm.integration.jpdl32.DialectHandlerImpl" />
<!-- Other Services -->
+ <bean name="BPMDeploymentService" class="org.jbpm.integration.service.DeploymentServiceImpl" />
<bean name="BPMExecutionService" class="org.jbpm.integration.service.ExecutionServiceImpl" />
<bean name="BPMIdentityService" class="org.jbpm.integration.service.IdentityServiceImpl" />
<bean name="BPMProcessBuilderService" class="org.jbpm.integration.service.ProcessBuilderServiceImpl" />
Modified: jbpm3/trunk/modules/integration/jboss42/src/main/java/org/jbpm/integration/jboss42/PARSubDeployer.java
===================================================================
--- jbpm3/trunk/modules/integration/jboss42/src/main/java/org/jbpm/integration/jboss42/PARSubDeployer.java 2008-11-28 13:50:24 UTC (rev 3146)
+++ jbpm3/trunk/modules/integration/jboss42/src/main/java/org/jbpm/integration/jboss42/PARSubDeployer.java 2008-11-28 13:54:21 UTC (rev 3147)
@@ -25,15 +25,13 @@
import java.net.URL;
-import javax.management.ObjectName;
-
+import org.jboss.bpm.api.client.Configuration;
+import org.jboss.bpm.api.client.ProcessEngine;
+import org.jboss.bpm.api.deployment.Deployment;
+import org.jboss.bpm.api.service.DeploymentService;
import org.jboss.deployment.DeploymentException;
import org.jboss.deployment.DeploymentInfo;
import org.jboss.deployment.SubDeployerSupport;
-import org.jboss.bpm.api.client.Configuration;
-import org.jboss.bpm.api.client.ProcessEngine;
-import org.jboss.bpm.api.model.ProcessDefinition;
-import org.jboss.bpm.api.service.ProcessDefinitionService;
/**
* A deployer service that manages jBPM Process Archive Deployments
@@ -44,9 +42,9 @@
public class PARSubDeployer extends SubDeployerSupport implements PARSubDeployerMBean
{
/** The suffixes we accept, along with their relative order */
- private static final String[] DEFAULT_ENHANCED_SUFFIXES = new String[] { "900:-process.xml" };
+ private static final String[] DEFAULT_ENHANCED_SUFFIXES = new String[] { "900:-process.xml", "900:.par" };
- private ProcessDefinitionService procDefService;
+ private DeploymentService depService;
public PARSubDeployer()
{
@@ -64,13 +62,12 @@
try
{
- // Parese and register the procdef
- ProcessDefinitionService pdService = getProcessDefinitionService();
- ProcessDefinition procDef = pdService.parseProcessDefinition(pdURL);
- pdService.registerProcessDefinition(procDef);
+ DeploymentService depService = getDeploymentService();
+ Deployment dep = depService.createDeployment(pdURL);
+ depService.deploy(dep);
// Remember the procDefID
- di.context.put(ProcessDefinition.class.getName(), procDef.getKey());
+ di.context.put(Deployment.class.getName(), dep);
}
catch (RuntimeException rte)
{
@@ -88,13 +85,13 @@
URL pdURL = getProcessDefinitionURL(di);
log.info("Undeploy ProcessDefinition: " + pdURL);
- ObjectName procDefID = (ObjectName)di.context.get(ProcessDefinition.class.getName());
- if (procDefID != null)
+ Deployment dep = (Deployment)di.context.get(Deployment.class.getName());
+ if (dep != null)
{
try
{
- ProcessDefinitionService pdService = getProcessDefinitionService();
- pdService.unregisterProcessDefinition(procDefID);
+ DeploymentService depService = getDeploymentService();
+ depService.undeploy(dep);
}
catch (RuntimeException rte)
{
@@ -117,14 +114,14 @@
return pdURL;
}
- private ProcessDefinitionService getProcessDefinitionService()
+ private DeploymentService getDeploymentService()
{
// This is done lazily because the deployers become available before MC beans
- if (procDefService == null)
+ if (depService == null)
{
ProcessEngine engine = Configuration.getProcessEngine();
- procDefService = engine.getService(ProcessDefinitionService.class);
+ depService = engine.getService(DeploymentService.class);
}
- return procDefService;
+ return depService;
}
}
\ No newline at end of file
Added: jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/AbstractDeployment.java
===================================================================
--- jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/AbstractDeployment.java (rev 0)
+++ jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/AbstractDeployment.java 2008-11-28 13:54:21 UTC (rev 3147)
@@ -0,0 +1,37 @@
+/*
+ * 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.integration.deployment;
+
+// $Id$
+
+import org.jboss.bpm.api.deployment.Deployment;
+import org.jboss.bpm.api.runtime.BasicAttachments;
+
+/**
+ * An abstraction of a process deployment
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 17-Sep-2008
+ */
+public abstract class AbstractDeployment extends BasicAttachments implements Deployment
+{
+}
Property changes on: jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/AbstractDeployment.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/PARDeployment.java
===================================================================
--- jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/PARDeployment.java (rev 0)
+++ jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/PARDeployment.java 2008-11-28 13:54:21 UTC (rev 3147)
@@ -0,0 +1,83 @@
+/*
+ * 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.integration.deployment;
+
+// $Id$
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * An in-memory persistence service.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 17-Sep-2008
+ */
+public class PARDeployment extends AbstractDeployment
+{
+ private static final String PROCESSDEFINITION_ENTRY = "processdefinition.xml";
+ private URL pdURL;
+
+ public PARDeployment(URL pdURL)
+ {
+ this.pdURL = pdURL;
+ }
+
+ public String getProcessDefinitionXML() throws IOException
+ {
+ String pdXML = null;
+
+ ZipInputStream zip = new ZipInputStream(pdURL.openStream());
+ ZipEntry zipEntry = zip.getNextEntry();
+ String entryName = zipEntry.getName();
+ if (PROCESSDEFINITION_ENTRY.equals(entryName))
+ {
+ long size = zipEntry.getSize();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ byte[] bytes = new byte[4096];
+ int len = (int)Math.min(4096, size);
+ while (len > 0)
+ {
+ int read = zip.read(bytes, 0, len);
+ baos.write(bytes, 0, read);
+
+ size = size - read;
+ len = (int)Math.min(4096, size);
+ }
+
+ pdXML = new String(baos.toByteArray());
+ }
+ else
+ {
+ zip.skip(zipEntry.getSize());
+ }
+
+ if (pdXML == null)
+ throw new IllegalStateException("Cannot obtain '" + PROCESSDEFINITION_ENTRY + "' from: " + pdURL);
+
+ return pdXML;
+ }
+}
Property changes on: jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/PARDeployment.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/XMLDeployment.java
===================================================================
--- jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/XMLDeployment.java (rev 0)
+++ jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/XMLDeployment.java 2008-11-28 13:54:21 UTC (rev 3147)
@@ -0,0 +1,64 @@
+/*
+ * 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.integration.deployment;
+
+// $Id$
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.URL;
+
+/**
+ * An abstraction of a process deployment
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 17-Sep-2008
+ */
+public class XMLDeployment extends AbstractDeployment
+{
+ private URL pdURL;
+
+ public XMLDeployment(URL pdURL)
+ {
+ this.pdURL = pdURL;
+ }
+
+ public String getProcessDefinitionXML() throws IOException
+ {
+ StringWriter sw = new StringWriter();
+ PrintWriter pr = new PrintWriter(sw);
+
+ BufferedReader br = new BufferedReader(new InputStreamReader(pdURL.openStream()));
+ String line = br.readLine();
+ while (line != null)
+ {
+ pr.println(line);
+ line = br.readLine();
+ }
+
+ String pdXML = sw.toString();
+ return pdXML;
+ }
+}
Property changes on: jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/deployment/XMLDeployment.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/service/DeploymentServiceImpl.java
===================================================================
--- jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/service/DeploymentServiceImpl.java (rev 0)
+++ jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/service/DeploymentServiceImpl.java 2008-11-28 13:54:21 UTC (rev 3147)
@@ -0,0 +1,107 @@
+/*
+ * 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.integration.service;
+
+// $Id$
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.management.ObjectName;
+
+import org.jboss.bpm.api.client.ProcessEngine;
+import org.jboss.bpm.api.deployment.Deployment;
+import org.jboss.bpm.api.model.ProcessDefinition;
+import org.jboss.bpm.api.service.DeploymentService;
+import org.jboss.bpm.api.service.ProcessDefinitionService;
+import org.jbpm.integration.deployment.PARDeployment;
+import org.jbpm.integration.deployment.XMLDeployment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The DeploymentService is the entry point to deploy and undeploy ProcessDefinitions.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 28-Nov-2008
+ */
+public class DeploymentServiceImpl extends DeploymentService implements MutableService
+{
+ // Provide logging
+ final Logger log = LoggerFactory.getLogger(DeploymentServiceImpl.class);
+
+ //@Override
+ public void setProcessEngine(ProcessEngine engine)
+ {
+ super.setProcessEngine(engine);
+ }
+
+ @Override
+ public Deployment createDeployment(URL depURL)
+ {
+ Deployment dep;
+ if (depURL.toExternalForm().endsWith("xml"))
+ {
+ dep = new XMLDeployment(depURL);
+ }
+ else if (depURL.toExternalForm().endsWith("par"))
+ {
+ dep = new PARDeployment(depURL);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unsupported deployment URL: " + depURL);
+ }
+ return dep;
+ }
+
+ @Override
+ public ObjectName deploy(Deployment dep)
+ {
+ try
+ {
+ String pdXML = dep.getProcessDefinitionXML();
+
+ // Parse and register the ProcessDefinition
+ ProcessDefinitionService pdService = getProcessEngine().getService(ProcessDefinitionService.class);
+ ProcessDefinition procDef = pdService.parseProcessDefinition(pdXML);
+ pdService.registerProcessDefinition(procDef);
+
+ ObjectName key = procDef.getKey();
+ dep.addAttachment(ObjectName.class, "procDefKey", key);
+
+ return key;
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot deploy: dep");
+ }
+ }
+
+ @Override
+ public void undeploy(Deployment dep)
+ {
+ ObjectName key = dep.getAttachment(ObjectName.class, "procDefKey");
+ ProcessDefinitionService pdService = getProcessEngine().getService(ProcessDefinitionService.class);
+ pdService.unregisterProcessDefinition(key);
+ }
+}
Property changes on: jbpm3/trunk/modules/integration/spec/src/main/java/org/jbpm/integration/service/DeploymentServiceImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the jbpm-commits
mailing list