Example usage for javax.xml.stream XMLStreamWriter writeEndElement

List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter writeEndElement.

Prototype

public void writeEndElement() throws XMLStreamException;

Source Link

Document

Writes an end tag to the output relying on the internal state of the writer to determine the prefix and local name of the event.

Usage

From source file:org.activiti.bpmn.converter.BpmnXMLConverter.java

private void createXML(FlowElement flowElement, BpmnModel model, XMLStreamWriter xtw) throws Exception {

    if (flowElement instanceof SubProcess) {

        SubProcess subProcess = (SubProcess) flowElement;
        xtw.writeStartElement(ELEMENT_SUBPROCESS);
        xtw.writeAttribute(ATTRIBUTE_ID, subProcess.getId());
        if (StringUtils.isNotEmpty(subProcess.getName())) {
            xtw.writeAttribute(ATTRIBUTE_NAME, subProcess.getName());
        } else {//from  w  w w  .j  a v a  2s .com
            xtw.writeAttribute(ATTRIBUTE_NAME, "subProcess");
        }

        if (subProcess instanceof EventSubProcess) {
            xtw.writeAttribute(ATTRIBUTE_TRIGGERED_BY, ATTRIBUTE_VALUE_TRUE);
        }

        if (StringUtils.isNotEmpty(subProcess.getDocumentation())) {

            xtw.writeStartElement(ELEMENT_DOCUMENTATION);
            xtw.writeCharacters(subProcess.getDocumentation());
            xtw.writeEndElement();
        }

        boolean didWriteExtensionStartElement = ActivitiListenerExport.writeListeners(subProcess, false, xtw);

        didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(subProcess,
                didWriteExtensionStartElement, xtw);
        if (didWriteExtensionStartElement) {
            // closing extensions element
            xtw.writeEndElement();
        }

        MultiInstanceExport.writeMultiInstance(subProcess, xtw);

        for (FlowElement subElement : subProcess.getFlowElements()) {
            createXML(subElement, model, xtw);
        }

        for (Artifact artifact : subProcess.getArtifacts()) {
            createXML(artifact, model, xtw);
        }

        xtw.writeEndElement();

    } else {

        BaseBpmnXMLConverter converter = convertersToXMLMap.get(flowElement.getClass());

        if (converter == null) {
            throw new XMLException("No converter for " + flowElement.getClass() + " found");
        }

        converter.convertToXML(xtw, flowElement, model);
    }
}

From source file:org.activiti.bpmn.converter.CallActivityXMLConverter.java

private boolean writeIOParameters(String elementName, List<IOParameter> parameterList,
        boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {
    if (parameterList.size() == 0)
        return didWriteExtensionStartElement;

    for (IOParameter ioParameter : parameterList) {
        if (didWriteExtensionStartElement == false) {
            xtw.writeStartElement(ELEMENT_EXTENSIONS);
            didWriteExtensionStartElement = true;
        }/*from www  . j  a v a 2 s  .c om*/

        xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, elementName, ACTIVITI_EXTENSIONS_NAMESPACE);
        if (StringUtils.isNotEmpty(ioParameter.getSource())) {
            writeDefaultAttribute(ATTRIBUTE_IOPARAMETER_SOURCE, ioParameter.getSource(), xtw);
        }
        if (StringUtils.isNotEmpty(ioParameter.getSourceExpression())) {
            writeDefaultAttribute(ATTRIBUTE_IOPARAMETER_SOURCE_EXPRESSION, ioParameter.getSourceExpression(),
                    xtw);
        }
        if (StringUtils.isNotEmpty(ioParameter.getTarget())) {
            writeDefaultAttribute(ATTRIBUTE_IOPARAMETER_TARGET, ioParameter.getTarget(), xtw);
        }

        xtw.writeEndElement();
    }

    return didWriteExtensionStartElement;
}

From source file:org.activiti.bpmn.converter.DataStoreReferenceXMLConverter.java

