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.eclipse.smila.datamodel.record.stax.RecordReader.java

/**
 * read an L element and add {@link Literal}s to the given {@link Attribute}.
 * /*from   w  ww  .j  a v  a2  s. c o m*/
 * @param staxReader
 *          XML stream
 * @param attribute
 *          current attribute
 * @throws XMLStreamException
 *           StAX error
 */
private void readLiteralElement(final XMLStreamReader staxReader, final Attribute attribute)
        throws XMLStreamException {
    final String defaultSemanticType = staxReader.getAttributeValue(null, RecordParser.ATTRIBUTE_SEMANTICTYPE);
    staxReader.nextTag();
    Literal literal = null;
    while (isStartTag(staxReader, RecordParser.TAG_VALUE)) {
        literal = _recordFactory.createLiteral();
        String semanticType = staxReader.getAttributeValue(null, RecordParser.ATTRIBUTE_SEMANTICTYPE);
        if (semanticType == null) {
            semanticType = defaultSemanticType;
        }
        literal.setSemanticType(semanticType);
        final String dataType = staxReader.getAttributeValue(null, RecordParser.ATTRIBUTE_TYPE);
        final String stringValue = staxReader.getElementText();
        setLiteralValue(literal, dataType, stringValue);
        attribute.addLiteral(literal);
        staxReader.nextTag();
    }
    if (isStartTag(staxReader, RecordParser.TAG_ANNOTATION)) {
        if (literal == null) { // literal without value, this is actually allowed by the schema.
            literal = _recordFactory.createLiteral();
        }
        readAnnotations(staxReader, attribute);
    }
}

From source file:org.eclipse.smila.datamodel.record.stax.RecordReader.java

/**
 * read an annotation from the stream and add it to the given {@link Annotatable}.
 * //from  ww w .  ja v a  2s.  com
 * @param staxReader
 *          XML stream
 * @param annotatable
 *          object to annotate
 * @throws XMLStreamException
 *           StAX error
 */
private void readAnnotation(final XMLStreamReader staxReader, final Annotatable annotatable)
        throws XMLStreamException {
    final Annotation annotation = _recordFactory.createAnnotation();
    final String annotationName = staxReader.getAttributeValue(null, RecordParser.ATTRIBUTE_NAME);
    staxReader.nextTag();
    while (isStartTag(staxReader, RecordParser.TAG_VALUE)) {
        final String valueName = staxReader.getAttributeValue(null, RecordParser.ATTRIBUTE_NAME);
        final String value = staxReader.getElementText();
        if (valueName == null) {
            annotation.addAnonValue(value);
        } else {
            annotation.setNamedValue(valueName, value);
        }
        staxReader.nextTag();
    }
    while (isStartTag(staxReader, RecordParser.TAG_ANNOTATION)) {
        readAnnotation(staxReader, annotation);
        staxReader.nextTag();
    }
    annotatable.addAnnotation(annotationName, annotation);
}

From source file:org.flowable.bpmn.converter.AssociationXMLConverter.java

@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
    Association association = new Association();
    BpmnXMLUtil.addXMLLocation(association, xtr);
    association.setSourceRef(xtr.getAttributeValue(null, ATTRIBUTE_FLOW_SOURCE_REF));
    association.setTargetRef(xtr.getAttributeValue(null, ATTRIBUTE_FLOW_TARGET_REF));
    association.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));

    String asociationDirectionString = xtr.getAttributeValue(null, ATTRIBUTE_ASSOCIATION_DIRECTION);
    if (StringUtils.isNotEmpty(asociationDirectionString)) {
        AssociationDirection associationDirection = AssociationDirection
                .valueOf(asociationDirectionString.toUpperCase());

        association.setAssociationDirection(associationDirection);
    }//from  w  ww  .j  a v  a2 s .c o m

    parseChildElements(getXMLElementName(), association, model, xtr);

    return association;
}

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

