List of usage examples for com.fasterxml.jackson.core JsonToken END_OBJECT
JsonToken END_OBJECT
To view the source code for com.fasterxml.jackson.core JsonToken END_OBJECT.
Click Source Link
From source file:org.apache.olingo.client.core.edm.xml.TermDeserializer.java
@Override protected TermImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final TermImpl term = new TermImpl(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { term.setName(jp.nextTextValue()); } else if ("Type".equals(jp.getCurrentName())) { term.setType(jp.nextTextValue()); } else if ("BaseTerm".equals(jp.getCurrentName())) { term.setBaseTerm(jp.nextTextValue()); } else if ("DefaultValue".equals(jp.getCurrentName())) { term.setDefaultValue(jp.nextTextValue()); } else if ("Nullable".equals(jp.getCurrentName())) { term.setNullable(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("MaxLength".equals(jp.getCurrentName())) { final String maxLenght = jp.nextTextValue(); term.setMaxLength(//from ww w.j a v a2 s .com maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght)); } else if ("Precision".equals(jp.getCurrentName())) { term.setPrecision(Integer.valueOf(jp.nextTextValue())); } else if ("Scale".equals(jp.getCurrentName())) { final String scale = jp.nextTextValue(); term.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale)); } else if ("SRID".equals(jp.getCurrentName())) { final String srid = jp.nextTextValue(); if (srid != null) { term.setSrid(SRID.valueOf(srid)); } } else if ("AppliesTo".equals(jp.getCurrentName())) { term.getAppliesTo().addAll(Arrays.asList(StringUtils.split(jp.nextTextValue()))); } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); term.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); } } } return term; }
From source file:org.apache.olingo.client.core.edm.xml.TypeDefinitionDeserializer.java
@Override protected TypeDefinitionImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final TypeDefinitionImpl typeDefinition = new TypeDefinitionImpl(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { typeDefinition.setName(jp.nextTextValue()); } else if ("UnderlyingType".equals(jp.getCurrentName())) { typeDefinition.setUnderlyingType(jp.nextTextValue()); } else if ("MaxLength".equals(jp.getCurrentName())) { typeDefinition.setMaxLength(jp.nextIntValue(0)); } else if ("Unicode".equals(jp.getCurrentName())) { typeDefinition.setUnicode(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("Precision".equals(jp.getCurrentName())) { typeDefinition.setPrecision(jp.nextIntValue(0)); } else if ("Scale".equals(jp.getCurrentName())) { final String scale = jp.nextTextValue(); typeDefinition.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale)); } else if ("SRID".equals(jp.getCurrentName())) { final String srid = jp.nextTextValue(); if (srid != null) { typeDefinition.setSrid(SRID.valueOf(srid)); }/*from w ww . j av a2 s.c o m*/ } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); typeDefinition.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); } } } return typeDefinition; }
From source file:org.apache.olingo.client.core.edm.xml.v3.FunctionImportDeserializer.java
@Override protected FunctionImportImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final FunctionImportImpl funcImp = new FunctionImportImpl(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { funcImp.setName(jp.nextTextValue()); } else if ("ReturnType".equals(jp.getCurrentName())) { funcImp.setReturnType(jp.nextTextValue()); } else if ("EntitySet".equals(jp.getCurrentName())) { funcImp.setEntitySet(jp.nextTextValue()); } else if ("EntitySetPath".equals(jp.getCurrentName())) { funcImp.setEntitySetPath(jp.nextTextValue()); } else if ("IsComposable".equals(jp.getCurrentName())) { funcImp.setComposable(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("IsSideEffecting".equals(jp.getCurrentName())) { funcImp.setSideEffecting(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("IsBindable".equals(jp.getCurrentName())) { funcImp.setBindable(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("IsAlwaysBindable".equals(jp.getCurrentName())) { funcImp.setAlwaysBindable(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("HttpMethod".equals(jp.getCurrentName())) { funcImp.setHttpMethod(jp.nextTextValue()); } else if ("Parameter".equals(jp.getCurrentName())) { jp.nextToken();// ww w . j a v a 2 s. com funcImp.getParameters().add(jp.readValueAs(ParameterImpl.class)); } } } return funcImp; }
From source file:org.eclipse.rdf4j.rio.rdfjson.RDFJSONParser.java
private void rdfJsonToHandlerInternal(final RDFHandler handler, final ValueFactory vf, final JsonParser jp) throws IOException, JsonParseException, RDFParseException, RDFHandlerException { if (jp.nextToken() != JsonToken.START_OBJECT) { reportFatalError("Expected RDF/JSON document to start with an Object", jp.getCurrentLocation()); }/*from w ww . j a v a2s . c om*/ while (jp.nextToken() != JsonToken.END_OBJECT) { final String subjStr = jp.getCurrentName(); Resource subject = null; subject = subjStr.startsWith("_:") ? createNode(subjStr.substring(2)) : vf.createIRI(subjStr); if (jp.nextToken() != JsonToken.START_OBJECT) { reportFatalError("Expected subject value to start with an Object", jp.getCurrentLocation()); } boolean foundPredicate = false; while (jp.nextToken() != JsonToken.END_OBJECT) { final String predStr = jp.getCurrentName(); final IRI predicate = vf.createIRI(predStr); foundPredicate = true; if (jp.nextToken() != JsonToken.START_ARRAY) { reportFatalError("Expected predicate value to start with an array", jp.getCurrentLocation()); } boolean foundObject = false; while (jp.nextToken() != JsonToken.END_ARRAY) { if (jp.getCurrentToken() != JsonToken.START_OBJECT) { reportFatalError("Expected object value to start with an Object: subject=<" + subjStr + "> predicate=<" + predStr + ">", jp.getCurrentLocation()); } String nextValue = null; String nextType = null; String nextDatatype = null; String nextLanguage = null; final Set<String> nextContexts = new HashSet<String>(2); while (jp.nextToken() != JsonToken.END_OBJECT) { final String fieldName = jp.getCurrentName(); if (RDFJSONUtility.VALUE.equals(fieldName)) { if (nextValue != null) { reportError( "Multiple values found for a single object: subject=" + subjStr + " predicate=" + predStr, jp.getCurrentLocation(), RDFJSONParserSettings.FAIL_ON_MULTIPLE_OBJECT_VALUES); } jp.nextToken(); nextValue = jp.getText(); } else if (RDFJSONUtility.TYPE.equals(fieldName)) { if (nextType != null) { reportError( "Multiple types found for a single object: subject=" + subjStr + " predicate=" + predStr, jp.getCurrentLocation(), RDFJSONParserSettings.FAIL_ON_MULTIPLE_OBJECT_TYPES); } jp.nextToken(); nextType = jp.getText(); } else if (RDFJSONUtility.LANG.equals(fieldName)) { if (nextLanguage != null) { reportError( "Multiple languages found for a single object: subject=" + subjStr + " predicate=" + predStr, jp.getCurrentLocation(), RDFJSONParserSettings.FAIL_ON_MULTIPLE_OBJECT_LANGUAGES); } jp.nextToken(); nextLanguage = jp.getText(); } else if (RDFJSONUtility.DATATYPE.equals(fieldName)) { if (nextDatatype != null) { reportError( "Multiple datatypes found for a single object: subject=" + subjStr + " predicate=" + predStr, jp.getCurrentLocation(), RDFJSONParserSettings.FAIL_ON_MULTIPLE_OBJECT_DATATYPES); } jp.nextToken(); nextDatatype = jp.getText(); } else if (RDFJSONUtility.GRAPHS.equals(fieldName)) { if (jp.nextToken() != JsonToken.START_ARRAY) { reportError("Expected graphs to start with an array", jp.getCurrentLocation(), RDFJSONParserSettings.SUPPORT_GRAPHS_EXTENSION); } while (jp.nextToken() != JsonToken.END_ARRAY) { final String nextGraph = jp.getText(); nextContexts.add(nextGraph); } } else { reportError( "Unrecognised JSON field name for object: subject=" + subjStr + " predicate=" + predStr + " fieldname=" + fieldName, jp.getCurrentLocation(), RDFJSONParserSettings.FAIL_ON_UNKNOWN_PROPERTY); } } Value object = null; if (nextType == null) { reportFatalError("No type for object: subject=" + subjStr + " predicate=" + predStr, jp.getCurrentLocation()); } if (nextValue == null) { reportFatalError("No value for object: subject=" + subjStr + " predicate=" + predStr, jp.getCurrentLocation()); } if (RDFJSONUtility.LITERAL.equals(nextType)) { if (nextLanguage != null) { object = this.createLiteral(nextValue, nextLanguage, null, jp.getCurrentLocation()); } else if (nextDatatype != null) { object = this.createLiteral(nextValue, null, this.createURI(nextDatatype), jp.getCurrentLocation()); } else { object = this.createLiteral(nextValue, null, null, jp.getCurrentLocation()); } } else if (RDFJSONUtility.BNODE.equals(nextType)) { if (nextLanguage != null) { reportFatalError("Language was attached to a blank node object: subject=" + subjStr + " predicate=" + predStr, jp.getCurrentLocation()); } if (nextDatatype != null) { reportFatalError("Datatype was attached to a blank node object: subject=" + subjStr + " predicate=" + predStr, jp.getCurrentLocation()); } object = createNode(nextValue.substring(2)); } else if (RDFJSONUtility.URI.equals(nextType)) { if (nextLanguage != null) { reportFatalError("Language was attached to a uri object: subject=" + subjStr + " predicate=" + predStr, jp.getCurrentLocation()); } if (nextDatatype != null) { reportFatalError("Datatype was attached to a uri object: subject=" + subjStr + " predicate=" + predStr, jp.getCurrentLocation()); } object = vf.createIRI(nextValue); } foundObject = true; if (!nextContexts.isEmpty()) { for (final String nextContext : nextContexts) { final Resource context; if (nextContext.equals(RDFJSONUtility.NULL)) { context = null; } else if (nextContext.startsWith("_:")) { context = createNode(nextContext.substring(2)); } else { context = vf.createIRI(nextContext); } Statement st = vf.createStatement(subject, predicate, object, context); if (handler != null) { handler.handleStatement(st); } } } else { Statement st = vf.createStatement(subject, predicate, object); if (handler != null) { handler.handleStatement(st); } } } if (!foundObject) { reportFatalError("No object for predicate: subject=" + subjStr + " predicate=" + predStr, jp.getCurrentLocation()); } } if (!foundPredicate) { reportFatalError("No predicate for object: subject=" + subjStr, jp.getCurrentLocation()); } } }
From source file:org.flockdata.integration.FileProcessor.java
private int processJsonEntities(String fileName, ExtractProfile extractProfile) throws FlockException { int rows = 0; File file = new File(fileName); InputStream stream = null;/* www . j a v a 2s. c om*/ if (!file.exists()) { stream = ClassLoader.class.getResourceAsStream(fileName); if (stream == null) { logger.error("{} does not exist", fileName); return 0; } } StopWatch watch = new StopWatch(); JsonFactory jfactory = new JsonFactory(); JsonParser jParser; List<EntityToEntityLinkInput> referenceInputBeans = new ArrayList<>(); try { //String docType = mappable.getDataType(); watch.start(); ObjectMapper om = FdJsonObjectMapper.getObjectMapper(); try { if (stream != null) jParser = jfactory.createParser(stream); else jParser = jfactory.createParser(file); JsonToken currentToken = jParser.nextToken(); long then = new DateTime().getMillis(); JsonNode node; if (currentToken == JsonToken.START_ARRAY || currentToken == JsonToken.START_OBJECT) { while (currentToken != null && currentToken != JsonToken.END_OBJECT) { while (currentToken != null && jParser.nextToken() != JsonToken.END_ARRAY) { node = om.readTree(jParser); if (node != null) { processJsonNode(node, extractProfile.getContentModel(), referenceInputBeans); if (stopProcessing(rows++, then)) { break; } } currentToken = jParser.nextToken(); } } } else if (currentToken == JsonToken.START_OBJECT) { //om.readTree(jParser); node = om.readTree(jParser); processJsonNode(node, extractProfile.getContentModel(), referenceInputBeans); } } catch (IOException e1) { logger.error("Unexpected", e1); } } finally { getPayloadWriter().flush(); } return endProcess(watch, rows, 0); }
From source file:org.hippoecm.frontend.service.restproxy.custom.json.deserializers.AnnotationJsonDeserializer.java
@SuppressWarnings("unchecked") @Override/* w w w . j ava 2s . co m*/ public Annotation deserialize(JsonParser jsonParser, DeserializationContext deserContext) throws IOException, JsonProcessingException { Annotation annotation = null; String annotationTypeName = null; Class<? extends Annotation> annotationClass = null; Map<String, Object> annotationAttributes = null; while (jsonParser.nextToken() != JsonToken.END_OBJECT) { // Read the '@class' field name jsonParser.nextToken(); // Now read the '@class' field value annotationTypeName = jsonParser.getText(); try { annotationClass = (Class<? extends Annotation>) Class.forName(annotationTypeName); annotationAttributes = new HashMap<String, Object>(annotationClass.getDeclaredMethods().length); while (jsonParser.nextToken() != JsonToken.END_OBJECT) { final String fieldName = jsonParser.getCurrentName(); final Method annotationAttribute = annotationClass.getDeclaredMethod(fieldName, new Class<?>[] {}); annotationAttributes.put(fieldName, deserializeAnnotationAttribute(annotationClass, annotationAttribute, jsonParser)); } // Annotation deserialization is done here break; } catch (ClassNotFoundException cnfe) { throw new AnnotationProcessingException("Error while processing annotation: " + annotationTypeName, cnfe); } catch (SecurityException se) { throw new AnnotationProcessingException("Error while processing annotation: " + annotationTypeName, se); } catch (NoSuchMethodException nsme) { if (log.isDebugEnabled()) { log.info("Error while processing annotation: " + annotationTypeName + ". " + nsme); } else { log.info("Error while processing annotation: {}. {}", annotationTypeName, nsme); } } } annotation = (Annotation) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { annotationClass }, new AnnotationProxyInvocationHandler(annotationClass, annotationAttributes)); return annotation; }
From source file:org.jbpm.designer.bpmn2.impl.Bpmn2JsonUnmarshaller.java
public BaseElement unmarshallItem(JsonParser parser, String preProcessingData) throws JsonParseException, IOException { String resourceId = null;//from www .j a v a 2 s .c o m Map<String, String> properties = null; String stencil = null; List<BaseElement> childElements = new ArrayList<BaseElement>(); List<String> outgoing = new ArrayList<String>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String fieldname = parser.getCurrentName(); parser.nextToken(); if ("resourceId".equals(fieldname)) { resourceId = parser.getText(); } else if ("properties".equals(fieldname)) { properties = unmarshallProperties(parser); } else if ("stencil".equals(fieldname)) { // "stencil":{"id":"Task"}, parser.nextToken(); parser.nextToken(); stencil = parser.getText(); parser.nextToken(); } else if ("childShapes".equals(fieldname)) { while (parser.nextToken() != JsonToken.END_ARRAY) { // open the // object // the childShapes element is a json array. We opened the // array. childElements.add(unmarshallItem(parser, preProcessingData)); } } else if ("bounds".equals(fieldname)) { // bounds: {"lowerRight":{"x":484.0,"y":198.0},"upperLeft":{"x":454.0,"y":168.0}} parser.nextToken(); parser.nextToken(); parser.nextToken(); parser.nextToken(); Integer x2 = parser.getIntValue(); parser.nextToken(); parser.nextToken(); Integer y2 = parser.getIntValue(); parser.nextToken(); parser.nextToken(); parser.nextToken(); parser.nextToken(); parser.nextToken(); Integer x1 = parser.getIntValue(); parser.nextToken(); parser.nextToken(); Integer y1 = parser.getIntValue(); parser.nextToken(); parser.nextToken(); // by default the org.eclipse.dd.dc bounds says // its features are set if they are non-zero // we need to change that so that nodes placed on the canvas borders // where x or y can be zero still are treated as set features // otherwise they will not end up as attributes in the produced xml BoundsImpl b = new BoundsImpl() { @Override public boolean eIsSet(int featureID) { switch (featureID) { case 0: if (this.height >= 0.0F) { return true; } return false; case 1: if (this.width >= 0.0F) { return true; } return false; case 2: if (this.x >= 0.0F) { return true; } return false; case 3: if (this.y >= 0.0F) { return true; } return false; default: return super.eIsSet(featureID); } } }; b.setX(x1); b.setY(y1); b.setWidth(x2 - x1); b.setHeight(y2 - y1); this._bounds.put(resourceId, b); } else if ("dockers".equals(fieldname)) { // "dockers":[{"x":50,"y":40},{"x":353.5,"y":115},{"x":353.5,"y":152},{"x":50,"y":40}], List<Point> dockers = new ArrayList<Point>(); JsonToken nextToken = parser.nextToken(); boolean end = JsonToken.END_ARRAY.equals(nextToken); while (!end) { nextToken = parser.nextToken(); nextToken = parser.nextToken(); Integer x = parser.getIntValue(); parser.nextToken(); parser.nextToken(); Integer y = parser.getIntValue(); Point point = DcFactory.eINSTANCE.createPoint(); point.setX(x); point.setY(y); dockers.add(point); parser.nextToken(); nextToken = parser.nextToken(); end = JsonToken.END_ARRAY.equals(nextToken); } this._dockers.put(resourceId, dockers); } else if ("outgoing".equals(fieldname)) { while (parser.nextToken() != JsonToken.END_ARRAY) { // {resourceId: oryx_1AAA8C9A-39A5-42FC-8ED1-507A7F3728EA} parser.nextToken(); parser.nextToken(); outgoing.add(parser.getText()); parser.nextToken(); } // pass on the array parser.skipChildren(); } else if ("target".equals(fieldname)) { // we already collected that info with the outgoing field. parser.skipChildren(); // "target": { // "resourceId": "oryx_A75E7546-DF71-48EA-84D3-2A8FD4A47568" // } // add to the map: // parser.nextToken(); // resourceId: // parser.nextToken(); // the value we want to save // targetId = parser.getText(); // parser.nextToken(); // }, closing the object } } properties.put("resourceId", resourceId); boolean customElement = isCustomElement(properties.get("tasktype"), preProcessingData); BaseElement baseElt = this.createBaseElement(stencil, properties.get("tasktype"), customElement); // register the sequence flow targets. if (baseElt instanceof SequenceFlow) { _sequenceFlowTargets.addAll(outgoing); } _outgoingFlows.put(baseElt, outgoing); _objMap.put(baseElt, resourceId); // keep the object around to do connections _idMap.put(resourceId, baseElt); // baseElt.setId(resourceId); commented out as bpmn2 seems to create // duplicate ids right now. applyProperties(baseElt, properties, preProcessingData); if (baseElt instanceof Definitions) { Process rootLevelProcess = null; if (childElements == null || childElements.size() < 1) { if (rootLevelProcess == null) { rootLevelProcess = Bpmn2Factory.eINSTANCE.createProcess(); // set the properties and item definitions first if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) { String[] vardefs = properties.get("vardefs").split(",\\s*"); for (String vardef : vardefs) { Property prop = Bpmn2Factory.eINSTANCE.createProperty(); ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition(); // check if we define a structure ref in the definition if (vardef.contains(":")) { String[] vardefParts = vardef.split(":\\s*"); prop.setId(vardefParts[0]); itemdef.setId("_" + prop.getId() + "Item"); boolean haveKPI = false; String kpiValue = ""; if (vardefParts.length == 3) { itemdef.setStructureRef(vardefParts[1]); if (vardefParts[2].equals("true")) { haveKPI = true; kpiValue = vardefParts[2]; } } if (vardefParts.length == 2) { if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) { if (vardefParts[1].equals("true")) { haveKPI = true; kpiValue = vardefParts[1]; } } else { itemdef.setStructureRef(vardefParts[1]); } } if (haveKPI) { Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue)); } } else { prop.setId(vardef); itemdef.setId("_" + prop.getId() + "Item"); } prop.setItemSubjectRef(itemdef); rootLevelProcess.getProperties().add(prop); ((Definitions) baseElt).getRootElements().add(itemdef); } } if (properties.get("adhocprocess") != null && properties.get("adhocprocess").equals("true")) { ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "adHoc", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("adhocprocess")); rootLevelProcess.getAnyAttribute().add(extensionEntry); } if (properties.get("customdescription") != null && properties.get("customdescription").length() > 0) { Utils.setMetaDataExtensionValue(rootLevelProcess, "customDescription", wrapInCDATABlock(properties.get("customdescription"))); } if (properties.get("customcaseidprefix") != null && properties.get("customcaseidprefix").length() > 0) { Utils.setMetaDataExtensionValue(rootLevelProcess, "customCaseIdPrefix", wrapInCDATABlock(properties.get("customcaseidprefix"))); } if (properties.get("customcaseroles") != null && properties.get("customcaseroles").length() > 0) { Utils.setMetaDataExtensionValue(rootLevelProcess, "customCaseRoles", wrapInCDATABlock(properties.get("customcaseroles"))); } // customsladuedate metadata applySlaDueDateProperties(rootLevelProcess, properties); rootLevelProcess.setId(properties.get("id")); applyProcessProperties(rootLevelProcess, properties); ((Definitions) baseElt).getRootElements().add(rootLevelProcess); } } else { for (BaseElement child : childElements) { // tasks are only permitted under processes. // a process should be created implicitly for tasks at the root // level. // process designer doesn't make a difference between tasks and // global tasks. // if a task has sequence edges it is considered a task, // otherwise it is considered a global task. // if (child instanceof Task && _outgoingFlows.get(child).isEmpty() && !_sequenceFlowTargets.contains(_objMap.get(child))) { // // no edges on a task at the top level! We replace it with a // // global task. // GlobalTask task = null; // if (child instanceof ScriptTask) { // task = Bpmn2Factory.eINSTANCE.createGlobalScriptTask(); // ((GlobalScriptTask) task).setScript(((ScriptTask) child).getScript()); // ((GlobalScriptTask) task).setScriptLanguage(((ScriptTask) child).getScriptFormat()); // // TODO scriptLanguage missing on scriptTask // } else if (child instanceof UserTask) { // task = Bpmn2Factory.eINSTANCE.createGlobalUserTask(); // } else if (child instanceof ServiceTask) { // // we don't have a global service task! Fallback on a // // normal global task // task = Bpmn2Factory.eINSTANCE.createGlobalTask(); // } else if (child instanceof BusinessRuleTask) { // task = Bpmn2Factory.eINSTANCE.createGlobalBusinessRuleTask(); // } else if (child instanceof ManualTask) { // task = Bpmn2Factory.eINSTANCE.createGlobalManualTask(); // } else { // task = Bpmn2Factory.eINSTANCE.createGlobalTask(); // } // // task.setName(((Task) child).getName()); // task.setIoSpecification(((Task) child).getIoSpecification()); // task.getDocumentation().addAll(((Task) child).getDocumentation()); // ((Definitions) baseElt).getRootElements().add(task); // continue; // } else { if (child instanceof SequenceFlow) { // for some reason sequence flows are placed as root elements. // find if the target has a container, and if we can use it: List<String> ids = _outgoingFlows.get(child); FlowElementsContainer container = null; for (String id : ids) { // yes, we iterate, but we'll take the first in the list that will work. Object obj = _idMap.get(id); if (obj instanceof EObject && ((EObject) obj).eContainer() instanceof FlowElementsContainer) { container = (FlowElementsContainer) ((EObject) obj).eContainer(); break; } } if (container != null) { container.getFlowElements().add((SequenceFlow) child); continue; } } if (child instanceof Task || child instanceof SequenceFlow || child instanceof Gateway || child instanceof Event || child instanceof Artifact || child instanceof DataObject || child instanceof SubProcess || child instanceof Lane || child instanceof CallActivity || child instanceof TextAnnotation) { if (rootLevelProcess == null) { rootLevelProcess = Bpmn2Factory.eINSTANCE.createProcess(); // set the properties and item definitions first if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) { String[] vardefs = properties.get("vardefs").split(",\\s*"); for (String vardef : vardefs) { Property prop = Bpmn2Factory.eINSTANCE.createProperty(); ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition(); // check if we define a structure ref in the definition if (vardef.contains(":")) { String[] vardefParts = vardef.split(":\\s*"); prop.setId(vardefParts[0]); itemdef.setId("_" + prop.getId() + "Item"); boolean haveKPI = false; String kpiValue = ""; if (vardefParts.length == 3) { itemdef.setStructureRef(vardefParts[1]); if (vardefParts[2].equals("true")) { haveKPI = true; kpiValue = vardefParts[2]; } } if (vardefParts.length == 2) { if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) { if (vardefParts[1].equals("true")) { haveKPI = true; kpiValue = vardefParts[1]; } } else { itemdef.setStructureRef(vardefParts[1]); } } if (haveKPI) { Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue)); } } else { prop.setId(vardef); itemdef.setId("_" + prop.getId() + "Item"); } prop.setItemSubjectRef(itemdef); rootLevelProcess.getProperties().add(prop); ((Definitions) baseElt).getRootElements().add(itemdef); } } if (properties.get("adhocprocess") != null && properties.get("adhocprocess").equals("true")) { ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "adHoc", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("adhocprocess")); rootLevelProcess.getAnyAttribute().add(extensionEntry); } if (properties.get("customdescription") != null && properties.get("customdescription").length() > 0) { Utils.setMetaDataExtensionValue(rootLevelProcess, "customDescription", wrapInCDATABlock(properties.get("customdescription"))); } if (properties.get("customcaseidprefix") != null && properties.get("customcaseidprefix").length() > 0) { Utils.setMetaDataExtensionValue(rootLevelProcess, "customCaseIdPrefix", wrapInCDATABlock(properties.get("customcaseidprefix"))); } if (properties.get("customcaseroles") != null && properties.get("customcaseroles").length() > 0) { Utils.setMetaDataExtensionValue(rootLevelProcess, "customCaseRoles", wrapInCDATABlock(properties.get("customcaseroles"))); } // customsladuedate metadata applySlaDueDateProperties(rootLevelProcess, properties); rootLevelProcess.setId(properties.get("id")); applyProcessProperties(rootLevelProcess, properties); ((Definitions) baseElt).getRootElements().add(rootLevelProcess); } } if (child instanceof Task) { rootLevelProcess.getFlowElements().add((Task) child); } else if (child instanceof CallActivity) { rootLevelProcess.getFlowElements().add((CallActivity) child); } else if (child instanceof RootElement) { ((Definitions) baseElt).getRootElements().add((RootElement) child); } else if (child instanceof SequenceFlow) { rootLevelProcess.getFlowElements().add((SequenceFlow) child); } else if (child instanceof Gateway) { rootLevelProcess.getFlowElements().add((Gateway) child); } else if (child instanceof Event) { rootLevelProcess.getFlowElements().add((Event) child); } else if (child instanceof TextAnnotation) { rootLevelProcess.getFlowElements().add((TextAnnotation) child); } else if (child instanceof Artifact) { rootLevelProcess.getArtifacts().add((Artifact) child); } else if (child instanceof DataObject) { // bubble up data objects //rootLevelProcess.getFlowElements().add(0, (DataObject) child); rootLevelProcess.getFlowElements().add((DataObject) child); // ItemDefinition def = ((DataObject) child).getItemSubjectRef(); // if (def != null) { // if (def.eResource() == null) { // ((Definitions) rootLevelProcess.eContainer()).getRootElements().add(0, def); // } // Import imported = def.getImport(); // if (imported != null && imported.eResource() == null) { // ((Definitions) rootLevelProcess.eContainer()).getImports().add(0, imported); // } // } } else if (child instanceof SubProcess) { rootLevelProcess.getFlowElements().add((SubProcess) child); } else if (child instanceof Lane) { // lanes handled later } else { _logger.error("Don't know what to do of " + child); } // } } } } else if (baseElt instanceof Process) { for (BaseElement child : childElements) { if (child instanceof Lane) { if (((Process) baseElt).getLaneSets().isEmpty()) { ((Process) baseElt).getLaneSets().add(Bpmn2Factory.eINSTANCE.createLaneSet()); } ((Process) baseElt).getLaneSets().get(0).getLanes().add((Lane) child); addLaneFlowNodes((Process) baseElt, (Lane) child); } else if (child instanceof Artifact) { ((Process) baseElt).getArtifacts().add((Artifact) child); } else { _logger.error("Don't know what to do of " + child); } } } else if (baseElt instanceof SubProcess) { for (BaseElement child : childElements) { if (child instanceof FlowElement) { ((SubProcess) baseElt).getFlowElements().add((FlowElement) child); } else if (child instanceof Artifact) { ((SubProcess) baseElt).getArtifacts().add((Artifact) child); } else { _logger.error("Subprocess - don't know what to do of " + child); } } } else if (baseElt instanceof Message) { // we do not support base-element messages from the json. They are created dynamically for events that use them. } else if (baseElt instanceof Lane) { for (BaseElement child : childElements) { if (child instanceof FlowNode) { ((Lane) baseElt).getFlowNodeRefs().add((FlowNode) child); } // no support for child-lanes at this point // else if (child instanceof Lane) { // if (((Lane) baseElt).getChildLaneSet() == null) { // ((Lane) baseElt).setChildLaneSet(Bpmn2Factory.eINSTANCE.createLaneSet()); // } // ((Lane) baseElt).getChildLaneSet().getLanes().add((Lane) child); // } else if (child instanceof Artifact) { _artifacts.add((Artifact) child); } else { _logger.error("Don't know what to do of " + childElements); } } _lanes.add((Lane) baseElt); } else { if (!childElements.isEmpty()) { _logger.error("Don't know what to do of " + childElements + " with " + baseElt); } } return baseElt; }
From source file:org.jbpm.designer.bpmn2.impl.Bpmn2JsonUnmarshaller.java
private Map<String, String> unmarshallProperties(JsonParser parser) throws JsonParseException, IOException { Map<String, String> properties = new HashMap<String, String>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String fieldname = parser.getCurrentName(); parser.nextToken();// w w w. j a v a 2 s.co m properties.put(fieldname, parser.getText()); } return properties; }
From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java
public BaseElement unmarshallItem(JsonParser parser, String preProcessingData) throws IOException { String resourceId = null;/*ww w .j av a 2 s . c o m*/ Map<String, String> properties = null; String stencil = null; List<BaseElement> childElements = new ArrayList<BaseElement>(); List<String> outgoing = new ArrayList<String>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String fieldname = parser.getCurrentName(); parser.nextToken(); if ("resourceId".equals(fieldname)) { resourceId = parser.getText(); } else if ("properties".equals(fieldname)) { properties = unmarshallProperties(parser); } else if ("stencil".equals(fieldname)) { // "stencil":{"id":"Task"}, parser.nextToken(); parser.nextToken(); stencil = parser.getText(); parser.nextToken(); } else if ("childShapes".equals(fieldname)) { while (parser.nextToken() != JsonToken.END_ARRAY) { // open the // object // the childShapes element is a json array. We opened the // array. childElements.add(unmarshallItem(parser, preProcessingData)); } } else if ("bounds".equals(fieldname)) { // bounds: {"lowerRight":{"x":484.0,"y":198.0},"upperLeft":{"x":454.0,"y":168.0}} parser.nextToken(); parser.nextToken(); parser.nextToken(); parser.nextToken(); Integer x2 = parser.getIntValue(); parser.nextToken(); parser.nextToken(); Integer y2 = parser.getIntValue(); parser.nextToken(); parser.nextToken(); parser.nextToken(); parser.nextToken(); parser.nextToken(); Integer x1 = parser.getIntValue(); parser.nextToken(); parser.nextToken(); Integer y1 = parser.getIntValue(); parser.nextToken(); parser.nextToken(); Bounds b = DcFactory.eINSTANCE.createBounds(); b.setX(x1); b.setY(y1); b.setWidth(x2 - x1); b.setHeight(y2 - y1); this._bounds.put(resourceId, b); } else if ("dockers".equals(fieldname)) { // "dockers":[{"x":50,"y":40},{"x":353.5,"y":115},{"x":353.5,"y":152},{"x":50,"y":40}], List<Point> dockers = new ArrayList<Point>(); JsonToken nextToken = parser.nextToken(); boolean end = JsonToken.END_ARRAY.equals(nextToken); while (!end) { nextToken = parser.nextToken(); nextToken = parser.nextToken(); Integer x = parser.getIntValue(); parser.nextToken(); parser.nextToken(); Integer y = parser.getIntValue(); Point point = DcFactory.eINSTANCE.createPoint(); point.setX(x); point.setY(y); dockers.add(point); parser.nextToken(); nextToken = parser.nextToken(); end = JsonToken.END_ARRAY.equals(nextToken); } this._dockers.put(resourceId, dockers); } else if ("outgoing".equals(fieldname)) { while (parser.nextToken() != JsonToken.END_ARRAY) { // {resourceId: oryx_1AAA8C9A-39A5-42FC-8ED1-507A7F3728EA} parser.nextToken(); parser.nextToken(); outgoing.add(parser.getText()); parser.nextToken(); } // pass on the array parser.skipChildren(); } else if ("target".equals(fieldname)) { // we already collected that info with the outgoing field. parser.skipChildren(); // "target": { // "resourceId": "oryx_A75E7546-DF71-48EA-84D3-2A8FD4A47568" // } // add to the map: // parser.nextToken(); // resourceId: // parser.nextToken(); // the value we want to save // targetId = parser.getText(); // parser.nextToken(); // }, closing the object } } properties.put("resourceId", resourceId); boolean customElement = isCustomElement(properties.get("tasktype"), preProcessingData); BaseElement baseElt = this.createBaseElement(stencil, properties.get("tasktype"), customElement); // register the sequence flow targets. if (baseElt instanceof SequenceFlow) { _sequenceFlowTargets.addAll(outgoing); } _outgoingFlows.put(baseElt, outgoing); _objMap.put(baseElt, resourceId); // keep the object around to do connections _idMap.put(resourceId, baseElt); // baseElt.setId(resourceId); commented out as bpmn2 seems to create // duplicate ids right now. applyProperties(baseElt, properties, preProcessingData); if (baseElt instanceof Definitions) { Process rootLevelProcess = null; if (childElements == null || childElements.size() < 1) { if (rootLevelProcess == null) { rootLevelProcess = Bpmn2Factory.eINSTANCE.createProcess(); // set the properties and item definitions first if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) { String[] vardefs = properties.get("vardefs").split(",\\s*"); for (String vardef : vardefs) { Property prop = Bpmn2Factory.eINSTANCE.createProperty(); ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition(); // check if we define a structure ref in the definition if (vardef.contains(":")) { String[] vardefParts = vardef.split(":\\s*"); prop.setId(vardefParts[0]); itemdef.setId("_" + prop.getId() + "Item"); boolean haveKPI = false; String kpiValue = ""; if (vardefParts.length == 3) { itemdef.setStructureRef(vardefParts[1]); if (vardefParts[2].equals("true")) { haveKPI = true; kpiValue = vardefParts[2]; } } if (vardefParts.length == 2) { if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) { if (vardefParts[1].equals("true")) { haveKPI = true; kpiValue = vardefParts[1]; } } else { itemdef.setStructureRef(vardefParts[1]); } } if (haveKPI) { Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue)); } } else { prop.setId(vardef); itemdef.setId("_" + prop.getId() + "Item"); } prop.setItemSubjectRef(itemdef); rootLevelProcess.getProperties().add(prop); ((Definitions) baseElt).getRootElements().add(itemdef); } } if (properties.get("adhocprocess") != null && properties.get("adhocprocess").equals("true")) { ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "adHoc", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("adhocprocess")); rootLevelProcess.getAnyAttribute().add(extensionEntry); } if (properties.get("customdescription") != null && properties.get("customdescription").length() > 0) { Utils.setMetaDataExtensionValue(rootLevelProcess, "customDescription", wrapInCDATABlock(properties.get("customdescription"))); } rootLevelProcess.setId(properties.get("id")); applyProcessProperties(rootLevelProcess, properties); ((Definitions) baseElt).getRootElements().add(rootLevelProcess); } } else { for (BaseElement child : childElements) { // tasks are only permitted under processes. // a process should be created implicitly for tasks at the root // level. // process designer doesn't make a difference between tasks and // global tasks. // if a task has sequence edges it is considered a task, // otherwise it is considered a global task. // if (child instanceof Task && _outgoingFlows.get(child).isEmpty() && !_sequenceFlowTargets.contains(_objMap.get(child))) { // // no edges on a task at the top level! We replace it with a // // global task. // GlobalTask task = null; // if (child instanceof ScriptTask) { // task = Bpmn2Factory.eINSTANCE.createGlobalScriptTask(); // ((GlobalScriptTask) task).setScript(((ScriptTask) child).getScript()); // ((GlobalScriptTask) task).setScriptLanguage(((ScriptTask) child).getScriptFormat()); // // TODO scriptLanguage missing on scriptTask // } else if (child instanceof UserTask) { // task = Bpmn2Factory.eINSTANCE.createGlobalUserTask(); // } else if (child instanceof ServiceTask) { // // we don't have a global service task! Fallback on a // // normal global task // task = Bpmn2Factory.eINSTANCE.createGlobalTask(); // } else if (child instanceof BusinessRuleTask) { // task = Bpmn2Factory.eINSTANCE.createGlobalBusinessRuleTask(); // } else if (child instanceof ManualTask) { // task = Bpmn2Factory.eINSTANCE.createGlobalManualTask(); // } else { // task = Bpmn2Factory.eINSTANCE.createGlobalTask(); // } // // task.setName(((Task) child).getName()); // task.setIoSpecification(((Task) child).getIoSpecification()); // task.getDocumentation().addAll(((Task) child).getDocumentation()); // ((Definitions) baseElt).getRootElements().add(task); // continue; // } else { if (child instanceof SequenceFlow) { // for some reason sequence flows are placed as root elements. // find if the target has a container, and if we can use it: List<String> ids = _outgoingFlows.get(child); FlowElementsContainer container = null; for (String id : ids) { // yes, we iterate, but we'll take the first in the list that will work. Object obj = _idMap.get(id); if (obj instanceof EObject && ((EObject) obj).eContainer() instanceof FlowElementsContainer) { container = (FlowElementsContainer) ((EObject) obj).eContainer(); break; } } if (container != null) { container.getFlowElements().add((SequenceFlow) child); continue; } } if (child instanceof Task || child instanceof SequenceFlow || child instanceof Gateway || child instanceof Event || child instanceof Artifact || child instanceof DataObject || child instanceof SubProcess || child instanceof Lane || child instanceof CallActivity || child instanceof TextAnnotation) { if (rootLevelProcess == null) { rootLevelProcess = Bpmn2Factory.eINSTANCE.createProcess(); // set the properties and item definitions first if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) { String[] vardefs = properties.get("vardefs").split(",\\s*"); for (String vardef : vardefs) { Property prop = Bpmn2Factory.eINSTANCE.createProperty(); ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition(); // check if we define a structure ref in the definition if (vardef.contains(":")) { String[] vardefParts = vardef.split(":\\s*"); prop.setId(vardefParts[0]); itemdef.setId("_" + prop.getId() + "Item"); boolean haveKPI = false; String kpiValue = ""; if (vardefParts.length == 3) { itemdef.setStructureRef(vardefParts[1]); if (vardefParts[2].equals("true")) { haveKPI = true; kpiValue = vardefParts[2]; } } if (vardefParts.length == 2) { if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) { if (vardefParts[1].equals("true")) { haveKPI = true; kpiValue = vardefParts[1]; } } else { itemdef.setStructureRef(vardefParts[1]); } } if (haveKPI) { Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue)); } } else { prop.setId(vardef); itemdef.setId("_" + prop.getId() + "Item"); } prop.setItemSubjectRef(itemdef); rootLevelProcess.getProperties().add(prop); ((Definitions) baseElt).getRootElements().add(itemdef); } } if (properties.get("adhocprocess") != null && properties.get("adhocprocess").equals("true")) { ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "adHoc", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("adhocprocess")); rootLevelProcess.getAnyAttribute().add(extensionEntry); } if (properties.get("customdescription") != null && properties.get("customdescription").length() > 0) { Utils.setMetaDataExtensionValue(rootLevelProcess, "customDescription", wrapInCDATABlock(properties.get("customdescription"))); } rootLevelProcess.setId(properties.get("id")); applyProcessProperties(rootLevelProcess, properties); ((Definitions) baseElt).getRootElements().add(rootLevelProcess); } } if (child instanceof Task) { rootLevelProcess.getFlowElements().add((Task) child); } else if (child instanceof CallActivity) { rootLevelProcess.getFlowElements().add((CallActivity) child); } else if (child instanceof RootElement) { ((Definitions) baseElt).getRootElements().add((RootElement) child); } else if (child instanceof SequenceFlow) { rootLevelProcess.getFlowElements().add((SequenceFlow) child); } else if (child instanceof Gateway) { rootLevelProcess.getFlowElements().add((Gateway) child); } else if (child instanceof Event) { rootLevelProcess.getFlowElements().add((Event) child); } else if (child instanceof TextAnnotation) { rootLevelProcess.getFlowElements().add((TextAnnotation) child); } else if (child instanceof Artifact) { rootLevelProcess.getArtifacts().add((Artifact) child); } else if (child instanceof DataObject) { // bubble up data objects //rootLevelProcess.getFlowElements().add(0, (DataObject) child); rootLevelProcess.getFlowElements().add((DataObject) child); // ItemDefinition def = ((DataObject) child).getItemSubjectRef(); // if (def != null) { // if (def.eResource() == null) { // ((Definitions) rootLevelProcess.eContainer()).getRootElements().add(0, def); // } // Import imported = def.getImport(); // if (imported != null && imported.eResource() == null) { // ((Definitions) rootLevelProcess.eContainer()).getImports().add(0, imported); // } // } } else if (child instanceof SubProcess) { rootLevelProcess.getFlowElements().add((SubProcess) child); } else if (child instanceof Lane) { // lanes handled later } else { _logger.error("Don't know what to do of " + child); } // } } } } else if (baseElt instanceof Process) { for (BaseElement child : childElements) { if (child instanceof Lane) { if (((Process) baseElt).getLaneSets().isEmpty()) { ((Process) baseElt).getLaneSets().add(Bpmn2Factory.eINSTANCE.createLaneSet()); } ((Process) baseElt).getLaneSets().get(0).getLanes().add((Lane) child); addLaneFlowNodes((Process) baseElt, (Lane) child); } else if (child instanceof Artifact) { ((Process) baseElt).getArtifacts().add((Artifact) child); } else { _logger.error("Don't know what to do of " + child); } } } else if (baseElt instanceof SubProcess) { for (BaseElement child : childElements) { if (child instanceof FlowElement) { ((SubProcess) baseElt).getFlowElements().add((FlowElement) child); } else if (child instanceof Artifact) { ((SubProcess) baseElt).getArtifacts().add((Artifact) child); } else { _logger.error("Subprocess - don't know what to do of " + child); } } } else if (baseElt instanceof Message) { // we do not support base-element messages from the json. They are created dynamically for events that use them. } else if (baseElt instanceof Lane) { for (BaseElement child : childElements) { if (child instanceof FlowNode) { ((Lane) baseElt).getFlowNodeRefs().add((FlowNode) child); } // no support for child-lanes at this point // else if (child instanceof Lane) { // if (((Lane) baseElt).getChildLaneSet() == null) { // ((Lane) baseElt).setChildLaneSet(Bpmn2Factory.eINSTANCE.createLaneSet()); // } // ((Lane) baseElt).getChildLaneSet().getLanes().add((Lane) child); // } else if (child instanceof Artifact) { _artifacts.add((Artifact) child); } else { _logger.error("Don't know what to do of " + childElements); } } _lanes.add((Lane) baseElt); } else { if (!childElements.isEmpty()) { _logger.error("Don't know what to do of " + childElements + " with " + baseElt); } } return baseElt; }
From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java
private Map<String, String> unmarshallProperties(JsonParser parser) throws IOException { Map<String, String> properties = new HashMap<String, String>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String fieldname = parser.getCurrentName(); parser.nextToken();//from w w w . j ava2 s . co m properties.put(fieldname, parser.getText()); } return properties; }