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.engine.ODEProcess.java

/**
 * Entry point for message exchanges aimed at the my role.
 *
 * @param mexdao Message Exchange DAO./*from w  w w .  j  a  v a  2 s  .c  o  m*/
 */
void invokeProcess(final MessageExchangeDAO mexdao) {
    InvocationStyle istyle = mexdao.getInvocationStyle();
    ConstantsModel constants = null;

    _hydrationLatch.latch(1);
    try {
        // The following check is mostly for sanity purposes. MexImpls should prevent this from
        // happening.
        PartnerLinkMyRoleImpl target = getMyRoleForService(mexdao.getCallee());
        constants = target._process.getProcessModel().getConstantsModel();
        Status oldstatus = mexdao.getStatus();
        if (target == null) {
            String errmsg = __msgs.msgMyRoleRoutingFailure(mexdao.getMessageExchangeId());
            __log.error(errmsg);
            MexDaoUtil.setFailed(mexdao, MessageExchange.FailureType.UNKNOWN_ENDPOINT, errmsg);
            onMyRoleMexAck(mexdao, oldstatus);
            return;
        }

        Operation op = target._plinkDef.getMyRoleOperation(mexdao.getOperation());
        if (op == null) {
            String errmsg = __msgs.msgMyRoleRoutingFailure(mexdao.getMessageExchangeId());
            __log.error(errmsg);
            MexDaoUtil.setFailed(mexdao, MessageExchange.FailureType.UNKNOWN_OPERATION, errmsg);
            onMyRoleMexAck(mexdao, oldstatus);
            return;
        }

        mexdao.setPattern((op.getOutput() == null) ? MessageExchangePattern.REQUEST_ONLY
                : MessageExchangePattern.REQUEST_RESPONSE);
        if (!processInterceptors(mexdao, InterceptorInvoker.__onProcessInvoked)) {
            __log.debug(
                    "Aborting processing of mex " + mexdao.getMessageExchangeId() + " due to interceptors.");
            onMyRoleMexAck(mexdao, oldstatus);
            return;
        }

        // "Acknowledge" any one-way invokes
        if (op.getOutput() == null) {
            if (__log.isDebugEnabled()) {
                __log.debug("Acknowledge one-way invokes....");
            }
            mexdao.setStatus(Status.ACK);
            mexdao.setAckType(AckType.ONEWAY);
            onMyRoleMexAck(mexdao, oldstatus);
        }

        mexdao.setProcess(getProcessDAO());

        markused();
        CorrelationStatus cstatus = target.invokeMyRole(mexdao);
        if (cstatus == null) {
            ; // do nothing
        } else if (cstatus == CorrelationStatus.CREATE_INSTANCE) {
            doInstanceWork(mexdao.getInstance().getInstanceId(), new Callable<Void>() {
                public Void call() {
                    executeCreateInstance(mexdao);
                    return null;
                }
            });

        } else if (cstatus == CorrelationStatus.MATCHED) {
            // This should not occur for in-memory processes, since they are technically not allowed to
            // have any <receive>/<pick> elements that are not start activities.
            if (isInMemory())
                __log.warn("In-memory process " + _pid + " is participating in a non-createinstance exchange!");

            // We don't like to do the work in the same TX that did the matching, since this creates fertile
            // conditions for deadlock in the correlation tables. However if invocation style is transacted,
            // we need to do the work right then and there.
            if (mexdao.getInstance().getState() == ProcessState.STATE_TERMINATED) {
                throw new InvalidInstanceException("Trying to invoke terminated process instance",
                        InvalidInstanceException.TERMINATED_CAUSE_CODE);
            }

            if (op.getOutput() != null) {
                // If the invoked operation is request-response type it's not good to store the request in
                // database until suspended instance is resumed. It's good to throw and exception in this case.
                // Then the client will know that this process is suspended.
                if (mexdao.getInstance().getState() == ProcessState.STATE_SUSPENDED) {
                    throw new InvalidInstanceException("Trying to invoke suspended instance",
                            InvalidInstanceException.SUSPENDED_CAUSE_CODE);
                }
            }

            if (istyle == InvocationStyle.TRANSACTED) {
                doInstanceWork(mexdao.getInstance().getInstanceId(), new Callable<Void>() {
                    public Void call() {
                        executeContinueInstanceMyRoleRequestReceived(mexdao);
                        return null;
                    }
                });
            } else if (istyle == InvocationStyle.P2P_TRANSACTED) /* transact p2p invoke in the same thread */ {
                executeContinueInstanceMyRoleRequestReceived(mexdao);
            } else /* non-transacted style */ {
                WorkEvent we = new WorkEvent();
                we.setType(WorkEvent.Type.MYROLE_INVOKE);
                we.setIID(mexdao.getInstance().getInstanceId());
                we.setMexId(mexdao.getMessageExchangeId());
                // Could be different to this pid when routing to an older version
                we.setProcessId(mexdao.getInstance().getProcess().getProcessId());

                scheduleWorkEvent(we, null);
            }
        } else if (cstatus == CorrelationStatus.QUEUED) {
            ; // do nothing
        }
    } catch (InvalidProcessException ipe) {
        QName faultQName = null;
        if (constants != null) {
            Document document = DOMUtils.newDocument();
            Element faultElement = document.createElementNS(Namespaces.SOAP_ENV_NS, "Fault");
            Element faultDetail = document.createElementNS(Namespaces.ODE_EXTENSION_NS, "fault");
            faultElement.appendChild(faultDetail);
            switch (ipe.getCauseCode()) {
            case InvalidProcessException.DUPLICATE_CAUSE_CODE:
                faultQName = constants.getDuplicateInstance();
                faultDetail.setTextContent("Found a duplicate instance with the same message key");
                break;
            case InvalidProcessException.RETIRED_CAUSE_CODE:
                faultQName = constants.getRetiredProcess();
                faultDetail.setTextContent("The process you're trying to instantiate has been retired");
                break;
            case InvalidProcessException.DEFAULT_CAUSE_CODE:
            default:
                faultQName = constants.getUnknownFault();
                break;
            }
            MexDaoUtil.setFaulted(mexdao, faultQName, faultElement);
        }
    } catch (InvalidInstanceException iie) {
        QName faultQname = null;
        if (constants != null) {
            Document document = DOMUtils.newDocument();
            Element faultElement = document.createElementNS(Namespaces.SOAP_ENV_NS, "Fault");
            Element faultDetail = document.createElementNS(Namespaces.ODE_EXTENSION_NS, "fault");
            faultElement.appendChild(faultDetail);
            switch (iie.getCauseCode()) {
            case InvalidInstanceException.TERMINATED_CAUSE_CODE:
                faultQname = new QName("ode", "TerminatedInstance");
                faultDetail.setTextContent(iie.getMessage());
                break;
            case InvalidInstanceException.SUSPENDED_CAUSE_CODE:
                faultQname = new QName("ode", "SuspendedInstance");
                faultDetail.setTextContent(iie.getMessage());
                break;
            default:
                faultQname = constants.getUnknownFault();
                break;
            }
            MexDaoUtil.setFaulted(mexdao, faultQname, faultElement);
        }
    } catch (BpelEngineException bee) {
        QName faultQname = null;
        Document document = DOMUtils.newDocument();
        Element faultElement = document.createElementNS(Namespaces.SOAP_ENV_NS, "Fault");
        Element faultDetail = document.createElementNS(Namespaces.ODE_EXTENSION_NS, "fault");
        faultElement.appendChild(faultDetail);
        faultQname = new QName("ode", "BpelEngineException");
        faultDetail.setTextContent(bee.getMessage());

        MexDaoUtil.setFaulted(mexdao, faultQname, faultElement);
    } finally {
        _hydrationLatch.release(1);

        // If we did not get an ACK during this method, then mark this MEX as needing an ASYNC wake-up
        if (mexdao.getStatus() != Status.ACK)
            mexdao.setStatus(Status.ASYNC);

        assert mexdao.getStatus() == Status.ACK || mexdao.getStatus() == Status.ASYNC;
    }

}

