public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException { parser.startElementBuilder(localName, attrs); return new Definitions(); }
private static Object findNodeOrDataStoreByUniqueId(Definitions definitions, NodeContainer nodeContainer, final String nodeRef, String errorMsg) { if( definitions != null ) { List<DataStore> dataStores = definitions.getDataStores(); if( dataStores != null ) { for( DataStore dataStore : dataStores ) { if( nodeRef.equals(dataStore.getId()) ) { return dataStore; } } } } return findNodeByIdOrUniqueIdInMetadata(nodeContainer, nodeRef, errorMsg); }
@SuppressWarnings("unchecked") public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException { parser.startElementBuilder(localName, attrs); String id = attrs.getValue("id"); String errorCode = attrs.getValue("errorCode"); String structureRef = attrs.getValue("structureRef"); Definitions definitions = (Definitions) parser.getParent(); List<Error> errors = definitions.getErrors(); if (errors == null) { errors = new ArrayList<Error>(); definitions.setErrors(errors); ((ProcessBuildData) parser.getData()).setMetaData("Errors", errors); } Error e = new Error(id, errorCode, structureRef); errors.add(e); return e; }
List<DataStore> dataStores = parent.getDataStores(); if (dataStores == null) { dataStores = new ArrayList<DataStore>(); parent.setDataStores(dataStores);
protected String getErrorIdForErrorCode(String errorCode, Node node) { org.kie.api.definition.process.NodeContainer parent = node.getNodeContainer(); while( ! (parent instanceof RuleFlowProcess) && parent instanceof Node ) { parent = ((Node) parent).getNodeContainer(); } if( ! (parent instanceof RuleFlowProcess) ) { throw new RuntimeException( "This should never happen: !(parent instanceof RuleFlowProcess): parent is " + parent.getClass().getSimpleName() ); } List<Error> errors = ((Definitions) ((RuleFlowProcess) parent).getMetaData("Definitions")).getErrors(); Error error = null; for( Error listError : errors ) { if( errorCode.equals(listError.getErrorCode()) ) { error = listError; break; } else if ( errorCode.equals(listError.getId()) ) { error = listError; break; } } if (error == null) { throw new IllegalArgumentException("Could not find error with errorCode " + errorCode); } return error.getId(); }
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException { final Element element = parser.endElementBuilder(); Definitions definitions = (Definitions) parser.getCurrent(); String namespace = element.getAttribute("targetNamespace"); List<Process> processes = ((ProcessBuildData) parser.getData()).getProcesses(); Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions"); List<Interface> interfaces = (List<Interface>) ((ProcessBuildData) parser.getData()).getMetaData("Interfaces"); for (Process process : processes) { RuleFlowProcess ruleFlowProcess = (RuleFlowProcess)process; ruleFlowProcess.setMetaData("TargetNamespace", namespace); postProcessItemDefinitions(ruleFlowProcess, itemDefinitions, parser.getClassLoader()); postProcessInterfaces(ruleFlowProcess, interfaces); } definitions.setTargetNamespace(namespace); return definitions; }
List<DataStore> dataStores = parent.getDataStores(); if (dataStores == null) { dataStores = new ArrayList<DataStore>(); parent.setDataStores(dataStores);
protected void visitErrors(Definitions definitions, StringBuilder xmlDump) { if( definitions == null ) { return; } List<Error> errors = definitions.getErrors(); if( errors == null || errors.isEmpty() ) { return; } for( org.jbpm.bpmn2.core.Error error : errors ) { String id = XmlBPMNProcessDumper.replaceIllegalCharsAttribute(error.getId()); String code = error.getErrorCode(); xmlDump.append(" <error id=\"" + id + "\"" ); if (error.getErrorCode() != null) { code = XmlBPMNProcessDumper.replaceIllegalCharsAttribute(code); xmlDump.append(" errorCode=\"" + code + "\"" ); } String structureRef = error.getStructureRef(); if( structureRef != null ) { structureRef = XmlBPMNProcessDumper.replaceIllegalCharsAttribute(structureRef); xmlDump.append(" structureRef=\"" + structureRef + "\""); } xmlDump.append("/>" + EOL ); } }
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException { final Element element = parser.endElementBuilder(); Definitions definitions = (Definitions) parser.getCurrent(); String namespace = element.getAttribute("targetNamespace"); List<Process> processes = ((ProcessBuildData) parser.getData()).getProcesses(); Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions"); List<Interface> interfaces = (List<Interface>) ((ProcessBuildData) parser.getData()).getMetaData("Interfaces"); for (Process process : processes) { RuleFlowProcess ruleFlowProcess = (RuleFlowProcess)process; ruleFlowProcess.setMetaData("TargetNamespace", namespace); postProcessItemDefinitions(ruleFlowProcess, itemDefinitions, parser.getClassLoader()); postProcessInterfaces(ruleFlowProcess, interfaces); } definitions.setTargetNamespace(namespace); return definitions; }
if (def != null && def.getDataStores() != null) { for (DataStore dataStore : def.getDataStores()) { visitDataStore(dataStore, xmlDump);
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException { parser.startElementBuilder(localName, attrs); return new Definitions(); }
@SuppressWarnings("unchecked") public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException { parser.startElementBuilder(localName, attrs); String id = attrs.getValue("id"); String errorCode = attrs.getValue("errorCode"); String structureRef = attrs.getValue("structureRef"); Definitions definitions = (Definitions) parser.getParent(); List<Error> errors = definitions.getErrors(); if (errors == null) { errors = new ArrayList<Error>(); definitions.setErrors(errors); ((ProcessBuildData) parser.getData()).setMetaData("Errors", errors); } Error e = new Error(id, errorCode, structureRef); errors.add(e); return e; }
protected String getErrorIdForErrorCode(String errorCode, Node node) { org.kie.api.definition.process.NodeContainer parent = node.getNodeContainer(); while( ! (parent instanceof RuleFlowProcess) && parent instanceof Node ) { parent = ((Node) parent).getNodeContainer(); } if( ! (parent instanceof RuleFlowProcess) ) { throw new RuntimeException( "This should never happen: !(parent instanceof RuleFlowProcess): parent is " + parent.getClass().getSimpleName() ); } List<Error> errors = ((Definitions) ((RuleFlowProcess) parent).getMetaData("Definitions")).getErrors(); Error error = null; for( Error listError : errors ) { if( errorCode.equals(listError.getErrorCode()) ) { error = listError; break; } else if ( errorCode.equals(listError.getId()) ) { error = listError; break; } } if (error == null) { throw new IllegalArgumentException("Could not find error with errorCode " + errorCode); } return error.getId(); }
@Test public void testDataStore() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-DataStore.bpmn2"); ksession = createKnowledgeSession(kbase); ProcessInstance processInstance = ksession.startProcess("Evaluation"); Definitions def = (Definitions) processInstance.getProcess() .getMetaData().get("Definitions"); assertNotNull(def.getDataStores()); assertTrue(def.getDataStores().size() == 1); DataStore dataStore = def.getDataStores().get(0); assertEquals("employee", dataStore.getId()); assertEquals("employeeStore", dataStore.getName()); assertEquals(String.class.getCanonicalName(), ((ObjectDataType) dataStore.getType()).getClassName()); }
public class Main { public static void main(String[] args) throws JAXBException { // initialize JAXB JAXBContext context = JAXBContext.newInstance(Model.class, Definitions.class); // Unmarshal input XML into Java object Unmarshaller unmarshaller = context.createUnmarshaller(); Model model = (Model) unmarshaller.unmarshal(Main.class.getClassLoader().getResourceAsStream("input.xml")); // Map old Java object to new Java object List<Task> tasks = new ArrayList<Task>(); for (Node node : model.getNodes()) { tasks.add(new Task(node.getId())); } // Marshal new Java object into XML Definitions definitions = new Definitions(new Process(model.getId(), tasks)); StringWriter sw = new StringWriter(); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.marshal(definitions, sw); System.out.println(sw.toString()); } }
protected void visitErrors(Definitions definitions, StringBuilder xmlDump) { if( definitions == null ) { return; } List<Error> errors = definitions.getErrors(); if( errors == null || errors.isEmpty() ) { return; } for( org.jbpm.bpmn2.core.Error error : errors ) { String id = XmlBPMNProcessDumper.replaceIllegalCharsAttribute(error.getId()); String code = error.getErrorCode(); xmlDump.append(" <error id=\"" + id + "\"" ); if (error.getErrorCode() != null) { code = XmlBPMNProcessDumper.replaceIllegalCharsAttribute(code); xmlDump.append(" errorCode=\"" + code + "\"" ); } String structureRef = error.getStructureRef(); if( structureRef != null ) { structureRef = XmlBPMNProcessDumper.replaceIllegalCharsAttribute(structureRef); xmlDump.append(" structureRef=\"" + structureRef + "\""); } xmlDump.append("/>" + EOL ); } }
private static Object findNodeOrDataStoreByUniqueId(Definitions definitions, NodeContainer nodeContainer, final String nodeRef, String errorMsg) { if( definitions != null ) { List<DataStore> dataStores = definitions.getDataStores(); if( dataStores != null ) { for( DataStore dataStore : dataStores ) { if( nodeRef.equals(dataStore.getId()) ) { return dataStore; } } } } return findNodeByIdOrUniqueIdInMetadata(nodeContainer, nodeRef, errorMsg); }
if (def != null && def.getDataStores() != null) { for (DataStore dataStore : def.getDataStores()) { visitDataStore(dataStore, xmlDump);
@Test public void testDataStore() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-DataStore.bpmn2"); ksession = createKnowledgeSession(kbase); ProcessInstance processInstance = ksession.startProcess("Evaluation"); Definitions def = (Definitions) processInstance.getProcess() .getMetaData().get("Definitions"); assertNotNull(def.getDataStores()); assertTrue(def.getDataStores().size() == 1); DataStore dataStore = def.getDataStores().get(0); assertEquals("employee", dataStore.getId()); assertEquals("employeeStore", dataStore.getName()); assertEquals(String.class.getCanonicalName(), ((ObjectDataType) dataStore.getType()).getClassName()); }