Example usage for org.w3c.dom Document importNode

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

Introduction

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

Prototype

public Node importNode(Node importedNode, boolean deep) throws DOMException;

Source Link

Document

Imports a node from another document to this document, without altering or removing the source node from the original document; this method creates a new copy of the source node.

Usage

From source file:org.apache.ode.bpel.engine.BpelRuntimeContextImpl.java

protected void buildOutgoingMessage(MessageDAO message, Element outgoingElmt) {
    if (outgoingElmt == null)
        return;/*from  w  w w. j a v  a 2s . com*/

    Document doc = DOMUtils.newDocument();
    Element header = doc.createElement("header");
    NodeList parts = outgoingElmt.getChildNodes();
    for (int m = 0; m < parts.getLength(); m++) {
        if (parts.item(m).getNodeType() == Node.ELEMENT_NODE) {
            Element part = (Element) parts.item(m);
            if (part.getAttribute("headerPart") != null && part.getAttribute("headerPart").length() > 0) {
                header.appendChild(doc.importNode(part, true));
                // remove the element from the list AND decrement the index to avoid skipping the next element!!
                outgoingElmt.removeChild(part);
                m--;
            }
        }
    }
    message.setData(outgoingElmt);
    message.setHeader(header);
}

From source file:org.apache.ode.bpel.engine.ProcessAndInstanceManagementImpl.java

/**
 * Fill in the <code>process-info</code> element of the transfer object.
 *
 * @param info/*w  w w  .ja v  a  2s.  c o  m*/
 *            destination XMLBean
 * @param pconf
 *            process configuration object (from store)
 * @param proc
 *            source DAO object
 * @param custom
 *            used to customize the quantity of information produced in the
 *            info
 */
private void fillProcessInfo(TProcessInfo info, ProcessConf pconf, ProcessInfoCustomizer custom) {
    if (pconf == null)
        throw new IllegalArgumentException("Null pconf.");

    if (__log.isDebugEnabled())
        __log.debug("Filling process info for " + pconf.getProcessId());

    info.setPid(pconf.getProcessId().toString());
    // TODO: ACTIVE and RETIRED should be used separately.
    // Active process may be retired at the same time
    if (pconf.getState() == ProcessState.RETIRED) {
        info.setStatus(TProcessStatus.RETIRED);
    } else if (pconf.getState() == ProcessState.DISABLED) {
        info.setStatus(TProcessStatus.DISABLED);
    } else {
        info.setStatus(TProcessStatus.ACTIVE);
    }
    info.setVersion(pconf.getVersion());

    TDefinitionInfo definfo = info.addNewDefinitionInfo();
    definfo.setProcessName(pconf.getType());

    TDeploymentInfo depinfo = info.addNewDeploymentInfo();
    depinfo.setPackage(pconf.getPackage());
    if (__log.isDebugEnabled())
        __log.debug(" package name: " + depinfo.getPackage());
    depinfo.setDocument(pconf.getBpelDocument());
    depinfo.setDeployDate(toCalendar(pconf.getDeployDate()));
    depinfo.setDeployer(pconf.getDeployer());

    if (custom.includeDocumentLists()) {
        TProcessInfo.Documents docinfo = info.addNewDocuments();
        List<File> files = pconf.getFiles();
        if (files != null)
            genDocumentInfo(docinfo, files.toArray(new File[files.size()]), true);
        else if (__log.isDebugEnabled())
            __log.debug("fillProcessInfo: No files for " + pconf.getProcessId());
    }

    TProcessProperties properties = info.addNewProperties();
    if (custom.includeProcessProperties()) {
        for (Map.Entry<QName, Node> propEntry : pconf.getProcessProperties().entrySet()) {
            TProcessProperties.Property tprocProp = properties.addNewProperty();
            tprocProp.setName(
                    new QName(propEntry.getKey().getNamespaceURI(), propEntry.getKey().getLocalPart()));
            Node propNode = tprocProp.getDomNode();
            Document processInfoDoc = propNode.getOwnerDocument();
            Node node2append = processInfoDoc.importNode(propEntry.getValue(), true);
            propNode.appendChild(node2append);
        }
    }

    TEndpointReferences eprs = info.addNewEndpoints();
    OProcess oprocess = _server._engine.getOProcess(pconf.getProcessId());
    if (custom.includeEndpoints() && oprocess != null) {
        for (OPartnerLink oplink : oprocess.getAllPartnerLinks()) {
            if (oplink.hasPartnerRole() && oplink.initializePartnerRole) {
                // TODO: this is very uncool.
                EndpointReference pepr = _server._engine._activeProcesses.get(pconf.getProcessId())
                        .getInitialPartnerRoleEPR(oplink);

                if (pepr != null) {
                    TEndpointReferences.EndpointRef epr = eprs.addNewEndpointRef();
                    Document eprNodeDoc = epr.getDomNode().getOwnerDocument();
                    epr.getDomNode()
                            .appendChild(eprNodeDoc.importNode(pepr.toXML().getDocumentElement(), true));
                }
            }
        }
    }

    // TODO: add documents to the above data structure.
}

From source file:org.apache.ode.bpel.engine.ProcessAndInstanceManagementImpl.java