From source file:org.apache.ode.bpel.epr.WSAEndpoint.java

public Document toXML() {
    // Wrapping/*from   w  w w .  j ava  2  s  .  c  o m*/
    Document doc = DOMUtils.newDocument();
    Element serviceRef = doc.createElementNS(SERVICE_REF_QNAME.getNamespaceURI(),
            SERVICE_REF_QNAME.getLocalPart());
    doc.appendChild(serviceRef);
    serviceRef.appendChild(doc.importNode(_eprElmt, true));
    return doc;
}

From source file:org.apache.ode.bpel.epr.WSAEndpoint.java

public void fromMap(Map eprMap) {
    Document doc = DOMUtils.newDocument();
    Element serviceRef = doc.createElementNS(SERVICE_REF_QNAME.getNamespaceURI(),
            SERVICE_REF_QNAME.getLocalPart());
    doc.appendChild(serviceRef);/*from w w w.  j a  v  a2s.  com*/
    _eprElmt = doc.createElementNS(Namespaces.WS_ADDRESSING_NS, "EndpointReference");
    serviceRef.appendChild(_eprElmt);
    Element addrElmt = doc.createElementNS(Namespaces.WS_ADDRESSING_NS, "Address");
    addrElmt.setTextContent((String) eprMap.get(ADDRESS));
    if (eprMap.get(SESSION) != null) {
        Element sessElmt = doc.createElementNS(Namespaces.ODE_SESSION_NS, "session");
        sessElmt.setTextContent((String) eprMap.get(SESSION));
        _eprElmt.appendChild(sessElmt);
        // and the same for the (deprecated) intalio namespace for backward compatibility
        sessElmt = doc.createElementNS(Namespaces.INTALIO_SESSION_NS, "session");
        sessElmt.setTextContent((String) eprMap.get(SESSION));
        _eprElmt.appendChild(sessElmt);
    }
    if (eprMap.get(SERVICE_QNAME) != null) {
        Element metadataElmt = doc.createElementNS(Namespaces.WS_ADDRESSING_NS, "Metadata");
        _eprElmt.appendChild(metadataElmt);
        Element serviceElmt = doc.createElementNS(Namespaces.WS_ADDRESSING_WSDL_NS, "ServiceName");
        metadataElmt.appendChild(serviceElmt);
        QName serviceQName = (QName) eprMap.get(SERVICE_QNAME);
        serviceElmt.setAttribute("xmlns:servicens", serviceQName.getNamespaceURI());
        serviceElmt.setTextContent("servicens:" + serviceQName.getLocalPart());
        serviceElmt.setAttribute("EndpointName", (String) eprMap.get(PORT_NAME));
    }
    _eprElmt.appendChild(addrElmt);
    if (__log.isDebugEnabled())
        __log.debug("Constructed a new WSAEndpoint: " + DOMUtils.domToString(_eprElmt));
}