public void convertToBpmnModel(XMLStreamReader xtr, BpmnModel model, Process activeProcess,
        List<SubProcess> activeSubProcessList) throws Exception {

    String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
    String elementName = xtr.getAttributeValue(null, ATTRIBUTE_NAME);
    boolean async = parseAsync(xtr);
    boolean notExclusive = parseNotExclusive(xtr);
    String defaultFlow = xtr.getAttributeValue(null, ATTRIBUTE_DEFAULT);
    boolean isForCompensation = parseForCompensation(xtr);

    BaseElement parsedElement = convertXMLToElement(xtr, model);

    if (parsedElement instanceof Artifact) {
        Artifact currentArtifact = (Artifact) parsedElement;
        currentArtifact.setId(elementId);

        if (!activeSubProcessList.isEmpty()) {
            activeSubProcessList.get(activeSubProcessList.size() - 1).addArtifact(currentArtifact);

        } else {//from w  w w  .  j  ava  2s.c  om
            activeProcess.addArtifact(currentArtifact);
        }
    }

    if (parsedElement instanceof FlowElement) {

        FlowElement currentFlowElement = (FlowElement) parsedElement;
        currentFlowElement.setId(elementId);
        currentFlowElement.setName(elementName);

        if (currentFlowElement instanceof FlowNode) {
            FlowNode flowNode = (FlowNode) currentFlowElement;
            flowNode.setAsynchronous(async);
            flowNode.setNotExclusive(notExclusive);

            if (currentFlowElement instanceof Activity) {

                Activity activity = (Activity) currentFlowElement;
                activity.setForCompensation(isForCompensation);
                if (StringUtils.isNotEmpty(defaultFlow)) {
                    activity.setDefaultFlow(defaultFlow);
                }
            }

            if (currentFlowElement instanceof Gateway) {
                Gateway gateway = (Gateway) currentFlowElement;
                if (StringUtils.isNotEmpty(defaultFlow)) {
                    gateway.setDefaultFlow(defaultFlow);
                }
            }
        }

        if (currentFlowElement instanceof DataObject) {
            if (!activeSubProcessList.isEmpty()) {
                SubProcess subProcess = activeSubProcessList.get(activeSubProcessList.size() - 1);
                subProcess.getDataObjects().add((ValuedDataObject) parsedElement);
            } else {
                activeProcess.getDataObjects().add((ValuedDataObject) parsedElement);
            }
        }

        if (!activeSubProcessList.isEmpty()) {

            SubProcess subProcess = activeSubProcessList.get(activeSubProcessList.size() - 1);
            subProcess.addFlowElement(currentFlowElement);

        } else {
            activeProcess.addFlowElement(currentFlowElement);
        }
    }
}

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

