Example usage for org.w3c.dom Document createElementNS

List of usage examples for org.w3c.dom Document createElementNS

Introduction

In this page you can find the example usage for org.w3c.dom Document createElementNS.

Prototype

public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException;

Source Link

Document

Creates an element of the given qualified name and namespace URI.

Usage

From source file:org.apache.ode.bpel.rtrep.v2.ASSIGN.java

private Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) {
    Document doc = ptr.getOwnerDocument();
    Node parent = ptr.getParentNode();
    if (keepSrcElement) {
        Element replacement = (Element) doc.importNode(src, true);
        parent.replaceChild(replacement, ptr);
        return (lval == ptr) ? replacement : lval;
    }//from   w  w  w  .j a  va  2s  .c o  m

    Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getLocalName());
    if (ptr.getPrefix() != null) {
        replacement.setPrefix(ptr.getPrefix());
    }
    NodeList nl = src.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i)
        replacement.appendChild(doc.importNode(nl.item(i), true));
    NamedNodeMap attrs = src.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Attr attr = (Attr) attrs.item(i);
        if (!attr.getName().startsWith("xmlns")) {
            replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true));
            // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually
            int colonIdx = attr.getValue().indexOf(":");
            if (colonIdx > 0) {
                String prefix = attr.getValue().substring(0, colonIdx);
                String attrValNs = src.lookupPrefix(prefix);
                if (attrValNs != null)
                    replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs);
            }
        }
    }
    parent.replaceChild(replacement, ptr);
    DOMUtils.copyNSContext(ptr, replacement);

    return (lval == ptr) ? replacement : lval;
}

From source file:org.apache.ode.bpel.rtrep.v2.AssignHelper.java

/**
 * Assumes that variable is variable not kind of partner links. 
 * // w  w  w .jav  a 2 s . com
 * @param var
 * @return
 * @throws FaultException
 * @throws ExternalVariableModuleException
 * @author madars.vitolins _at gmail.com
 */
public Node evalLValue(Variable var) throws FaultException, ExternalVariableModuleException {
    final OdeInternalInstance napi = getBpelRuntime();
    Node lval = null;
    VariableInstance lvar = _scopeFrame.resolve(var);
    if (!napi.isVariableInitialized(lvar)) {
        Document doc = DOMUtils.newDocument();
        Node val = var.type.newInstance(doc);
        if (val.getNodeType() == Node.TEXT_NODE) {
            Element tempwrapper = doc.createElementNS(null, "temporary-simple-type-wrapper");
            doc.appendChild(tempwrapper);
            tempwrapper.appendChild(val);
            val = tempwrapper;
        } else
            doc.appendChild(val);
        // Only external variables need to be initialized, others are new
        // and going to be overwritten
        if (lvar.declaration.extVar != null)
            lval = initializeVariable(lvar, val);
        else
            lval = val;
    } else
        lval = fetchVariableData(lvar, true);
    return lval;
}

From source file:org.apache.ode.bpel.rtrep.v2.AssignHelper.java

/**
 * madars.vitolins _at gmail.com - 2009.04.17 - Moved from ASSIGN here
 * @param to/*from  w w  w.  j  a  va2 s  . c o  m*/
 * @return
 * @throws FaultException
 * @throws ExternalVariableModuleException
 */
public Node evalLValue(OAssign.LValue to) throws FaultException, ExternalVariableModuleException {
    final OdeInternalInstance napi = getBpelRuntime();
    Node lval = null;
    if (!(to instanceof OAssign.PartnerLinkRef) && !(to instanceof OAssign.ContextRef)) {
        VariableInstance lvar;
        try {
            lvar = _scopeFrame.resolve(to.getVariable());
        } catch (RuntimeException e) {
            __log.error("iid: " + napi.getInstanceId() + " error evaluating lvalue");
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, e.getMessage());
        }
        if (!napi.isVariableInitialized(lvar)) {
            Document doc = DOMUtils.newDocument();
            Node val = to.getVariable().type.newInstance(doc);
            if (val.getNodeType() == Node.TEXT_NODE) {
                Element tempwrapper = doc.createElementNS(null, "temporary-simple-type-wrapper");
                doc.appendChild(tempwrapper);
                tempwrapper.appendChild(val);
                val = tempwrapper;
            } else
                doc.appendChild(val);
            // Only external variables need to be initialized, others are new and going to be overwritten
            if (lvar.declaration.extVar != null)
                lval = initializeVariable(lvar, val);
            else
                lval = val;
        } else
            lval = fetchVariableData(lvar, true);
    }
    return lval;
}