From source file:org.apache.ode.bpel.extvar.jdbc.DbExternalVariable.java

<T extends RowSubset> Element renderXmlRow(Locator locator, QName varType, T value)
        throws ExternalVariableModuleException {
    Document doc = DOMUtils.newDocument();
    Element el = doc.createElementNS(varType.getNamespaceURI(), varType.getLocalPart());
    doc.appendChild(el);/*  w w w. j av  a 2  s . c o m*/
    if (value != null) {
        for (Column c : value._columns) {
            Object data = value.get(c.idx);
            addElement(el, varType, c, data);
        }
    } else {
        // initialize variable with default/generated values
        RowKey keys = keyFromLocator(locator);
        for (Column c : _columns) {
            Object data = c.getValue(c.name, keys, new RowVal(), locator.iid);
            addElement(el, varType, c, data);
        }
    }
    return el;
}

From source file:org.apache.ode.bpel.extvar.jdbc.DbExternalVariable.java

private void addElement(Element parent, QName varType, Column c, Object data) {
    Document doc = parent.getOwnerDocument();
    Element cel = doc.createElementNS(varType.getNamespaceURI(), c.name);
    String strdat = c.toText(data);
    if (strdat != null) {
        cel.appendChild(doc.createTextNode(strdat));
    } else if (c.nullok || c.isGenerated()) {
        cel.setAttributeNS(XSI_NS, "xsi:nil", "true");
    }//from  ww w. j a  va  2 s . c o  m
    parent.appendChild(cel);
}

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

private Node evalLValue(OAssign.LValue to) throws FaultException, ExternalVariableModuleException {
    final OdeInternalInstance napi = getBpelRuntime();
    Node lval = null;/* w w  w.j  a v  a 2 s. c  om*/
    if (!(to instanceof OAssign.PartnerLinkRef)) {
        VariableInstance lvar = _scopeFrame.resolve(to.getVariable());
        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.rtrep.v1.ASSIGN.java

private void replaceEndpointRefence(PartnerLinkInstance plval, Node rvalue) throws FaultException {
    // 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);/*  ww  w  .  j  a v a 2  s. co  m*/
        if (rvalue.getNodeType() == Node.TEXT_NODE) {
            serviceRef.appendChild(doc.importNode(rvalue, true));
        } else {
            NodeList children = rvalue.getChildNodes();
            for (int m = 0; m < children.getLength(); m++) {
                Node child = children.item(m);
                serviceRef.appendChild(doc.importNode(child, true));
            }
        }
        rvalue = serviceRef;
    }

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

From source file:org.apache.ode.bpel.rtrep.v1.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 av  a 2 s  .  c o m

    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.rtrep.v2.ASSIGN.java

private Node evalLValue(OAssign.LValue to) throws FaultException, ExternalVariableModuleException {
    final OdeInternalInstance napi = getBpelRuntime();
    Node lval = null;//w w  w.  j av a  2  s  .  c o  m
    if (!(to instanceof OAssign.PartnerLinkRef)) {
        VariableInstance lvar = _scopeFrame.resolve(to.getVariable());
        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.ASSIGN.java

private void replaceEndpointRefence(PartnerLinkInstance plval, Node rvalue) throws FaultException {
    if (rvalue.getNodeType() == Node.ATTRIBUTE_NODE)
        throw new FaultException(getOAsssign().getOwner().constants.qnMismatchedAssignmentFailure,
                "Can't assign an attribute to an endpoint, you probably want to select the attribute text.");

    // 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);/*from   w  w w  .j ava  2 s. com*/
        NodeList children = rvalue.getChildNodes();
        for (int m = 0; m < children.getLength(); m++) {
            Node child = children.item(m);
            serviceRef.appendChild(doc.importNode(child, true));
        }
        rvalue = serviceRef;
    }

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