List of usage examples for com.fasterxml.jackson.core JsonGenerator writeObjectFieldStart
public final void writeObjectFieldStart(String fieldName) throws IOException, JsonGenerationException
From source file:de.escalon.hypermedia.spring.hydra.LinkListSerializer.java
/** * Writes bean description recursively./*from w w w . j ava2s . c o m*/ * * @param jgen * to write to * @param currentVocab * in context * @param valueType * class of value * @param allRootParameters * of the method that receives the request body * @param rootParameter * the request body * @param currentCallValue * the value at the current recursion level * @param propertyPath * of the current recursion level * @throws IntrospectionException * @throws IOException */ private void recurseSupportedProperties(JsonGenerator jgen, String currentVocab, Class<?> valueType, ActionDescriptor allRootParameters, ActionInputParameter rootParameter, Object currentCallValue, String propertyPath) throws IntrospectionException, IOException { Map<String, ActionInputParameter> properties = new HashMap<String, ActionInputParameter>(); // collect supported properties from ctor Constructor[] constructors = valueType.getConstructors(); // find default ctor Constructor constructor = PropertyUtils.findDefaultCtor(constructors); // find ctor with JsonCreator ann if (constructor == null) { constructor = PropertyUtils.findJsonCreator(constructors, JsonCreator.class); } if (constructor == null) { // TODO this can be a generic collection, find a way to describe it LOG.warn("can't describe supported properties, no default constructor or JsonCreator found for type " + valueType.getName()); return; } int parameterCount = constructor.getParameterTypes().length; if (parameterCount > 0) { Annotation[][] annotationsOnParameters = constructor.getParameterAnnotations(); Class[] parameters = constructor.getParameterTypes(); int paramIndex = 0; for (Annotation[] annotationsOnParameter : annotationsOnParameters) { for (Annotation annotation : annotationsOnParameter) { if (JsonProperty.class == annotation.annotationType()) { JsonProperty jsonProperty = (JsonProperty) annotation; // TODO use required attribute of JsonProperty String paramName = jsonProperty.value(); Object propertyValue = PropertyUtils.getPropertyOrFieldValue(currentCallValue, paramName); ActionInputParameter constructorParamInputParameter = new SpringActionInputParameter( new MethodParameter(constructor, paramIndex), propertyValue); // TODO collect ctor params, setter params and process // TODO then handle single, collection and bean for both properties.put(paramName, constructorParamInputParameter); paramIndex++; // increase for each @JsonProperty } } } Assert.isTrue(parameters.length == paramIndex, "not all constructor arguments of @JsonCreator " + constructor.getName() + " are annotated with @JsonProperty"); } // collect supported properties from setters // TODO support Option provider by other method args? final BeanInfo beanInfo = Introspector.getBeanInfo(valueType); final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); // TODO collection and map // TODO distinguish which properties should be printed as supported - now just setters for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { final Method writeMethod = propertyDescriptor.getWriteMethod(); if (writeMethod == null) { continue; } // TODO: the property name must be a valid URI - need to check context for terms? String propertyName = getWritableExposedPropertyOrPropertyName(propertyDescriptor); Object propertyValue = PropertyUtils.getPropertyOrFieldValue(currentCallValue, propertyDescriptor.getName()); MethodParameter methodParameter = new MethodParameter(propertyDescriptor.getWriteMethod(), 0); ActionInputParameter propertySetterInputParameter = new SpringActionInputParameter(methodParameter, propertyValue); properties.put(propertyName, propertySetterInputParameter); } // write all supported properties // TODO we are using the annotatedParameter.parameterName but should use the key of properties here: for (ActionInputParameter annotatedParameter : properties.values()) { String nextPropertyPathLevel = propertyPath.isEmpty() ? annotatedParameter.getParameterName() : propertyPath + '.' + annotatedParameter.getParameterName(); if (DataType.isSingleValueType(annotatedParameter.getParameterType())) { final Object[] possiblePropertyValues = rootParameter.getPossibleValues(allRootParameters); if (rootParameter.isIncluded(nextPropertyPathLevel) && !rootParameter.isExcluded(nextPropertyPathLevel)) { writeSupportedProperty(jgen, currentVocab, annotatedParameter, annotatedParameter.getParameterName(), possiblePropertyValues); } // TODO collections? // } else if (DataType.isArrayOrCollection(parameterType)) { // Object[] callValues = rootParameter.getValues(); // int items = callValues.length; // for (int i = 0; i < items; i++) { // Object value; // if (i < callValues.length) { // value = callValues[i]; // } else { // value = null; // } // recurseSupportedProperties(jgen, currentVocab, rootParameter // .getParameterType(), // allRootParameters, rootParameter, value); // } } else { jgen.writeStartObject(); jgen.writeStringField("hydra:property", annotatedParameter.getParameterName()); // TODO: is the property required -> for bean props we need the Access annotation to express that jgen.writeObjectFieldStart(getPropertyOrClassNameInVocab(currentVocab, "rangeIncludes", LdContextFactory.HTTP_SCHEMA_ORG, "schema:")); Expose expose = AnnotationUtils.getAnnotation(annotatedParameter.getParameterType(), Expose.class); String subClass; if (expose != null) { subClass = expose.value(); } else { subClass = annotatedParameter.getParameterType().getSimpleName(); } jgen.writeStringField(getPropertyOrClassNameInVocab(currentVocab, "subClassOf", "http://www.w3" + ".org/2000/01/rdf-schema#", "rdfs:"), subClass); jgen.writeArrayFieldStart("hydra:supportedProperty"); Object propertyValue = PropertyUtils.getPropertyOrFieldValue(currentCallValue, annotatedParameter.getParameterName()); recurseSupportedProperties(jgen, currentVocab, annotatedParameter.getParameterType(), allRootParameters, rootParameter, propertyValue, nextPropertyPathLevel); jgen.writeEndArray(); jgen.writeEndObject(); jgen.writeEndObject(); } } }
From source file:org.apache.olingo.client.core.serialization.JsonEntitySerializer.java
protected void doContainerSerialize(final ResWrap<Entity> container, final JsonGenerator jgen) throws IOException, EdmPrimitiveTypeException { final Entity entity = container.getPayload(); jgen.writeStartObject();//ww w .j av a2 s . c o m if (serverMode) { if (container.getContextURL() != null) { jgen.writeStringField(Constants.JSON_CONTEXT, container.getContextURL().toASCIIString()); } if (StringUtils.isNotBlank(container.getMetadataETag())) { jgen.writeStringField(Constants.JSON_METADATA_ETAG, container.getMetadataETag()); } if (StringUtils.isNotBlank(entity.getETag())) { jgen.writeStringField(Constants.JSON_ETAG, entity.getETag()); } } if (StringUtils.isNotBlank(entity.getType()) && !isODataMetadataNone(contentType)) { jgen.writeStringField(Constants.JSON_TYPE, new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external()); } if (entity.getId() != null && !isODataMetadataNone(contentType)) { jgen.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString()); } for (Annotation annotation : entity.getAnnotations()) { valuable(jgen, annotation, "@" + annotation.getTerm()); } for (Property property : entity.getProperties()) { valuable(jgen, property, property.getName()); } if (serverMode && entity.getEditLink() != null && StringUtils.isNotBlank(entity.getEditLink().getHref())) { jgen.writeStringField(Constants.JSON_EDIT_LINK, entity.getEditLink().getHref()); if (entity.isMediaEntity()) { jgen.writeStringField(Constants.JSON_MEDIA_READ_LINK, entity.getEditLink().getHref() + "/$value"); } } if (!isODataMetadataNone(contentType)) { links(entity, jgen); } for (Link link : entity.getMediaEditLinks()) { if (link.getTitle() == null) { jgen.writeStringField(Constants.JSON_MEDIA_EDIT_LINK, link.getHref()); } if (link.getInlineEntity() != null) { jgen.writeObjectField(link.getTitle(), link.getInlineEntity()); } if (link.getInlineEntitySet() != null) { jgen.writeArrayFieldStart(link.getTitle()); for (Entity subEntry : link.getInlineEntitySet().getEntities()) { jgen.writeObject(subEntry); } jgen.writeEndArray(); } } if (serverMode) { for (Operation operation : entity.getOperations()) { jgen.writeObjectFieldStart( "#" + StringUtils.substringAfterLast(operation.getMetadataAnchor(), "#")); jgen.writeStringField(Constants.ATTR_TITLE, operation.getTitle()); jgen.writeStringField(Constants.ATTR_TARGET, operation.getTarget().toASCIIString()); jgen.writeEndObject(); } } jgen.writeEndObject(); }
From source file:org.apache.olingo.commons.core.serialization.JsonEntitySerializer.java
protected void doContainerSerialize(final ResWrap<Entity> container, final JsonGenerator jgen) throws IOException, EdmPrimitiveTypeException { final Entity entity = container.getPayload(); jgen.writeStartObject();/* w w w . j a v a 2s . c o m*/ if (serverMode) { if (container.getContextURL() != null) { jgen.writeStringField(version.compareTo(ODataServiceVersion.V40) >= 0 ? Constants.JSON_CONTEXT : Constants.JSON_METADATA, container.getContextURL().toASCIIString()); } if (version.compareTo(ODataServiceVersion.V40) >= 0 && StringUtils.isNotBlank(container.getMetadataETag())) { jgen.writeStringField(Constants.JSON_METADATA_ETAG, container.getMetadataETag()); } if (StringUtils.isNotBlank(entity.getETag())) { jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.ETAG), entity.getETag()); } } if (StringUtils.isNotBlank(entity.getType())) { jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.TYPE), new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version)); } if (entity.getId() != null) { jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.ID), entity.getId().toASCIIString()); } for (Annotation annotation : entity.getAnnotations()) { valuable(jgen, annotation, "@" + annotation.getTerm()); } for (Property property : entity.getProperties()) { valuable(jgen, property, property.getName()); } if (serverMode && entity.getEditLink() != null && StringUtils.isNotBlank(entity.getEditLink().getHref())) { jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.EDIT_LINK), entity.getEditLink().getHref()); if (entity.isMediaEntity()) { jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_READ_LINK), entity.getEditLink().getHref() + "/$value"); } } links(entity, jgen); for (Link link : entity.getMediaEditLinks()) { if (link.getTitle() == null) { jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK), link.getHref()); } if (link.getInlineEntity() != null) { jgen.writeObjectField(link.getTitle(), link.getInlineEntity()); } if (link.getInlineEntitySet() != null) { jgen.writeArrayFieldStart(link.getTitle()); for (Entity subEntry : link.getInlineEntitySet().getEntities()) { jgen.writeObject(subEntry); } jgen.writeEndArray(); } } if (serverMode) { for (ODataOperation operation : entity.getOperations()) { jgen.writeObjectFieldStart( "#" + StringUtils.substringAfterLast(operation.getMetadataAnchor(), "#")); jgen.writeStringField(Constants.ATTR_TITLE, operation.getTitle()); jgen.writeStringField(Constants.ATTR_TARGET, operation.getTarget().toASCIIString()); jgen.writeEndObject(); } } jgen.writeEndObject(); }
From source file:org.apache.olingo.server.core.serializer.json.ODataJsonSerializer.java
private void writeOperations(final List<Operation> operations, final JsonGenerator json) throws IOException { if (isODataMetadataFull) { for (Operation operation : operations) { json.writeObjectFieldStart(operation.getMetadataAnchor()); json.writeStringField(Constants.ATTR_TITLE, operation.getTitle()); json.writeStringField(Constants.ATTR_TARGET, operation.getTarget().toASCIIString()); json.writeEndObject();//from ww w . ja v a 2 s . com } } }
From source file:org.apache.olingo.server.core.serializer.json.ODataJsonSerializer.java
private void srid(final JsonGenerator jgen, final SRID srid) throws IOException { jgen.writeObjectFieldStart(Constants.JSON_CRS); jgen.writeStringField(Constants.ATTR_TYPE, Constants.JSON_NAME); jgen.writeObjectFieldStart(Constants.PROPERTIES); jgen.writeStringField(Constants.JSON_NAME, "EPSG:" + srid.toString()); jgen.writeEndObject();//from www . j a v a2 s .c om jgen.writeEndObject(); }
From source file:org.jbpm.designer.bpmn2.impl.Bpmn2JsonMarshaller.java
protected void marshallDefinitions(Definitions def, JsonGenerator generator, String preProcessingData) throws JsonGenerationException, IOException { try {//from w w w.j ava2s . c o m generator.writeStartObject(); generator.writeObjectField("resourceId", def.getId()); /** * "properties":{"name":"", * "documentation":"", * "auditing":"", * "monitoring":"", * "executable":"true", * "package":"com.sample", * "vardefs":"a,b,c,d", * "lanes" : "a,b,c", * "id":"", * "version":"", * "author":"", * "language":"", * "namespaces":"", * "targetnamespace":"", * "expressionlanguage":"", * "typelanguage":"", * "creationdate":"", * "modificationdate":"" * } */ Map<String, Object> props = new LinkedHashMap<String, Object>(); props.put("namespaces", ""); //props.put("targetnamespace", def.getTargetNamespace()); props.put("targetnamespace", "http://www.omg.org/bpmn20"); props.put("typelanguage", def.getTypeLanguage()); props.put("name", unescapeXml(def.getName())); props.put("id", def.getId()); props.put("expressionlanguage", def.getExpressionLanguage()); props.put("exporter", StringUtils.isNotEmpty(def.getExporter()) ? def.getExporter() : ""); props.put("exporterversion", StringUtils.isNotEmpty(def.getExporterVersion()) ? def.getExporterVersion() : ""); // backwards compat for BZ 1048191 if (def.getDocumentation() != null && def.getDocumentation().size() > 0) { props.put("documentation", def.getDocumentation().get(0).getText()); } for (RootElement rootElement : def.getRootElements()) { if (rootElement instanceof Process) { // have to wait for process node to finish properties and stencil marshalling props.put("executable", ((Process) rootElement).isIsExecutable() + ""); props.put("id", rootElement.getId()); if (rootElement.getDocumentation() != null && rootElement.getDocumentation().size() > 0) { props.put("documentation", rootElement.getDocumentation().get(0).getText()); } Process pr = (Process) rootElement; if (pr.getName() != null && pr.getName().length() > 0) { props.put("processn", unescapeXml(((Process) rootElement).getName())); } List<Property> processProperties = ((Process) rootElement).getProperties(); if (processProperties != null && processProperties.size() > 0) { String propVal = ""; for (int i = 0; i < processProperties.size(); i++) { Property p = processProperties.get(i); String pKPI = Utils.getMetaDataValue(p.getExtensionValues(), "customKPI"); propVal += p.getId(); // check the structureRef value if (p.getItemSubjectRef() != null && p.getItemSubjectRef().getStructureRef() != null) { propVal += ":" + p.getItemSubjectRef().getStructureRef(); } if (pKPI != null && pKPI.length() > 0) { propVal += ":" + pKPI; } if (i != processProperties.size() - 1) { propVal += ","; } } props.put("vardefs", propVal); } // packageName and version and adHoc are jbpm-specific extension attribute Iterator<FeatureMap.Entry> iter = ((Process) rootElement).getAnyAttribute().iterator(); while (iter.hasNext()) { FeatureMap.Entry entry = iter.next(); if (entry.getEStructuralFeature().getName().equals("packageName")) { props.put("package", entry.getValue()); } if (entry.getEStructuralFeature().getName().equals("version")) { props.put("version", entry.getValue()); } if (entry.getEStructuralFeature().getName().equals("adHoc")) { props.put("adhocprocess", entry.getValue()); } } // process imports, custom description and globals extension elements String allImports = ""; if ((rootElement).getExtensionValues() != null && (rootElement).getExtensionValues().size() > 0) { String importsStr = ""; String globalsStr = ""; for (ExtensionAttributeValue extattrval : rootElement.getExtensionValues()) { FeatureMap extensionElements = extattrval.getValue(); @SuppressWarnings("unchecked") List<ImportType> importExtensions = (List<ImportType>) extensionElements .get(DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, true); @SuppressWarnings("unchecked") List<GlobalType> globalExtensions = (List<GlobalType>) extensionElements .get(DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, true); List<MetaDataType> metadataExtensions = (List<MetaDataType>) extensionElements .get(DroolsPackage.Literals.DOCUMENT_ROOT__META_DATA, true); for (ImportType importType : importExtensions) { importsStr += importType.getName(); importsStr += "|default,"; } for (GlobalType globalType : globalExtensions) { globalsStr += (globalType.getIdentifier() + ":" + globalType.getType()); globalsStr += ","; } for (MetaDataType metaType : metadataExtensions) { if (metaType.getName().equals("customDescription")) { props.put("customdescription", metaType.getMetaValue()); } else if (metaType.getName().equals("customCaseIdPrefix")) { props.put("customcaseidprefix", metaType.getMetaValue()); } else if (metaType.getName().equals("customCaseRoles")) { props.put("customcaseroles", metaType.getMetaValue()); } else if (metaType.getName().equals("customSLADueDate")) { props.put("customsladuedate", metaType.getMetaValue()); } else { props.put(metaType.getName(), metaType.getMetaValue()); } } } allImports += importsStr; if (globalsStr.length() > 0) { if (globalsStr.endsWith(",")) { globalsStr = globalsStr.substring(0, globalsStr.length() - 1); } props.put("globals", globalsStr); } } // definitions imports (wsdl) List<org.eclipse.bpmn2.Import> wsdlImports = def.getImports(); if (wsdlImports != null) { for (org.eclipse.bpmn2.Import imp : wsdlImports) { allImports += imp.getLocation() + "|" + imp.getNamespace() + "|wsdl,"; } } if (allImports.endsWith(",")) { allImports = allImports.substring(0, allImports.length() - 1); } props.put("imports", allImports); // simulation if (_simulationScenario != null && _simulationScenario.getScenarioParameters() != null) { props.put("currency", _simulationScenario.getScenarioParameters().getBaseCurrencyUnit() == null ? "" : _simulationScenario.getScenarioParameters().getBaseCurrencyUnit()); props.put("timeunit", _simulationScenario.getScenarioParameters().getBaseTimeUnit().getName()); } marshallProperties(props, generator); marshallStencil("BPMNDiagram", generator); linkSequenceFlows(((Process) rootElement).getFlowElements()); marshallProcess((Process) rootElement, def, generator, preProcessingData); } else if (rootElement instanceof Interface) { // TODO } else if (rootElement instanceof ItemDefinition) { // TODO } else if (rootElement instanceof Resource) { // TODO } else if (rootElement instanceof Error) { // TODO } else if (rootElement instanceof Message) { // TODO } else if (rootElement instanceof Signal) { // TODO } else if (rootElement instanceof Escalation) { // TODO } else if (rootElement instanceof Collaboration) { } else { _logger.warn("Unknown root element " + rootElement + ". This element will not be parsed."); } } generator.writeObjectFieldStart("stencilset"); generator.writeObjectField("url", this.profile.getStencilSetURL()); generator.writeObjectField("namespace", this.profile.getStencilSetNamespaceURL()); generator.writeEndObject(); generator.writeArrayFieldStart("ssextensions"); generator.writeObject(this.profile.getStencilSetExtensionURL()); generator.writeEndArray(); generator.writeEndObject(); } finally { _diagramElements.clear(); } }
From source file:org.jbpm.designer.bpmn2.impl.Bpmn2JsonMarshaller.java
private List<String> marshallLanes(Lane lane, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def) throws JsonGenerationException, IOException { Bounds bounds = ((BPMNShape) findDiagramElement(plane, lane)).getBounds(); List<String> nodeRefIds = new ArrayList<String>(); if (bounds != null) { generator.writeStartObject();//from w ww . j a v a2s. c om generator.writeObjectField("resourceId", lane.getId()); Map<String, Object> laneProperties = new LinkedHashMap<String, Object>(); if (lane.getName() != null) { laneProperties.put("name", unescapeXml(lane.getName())); } else { laneProperties.put("name", ""); } // overwrite name if elementname extension element is present String elementName = Utils.getMetaDataValue(lane.getExtensionValues(), "elementname"); if (elementName != null) { laneProperties.put("name", elementName); } Documentation doc = getDocumentation(lane); if (doc != null) { laneProperties.put("documentation", doc.getText()); } Iterator<FeatureMap.Entry> iter = lane.getAnyAttribute().iterator(); boolean foundBgColor = false; boolean foundBrColor = false; boolean foundFontColor = false; boolean foundSelectable = false; while (iter.hasNext()) { FeatureMap.Entry entry = iter.next(); if (entry.getEStructuralFeature().getName().equals("background-color") || entry.getEStructuralFeature().getName().equals("bgcolor")) { laneProperties.put("bgcolor", entry.getValue()); foundBgColor = true; } if (entry.getEStructuralFeature().getName().equals("border-color") || entry.getEStructuralFeature().getName().equals("bordercolor")) { laneProperties.put("bordercolor", entry.getValue()); foundBrColor = true; } if (entry.getEStructuralFeature().getName().equals("fontsize")) { laneProperties.put("fontsize", entry.getValue()); foundBrColor = true; } if (entry.getEStructuralFeature().getName().equals("color") || entry.getEStructuralFeature().getName().equals("fontcolor")) { laneProperties.put("fontcolor", entry.getValue()); foundFontColor = true; } if (entry.getEStructuralFeature().getName().equals("selectable")) { laneProperties.put("isselectable", entry.getValue()); foundSelectable = true; } } if (!foundBgColor) { laneProperties.put("bgcolor", defaultBgColor_Swimlanes); } if (!foundBrColor) { laneProperties.put("bordercolor", defaultBrColor); } if (!foundFontColor) { laneProperties.put("fontcolor", defaultFontColor); } if (!foundSelectable) { laneProperties.put("isselectable", "true"); } marshallProperties(laneProperties, generator); generator.writeObjectFieldStart("stencil"); generator.writeObjectField("id", "Lane"); generator.writeEndObject(); generator.writeArrayFieldStart("childShapes"); for (FlowElement flowElement : lane.getFlowNodeRefs()) { nodeRefIds.add(flowElement.getId()); if (coordianteManipulation) { marshallFlowElement(flowElement, plane, generator, bounds.getX(), bounds.getY(), preProcessingData, def); } else { marshallFlowElement(flowElement, plane, generator, 0, 0, preProcessingData, def); } } generator.writeEndArray(); generator.writeArrayFieldStart("outgoing"); Process process = (Process) plane.getBpmnElement(); writeAssociations(process, lane.getId(), generator); generator.writeEndArray(); generator.writeObjectFieldStart("bounds"); generator.writeObjectFieldStart("lowerRight"); generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset); generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset); generator.writeEndObject(); generator.writeObjectFieldStart("upperLeft"); generator.writeObjectField("x", bounds.getX() - xOffset); generator.writeObjectField("y", bounds.getY() - yOffset); generator.writeEndObject(); generator.writeEndObject(); generator.writeEndObject(); } else { // dont marshall the lane unless it has BPMNDI info (eclipse editor does not generate it for lanes currently. for (FlowElement flowElement : lane.getFlowNodeRefs()) { nodeRefIds.add(flowElement.getId()); // we dont want an offset here! marshallFlowElement(flowElement, plane, generator, 0, 0, preProcessingData, def); } } return nodeRefIds; }
From source file:org.jbpm.designer.bpmn2.impl.Bpmn2JsonMarshaller.java
protected void marshallNode(FlowNode node, Map<String, Object> properties, String stencil, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset) throws JsonGenerationException, IOException { if (properties == null) { properties = new LinkedHashMap<String, Object>(); }/* w w w . java 2 s . c om*/ if (node.getDocumentation() != null && node.getDocumentation().size() > 0) { properties.put("documentation", node.getDocumentation().get(0).getText()); } if (node.getName() != null) { properties.put("name", unescapeXml(node.getName())); } else { if (node instanceof TextAnnotation) { if (((TextAnnotation) node).getText() != null) { properties.put("name", ((TextAnnotation) node).getText()); } else { properties.put("name", ""); } } else { properties.put("name", ""); } } // overwrite name if elementname extension element is present String elementName = Utils.getMetaDataValue(node.getExtensionValues(), "elementname"); if (elementName != null) { properties.put("name", elementName); } marshallProperties(properties, generator); generator.writeObjectFieldStart("stencil"); generator.writeObjectField("id", stencil); generator.writeEndObject(); generator.writeArrayFieldStart("childShapes"); generator.writeEndArray(); generator.writeArrayFieldStart("outgoing"); for (SequenceFlow outgoing : node.getOutgoing()) { generator.writeStartObject(); generator.writeObjectField("resourceId", outgoing.getId()); generator.writeEndObject(); } // we need to also add associations as outgoing elements Process process = (Process) plane.getBpmnElement(); writeAssociations(process, node.getId(), generator); // and boundary events for activities List<BoundaryEvent> boundaryEvents = new ArrayList<BoundaryEvent>(); findBoundaryEvents(process, boundaryEvents); for (BoundaryEvent be : boundaryEvents) { if (be.getAttachedToRef().getId().equals(node.getId())) { generator.writeStartObject(); generator.writeObjectField("resourceId", be.getId()); generator.writeEndObject(); } } generator.writeEndArray(); // boundary events have a docker if (node instanceof BoundaryEvent) { Iterator<FeatureMap.Entry> iter = node.getAnyAttribute().iterator(); boolean foundDockerInfo = false; while (iter.hasNext()) { FeatureMap.Entry entry = iter.next(); if (entry.getEStructuralFeature().getName().equals("dockerinfo")) { foundDockerInfo = true; String dockerInfoStr = String.valueOf(entry.getValue()); if (dockerInfoStr != null && dockerInfoStr.length() > 0) { if (dockerInfoStr.endsWith("|")) { dockerInfoStr = dockerInfoStr.substring(0, dockerInfoStr.length() - 1); String[] dockerInfoParts = dockerInfoStr.split("\\|"); String infoPartsToUse = dockerInfoParts[0]; String[] infoPartsToUseParts = infoPartsToUse.split("\\^"); if (infoPartsToUseParts != null && infoPartsToUseParts.length > 0) { generator.writeArrayFieldStart("dockers"); generator.writeStartObject(); generator.writeObjectField("x", Double.valueOf(infoPartsToUseParts[0])); generator.writeObjectField("y", Double.valueOf(infoPartsToUseParts[1])); generator.writeEndObject(); generator.writeEndArray(); } } } } } // backwards compatibility to older versions -- BZ 1196259 if (!foundDockerInfo) { // find the edge associated with this boundary event for (DiagramElement element : plane.getPlaneElement()) { if (element instanceof BPMNEdge && ((BPMNEdge) element).getBpmnElement() == node) { List<Point> waypoints = ((BPMNEdge) element).getWaypoint(); if (waypoints != null && waypoints.size() > 0) { // one per boundary event Point p = waypoints.get(0); if (p != null) { generator.writeArrayFieldStart("dockers"); generator.writeStartObject(); generator.writeObjectField("x", p.getX()); generator.writeObjectField("y", p.getY()); generator.writeEndObject(); generator.writeEndArray(); } } } } } } BPMNShape shape = (BPMNShape) findDiagramElement(plane, node); Bounds bounds = shape.getBounds(); correctEventNodeSize(shape); generator.writeObjectFieldStart("bounds"); generator.writeObjectFieldStart("lowerRight"); generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset); generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset); generator.writeEndObject(); generator.writeObjectFieldStart("upperLeft"); generator.writeObjectField("x", bounds.getX() - xOffset); generator.writeObjectField("y", bounds.getY() - yOffset); generator.writeEndObject(); generator.writeEndObject(); }
From source file:org.jbpm.designer.bpmn2.impl.Bpmn2JsonMarshaller.java
protected void marshallDataObject(DataObject dataObject, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException { Map<String, Object> properties = new LinkedHashMap<String, Object>(flowElementProperties); if (dataObject.getDocumentation() != null && dataObject.getDocumentation().size() > 0) { properties.put("documentation", dataObject.getDocumentation().get(0).getText()); }//from ww w. j a v a2 s. c o m if (dataObject.getName() != null && dataObject.getName().length() > 0) { properties.put("name", unescapeXml(dataObject.getName())); } else { // we need a name, use id instead properties.put("name", dataObject.getId()); } // overwrite name if elementname extension element is present String elementName = Utils.getMetaDataValue(dataObject.getExtensionValues(), "elementname"); if (elementName != null) { properties.put("name", elementName); } if (dataObject.getItemSubjectRef().getStructureRef() != null && dataObject.getItemSubjectRef().getStructureRef().length() > 0) { if (defaultTypesList.contains(dataObject.getItemSubjectRef().getStructureRef())) { properties.put("standardtype", dataObject.getItemSubjectRef().getStructureRef()); } else { properties.put("customtype", dataObject.getItemSubjectRef().getStructureRef()); } } Association outgoingAssociaton = findOutgoingAssociation(plane, dataObject); Association incomingAssociation = null; Process process = (Process) plane.getBpmnElement(); for (Artifact artifact : process.getArtifacts()) { if (artifact instanceof Association) { Association association = (Association) artifact; if (association.getTargetRef() == dataObject) { incomingAssociation = association; } } } if (outgoingAssociaton != null && incomingAssociation == null) { properties.put("input_output", "Input"); } if (outgoingAssociaton == null && incomingAssociation != null) { properties.put("input_output", "Output"); } marshallProperties(properties, generator); generator.writeObjectFieldStart("stencil"); generator.writeObjectField("id", "DataObject"); generator.writeEndObject(); generator.writeArrayFieldStart("childShapes"); generator.writeEndArray(); generator.writeArrayFieldStart("outgoing"); List<Association> associations = findOutgoingAssociations(plane, dataObject); if (associations != null) { for (Association as : associations) { generator.writeStartObject(); generator.writeObjectField("resourceId", as.getId()); generator.writeEndObject(); } } generator.writeEndArray(); Bounds bounds = ((BPMNShape) findDiagramElement(plane, dataObject)).getBounds(); generator.writeObjectFieldStart("bounds"); generator.writeObjectFieldStart("lowerRight"); generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset); generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset); generator.writeEndObject(); generator.writeObjectFieldStart("upperLeft"); generator.writeObjectField("x", bounds.getX() - xOffset); generator.writeObjectField("y", bounds.getY() - yOffset); generator.writeEndObject(); generator.writeEndObject(); }