private void fillScopeInfo(TScopeInfo scopeInfo, ScopeDAO scope, boolean includeActivityInfo) {
    scopeInfo.setSiid("" + scope.getScopeInstanceId());
    scopeInfo.setName(scope.getName());/*w  w  w .j av a 2s  .co  m*/
    if (scope.getParentScope() != null)
        scopeInfo.setParentScopeRef(genScopeRef(scope.getParentScope()));

    scopeInfo.setStatus(__psc.cvtScopeStatus(scope.getState()));

    TScopeInfo.Children children = scopeInfo.addNewChildren();
    for (ScopeDAO i : scope.getChildScopes())
        fillScopeRef(children.addNewChildRef(), i);

    TScopeInfo.Variables vars = scopeInfo.addNewVariables();
    for (XmlDataDAO i : scope.getVariables())
        fillVariableRef(vars.addNewVariableRef(), i);

    // Setting correlations and their valued properties
    if (!scope.getCorrelationSets().isEmpty()) {
        TScopeInfo.CorrelationSets correlationSets = scopeInfo.addNewCorrelationSets();
        for (CorrelationSetDAO correlationSetDAO : scope.getCorrelationSets()) {
            TScopeInfo.CorrelationSets.CorrelationSet correlationSet = correlationSets.addNewCorrelationSet();
            correlationSet.setCsetid("" + correlationSetDAO.getCorrelationSetId());
            correlationSet.setName(correlationSetDAO.getName());
            for (Map.Entry<QName, String> property : correlationSetDAO.getProperties().entrySet()) {
                TCorrelationProperty tproperty = correlationSet.addNewCorrelationProperty();
                tproperty.setCsetid("" + correlationSetDAO.getCorrelationSetId());
                tproperty.setPropertyName(property.getKey());
                tproperty.setStringValue(property.getValue());
            }
        }

    }

    if (includeActivityInfo) {
        Collection<ActivityRecoveryDAO> recoveries = scope.getProcessInstance().getActivityRecoveries();

        TScopeInfo.Activities activities = scopeInfo.addNewActivities();
        List<BpelEvent> events = scope.listEvents();

        // if event generation was enabled
        if (events != null && events.size() > 0) {
            ActivityStateDocumentBuilder b = new ActivityStateDocumentBuilder();
            for (BpelEvent e : events)
                b.onEvent(e);
            for (ActivityInfoDocument ai : b.getActivities()) {
                for (ActivityRecoveryDAO recovery : recoveries) {
                    if (String.valueOf(recovery.getActivityId()).equals(ai.getActivityInfo().getAiid())) {
                        TFailureInfo failure = ai.getActivityInfo().addNewFailure();
                        failure.setReason(recovery.getReason());
                        failure.setDtFailure(toCalendar(recovery.getDateTime()));
                        failure.setActions(recovery.getActions());
                        failure.setRetries(recovery.getRetries());
                        ai.getActivityInfo().setStatus(TActivityStatus.FAILURE);
                    }
                }
                activities.addNewActivityInfo().set(ai.getActivityInfo());
            }
        }

        // otherwise at least try to get the information about failed activities
        // TODO: we are losing information about which scope does failed activities belong to
        // as failure table does not have scope id, we would attach every failed activity to process scope
        else {
            if (scope.getParentScope() == null) {
                for (ActivityRecoveryDAO recovery : recoveries) {
                    ActivityInfoDocument ai = ActivityInfoDocument.Factory.newInstance();
                    ai.addNewActivityInfo().setAiid(String.valueOf(recovery.getActivityId()));
                    ai.getActivityInfo().setType("OActivity");
                    ai.getActivityInfo().setScope(TScopeRef.Factory.newInstance());
                    TFailureInfo failure = ai.getActivityInfo().addNewFailure();
                    failure.setReason(recovery.getReason());
                    failure.setDtFailure(toCalendar(recovery.getDateTime()));
                    failure.setActions(recovery.getActions());
                    failure.setRetries(recovery.getRetries());
                    ai.getActivityInfo().setStatus(TActivityStatus.FAILURE);
                    activities.addNewActivityInfo().set(ai.getActivityInfo());
                }
            }
        }
    }

    Collection<PartnerLinkDAO> plinks = scope.getPartnerLinks();
    if (plinks.size() > 0) {
        TEndpointReferences refs = scopeInfo.addNewEndpoints();
        for (PartnerLinkDAO plink : plinks) {
            if (plink.getPartnerRoleName() != null && plink.getPartnerRoleName().length() > 0) {
                TEndpointReferences.EndpointRef ref = refs.addNewEndpointRef();
                ref.setPartnerLink(plink.getPartnerLinkName());
                ref.setPartnerRole(plink.getPartnerRoleName());
                if (plink.getPartnerEPR() != null) {
                    Document eprNodeDoc = ref.getDomNode().getOwnerDocument();
                    ref.getDomNode().appendChild(eprNodeDoc.importNode(plink.getPartnerEPR(), true));
                }
            }
        }
    }
}

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

public Document toXML() {
    // Wrapping/*w w  w .j  a  va  2 s. c  om*/
    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.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);/*from w w  w .j  ava2 s. com*/
        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;
    }/*from ww  w. j a va 2s  . c  om*/

    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 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);// w w w .  j  a v  a 2s .  c  om
        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.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;
    }/*w  w  w  . jav  a2s  .  co 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

/**
 * madars.vitolins _at gmail.com - 2009.04.17 - moved from ASSIGN here
 *///from w w  w  .  ja va 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 void replaceEndpointRefence(PartnerLinkInstance plval, Node rvalue) throws FaultException {
    if (rvalue.getNodeType() == Node.ATTRIBUTE_NODE) {
        rvalue = rvalue.getOwnerDocument().createTextNode(((Attr) rvalue).getValue());
    }/*  ww w  . j  a v a  2  s.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);
}