/jbpm-flow/src/main/java/org/jbpm/process/core/impl/ProcessImpl.java

https://github.com/mariofusco/jbpm · Java · 221 lines · 156 code · 42 blank · 23 comment · 12 complexity · 59ceacb7e5d62e316797b615963e81c6 MD5 · raw file

  1. /**
  2. * Copyright 2010 JBoss Inc
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.jbpm.process.core.impl;
  17. import java.io.IOException;
  18. import java.io.Serializable;
  19. import java.util.ArrayList;
  20. import java.util.HashMap;
  21. import java.util.Iterator;
  22. import java.util.List;
  23. import java.util.Map;
  24. import org.jbpm.process.core.Context;
  25. import org.jbpm.process.core.ContextContainer;
  26. import org.jbpm.process.core.ContextResolver;
  27. import org.jbpm.process.core.Process;
  28. import org.jbpm.process.core.context.AbstractContext;
  29. import org.kie.api.io.Resource;
  30. /**
  31. * Default implementation of a Process
  32. *
  33. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  34. */
  35. public class ProcessImpl implements Process, Serializable, ContextResolver {
  36. private static final long serialVersionUID = 510l;
  37. private String id;
  38. private String name;
  39. private String version;
  40. private String type;
  41. private String packageName;
  42. private Resource resource;
  43. private ContextContainer contextContainer = new ContextContainerImpl();
  44. private Map<String, Object> metaData = new HashMap<String, Object>();
  45. private transient Map<String, Object> runtimeMetaData = new HashMap<String, Object>();
  46. private List<String> imports;
  47. private Map<String, String> globals;
  48. private List<String> functionImports;
  49. public void setId(final String id) {
  50. this.id = id;
  51. }
  52. public String getId() {
  53. return this.id;
  54. }
  55. public void setName(final String name) {
  56. this.name = name;
  57. }
  58. public String getName() {
  59. return this.name;
  60. }
  61. public void setVersion(final String version) {
  62. this.version = version;
  63. }
  64. public String getVersion() {
  65. return this.version;
  66. }
  67. public String getType() {
  68. return this.type;
  69. }
  70. public void setType(final String type) {
  71. this.type = type;
  72. }
  73. public String getPackageName() {
  74. return packageName;
  75. }
  76. public void setPackageName(String packageName) {
  77. this.packageName = packageName;
  78. }
  79. public List<Context> getContexts(String contextType) {
  80. return this.contextContainer.getContexts(contextType);
  81. }
  82. public void addContext(Context context) {
  83. this.contextContainer.addContext(context);
  84. ((AbstractContext) context).setContextContainer(this);
  85. }
  86. public Context getContext(String contextType, long id) {
  87. return this.contextContainer.getContext(contextType, id);
  88. }
  89. public void setDefaultContext(Context context) {
  90. this.contextContainer.setDefaultContext(context);
  91. ((AbstractContext) context).setContextContainer(this);
  92. }
  93. public Context getDefaultContext(String contextType) {
  94. return this.contextContainer.getDefaultContext(contextType);
  95. }
  96. public boolean equals(final Object o) {
  97. if ( o instanceof ProcessImpl ) {
  98. if (this.id == null) {
  99. return ((ProcessImpl) o).getId() == null;
  100. }
  101. return this.id.equals(((ProcessImpl) o).getId());
  102. }
  103. return false;
  104. }
  105. public int hashCode() {
  106. return this.id == null ? 0 : 3 * this.id.hashCode();
  107. }
  108. public Context resolveContext(String contextId, Object param) {
  109. Context context = getDefaultContext(contextId);
  110. if (context != null) {
  111. context = context.resolveContext(param);
  112. if (context != null) {
  113. return context;
  114. }
  115. }
  116. return null;
  117. }
  118. public Map<String, Object> getMetaData() {
  119. return this.metaData;
  120. }
  121. public void setMetaData(String name, Object data) {
  122. this.metaData.put(name, data);
  123. }
  124. public Object getMetaData(String name) {
  125. return this.metaData.get(name);
  126. }
  127. public Resource getResource() {
  128. return this.resource;
  129. }
  130. public void setResource(Resource resource) {
  131. this.resource = resource;
  132. }
  133. public List<String> getImports() {
  134. return imports;
  135. }
  136. public void setImports(List<String> imports) {
  137. this.imports = imports;
  138. }
  139. public List<String> getFunctionImports() {
  140. return functionImports;
  141. }
  142. public void setFunctionImports(List<String> functionImports) {
  143. this.functionImports = functionImports;
  144. }
  145. public Map<String, String> getGlobals() {
  146. return globals;
  147. }
  148. public void setGlobals(Map<String, String> globals) {
  149. this.globals = globals;
  150. }
  151. public String[] getGlobalNames() {
  152. final List<String> result = new ArrayList<String>();
  153. if (this.globals != null) {
  154. for ( Iterator<String> iterator = this.globals.keySet().iterator(); iterator.hasNext(); ) {
  155. result.add(iterator.next());
  156. }
  157. }
  158. return result.toArray(new String[result.size()]);
  159. }
  160. public KnowledgeType getKnowledgeType() {
  161. return KnowledgeType.PROCESS;
  162. }
  163. public String getNamespace() {
  164. return packageName;
  165. }
  166. public Map<String, Object> getRuntimeMetaData() {
  167. return runtimeMetaData;
  168. }
  169. public void setRuntimeMetaData(Map<String, Object> runtimeMetaData) {
  170. this.runtimeMetaData = runtimeMetaData;
  171. }
  172. /*
  173. * Special handling for serialization to initialize transient (runtime related) meta data
  174. */
  175. private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
  176. in.defaultReadObject();
  177. this.runtimeMetaData = new HashMap<String, Object>();
  178. }
  179. }