From source file:org.apache.ode.bpel.rtrep.v2.AssignHelper.java

/**
 * madars.vitolins _at gmail.com - 2009.04.17 - moved from ASSIGN here
 *///from  w ww . j ava 2  s . c o  m
public Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) {
    Document doc = ptr.getOwnerDocument();
    Node parent = ptr.getParentNode();
    if (keepSrcElement) {
        Element replacement = (Element) doc.importNode(src, true);
        parent.replaceChild(replacement, ptr);
        return (lval == ptr) ? replacement : lval;
    }

    Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getLocalName());
    NodeList nl = src.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i)
        replacement.appendChild(doc.importNode(nl.item(i), true));
    NamedNodeMap attrs = src.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Attr attr = (Attr) attrs.item(i);
        if (!attr.getName().startsWith("xmlns")) {
            replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true));
            // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually
            int colonIdx = attr.getValue().indexOf(":");
            if (colonIdx > 0) {
                String prefix = attr.getValue().substring(0, colonIdx);
                String attrValNs = src.lookupPrefix(prefix);
                if (attrValNs != null)
                    replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs);
            }
        }
    }
    parent.replaceChild(replacement, ptr);
    DOMUtils.copyNSContext(ptr, replacement);

    return (lval == ptr) ? replacement : lval;
}

From source file:org.apache.ode.bpel.runtime.ASSIGN.java

private Node evalLValue(OAssign.LValue to) throws FaultException, ExternalVariableModuleException {
    final BpelRuntimeContext napi = getBpelRuntimeContext();
    Node lval = null;/*w w w .j a  va2s .  c  o  m*/
    if (!(to instanceof OAssign.PartnerLinkRef)) {
        VariableInstance lvar;
        try {
            lvar = _scopeFrame.resolve(to.getVariable());
        } catch (RuntimeException e) {
            __log.error("iid: " + getBpelRuntimeContext().getPid() + " error evaluating lvalue");
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, e.getMessage());
        }
        if (lvar == null) {
            String msg = __msgs.msgEvalException(to.toString(), "Could not resolve variable in current scope");
            if (__log.isDebugEnabled())
                __log.debug(to + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
        }
        if (!napi.isVariableInitialized(lvar)) {
            Document doc = DOMUtils.newDocument();
            Node val = to.getVariable().type.newInstance(doc);
            if (val.getNodeType() == Node.TEXT_NODE) {
                Element tempwrapper = doc.createElementNS(null, "temporary-simple-type-wrapper");
                doc.appendChild(tempwrapper);
                tempwrapper.appendChild(val);
                val = tempwrapper;
            } else
                doc.appendChild(val);
            // Only external variables need to be initialized, others are new and going to be overwtitten
            if (lvar.declaration.extVar != null)
                lval = initializeVariable(lvar, val);
            else
                lval = val;
        } else
            lval = fetchVariableData(lvar, true);
    }
    return lval;
}

From source file:org.apache.ode.bpel.runtime.ASSIGN.java

private void replaceEndpointRefence(PartnerLinkInstance plval, Node rvalue) throws FaultException {
    if (rvalue.getNodeType() == Node.ATTRIBUTE_NODE) {
        rvalue = rvalue.getOwnerDocument().createTextNode(((Attr) rvalue).getValue());
    }//  w  w  w . j  ava 2s .c  o  m
    // Eventually wrapping with service-ref element if we've been directly assigned some
    // value that isn't wrapped.
    if (rvalue.getNodeType() == Node.TEXT_NODE
            || (rvalue.getNodeType() == Node.ELEMENT_NODE && !rvalue.getLocalName().equals("service-ref"))) {
        Document doc = DOMUtils.newDocument();
        Element serviceRef = doc.createElementNS(Namespaces.WSBPEL2_0_FINAL_SERVREF, "service-ref");
        doc.appendChild(serviceRef);
        serviceRef.appendChild(doc.importNode(rvalue, true));
        rvalue = serviceRef;
    }

    getBpelRuntimeContext().writeEndpointReference(plval, (Element) rvalue);
}

From source file:org.apache.ode.bpel.runtime.ASSIGN.java

private Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) {
    Document doc = ptr.getOwnerDocument();
    Node parent = ptr.getParentNode();
    if (keepSrcElement) {
        Element replacement = (Element) doc.importNode(src, true);
        parent.replaceChild(replacement, ptr);
        return (lval == ptr) ? replacement : lval;
    }/*  w w  w . j  a  va2  s  .c om*/

    Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getTagName());
    NodeList nl = src.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i)
        replacement.appendChild(doc.importNode(nl.item(i), true));
    copyAttributes(doc, ptr, replacement);
    copyAttributes(doc, src, replacement);
    parent.replaceChild(replacement, ptr);
    DOMUtils.copyNSContext(ptr, replacement);

    return (lval == ptr) ? replacement : lval;
}

From source file:org.apache.ode.bpel.runtime.AssignHelper.java

/**
 * Assumes that variable is variable not kind of partner links. 
 * //from ww  w.j av  a2s.com
 * @param var
 * @return
 * @throws FaultException
 * @throws ExternalVariableModuleException
 * @author madars.vitolins _at gmail.com
 */
public Node evalLValue(Variable var) throws FaultException, ExternalVariableModuleException {
    final BpelRuntimeContext napi = getBpelRuntimeContext();
    Node lval = null;
    VariableInstance lvar = _scopeFrame.resolve(var);
    if (!napi.isVariableInitialized(lvar)) {
        Document doc = DOMUtils.newDocument();
        Node val = var.type.newInstance(doc);
        if (val.getNodeType() == Node.TEXT_NODE) {
            Element tempwrapper = doc.createElementNS(null, "temporary-simple-type-wrapper");
            doc.appendChild(tempwrapper);
            tempwrapper.appendChild(val);
            val = tempwrapper;
        } else
            doc.appendChild(val);
        // Only external variables need to be initialized, others are new
        // and going to be overwritten
        if (lvar.declaration.extVar != null)
            lval = initializeVariable(lvar, val);
        else
            lval = val;
    } else
        lval = fetchVariableData(lvar, true);
    return lval;
}

From source file:org.apache.ode.bpel.runtime.AssignHelper.java

private Node evalLValue(OAssign.LValue to) throws FaultException, ExternalVariableModuleException {
    final BpelRuntimeContext napi = getBpelRuntimeContext();
    Node lval = null;/*  w  w w .  j a  va 2  s .  co m*/
    if (!(to instanceof OAssign.PartnerLinkRef)) {
        VariableInstance lvar;
        try {
            lvar = _scopeFrame.resolve(to.getVariable());
        } catch (RuntimeException e) {
            __log.error("iid: " + getBpelRuntimeContext().getPid() + " error evaluating lvalue");
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, e.getMessage());
        }
        if (lvar == null) {
            String msg = __msgs.msgEvalException(to.toString(), "Could not resolve variable in current scope");
            if (__log.isDebugEnabled())
                __log.debug(to + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
        }
        if (!napi.isVariableInitialized(lvar)) {
            Document doc = DOMUtils.newDocument();
            Node val = to.getVariable().type.newInstance(doc);
            if (val.getNodeType() == Node.TEXT_NODE) {
                Element tempwrapper = doc.createElementNS(null, "temporary-simple-type-wrapper");
                doc.appendChild(tempwrapper);
                tempwrapper.appendChild(val);
                val = tempwrapper;
            } else
                doc.appendChild(val);
            // Only external variables need to be initialized, others are new and going to be overwtitten
            if (lvar.declaration.extVar != null)
                lval = initializeVariable(lvar, val);
            else
                lval = val;
        } else
            lval = fetchVariableData(lvar, true);
    }
    return lval;
}

From source file:org.apache.ode.bpel.runtime.AssignHelper.java

private Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) {
    Document doc = ptr.getOwnerDocument();
    Node parent = ptr.getParentNode();
    if (keepSrcElement) {
        Element replacement = (Element) doc.importNode(src, true);
        parent.replaceChild(replacement, ptr);
        return (lval == ptr) ? replacement : lval;
    }/*w w w .j a v a 2 s  .  c  o  m*/

    Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getTagName());
    NodeList nl = src.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i)
        replacement.appendChild(doc.importNode(nl.item(i), true));
    NamedNodeMap attrs = src.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Attr attr = (Attr) attrs.item(i);
        if (!attr.getName().startsWith("xmlns")) {
            replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true));
            // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually
            int colonIdx = attr.getValue().indexOf(":");
            if (colonIdx > 0) {
                String prefix = attr.getValue().substring(0, colonIdx);
                String attrValNs = src.lookupPrefix(prefix);
                if (attrValNs != null)
                    replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs);
            }
        }
    }
    parent.replaceChild(replacement, ptr);
    DOMUtils.copyNSContext(ptr, replacement);

    return (lval == ptr) ? replacement : lval;
}