Example usage for javax.xml.stream XMLStreamReader getAttributeValue

List of usage examples for javax.xml.stream XMLStreamReader getAttributeValue

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader getAttributeValue.

Prototype

public String getAttributeValue(String namespaceURI, String localName);

Source Link

Document

Returns the normalized attribute value of the attribute with the namespace and localName If the namespaceURI is null the namespace is not checked for equality

Usage

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

protected boolean parseNotExclusive(XMLStreamReader xtr) {
    boolean notExclusive = false;
    String exclusiveString = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_ACTIVITY_EXCLUSIVE);
    if (ATTRIBUTE_VALUE_FALSE.equalsIgnoreCase(exclusiveString)) {
        notExclusive = true;//from   w ww  .  j a v  a  2 s . co m
    }
    return notExclusive;
}

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

protected boolean parseForCompensation(XMLStreamReader xtr) {
    boolean isForCompensation = false;
    String compensationString = xtr.getAttributeValue(null, ATTRIBUTE_ACTIVITY_ISFORCOMPENSATION);
    if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(compensationString)) {
        isForCompensation = true;//w w w.  ja  va  2 s  .c  o m
    }
    return isForCompensation;
}

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

@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
    BoundaryEvent boundaryEvent = new BoundaryEvent();
    BpmnXMLUtil.addXMLLocation(boundaryEvent, xtr);
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_BOUNDARY_CANCELACTIVITY))) {
        String cancelActivity = xtr.getAttributeValue(null, ATTRIBUTE_BOUNDARY_CANCELACTIVITY);
        if (ATTRIBUTE_VALUE_FALSE.equalsIgnoreCase(cancelActivity)) {
            boundaryEvent.setCancelActivity(false);
        }/*w ww. j  av  a2  s. co m*/
    }
    boundaryEvent.setAttachedToRefId(xtr.getAttributeValue(null, ATTRIBUTE_BOUNDARY_ATTACHEDTOREF));
    parseChildElements(getXMLElementName(), boundaryEvent, model, xtr);

    // Explicitly set cancel activity to false for error boundary events
    if (boundaryEvent.getEventDefinitions().size() == 1) {
        EventDefinition eventDef = boundaryEvent.getEventDefinitions().get(0);

        if (eventDef instanceof ErrorEventDefinition) {
            boundaryEvent.setCancelActivity(false);
        }
    }

    return boundaryEvent;
}

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

