Example usage for org.w3c.dom Element getLocalName

List of usage examples for org.w3c.dom Element getLocalName

Introduction

In this page you can find the example usage for org.w3c.dom Element getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:org.wso2.developerstudio.eclipse.esb.impl.ModelObjectImpl.java

/**
 * Utility method for loading a {@link ModelObject} instance from the
 * corresponding XML {@link Element}./*from   www .ja  v a  2s .c o m*/
 * 
 * @param <T>
 *            {@link ModelObject} sub type.
 * @param element
 *            {@link Element} which holds the {@link ModelObject}
 *            definition.
 * @param clazz
 *            {@link Class} of the object to be loaded.
 * @param isMandatory
 *            whether this object is mandatory.
 * @param handler
 *            call back used to report back upon a successful loading
 *            operation.
 * @throws Exception
 *             if a mandatory object cannot be loaded.
 */
protected <T extends ModelObject> void loadObject(Element element, Class<T> clazz, boolean isMandatory,
        ObjectHandler<T> handler) throws Exception {
    T result = getEsbFactory().loadModelObject(element, clazz, this);
    if (null != result) {
        handler.handle(result);
    } else if (isMandatory) {
        throw new Exception(String.format("Error while loading mandatory object corresponding to element [%s].",
                element.getLocalName()));
    }
}

From source file:org.wso2.developerstudio.eclipse.esb.impl.ModelObjectImpl.java

/**
 * Attempts to load the {@link ModelObject} corresponding to the specified
 * child {@link Element}.//from  w  ww  .ja v  a 2s.c  o m
 * 
 * @param <T>
 *            {@link ModelObject} sub type.
 * @param parent
 *            parent element.
 * @param childName
 *            local name of the child element.
 * @param clazz
 *            class of the child object to be loaded.
 * @param isMandatory
 *            whether this object is mandatory.
 * @param handler
 *            call back used to report back upon a successful loading
 *            operation.
 * @throws Exception
 *             if a mandatory object cannot be loaded.
 */
protected <T extends ModelObject> void loadObject(Element parent, String childName, Class<T> clazz,
        boolean isMandatory, ObjectHandler<T> handler) throws Exception {
    Element childElem = getChildElement(parent, childName);
    if (null != childElem) {
        loadObject(childElem, clazz, isMandatory, handler);
    } else if (isMandatory) {
        throw new Exception(String.format("The element [%s] is missing the required child element [%s].",
                parent.getLocalName(), childName));
    }
}

From source file:org.wso2.developerstudio.eclipse.esb.impl.ModelObjectImpl.java

/**
 * Search within the parent element for the specified child element.
 * //from  ww  w. ja va 2s .  com
 * @param parent
 *            parent {@link Element}.
 * @param localName
 *            local name of the child element.
 * @return child {@link Element} if found or null.
 */
protected Element getChildElement(Element parent, String localName) {
    NodeList children = parent.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node node = children.item(i);
        if (node instanceof Element) {
            Element child = (Element) node;
            if (child.getLocalName().equalsIgnoreCase(localName)) {
                return child;
            }
        }
    }
    return null;
}

From source file:org.wso2.developerstudio.eclipse.esb.impl.ModelObjectImpl.java

/**
 * Search within the parent element for all child elements bearing the
 * specified local name./*w ww. ja va2s . c o m*/
 * 
 * @param parent
 *            parent {@link Element}.
 * @param localName
 *            local name of child elements.
 * @return list of child elements having the specified local name.
 */
protected List<Element> getChildElements(Element parent, String localName) {
    NodeList children = parent.getChildNodes();
    List<Element> result = new ArrayList<Element>();
    for (int i = 0; i < children.getLength(); i++) {
        Node node = children.item(i);
        if (node instanceof Element) {
            Element child = (Element) node;
            if (child.getLocalName().equalsIgnoreCase(localName)) {
                result.add(child);
            }
        }
    }
    return result;
}

From source file:org.wyona.yanel.core.util.ConfigurationUtil.java

/**
 * Parse a configuration node into a element and add it to the document. <br/>This method may
 * call itself recusively./*from   w  w  w  .  j  a  v a2s. c o m*/
 *
 * @param conf
 *            The configuration element to parse
 * @param doc
 *            The DOM document to create elements for
 *
 * @return Returns the created element
 */
private static Element createElement(Configuration config, Document doc) throws Exception {

    Element element = doc.createElementNS(config.getNamespace(), config.getName());
    String[] attrs = config.getAttributeNames();
    for (int i = 0; i < attrs.length; i++) {
        element.setAttributeNS(config.getNamespace(), attrs[i], config.getAttribute(attrs[i]));
    }
    // TODO: Does not work for elements with mixed content (text and
    // elements)
    try {
        element.appendChild(doc.createTextNode(config.getValue()));
    } catch (Exception e) {
        log.debug("No value: " + element.getLocalName() + "  - skipped child creation");
    }
    Configuration[] children = config.getChildren();
    if (children.length > 0) {
        for (int i = 0; i < children.length; i++) {
            element.appendChild(ConfigurationUtil.createElement(children[i], doc));
        }
    }
    return element;
}