public BpmnModel convertToBpmnModel(XMLStreamReader xtr) {
    BpmnModel model = new BpmnModel();
    model.setStartEventFormTypes(startEventFormTypes);
    model.setUserTaskFormTypes(userTaskFormTypes);
    try {/*from www .  j av  a2  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())
                    || ELEMENT_TRANSACTION.equals(xtr.getLocalName())
                    || ELEMENT_ADHOC_SUBPROCESS.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_RESOURCE.equals(xtr.getLocalName())) {
                resourceParser.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_DATA_STORE.equals(xtr.getLocalName())) {
                dataStoreParser.parse(xtr, model);

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

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

            } else if (ELEMENT_PARTICIPANT.equals(xtr.getLocalName())) {
                participantParser.parse(xtr, model);

            } else if (ELEMENT_MESSAGE_FLOW.equals(xtr.getLocalName())) {
                messageFlowParser.parse(xtr, model);

            } 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.isEmpty()) {
                    parentElement = activeSubProcessList.get(activeSubProcessList.size() - 1);
                } else if (activeProcess != null) {
                    parentElement = activeProcess;
                }
                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())) {
                extensionElementsParser.parse(xtr, activeSubProcessList, activeProcess, model);

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

            } else if (ELEMENT_COMPLETION_CONDITION.equals(xtr.getLocalName())) {
                if (!activeSubProcessList.isEmpty()) {
                    SubProcess subProcess = activeSubProcessList.get(activeSubProcessList.size() - 1);
                    if (subProcess instanceof AdhocSubProcess) {
                        AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess;
                        adhocSubProcess.setCompletionCondition(xtr.getElementText());
                    }
                }

            } 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.isEmpty()
                        && ELEMENT_MULTIINSTANCE.equalsIgnoreCase(xtr.getLocalName())) {

                    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.flowable.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));
    callActivity.setBusinessKey(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_CALL_ACTIVITY_BUSINESS_KEY, xtr));
    callActivity.setInheritBusinessKey(Boolean
            .parseBoolean(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_CALL_ACTIVITY_INHERIT_BUSINESS_KEY, xtr)));
    callActivity.setInheritVariables(//  w  w w  .j av  a  2  s. c om
            Boolean.valueOf(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_CALL_ACTIVITY_INHERITVARIABLES, xtr)));
    parseChildElements(getXMLElementName(), callActivity, childParserMap, model, xtr);
    return callActivity;
}

From source file:org.flowable.bpmn.converter.child.DataAssociationParser.java

public static void parseDataAssociation(DataAssociation dataAssociation, String elementName,
        XMLStreamReader xtr) {
    boolean readyWithDataAssociation = false;
    Assignment assignment = null;//from   w ww  .j  a v  a 2s  .  c  om
    try {

        dataAssociation.setId(xtr.getAttributeValue(null, "id"));

        while (readyWithDataAssociation == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && ELEMENT_SOURCE_REF.equals(xtr.getLocalName())) {
                String sourceRef = xtr.getElementText();
                if (StringUtils.isNotEmpty(sourceRef)) {
                    dataAssociation.setSourceRef(sourceRef.trim());
                }

            } else if (xtr.isStartElement() && ELEMENT_TARGET_REF.equals(xtr.getLocalName())) {
                String targetRef = xtr.getElementText();
                if (StringUtils.isNotEmpty(targetRef)) {
                    dataAssociation.setTargetRef(targetRef.trim());
                }

            } else if (xtr.isStartElement() && ELEMENT_TRANSFORMATION.equals(xtr.getLocalName())) {
                String transformation = xtr.getElementText();
                if (StringUtils.isNotEmpty(transformation)) {
                    dataAssociation.setTransformation(transformation.trim());
                }

            } else if (xtr.isStartElement() && ELEMENT_ASSIGNMENT.equals(xtr.getLocalName())) {
                assignment = new Assignment();
                BpmnXMLUtil.addXMLLocation(assignment, xtr);

            } else if (xtr.isStartElement() && ELEMENT_FROM.equals(xtr.getLocalName())) {
                String from = xtr.getElementText();
                if (assignment != null && StringUtils.isNotEmpty(from)) {
                    assignment.setFrom(from.trim());
                }

            } else if (xtr.isStartElement() && ELEMENT_TO.equals(xtr.getLocalName())) {
                String to = xtr.getElementText();
                if (assignment != null && StringUtils.isNotEmpty(to)) {
                    assignment.setTo(to.trim());
                }

            } else if (xtr.isEndElement() && ELEMENT_ASSIGNMENT.equals(xtr.getLocalName())) {
                if (StringUtils.isNotEmpty(assignment.getFrom())
                        && StringUtils.isNotEmpty(assignment.getTo())) {
                    dataAssociation.getAssignments().add(assignment);
                }

            } else if (xtr.isEndElement() && elementName.equals(xtr.getLocalName())) {
                readyWithDataAssociation = true;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error parsing data association child elements", e);
    }
}

From source file:org.flowable.bpmn.converter.child.FieldExtensionParser.java

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

    if (!accepts(parentElement))
        return;//from w  w w.  j  a v  a 2  s .  c o  m

    FieldExtension extension = new FieldExtension();
    BpmnXMLUtil.addXMLLocation(extension, xtr);
    extension.setFieldName(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_NAME));

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_STRING))) {
        extension.setStringValue(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_STRING));

    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_EXPRESSION))) {
        extension.setExpression(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_EXPRESSION));

    } else {
        boolean readyWithFieldExtension = false;
        try {
            while (readyWithFieldExtension == false && xtr.hasNext()) {
                xtr.next();
                if (xtr.isStartElement() && ELEMENT_FIELD_STRING.equalsIgnoreCase(xtr.getLocalName())) {
                    extension.setStringValue(xtr.getElementText().trim());

                } else if (xtr.isStartElement()
                        && ATTRIBUTE_FIELD_EXPRESSION.equalsIgnoreCase(xtr.getLocalName())) {
                    extension.setExpression(xtr.getElementText().trim());

                } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
                    readyWithFieldExtension = true;
                }
            }
        } catch (Exception e) {
            LOGGER.warn("Error parsing field extension child elements", e);
        }
    }

    if (parentElement instanceof FlowableListener) {
        ((FlowableListener) parentElement).getFieldExtensions().add(extension);
    } else if (parentElement instanceof ServiceTask) {
        ((ServiceTask) parentElement).getFieldExtensions().add(extension);
    } else {
        ((SendTask) parentElement).getFieldExtensions().add(extension);
    }
}

From source file:org.flowable.bpmn.converter.child.FlowableCollectionParser.java

@Override
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        throws Exception {
    if (!(parentElement instanceof MultiInstanceLoopCharacteristics)) {
        return;/*w w w .j  av  a2s  . com*/
    }

    MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics = (MultiInstanceLoopCharacteristics) parentElement;

    CollectionHandler collectionHandler = null;

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_COLLECTION_CLASS))) {
        collectionHandler = new CollectionHandler();
        collectionHandler
                .setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_COLLECTION_CLASS));
        collectionHandler.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);

    } else if (StringUtils
            .isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_COLLECTION_DELEGATEEXPRESSION))) {
        collectionHandler = new CollectionHandler();
        collectionHandler.setImplementation(
                xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_COLLECTION_DELEGATEEXPRESSION));
        collectionHandler.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
    }

    if (collectionHandler != null) {
        BpmnXMLUtil.addXMLLocation(collectionHandler, xtr);
        multiInstanceLoopCharacteristics.setHandler(collectionHandler);
    }

    boolean readyWithCollection = false;
    try {
        while (!readyWithCollection && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement()
                    && ELEMENT_MULTIINSTANCE_COLLECTION_STRING.equalsIgnoreCase(xtr.getLocalName())) {
                // it is a string value
                multiInstanceLoopCharacteristics.setCollectionString(xtr.getElementText());

            } else if (xtr.isStartElement()
                    && ELEMENT_MULTIINSTANCE_COLLECTION_EXPRESSION.equalsIgnoreCase(xtr.getLocalName())) {
                // it is an expression
                multiInstanceLoopCharacteristics.setInputDataItem(xtr.getElementText());

            } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
                readyWithCollection = true;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error parsing collection child elements", e);
    }
}

From source file:org.flowable.bpmn.converter.child.FlowableHttpRequestHandlerParser.java

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

    FlowableHttpRequestHandler requestHandler = new FlowableHttpRequestHandler();
    BpmnXMLUtil.addXMLLocation(requestHandler, xtr);
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CLASS))) {
        requestHandler.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CLASS));
        requestHandler.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);

    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_DELEGATEEXPRESSION))) {
        requestHandler.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_DELEGATEEXPRESSION));
        requestHandler.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
    }/*from   ww  w  . j  av a 2  s .c  o  m*/

    if (parentElement instanceof HttpServiceTask) {
        ((HttpServiceTask) parentElement).setHttpRequestHandler(requestHandler);
        parseChildElements(xtr, requestHandler, model, new FieldExtensionParser());
    }
}