public BpmnModel convertToBpmnModel(XMLStreamReader xtr) {
    BpmnModel model = new BpmnModel();
    model.setStartEventFormTypes(startEventFormTypes);
    model.setUserTaskFormTypes(userTaskFormTypes);
    try {/*from ww w .j a  v a 2 s  .c o m*/
        Process activeProcess = null;
        List<SubProcess> activeSubProcessList = new ArrayList<SubProcess>();
        while (xtr.hasNext()) {
            try {
                xtr.next();
            } catch (Exception e) {
                LOGGER.debug("Error reading XML document", e);
                throw new XMLException("Error reading XML", e);
            }

            if (xtr.isEndElement() && ELEMENT_SUBPROCESS.equals(xtr.getLocalName())) {
                activeSubProcessList.remove(activeSubProcessList.size() - 1);
            }

            if (xtr.isEndElement() && ELEMENT_TRANSACTION.equals(xtr.getLocalName())) {
                activeSubProcessList.remove(activeSubProcessList.size() - 1);
            }

            if (xtr.isStartElement() == false)
                continue;

            if (ELEMENT_DEFINITIONS.equals(xtr.getLocalName())) {
                definitionsParser.parse(xtr, model);

            } else if (ELEMENT_SIGNAL.equals(xtr.getLocalName())) {
                signalParser.parse(xtr, model);

            } else if (ELEMENT_MESSAGE.equals(xtr.getLocalName())) {
                messageParser.parse(xtr, model);

            } else if (ELEMENT_ERROR.equals(xtr.getLocalName())) {

                if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) {
                    model.addError(xtr.getAttributeValue(null, ATTRIBUTE_ID),
                            xtr.getAttributeValue(null, ATTRIBUTE_ERROR_CODE));
                }

            } else if (ELEMENT_IMPORT.equals(xtr.getLocalName())) {
                importParser.parse(xtr, model);

            } else if (ELEMENT_ITEM_DEFINITION.equals(xtr.getLocalName())) {
                itemDefinitionParser.parse(xtr, model);

            } else if (ELEMENT_INTERFACE.equals(xtr.getLocalName())) {
                interfaceParser.parse(xtr, model);

            } else if (ELEMENT_IOSPECIFICATION.equals(xtr.getLocalName())) {
                new IOSpecificationParser().parseChildElement(xtr, activeProcess, model);

            } else if (ELEMENT_PARTICIPANT.equals(xtr.getLocalName())) {

                if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) {
                    Pool pool = new Pool();
                    pool.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                    pool.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                    pool.setProcessRef(xtr.getAttributeValue(null, ATTRIBUTE_PROCESS_REF));
                    BpmnXMLUtil.parseChildElements(ELEMENT_PARTICIPANT, pool, xtr, model);
                    model.getPools().add(pool);
                }

            } else if (ELEMENT_PROCESS.equals(xtr.getLocalName())) {

                Process process = processParser.parse(xtr, model);
                if (process != null) {
                    activeProcess = process;
                }

            } else if (ELEMENT_POTENTIAL_STARTER.equals(xtr.getLocalName())) {
                potentialStarterParser.parse(xtr, activeProcess);

            } else if (ELEMENT_LANE.equals(xtr.getLocalName())) {
                laneParser.parse(xtr, activeProcess, model);

            } else if (ELEMENT_DOCUMENTATION.equals(xtr.getLocalName())) {

                BaseElement parentElement = null;
                if (activeSubProcessList.size() > 0) {
                    parentElement = activeSubProcessList.get(activeSubProcessList.size() - 1);
                } else if (activeProcess != null) {
                    parentElement = activeProcess;
                }
                new DocumentationParser().parseChildElement(xtr, parentElement, model);

            } else if (activeProcess == null && ELEMENT_TEXT_ANNOTATION.equals(xtr.getLocalName())) {
                String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
                TextAnnotation textAnnotation = (TextAnnotation) new TextAnnotationXMLConverter()
                        .convertXMLToElement(xtr, model);
                textAnnotation.setId(elementId);
                model.getGlobalArtifacts().add(textAnnotation);

            } else if (activeProcess == null && ELEMENT_ASSOCIATION.equals(xtr.getLocalName())) {
                String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
                Association association = (Association) new AssociationXMLConverter().convertXMLToElement(xtr,
                        model);
                association.setId(elementId);
                model.getGlobalArtifacts().add(association);

            } else if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                new ExtensionElementsParser().parse(xtr, activeSubProcessList, activeProcess, model);

            } else if (ELEMENT_SUBPROCESS.equals(xtr.getLocalName())) {
                subProcessParser.parse(xtr, activeSubProcessList, activeProcess);

            } else if (ELEMENT_TRANSACTION.equals(xtr.getLocalName())) {
                subProcessParser.parse(xtr, activeSubProcessList, activeProcess);

            } else if (ELEMENT_DI_SHAPE.equals(xtr.getLocalName())) {
                bpmnShapeParser.parse(xtr, model);

            } else if (ELEMENT_DI_EDGE.equals(xtr.getLocalName())) {
                bpmnEdgeParser.parse(xtr, model);

            } else {

                if (activeSubProcessList.size() > 0
                        && ELEMENT_MULTIINSTANCE.equalsIgnoreCase(xtr.getLocalName())) {

                    new MultiInstanceParser().parseChildElement(xtr,
                            activeSubProcessList.get(activeSubProcessList.size() - 1), model);

                } else if (convertersToBpmnMap.containsKey(xtr.getLocalName())) {
                    if (activeProcess != null) {
                        BaseBpmnXMLConverter converter = convertersToBpmnMap.get(xtr.getLocalName());
                        converter.convertToBpmnModel(xtr, model, activeProcess, activeSubProcessList);
                    }
                }
            }
        }

        for (Process process : model.getProcesses()) {
            for (Pool pool : model.getPools()) {
                if (process.getId().equals(pool.getProcessRef())) {
                    pool.setExecutable(process.isExecutable());
                }
            }
            processFlowElements(process.getFlowElements(), process);
        }

    } catch (XMLException e) {
        throw e;

    } catch (Exception e) {
        LOGGER.error("Error processing BPMN document", e);
        throw new XMLException("Error processing BPMN document", e);
    }
    return model;
}

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

@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
    BusinessRuleTask businessRuleTask = new BusinessRuleTask();
    BpmnXMLUtil.addXMLLocation(businessRuleTask, xtr);
    businessRuleTask.setInputVariables(parseDelimitedList(
            xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_RULE_VARIABLES_INPUT)));
    businessRuleTask.setRuleNames(parseDelimitedList(
            xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_RULE_RULES)));
    businessRuleTask.setResultVariableName(
            xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_RULE_RESULT_VARIABLE));
    businessRuleTask//from w w  w  .  j a v a2s . c  om
            .setClassName(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_RULE_CLASS));
    String exclude = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_RULE_EXCLUDE);
    if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(exclude)) {
        businessRuleTask.setExclude(true);
    }
    parseChildElements(getXMLElementName(), businessRuleTask, model, xtr);
    return businessRuleTask;
}

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