@Override
protected void writeAdditionalChildElements(BaseElement element, BpmnModel model, XMLStreamWriter xtw)
        throws Exception {
    DataStoreReference dataStoreRef = (DataStoreReference) element;
    if (StringUtils.isNotEmpty(dataStoreRef.getDataState())) {
        xtw.writeStartElement(ELEMENT_DATA_STATE);
        xtw.writeCharacters(dataStoreRef.getDataState());
        xtw.writeEndElement();
    }/*from   w w  w .ja v  a 2s.  c  o  m*/
}

From source file:org.activiti.bpmn.converter.export.ActivitiListenerExport.java

protected static boolean writeEventListeners(List<EventListener> eventListeners,
        boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {

    if (eventListeners != null && !eventListeners.isEmpty()) {
        for (EventListener eventListener : eventListeners) {
            if (!didWriteExtensionStartElement) {
                xtw.writeStartElement(ELEMENT_EXTENSIONS);
                didWriteExtensionStartElement = true;
            }//w w w.  j a v a2  s .  co  m

            xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_EVENT_LISTENER,
                    ACTIVITI_EXTENSIONS_NAMESPACE);
            BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_EVENTS, eventListener.getEvents(), xtw);
            BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_ENTITY_TYPE, eventListener.getEntityType(),
                    xtw);

            if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(eventListener.getImplementationType())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_CLASS, eventListener.getImplementation(),
                        xtw);
            } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION
                    .equals(eventListener.getImplementationType())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_DELEGATEEXPRESSION,
                        eventListener.getImplementation(), xtw);
            } else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_SIGNAL_EVENT
                    .equals(eventListener.getImplementationType())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_SIGNAL_EVENT_NAME,
                        eventListener.getImplementation(), xtw);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_EVENT_TYPE,
                        ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_SIGNAL, xtw);
            } else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_SIGNAL_EVENT
                    .equals(eventListener.getImplementationType())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_SIGNAL_EVENT_NAME,
                        eventListener.getImplementation(), xtw);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_EVENT_TYPE,
                        ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_GLOBAL_SIGNAL, xtw);
            } else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_MESSAGE_EVENT
                    .equals(eventListener.getImplementationType())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_MESSAGE_EVENT_NAME,
                        eventListener.getImplementation(), xtw);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_EVENT_TYPE,
                        ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_MESSAGE, xtw);
            } else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_ERROR_EVENT
                    .equals(eventListener.getImplementationType())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_ERROR_EVENT_CODE,
                        eventListener.getImplementation(), xtw);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_EVENT_TYPE,
                        ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_ERROR, xtw);
            }

            xtw.writeEndElement();
        }
    }

    return didWriteExtensionStartElement;
}

From source file:org.activiti.bpmn.converter.export.ActivitiListenerExport.java

private static boolean writeListeners(String xmlElementName, List<ActivitiListener> listenerList,
        boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {
    if (listenerList != null) {

        for (ActivitiListener listener : listenerList) {

            if (StringUtils.isNotEmpty(listener.getEvent())) {

                if (!didWriteExtensionStartElement) {
                    xtw.writeStartElement(ELEMENT_EXTENSIONS);
                    didWriteExtensionStartElement = true;
                }/*from w w  w  .j a  v a 2  s.  c  om*/

                xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, xmlElementName,
                        ACTIVITI_EXTENSIONS_NAMESPACE);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_EVENT, listener.getEvent(), xtw);

                if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(listener.getImplementationType())) {
                    BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_CLASS, listener.getImplementation(),
                            xtw);
                } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION
                        .equals(listener.getImplementationType())) {
                    BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_EXPRESSION,
                            listener.getImplementation(), xtw);
                } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION
                        .equals(listener.getImplementationType())) {
                    BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_DELEGATEEXPRESSION,
                            listener.getImplementation(), xtw);
                }

                FieldExtensionExport.writeFieldExtensions(listener.getFieldExtensions(), true, xtw);

                xtw.writeEndElement();
            }
        }
    }
    return didWriteExtensionStartElement;
}

From source file:org.activiti.bpmn.converter.export.BPMNDIExport.java

