@Override public void validate(Definition definition) throws WorkflowException { State initialState = definition.getInitialState(); if (initialState == null) { throw new WorkflowException("No initial state defined"); } List<State> terminalStates = definition.getTerminalStates(); if (terminalStates.isEmpty()) { throw new WorkflowException("No terminal states defined"); } if (definition.getForksCount() != definition.getJoinsCount()) { throw new WorkflowException("There are unbalanced fork and join nodes"); } Collection<Node> nodes = definition.getNodes(); for (Node node : nodes) { NodeValidator<Node> nodeValidator = _nodeValidatorRegistry.getNodeValidator(node.getNodeType()); nodeValidator.validate(definition, node); } }
protected String doExport(Definition definition) { try { Document document = SAXReaderUtil.createDocument(); Element workflowDefinitionElement = document.addElement("workflow-definition"); workflowDefinitionElement.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); workflowDefinitionElement.addAttribute( "xsi:schemaLocation", "urn:liferay.com:liferay-workflow_" + _version + " http://www.liferay.com/dtd/liferay-workflow-definition_" + _schemaVersion + ".xsd"); workflowDefinitionElement.addNamespace("", "urn:liferay.com:liferay-workflow_" + _version); Element nameElement = workflowDefinitionElement.addElement("name", _namespace); nameElement.addText(definition.getName()); if (Validator.isNotNull(definition.getDescription())) { Element descriptionElement = workflowDefinitionElement.addElement("description", _namespace); descriptionElement.addText(definition.getDescription()); } Element versionElement = workflowDefinitionElement.addElement("version", _namespace); versionElement.addText(String.valueOf(definition.getVersion())); Collection<Node> nodes = definition.getNodes(); for (Node node : nodes) { NodeExporter nodeExporter = NodeExporterRegistry.getNodeExporter(node.getNodeType()); nodeExporter.exportNode(node, workflowDefinitionElement, _namespace); } return document.formattedString(); } catch (IOException ioe) { throw new SystemException("Unable to export definition", ioe); } }