@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
    CallActivity callActivity = new CallActivity();
    BpmnXMLUtil.addXMLLocation(callActivity, xtr);
    callActivity.setCalledElement(xtr.getAttributeValue(null, ATTRIBUTE_CALL_ACTIVITY_CALLEDELEMENT));
    parseChildElements(getXMLElementName(), callActivity, childParserMap, model, xtr);
    return callActivity;
}

From source file:org.activiti.bpmn.converter.child.ActivitiEventListenerParser.java

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        throws Exception {
    EventListener listener = new EventListener();
    BpmnXMLUtil.addXMLLocation(listener, xtr);
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CLASS))) {
        listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CLASS));
        listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_DELEGATEEXPRESSION))) {
        listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_DELEGATEEXPRESSION));
        listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_THROW_EVENT_TYPE))) {
        String eventType = xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_THROW_EVENT_TYPE);
        if (ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_SIGNAL.equals(eventType)) {
            listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_THROW_SIGNAL_EVENT);
            listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_THROW_SIGNAL_EVENT_NAME));
        } else if (ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_GLOBAL_SIGNAL.equals(eventType)) {
            listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_THROW_GLOBAL_SIGNAL_EVENT);
            listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_THROW_SIGNAL_EVENT_NAME));
        } else if (ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_MESSAGE.equals(eventType)) {
            listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_THROW_MESSAGE_EVENT);
            listener.setImplementation(/*w w w  .  java 2s. c  om*/
                    xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_THROW_MESSAGE_EVENT_NAME));
        } else if (ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_ERROR.equals(eventType)) {
            listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_THROW_ERROR_EVENT);
            listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_THROW_ERROR_EVENT_CODE));
        } else {
            listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_INVALID_THROW_EVENT);
        }
    }
    listener.setEvents(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_EVENTS));
    listener.setEntityType(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_ENTITY_TYPE));

    Process parentProcess = (Process) parentElement;
    parentProcess.getEventListeners().add(listener);
}

From source file:org.activiti.bpmn.converter.child.ActivitiListenerParser.java

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        throws Exception {

    ActivitiListener listener = new ActivitiListener();
    BpmnXMLUtil.addXMLLocation(listener, xtr);
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CLASS))) {
        listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CLASS));
        listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_EXPRESSION))) {
        listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_EXPRESSION));
        listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_DELEGATEEXPRESSION))) {
        listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_DELEGATEEXPRESSION));
        listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
    }//from w w w.  j  a v  a  2  s .c  o  m
    listener.setEvent(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_EVENT));
    addListenerToParent(listener, parentElement);
    parseChildElements(xtr, listener, model, new FieldExtensionParser());
}

From source file:org.activiti.bpmn.converter.child.ActivitiMapExceptionParser.java

@Override
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        throws Exception {
    if (!(parentElement instanceof Activity))
        return;/*from   w w  w.  ja  va  2 s  .c om*/

    String errorCode = xtr.getAttributeValue(null, MAP_EXCEPTION_ERRORCODE);
    String andChildren = xtr.getAttributeValue(null, MAP_EXCEPTION_ANDCHILDREN);
    String exceptionClass = xtr.getElementText();
    boolean hasChildrenBool = false;

    if (StringUtils.isEmpty(andChildren) || andChildren.toLowerCase().equals("false")) {
        hasChildrenBool = false;
    } else if (andChildren.toLowerCase().equals("true")) {
        hasChildrenBool = true;
    } else {
        throw new XMLException("'" + andChildren + "' is not valid boolean in mapException with errorCode="
                + errorCode + " and class=" + exceptionClass);
    }

    if (StringUtils.isEmpty(errorCode) || StringUtils.isEmpty(errorCode.trim())) {
        throw new XMLException("No errorCode defined mapException with errorCode=" + errorCode + " and class="
                + exceptionClass);
    }

    ((Activity) parentElement).getMapExceptions()
            .add(new MapExceptionEntry(errorCode, exceptionClass, hasChildrenBool));
}

From source file:org.activiti.bpmn.converter.child.CompensateEventDefinitionParser.java

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        throws Exception {
    if (parentElement instanceof Event == false)
        return;//from  www.  ja  v  a 2s. c  om

    CompensateEventDefinition eventDefinition = new CompensateEventDefinition();
    BpmnXMLUtil.addXMLLocation(eventDefinition, xtr);
    eventDefinition.setActivityRef(xtr.getAttributeValue(null, ATTRIBUTE_COMPENSATE_ACTIVITYREF));
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_COMPENSATE_WAITFORCOMPLETION))) {
        eventDefinition.setWaitForCompletion(
                Boolean.parseBoolean(xtr.getAttributeValue(null, ATTRIBUTE_COMPENSATE_WAITFORCOMPLETION)));
    }

    BpmnXMLUtil.parseChildElements(ELEMENT_EVENT_COMPENSATEDEFINITION, eventDefinition, xtr, model);

    ((Event) parentElement).getEventDefinitions().add(eventDefinition);
}