From source file:org.xsystem.bpmn2.formats.xml.XMLParser3.java

void parseDataAssociation(DataAssociation dataAssoc, Element rootElement) {
    parseAttributes(dataAssoc, rootElement);
    List<Element> childs = XMLUtil.elements(rootElement);
    for (Element child : childs) {
        String ns = child.getNamespaceURI();
        String nodeName = child.getLocalName();
        //  getNodeName();

        if (ns.equals(BPMN2_NS)) {
            switch (nodeName) {
            case "sourceRef": {
                Reference ref = createReference(child);
                dataAssoc.getSourceRef().add(ref);
                break;
            }// w  w  w .  j  a v a  2s .c o  m
            case "targetRef": {
                Reference ref = createReference(child);
                dataAssoc.setTargetRef(ref);
                break;
            }
            case "assignment":
                Assignment assignment = pareseAssignment(child);
                dataAssoc.getAssignment().add(assignment);
                break;
            }
        }
    }
}

From source file:org.xsystem.bpmn2.formats.xml.XMLParser3.java

Assignment pareseAssignment(Element root) {
    Assignment assignment = new AssignmentImpl(definitions);
    parseAttributes(assignment, root);//from   w ww . j ava 2s.c o m
    List<Element> childs = XMLUtil.elements(root);
    for (Element child : childs) {
        String ns = child.getNamespaceURI();
        String nodeName = child.getLocalName();
        if (ns.equals(BPMN2_NS)) {
            switch (nodeName) {
            case "from": {
                Expression from = parseExpression(child);
                assignment.setFrom(from);
                break;
            }
            case "to": {
                Expression to = parseExpression(child);
                assignment.setTo(to);
                break;
            }
            }
        }
    }
    return assignment;
}

From source file:org.xsystem.bpmn2.formats.xml.XMLParser3.java

void parseMultiInstanceLoopCharacteristics(MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics,
        Element rootElement) {//from  ww  w  .  j a v a 2  s  .co m
    parseAttributes(multiInstanceLoopCharacteristics, rootElement);
    List<Element> childs = XMLUtil.elements(rootElement);
    for (Element child : childs) {
        String ns = child.getNamespaceURI();
        String nodeName = child.getLocalName();
        if (ns.equals(BPMN2_NS)) {
            switch (nodeName) {
            case "loopCardinality": {
                Expression expr = parseExpression(child);
                multiInstanceLoopCharacteristics.setLoopCardinality(expr);
                break;
            }
            default: {
                System.out.println("(MultiInstanceLoopCharacteristics not imp element " + nodeName);
            }
            }
        }
    }
}

From source file:org.xsystem.bpmn2.formats.xml.XMLParser3.java

void parseResourceRoleElement(ResourceRole resourceRole, List<Element> childs) {
    childs.stream().forEach((child) -> {
        String ns = child.getNamespaceURI();
        String nodeName = child.getLocalName();
        if (ns.equals(BPMN2_NS)) {
            if (nodeName.equals("resourceAssignmentExpression")) {
                Element elem = XMLUtil.getFirstChildElement(child);
                ResourceAssignmentExpression resourceAssignmentExpression = new ResourceAssignmentExpressionImpl(
                        definitions);/*from   w w w. ja va2 s .  c o m*/

                if (elem != null) {
                    String ns1 = elem.getNamespaceURI();
                    String nodeName1 = elem.getLocalName();
                    if (ns1.equals(BPMN2_NS) && nodeName1.equals("formalExpression")) {
                        String script = XMLUtil.getContentText(elem);
                        FormalExpression formalExpression = new FormalExpressionImpl(definitions);
                        formalExpression.setBody(script);
                        resourceAssignmentExpression.setExpression(formalExpression);
                        resourceRole.setResourceAssignmentExpression(resourceAssignmentExpression);
                    }
                }
            }
        }
    });
}

From source file:org.xsystem.bpmn2.formats.xml.XMLParser3.java

void parseOperation(Operation operation, List<Element> childs) {
    for (Element child : childs) {
        String ns = child.getNamespaceURI();
        String nodeName = child.getLocalName();
        //getNodeName();
        if (ns.equals(BPMN2_NS)) {
            switch (nodeName) {
            case "inMessageRef": {
                Reference ref = createReference(child);
                operation.setInMessageRef(ref);
                break;
            }//ww  w.j a  va2s.c  o  m
            case "outMessageRef": {
                Reference ref = createReference(child);
                operation.setOutMessageRef(ref);
                break;
            }
            }
        }
    }
}