01: package org.jbpm.command;
02:
03: import java.io.ByteArrayInputStream;
04: import java.io.StringReader;
05: import java.util.zip.ZipInputStream;
06:
07: import org.jbpm.JbpmContext;
08: import org.jbpm.JbpmException;
09: import org.jbpm.db.JbpmSchema;
10: import org.jbpm.graph.def.ProcessDefinition;
11: import org.jbpm.jpdl.xml.JpdlXmlReader;
12: import org.apache.commons.logging.Log;
13: import org.apache.commons.logging.LogFactory;
14:
15: /**
16: * Deploys a process, given as XML-String (be patient with Umlauts or something
17: * like that) or par archive (byte-array). if both is given, the byte-array will
18: * be preferred
19: *
20: * The deplpoyed process definition is returned
21: *
22: * @author Bernd Ruecker (bernd.ruecker@camunda.com)
23: *
24: */
25: public class DeployProcessCommand extends AbstractGetObjectBaseCommand {
26:
27: private static final long serialVersionUID = -5861811926680981061L;
28:
29: private String xml;
30:
31: private byte[] par;
32:
33: private static final Log log = LogFactory
34: .getLog(DeployProcessCommand.class);
35:
36: public DeployProcessCommand() {
37: }
38:
39: public DeployProcessCommand(byte[] par) {
40: this .par = par;
41: }
42:
43: public DeployProcessCommand(String xml) {
44: this .xml = xml;
45: }
46:
47: /**
48: * @return deployed ProcessDefinition
49: */
50: public Object execute(JbpmContext jbpmContext) throws Exception {
51: ProcessDefinition processDefinition = null;
52: if (par != null && par.length > 0) {
53: log.info("start parsing process from par");
54:
55: // Thanks to George Mournos who helped to improve this:
56: ZipInputStream zipInputStream = new ZipInputStream(
57: new ByteArrayInputStream(par));
58: processDefinition = ProcessDefinition
59: .parseParZipInputStream(zipInputStream);
60:
61: jbpmContext.deployProcessDefinition(processDefinition);
62: log.info("deployment sucessfull");
63: } else if (xml != null && xml.length() > 0) {
64: log.info("parse process from String");
65: log.debug("deploy process:\n" + xml);
66:
67: processDefinition = ProcessDefinition.parseXmlString(xml);
68:
69: jbpmContext.deployProcessDefinition(processDefinition);
70: log.info("deployment sucessfull");
71: } else
72: throw new JbpmException(
73: "either xml string or par archive must be given.");
74: return retrieveProcessDefinition(processDefinition);
75: }
76:
77: public byte[] getPar() {
78: return par;
79: }
80:
81: public void setPar(byte[] par) {
82: this .par = par;
83: }
84:
85: public String getXml() {
86: return xml;
87: }
88:
89: public void setXml(String xml) {
90: this.xml = xml;
91: }
92:
93: }
|