public static void writeBPMNDI(BpmnModel model, XMLStreamWriter xtw) throws Exception {
    // BPMN DI information
    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_DIAGRAM, BPMNDI_NAMESPACE);

    String processId = null;//from  w  w  w. j  a  va  2  s.  com
    if (model.getPools().size() > 0) {
        processId = "Collaboration";
    } else {
        processId = model.getMainProcess().getId();
    }

    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNDiagram_" + processId);

    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_PLANE, BPMNDI_NAMESPACE);
    xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, processId);
    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNPlane_" + processId);

    for (String elementId : model.getLocationMap().keySet()) {

        if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null
                || model.getPool(elementId) != null || model.getLane(elementId) != null) {

            xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_SHAPE, BPMNDI_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
            xtw.writeAttribute(ATTRIBUTE_ID, "BPMNShape_" + elementId);

            GraphicInfo graphicInfo = model.getGraphicInfo(elementId);
            FlowElement flowElement = model.getFlowElement(elementId);
            if (flowElement instanceof SubProcess && graphicInfo.getExpanded() != null) {
                xtw.writeAttribute(ATTRIBUTE_DI_IS_EXPANDED, String.valueOf(graphicInfo.getExpanded()));
            }

            xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + graphicInfo.getHeight());
            xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + graphicInfo.getWidth());
            xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
            xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
            xtw.writeEndElement();

            xtw.writeEndElement();
        }
    }

    for (String elementId : model.getFlowLocationMap().keySet()) {

        if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null) {

            xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_EDGE, BPMNDI_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
            xtw.writeAttribute(ATTRIBUTE_ID, "BPMNEdge_" + elementId);

            List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(elementId);
            for (GraphicInfo graphicInfo : graphicInfoList) {
                xtw.writeStartElement(OMGDI_PREFIX, ELEMENT_DI_WAYPOINT, OMGDI_NAMESPACE);
                xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
                xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
                xtw.writeEndElement();
            }

            GraphicInfo labelGraphicInfo = model.getLabelGraphicInfo(elementId);
            FlowElement flowElement = model.getFlowElement(elementId);
            if (labelGraphicInfo != null && flowElement != null
                    && StringUtils.isNotEmpty(flowElement.getName())) {
                xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_LABEL, BPMNDI_NAMESPACE);
                xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
                xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + labelGraphicInfo.getHeight());
                xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + labelGraphicInfo.getWidth());
                xtw.writeAttribute(ATTRIBUTE_DI_X, "" + labelGraphicInfo.getX());
                xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + labelGraphicInfo.getY());
                xtw.writeEndElement();
                xtw.writeEndElement();
            }

            xtw.writeEndElement();
        }
    }

    // end BPMN DI elements
    xtw.writeEndElement();
    xtw.writeEndElement();
}

From source file:org.activiti.bpmn.converter.export.CollaborationExport.java

public static void writePools(BpmnModel model, XMLStreamWriter xtw) throws Exception {
    if (!model.getPools().isEmpty()) {
        xtw.writeStartElement(ELEMENT_COLLABORATION);
        xtw.writeAttribute(ATTRIBUTE_ID, "Collaboration");
        for (Pool pool : model.getPools()) {
            xtw.writeStartElement(ELEMENT_PARTICIPANT);
            xtw.writeAttribute(ATTRIBUTE_ID, pool.getId());
            if (StringUtils.isNotEmpty(pool.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, pool.getName());
            }//from  www . j a  v a2  s  .c  om
            if (StringUtils.isNotEmpty(pool.getProcessRef())) {
                xtw.writeAttribute(ATTRIBUTE_PROCESS_REF, pool.getProcessRef());
            }
            xtw.writeEndElement();
        }

        for (MessageFlow messageFlow : model.getMessageFlows().values()) {
            xtw.writeStartElement(ELEMENT_MESSAGE_FLOW);
            xtw.writeAttribute(ATTRIBUTE_ID, messageFlow.getId());
            if (StringUtils.isNotEmpty(messageFlow.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, messageFlow.getName());
            }
            if (StringUtils.isNotEmpty(messageFlow.getSourceRef())) {
                xtw.writeAttribute(ATTRIBUTE_FLOW_SOURCE_REF, messageFlow.getSourceRef());
            }
            if (StringUtils.isNotEmpty(messageFlow.getTargetRef())) {
                xtw.writeAttribute(ATTRIBUTE_FLOW_TARGET_REF, messageFlow.getTargetRef());
            }
            if (StringUtils.isNotEmpty(messageFlow.getMessageRef())) {
                xtw.writeAttribute(ATTRIBUTE_MESSAGE_REF, messageFlow.getMessageRef());
            }
            xtw.writeEndElement();
        }

        xtw.writeEndElement();
    }
}

