1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.xml.export; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.jdom.Document; |
21 | |
import org.jdom.Element; |
22 | |
import org.jdom.JDOMException; |
23 | |
import org.jdom.input.SAXBuilder; |
24 | |
import org.kuali.rice.core.api.impex.ExportDataSet; |
25 | |
import org.kuali.rice.core.api.util.xml.XmlException; |
26 | |
import org.kuali.rice.core.api.util.xml.XmlHelper; |
27 | |
import org.kuali.rice.core.api.util.xml.XmlRenderer; |
28 | |
import org.kuali.rice.core.framework.impex.xml.XmlExporter; |
29 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
30 | |
import org.kuali.rice.kew.doctype.DocumentTypeAttribute; |
31 | |
import org.kuali.rice.kew.doctype.DocumentTypePolicy; |
32 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
33 | |
import org.kuali.rice.kew.engine.node.BranchPrototype; |
34 | |
import org.kuali.rice.kew.engine.node.NodeType; |
35 | |
import org.kuali.rice.kew.engine.node.Process; |
36 | |
import org.kuali.rice.kew.engine.node.RouteNode; |
37 | |
import org.kuali.rice.kew.exception.ResourceUnavailableException; |
38 | |
import org.kuali.rice.kew.export.KewExportDataSet; |
39 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
40 | |
import org.kuali.rice.kew.util.KEWConstants; |
41 | |
import org.kuali.rice.kim.api.group.Group; |
42 | |
|
43 | |
import java.io.IOException; |
44 | |
import java.io.StringReader; |
45 | |
import java.util.Collection; |
46 | |
import java.util.Collections; |
47 | |
import java.util.Comparator; |
48 | |
import java.util.Iterator; |
49 | |
import java.util.List; |
50 | |
|
51 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.*; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | 0 | public class DocumentTypeXmlExporter implements XmlExporter { |
61 | |
|
62 | 0 | protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass()); |
63 | |
|
64 | 0 | private XmlRenderer renderer = new XmlRenderer(DOCUMENT_TYPE_NAMESPACE); |
65 | |
|
66 | |
@Override |
67 | |
public boolean supportPrettyPrint() { |
68 | 0 | return true; |
69 | |
} |
70 | |
|
71 | |
public Element export(ExportDataSet exportDataSet) { |
72 | 0 | KewExportDataSet dataSet = KewExportDataSet.fromExportDataSet(exportDataSet); |
73 | 0 | if (!dataSet.getDocumentTypes().isEmpty()) { |
74 | 0 | Collections.sort(dataSet.getDocumentTypes(), new DocumentTypeParentComparator()); |
75 | 0 | Element rootElement = renderer.renderElement(null, DOCUMENT_TYPES); |
76 | 0 | rootElement.setAttribute(SCHEMA_LOCATION_ATTR, DOCUMENT_TYPE_SCHEMA_LOCATION, SCHEMA_NAMESPACE); |
77 | 0 | for (Iterator iterator = dataSet.getDocumentTypes().iterator(); iterator.hasNext();) { |
78 | 0 | DocumentType documentType = (DocumentType) iterator.next(); |
79 | 0 | exportDocumentType(rootElement, documentType); |
80 | 0 | } |
81 | 0 | return rootElement; |
82 | |
} |
83 | 0 | return null; |
84 | |
} |
85 | |
|
86 | |
private void exportDocumentType(Element parent, DocumentType documentType) { |
87 | 0 | Element docTypeElement = renderer.renderElement(parent, DOCUMENT_TYPE); |
88 | 0 | List flattenedNodes = KEWServiceLocator.getRouteNodeService().getFlattenedNodes(documentType, false); |
89 | |
|
90 | 0 | boolean hasDefaultExceptionWorkgroup = hasDefaultExceptionWorkgroup(flattenedNodes); |
91 | 0 | renderer.renderTextElement(docTypeElement, NAME, documentType.getName()); |
92 | 0 | if (documentType.getParentDocType() != null) { |
93 | 0 | renderer.renderTextElement(docTypeElement, PARENT, documentType.getParentDocType().getName()); |
94 | |
} |
95 | 0 | renderer.renderTextElement(docTypeElement, DESCRIPTION, documentType.getDescription()); |
96 | 0 | renderer.renderTextElement(docTypeElement, LABEL, documentType.getLabel()); |
97 | 0 | if (!StringUtils.isBlank(documentType.getActualApplicationId())) { |
98 | 0 | renderer.renderTextElement(docTypeElement, APPLICATION_ID, documentType.getActualApplicationId()); |
99 | |
} |
100 | 0 | renderer.renderTextElement(docTypeElement, POST_PROCESSOR_NAME, documentType.getPostProcessorName()); |
101 | 0 | Group superUserWorkgroup = documentType.getSuperUserWorkgroupNoInheritence(); |
102 | 0 | if (superUserWorkgroup != null) { |
103 | 0 | Element superUserGroupElement = renderer.renderTextElement(docTypeElement, SUPER_USER_GROUP_NAME, superUserWorkgroup.getName().trim()); |
104 | 0 | superUserGroupElement.setAttribute(NAMESPACE, superUserWorkgroup.getNamespaceCode().trim()); |
105 | |
} |
106 | 0 | Group blanketWorkgroup = documentType.getBlanketApproveWorkgroup(); |
107 | 0 | if (blanketWorkgroup != null){ |
108 | 0 | Element blanketGroupElement = renderer.renderTextElement(docTypeElement, BLANKET_APPROVE_GROUP_NAME, blanketWorkgroup.getName().trim()); |
109 | 0 | blanketGroupElement.setAttribute(NAMESPACE, blanketWorkgroup.getNamespaceCode().trim()); |
110 | |
} |
111 | 0 | if (documentType.getBlanketApprovePolicy() != null){ |
112 | 0 | renderer.renderTextElement(docTypeElement, BLANKET_APPROVE_POLICY, documentType.getBlanketApprovePolicy()); |
113 | |
} |
114 | 0 | Group reportingWorkgroup = documentType.getReportingWorkgroup(); |
115 | 0 | if (reportingWorkgroup != null) { |
116 | 0 | Element reportingGroupElement = renderer.renderTextElement(docTypeElement, REPORTING_GROUP_NAME, reportingWorkgroup.getName().trim()); |
117 | 0 | reportingGroupElement.setAttribute(NAMESPACE, reportingWorkgroup.getNamespaceCode().trim()); |
118 | |
} |
119 | 0 | if (!flattenedNodes.isEmpty() && hasDefaultExceptionWorkgroup) { |
120 | 0 | Group exceptionWorkgroup = ((RouteNode)flattenedNodes.get(0)).getExceptionWorkgroup(); |
121 | 0 | if (exceptionWorkgroup != null) { |
122 | 0 | Element exceptionGroupElement = renderer.renderTextElement(docTypeElement, DEFAULT_EXCEPTION_GROUP_NAME, exceptionWorkgroup.getName().trim()); |
123 | 0 | exceptionGroupElement.setAttribute(NAMESPACE, exceptionWorkgroup.getNamespaceCode().trim()); |
124 | |
} |
125 | |
} |
126 | 0 | if (StringUtils.isNotBlank(documentType.getUnresolvedDocHandlerUrl())) { |
127 | 0 | renderer.renderTextElement(docTypeElement, DOC_HANDLER, documentType.getUnresolvedDocHandlerUrl()); |
128 | |
} |
129 | 0 | if (!StringUtils.isBlank(documentType.getUnresolvedHelpDefinitionUrl())) { |
130 | 0 | renderer.renderTextElement(docTypeElement, HELP_DEFINITION_URL, documentType.getUnresolvedHelpDefinitionUrl()); |
131 | |
} |
132 | 0 | if (!StringUtils.isBlank(documentType.getUnresolvedDocSearchHelpUrl())) { |
133 | 0 | renderer.renderTextElement(docTypeElement, DOC_SEARCH_HELP_URL, documentType.getUnresolvedDocSearchHelpUrl()); |
134 | |
} |
135 | 0 | if (!StringUtils.isBlank(documentType.getActualNotificationFromAddress())) { |
136 | 0 | renderer.renderTextElement(docTypeElement, NOTIFICATION_FROM_ADDRESS, documentType.getActualNotificationFromAddress()); |
137 | |
} |
138 | 0 | renderer.renderBooleanElement(docTypeElement, ACTIVE, documentType.getActive(), true); |
139 | 0 | exportPolicies(docTypeElement, documentType.getDocumentTypePolicies()); |
140 | 0 | exportAttributes(docTypeElement, documentType.getDocumentTypeAttributes()); |
141 | 0 | exportSecurity(docTypeElement, documentType.getDocumentTypeSecurityXml()); |
142 | 0 | if (!StringUtils.isBlank(documentType.getRoutingVersion())) { |
143 | 0 | renderer.renderTextElement(docTypeElement, ROUTING_VERSION, documentType.getRoutingVersion()); |
144 | |
} |
145 | 0 | Process process = null; |
146 | 0 | if (documentType.getProcesses().size() > 0) { |
147 | 0 | process = (Process)documentType.getProcesses().get(0); |
148 | |
} |
149 | 0 | if (process != null && process.getInitialRouteNode() != null) { |
150 | 0 | exportRouteData(docTypeElement, documentType, flattenedNodes, hasDefaultExceptionWorkgroup); |
151 | |
} else { |
152 | 0 | renderer.renderElement(docTypeElement, ROUTE_PATHS); |
153 | |
} |
154 | 0 | } |
155 | |
|
156 | |
private void exportPolicies(Element parent, Collection policies) { |
157 | 0 | if (!policies.isEmpty()) { |
158 | 0 | Element policiesElement = renderer.renderElement(parent, POLICIES); |
159 | 0 | for (Iterator iterator = policies.iterator(); iterator.hasNext();) { |
160 | 0 | DocumentTypePolicy policy = (DocumentTypePolicy) iterator.next(); |
161 | 0 | Element policyElement = renderer.renderElement(policiesElement, POLICY); |
162 | 0 | renderer.renderTextElement(policyElement, NAME, policy.getPolicyName()); |
163 | 0 | renderer.renderBooleanElement(policyElement, VALUE, policy.getPolicyValue(), false); |
164 | 0 | } |
165 | |
} |
166 | 0 | } |
167 | |
|
168 | |
private void exportAttributes(Element parent, List attributes) { |
169 | 0 | if (!attributes.isEmpty()) { |
170 | 0 | Element attributesElement = renderer.renderElement(parent, ATTRIBUTES); |
171 | 0 | for (Iterator iterator = attributes.iterator(); iterator.hasNext();) { |
172 | 0 | DocumentTypeAttribute attribute = (DocumentTypeAttribute) iterator.next(); |
173 | 0 | Element attributeElement = renderer.renderElement(attributesElement, ATTRIBUTE); |
174 | 0 | renderer.renderTextElement(attributeElement, NAME, attribute.getRuleAttribute().getName()); |
175 | 0 | } |
176 | |
} |
177 | 0 | } |
178 | |
|
179 | |
private void exportSecurity(Element parent, String securityXML) { |
180 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(securityXML)) { |
181 | |
try { |
182 | 0 | org.jdom.Document securityDoc = new SAXBuilder().build(new StringReader(securityXML)); |
183 | 0 | XmlHelper.propagateNamespace(securityDoc.getRootElement(), DOCUMENT_TYPE_NAMESPACE); |
184 | 0 | parent.addContent(securityDoc.getRootElement().detach()); |
185 | 0 | } catch (IOException e) { |
186 | 0 | throw new WorkflowRuntimeException("Error parsing doctype security XML."); |
187 | 0 | } catch (JDOMException e) { |
188 | 0 | throw new WorkflowRuntimeException("Error parsing doctype security XML."); |
189 | 0 | } |
190 | |
} |
191 | 0 | } |
192 | |
|
193 | |
private void exportRouteData(Element parent, DocumentType documentType, List flattenedNodes, boolean hasDefaultExceptionWorkgroup) { |
194 | 0 | if (!flattenedNodes.isEmpty()) { |
195 | 0 | Element routePathsElement = renderer.renderElement(parent, ROUTE_PATHS); |
196 | 0 | for (Iterator iterator = documentType.getProcesses().iterator(); iterator.hasNext();) { |
197 | 0 | Process process = (Process) iterator.next(); |
198 | 0 | Element routePathElement = renderer.renderElement(routePathsElement, ROUTE_PATH); |
199 | 0 | if (!process.isInitial()) { |
200 | 0 | renderer.renderAttribute(routePathElement, INITIAL_NODE, process.getInitialRouteNode().getRouteNodeName()); |
201 | 0 | renderer.renderAttribute(routePathElement, PROCESS_NAME, process.getName()); |
202 | |
} |
203 | 0 | exportProcess(routePathElement, process); |
204 | 0 | } |
205 | |
|
206 | 0 | Element routeNodesElement = renderer.renderElement(parent, ROUTE_NODES); |
207 | 0 | for (Iterator iterator = flattenedNodes.iterator(); iterator.hasNext();) { |
208 | 0 | RouteNode node = (RouteNode) iterator.next(); |
209 | 0 | exportRouteNode(routeNodesElement, node, hasDefaultExceptionWorkgroup); |
210 | 0 | } |
211 | |
} |
212 | 0 | } |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
private boolean hasDefaultExceptionWorkgroup(List flattenedNodes) { |
220 | 0 | boolean hasDefaultExceptionWorkgroup = true; |
221 | 0 | String exceptionWorkgroupName = null; |
222 | 0 | for (Iterator iterator = flattenedNodes.iterator(); iterator.hasNext();) { |
223 | 0 | RouteNode node = (RouteNode) iterator.next(); |
224 | 0 | if (exceptionWorkgroupName == null) { |
225 | 0 | exceptionWorkgroupName = node.getExceptionWorkgroupName(); |
226 | |
} |
227 | 0 | if (exceptionWorkgroupName == null || !exceptionWorkgroupName.equals(node.getExceptionWorkgroupName())) { |
228 | 0 | hasDefaultExceptionWorkgroup = false; |
229 | 0 | break; |
230 | |
} |
231 | 0 | } |
232 | 0 | return hasDefaultExceptionWorkgroup; |
233 | |
} |
234 | |
|
235 | |
private void exportProcess(Element parent, Process process) { |
236 | 0 | exportNodeGraph(parent, process.getInitialRouteNode(), null); |
237 | 0 | } |
238 | |
|
239 | |
private void exportNodeGraph(Element parent, RouteNode node, SplitJoinContext splitJoinContext) { |
240 | 0 | NodeType nodeType = null; |
241 | |
|
242 | 0 | String contentFragment = node.getContentFragment(); |
243 | |
|
244 | 0 | if(contentFragment == null || "".equals(contentFragment)){ |
245 | 0 | nodeType = getNodeTypeForNode(node); |
246 | |
}else{ |
247 | |
|
248 | |
|
249 | 0 | nodeType = this.getNodeTypeForNodeFromFragment(node); |
250 | |
} |
251 | |
|
252 | 0 | if (nodeType.isAssignableFrom(NodeType.SPLIT)) { |
253 | 0 | exportSplitNode(parent, node, nodeType, splitJoinContext); |
254 | 0 | } else if (nodeType.isAssignableFrom(NodeType.JOIN)) { |
255 | 0 | exportJoinNode(parent, node, nodeType, splitJoinContext); |
256 | |
} else { |
257 | 0 | exportSimpleNode(parent, node, nodeType, splitJoinContext); |
258 | |
} |
259 | 0 | } |
260 | |
|
261 | |
private void exportSimpleNode(Element parent, RouteNode node, NodeType nodeType, SplitJoinContext splitJoinContext) { |
262 | 0 | Element simpleElement = renderNodeElement(parent, node, nodeType); |
263 | 0 | if (node.getNextNodes().size() > 1) { |
264 | 0 | throw new WorkflowRuntimeException("Simple node cannot have more than one next node: " + node.getRouteNodeName()); |
265 | |
} |
266 | 0 | if (node.getNextNodes().size() == 1) { |
267 | 0 | RouteNode nextNode = (RouteNode)node.getNextNodes().get(0); |
268 | 0 | renderer.renderAttribute(simpleElement, NEXT_NODE, nextNode.getRouteNodeName()); |
269 | 0 | exportNodeGraph(parent, nextNode, splitJoinContext); |
270 | |
} |
271 | 0 | } |
272 | |
|
273 | |
private void exportSplitNode(Element parent, RouteNode node, NodeType nodeType, SplitJoinContext splitJoinContext) { |
274 | 0 | Element splitElement = renderNodeElement(parent, node, nodeType); |
275 | 0 | SplitJoinContext newSplitJoinContext = new SplitJoinContext(node); |
276 | 0 | for (Iterator iterator = node.getNextNodes().iterator(); iterator.hasNext();) { |
277 | 0 | RouteNode nextNode = (RouteNode) iterator.next(); |
278 | 0 | BranchPrototype branch = nextNode.getBranch(); |
279 | 0 | if (branch == null) { |
280 | 0 | throw new WorkflowRuntimeException("Found a split next node with no associated branch prototype: " + nextNode.getRouteNodeName()); |
281 | |
} |
282 | 0 | exportBranch(splitElement, nextNode, branch, newSplitJoinContext); |
283 | 0 | } |
284 | 0 | RouteNode joinNode = newSplitJoinContext.joinNode; |
285 | 0 | if (joinNode == null) { |
286 | 0 | if (node.getNextNodes().size() > 0) { |
287 | 0 | throw new WorkflowRuntimeException("Could not locate the join node for the given split node " + node.getRouteNodeName()); |
288 | |
} |
289 | |
} else { |
290 | 0 | renderNodeElement(splitElement, joinNode, newSplitJoinContext.joinNodeType); |
291 | 0 | if (joinNode.getNextNodes().size() > 1) { |
292 | 0 | throw new WorkflowRuntimeException("Join node cannot have more than one next node: " + joinNode.getRouteNodeName()); |
293 | |
} |
294 | 0 | if (joinNode.getNextNodes().size() == 1) { |
295 | 0 | RouteNode nextNode = (RouteNode)joinNode.getNextNodes().get(0); |
296 | 0 | renderer.renderAttribute(splitElement, NEXT_NODE, nextNode.getRouteNodeName()); |
297 | 0 | exportNodeGraph(parent, nextNode, splitJoinContext); |
298 | |
} |
299 | |
} |
300 | 0 | } |
301 | |
|
302 | |
private void exportBranch(Element parent, RouteNode node, BranchPrototype branch, SplitJoinContext splitJoinContext) { |
303 | 0 | Element branchElement = renderer.renderElement(parent, BRANCH); |
304 | 0 | renderer.renderAttribute(branchElement, NAME, branch.getName()); |
305 | 0 | exportNodeGraph(branchElement, node, splitJoinContext); |
306 | 0 | } |
307 | |
|
308 | |
private void exportJoinNode(Element parent, RouteNode node, NodeType nodeType, SplitJoinContext splitJoinContext) { |
309 | 0 | if (splitJoinContext == null) { |
310 | |
|
311 | |
|
312 | 0 | if (!node.getNextNodes().isEmpty()) { |
313 | 0 | throw new WorkflowRuntimeException("Could not export join node with next nodes that is not contained within a split."); |
314 | |
} |
315 | 0 | renderNodeElement(parent, node, nodeType); |
316 | 0 | } else if (splitJoinContext.joinNode == null) { |
317 | |
|
318 | |
|
319 | |
|
320 | 0 | splitJoinContext.joinNode = node; |
321 | 0 | splitJoinContext.joinNodeType = nodeType; |
322 | |
} |
323 | 0 | } |
324 | |
|
325 | |
private Element renderNodeElement(Element parent, RouteNode node, NodeType nodeType) { |
326 | 0 | String nodeName = nodeType.getName(); |
327 | |
|
328 | 0 | if (nodeType.equals(NodeType.REQUEST_ACTIVATION)) { |
329 | 0 | nodeName = NodeType.SIMPLE.getName(); |
330 | |
} |
331 | 0 | Element nodeElement = renderer.renderElement(parent, nodeName); |
332 | 0 | renderer.renderAttribute(nodeElement, NAME, node.getRouteNodeName()); |
333 | 0 | return nodeElement; |
334 | |
} |
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
private void exportRouteNodeOld(Element parent, RouteNode node, boolean hasDefaultExceptionWorkgroup) { |
340 | 0 | NodeType nodeType = getNodeTypeForNode(node); |
341 | 0 | Element nodeElement = renderer.renderElement(parent, nodeType.getName()); |
342 | 0 | renderer.renderAttribute(nodeElement, NAME, node.getRouteNodeName()); |
343 | 0 | if (!hasDefaultExceptionWorkgroup) { |
344 | 0 | if (!StringUtils.isBlank(node.getExceptionWorkgroupName())) { |
345 | 0 | Element exceptionGroupElement = renderer.renderTextElement(nodeElement, EXCEPTION_GROUP_NAME, node.getExceptionWorkgroupName()); |
346 | 0 | exceptionGroupElement.setAttribute(NAMESPACE, node.getExceptionWorkgroup().getNamespaceCode()); |
347 | |
} |
348 | |
} |
349 | 0 | if (supportsActivationType(nodeType) && !StringUtils.isBlank(node.getActivationType())) { |
350 | 0 | renderer.renderTextElement(nodeElement, ACTIVATION_TYPE, node.getActivationType()); |
351 | |
} |
352 | 0 | if (supportsRouteMethod(nodeType)) { |
353 | 0 | exportRouteMethod(nodeElement, node); |
354 | 0 | renderer.renderBooleanElement(nodeElement, MANDATORY_ROUTE, node.getMandatoryRouteInd(), false); |
355 | 0 | renderer.renderBooleanElement(nodeElement, FINAL_APPROVAL, node.getFinalApprovalInd(), false); |
356 | |
} |
357 | 0 | if (nodeType.isCustomNode(node.getNodeType())) { |
358 | 0 | renderer.renderTextElement(nodeElement, TYPE, node.getNodeType()); |
359 | |
} |
360 | 0 | } |
361 | |
|
362 | |
private void exportRouteNode(Element parent, RouteNode node, boolean hasDefaultExceptionWorkgroup) { |
363 | 0 | String contentFragment = node.getContentFragment(); |
364 | 0 | if (StringUtils.isBlank(contentFragment)) { |
365 | 0 | exportRouteNodeOld(parent, node, hasDefaultExceptionWorkgroup); |
366 | |
} else { |
367 | |
try { |
368 | 0 | Document document = XmlHelper.buildJDocument(new StringReader(contentFragment)); |
369 | 0 | Element rootElement = document.detachRootElement(); |
370 | 0 | XmlHelper.propagateNamespace(rootElement, parent.getNamespace()); |
371 | 0 | parent.addContent(rootElement); |
372 | 0 | } catch (XmlException e) { |
373 | 0 | throw new WorkflowRuntimeException("Failed to load the content fragment.", e); |
374 | 0 | } |
375 | |
} |
376 | 0 | } |
377 | |
|
378 | |
|
379 | |
private NodeType getNodeTypeForNode(RouteNode node) { |
380 | 0 | NodeType nodeType = null; |
381 | 0 | String errorMessage = "Could not determine proper XML element for the given node type: " + node.getNodeType(); |
382 | |
|
383 | |
try { |
384 | 0 | nodeType = NodeType.fromClassName(node.getNodeType()); |
385 | 0 | } catch (ResourceUnavailableException e) { |
386 | 0 | throw new WorkflowRuntimeException(errorMessage, e); |
387 | 0 | } |
388 | 0 | if (nodeType == null) { |
389 | 0 | throw new WorkflowRuntimeException(errorMessage); |
390 | |
} |
391 | 0 | return nodeType; |
392 | |
} |
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | |
|
404 | |
|
405 | |
private NodeType getNodeTypeForNodeFromFragment(RouteNode node) { |
406 | 0 | NodeType nodeType = null; |
407 | 0 | String contentFragment = node.getContentFragment(); |
408 | 0 | String errorMessage = "Could not determine proper XML element for the given node type: " + node.getNodeType(); |
409 | |
|
410 | 0 | for (Iterator<NodeType> iterator = NodeType.getTypeList().iterator(); iterator.hasNext();) { |
411 | 0 | NodeType nType = iterator.next(); |
412 | |
|
413 | |
|
414 | |
|
415 | 0 | if(contentFragment.startsWith("<" + nType.getName())){ |
416 | 0 | nodeType = nType; |
417 | |
} |
418 | 0 | } |
419 | |
|
420 | 0 | if (nodeType == null) { |
421 | 0 | throw new WorkflowRuntimeException(errorMessage); |
422 | |
} |
423 | 0 | return nodeType; |
424 | |
} |
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
private boolean supportsActivationType(NodeType nodeType) { |
430 | 0 | return true; |
431 | |
} |
432 | |
|
433 | |
|
434 | |
|
435 | |
|
436 | |
private boolean supportsRouteMethod(NodeType nodeType) { |
437 | 0 | return true; |
438 | |
} |
439 | |
|
440 | |
private void exportRouteMethod(Element parent, RouteNode node) { |
441 | 0 | if (!StringUtils.isBlank(node.getRouteMethodName())) { |
442 | 0 | String routeMethodCode = node.getRouteMethodCode(); |
443 | 0 | String elementName = null; |
444 | 0 | if (KEWConstants.ROUTE_LEVEL_FLEX_RM.equals(routeMethodCode)) { |
445 | 0 | elementName = RULE_TEMPLATE; |
446 | 0 | } else if (KEWConstants.ROUTE_LEVEL_ROUTE_MODULE.equals(routeMethodCode)) { |
447 | 0 | elementName = ROUTE_MODULE; |
448 | |
} else { |
449 | 0 | throw new WorkflowRuntimeException("Invalid route method code '"+routeMethodCode+"' for node " + node.getRouteNodeName()); |
450 | |
} |
451 | 0 | renderer.renderTextElement(parent, elementName, node.getRouteMethodName()); |
452 | |
} |
453 | 0 | } |
454 | |
|
455 | 0 | private class DocumentTypeParentComparator implements Comparator { |
456 | |
|
457 | |
public int compare(Object object1, Object object2) { |
458 | 0 | DocumentType docType1 = (DocumentType)object1; |
459 | 0 | DocumentType docType2 = (DocumentType)object2; |
460 | 0 | Integer depth1 = getDepth(docType1); |
461 | 0 | Integer depth2 = getDepth(docType2); |
462 | 0 | return depth1.compareTo(depth2); |
463 | |
} |
464 | |
|
465 | |
private Integer getDepth(DocumentType docType) { |
466 | 0 | int depth = 0; |
467 | 0 | while ((docType = docType.getParentDocType()) != null) { |
468 | 0 | depth++; |
469 | |
} |
470 | 0 | return new Integer(depth); |
471 | |
} |
472 | |
|
473 | |
} |
474 | |
|
475 | 0 | private class SplitJoinContext { |
476 | |
public RouteNode splitNode; |
477 | |
public RouteNode joinNode; |
478 | |
public NodeType joinNodeType; |
479 | 0 | public SplitJoinContext(RouteNode splitNode) { |
480 | 0 | this.splitNode = splitNode; |
481 | 0 | } |
482 | |
} |
483 | |
|
484 | |
|
485 | |
} |