From source file:org.activiti.bpmn.converter.export.FailedJobRetryCountExport.java

public static void writeFailedJobRetryCount(Activity activity, XMLStreamWriter xtw) throws Exception {
    String failedJobRetryCycle = activity.getFailedJobRetryTimeCycleValue();
    if (failedJobRetryCycle != null) {

        if (StringUtils.isNotEmpty(failedJobRetryCycle)) {
            xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, FAILED_JOB_RETRY_TIME_CYCLE,
                    ACTIVITI_EXTENSIONS_NAMESPACE);
            xtw.writeCharacters(failedJobRetryCycle);
            xtw.writeEndElement();
        }/*from  w ww  . ja v  a2s . com*/
    }
}

From source file:org.activiti.bpmn.converter.export.FieldExtensionExport.java

public static boolean writeFieldExtensions(List<FieldExtension> fieldExtensionList,
        boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {

    for (FieldExtension fieldExtension : fieldExtensionList) {

        if (StringUtils.isNotEmpty(fieldExtension.getFieldName())) {

            if (StringUtils.isNotEmpty(fieldExtension.getStringValue())
                    || StringUtils.isNotEmpty(fieldExtension.getExpression())) {

                if (didWriteExtensionStartElement == false) {
                    xtw.writeStartElement(ELEMENT_EXTENSIONS);
                    didWriteExtensionStartElement = true;
                }/*from  w  w  w  .j  ava 2s.  c  om*/

                xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_FIELD, ACTIVITI_EXTENSIONS_NAMESPACE);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_FIELD_NAME, fieldExtension.getFieldName(), xtw);

                if (StringUtils.isNotEmpty(fieldExtension.getStringValue())) {
                    xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_FIELD_STRING,
                            ACTIVITI_EXTENSIONS_NAMESPACE);
                    xtw.writeCData(fieldExtension.getStringValue());
                } else {
                    xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ATTRIBUTE_FIELD_EXPRESSION,
                            ACTIVITI_EXTENSIONS_NAMESPACE);
                    xtw.writeCharacters(fieldExtension.getExpression());
                }
                xtw.writeEndElement();
                xtw.writeEndElement();
            }
        }
    }
    return didWriteExtensionStartElement;
}

From source file:org.activiti.bpmn.converter.export.LaneExport.java

public static void writeLanes(Process process, XMLStreamWriter xtw) throws Exception {
    if (process.getLanes().size() > 0) {
        xtw.writeStartElement(ELEMENT_LANESET);
        xtw.writeAttribute(ATTRIBUTE_ID, "laneSet_" + process.getId());
        for (Lane lane : process.getLanes()) {
            xtw.writeStartElement(ELEMENT_LANE);
            xtw.writeAttribute(ATTRIBUTE_ID, lane.getId());
            if (StringUtils.isNotEmpty(lane.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, lane.getName());
            }//  ww w. java  2 s.  c  o m

            for (String flowNodeRef : lane.getFlowReferences()) {
                xtw.writeStartElement(ATTRIBUTE_FLOWNODE_REF);
                xtw.writeCharacters(flowNodeRef);
                xtw.writeEndElement();
            }

            xtw.writeEndElement();
        }
        xtw.writeEndElement();
    }
}