Search in sources :

Example 76 with XmlElement

use of org.xmlpull.infoset.XmlElement in project airavata by apache.

the class XMLUtil method deepClone.

/**
 * @param element
 * @return The cloned XmlElement.
 */
public static org.xmlpull.infoset.XmlElement deepClone(org.xmlpull.infoset.XmlElement element) throws AiravataException {
    try {
        XmlElement clonedElement = element.clone();
        clonedElement.setParent(null);
        return clonedElement;
    } catch (CloneNotSupportedException e) {
        // This should not happen because we don't put any special Objects.
        throw new AiravataException(e.getMessage(), e);
    }
}
Also used : XmlElement(org.xmlpull.infoset.XmlElement) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 77 with XmlElement

use of org.xmlpull.infoset.XmlElement in project airavata by apache.

the class XMLUtil method isEqual.

public static boolean isEqual(XmlElement elem1, XmlElement elem2) throws Exception {
    if (elem1 == null && elem2 == null) {
        return true;
    } else if (elem1 == null) {
        return false;
    } else if (elem2 == null) {
        return false;
    }
    if (!elem1.getName().equals(elem2.getName())) {
        return false;
    } else {
        // now check if children are the same
        Iterator children1 = elem1.children().iterator();
        Iterator children2 = elem2.children().iterator();
        // check first ones for string
        Object child1 = null;
        Object child2 = null;
        if (children1.hasNext() && children2.hasNext()) {
            child1 = children1.next();
            child2 = children2.next();
            if (!children1.hasNext() && !children2.hasNext()) {
                // only one node could be string could be xmlelement
                return compareObjs(child1, child2);
            } else {
                // get new iterators
                List<XmlElement> elemSet1 = getXmlElementsOnly(elem1.children().iterator());
                List<XmlElement> elemSet2 = getXmlElementsOnly(elem2.children().iterator());
                if (elemSet1.size() != elemSet2.size()) {
                    return false;
                }
                for (int i = 0; i < elemSet1.size(); ++i) {
                    if (!isEqual(elemSet1.get(i), elemSet2.get(i))) {
                        return false;
                    }
                }
                return true;
            }
        } else {
            return true;
        }
    }
}
Also used : Iterator(java.util.Iterator) XmlElement(org.xmlpull.infoset.XmlElement) XmlObject(org.apache.xmlbeans.XmlObject)

Example 78 with XmlElement

use of org.xmlpull.infoset.XmlElement in project airavata by apache.

the class Workflow method toXML.

/**
 * Returns the XmlElement of the workflow.
 *
 * @return The XmlElement of the workflow
 */
public XmlElement toXML() {
    // This must be before graph.toXML() to set WSDL ID to each node.
    // FIXME
    // Map<String, WsdlDefinitions> wsdls = getWSDLs();
    XmlElement workflowElement = XMLUtil.BUILDER.newFragment(NS_XWF, WORKFLOW_TAG);
    // Version
    workflowElement.setAttributeValue(NS_XWF, VERSION_ATTRIBUTE, ApplicationVersion.VERSION.getVersion());
    // Date
    // TODO add modification time
    // XmlElement modifiedTimeElement = graphElement.addElement(
    // XgraphSchema.NS, "modifiedTime");
    // modifiedTimeElement.addChild(new GregorianCalendar().toString());
    // Graph
    workflowElement.addElement(this.graph.toXML());
    // WSDLs
    XmlElement wsdlsElement = workflowElement.addElement(NS_XWF, WSDLS_TAG);
    // Image
    if (this.image != null) {
        try {
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            ImageIO.write(this.image, WorkflowConstants.PNG_FORMAT_NAME, outStream);
            byte[] bytes = outStream.toByteArray();
            byte[] base64 = Base64.encodeBase64Chunked(bytes);
            XmlElement imageElement = workflowElement.addElement(NS_XWF, IMAGE_TAG);
            imageElement.setText(new String(base64));
        } catch (IOException e) {
            // No image
            logger.error(e.getMessage(), e);
        }
    }
    return workflowElement;
}
Also used : XmlElement(org.xmlpull.infoset.XmlElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 79 with XmlElement

use of org.xmlpull.infoset.XmlElement in project airavata by apache.

the class Workflow method parse.

/**
 * @param workflowElement
 * @throws GraphException
 * @throws ComponentException
 */
private void parse(XmlElement workflowElement) throws GraphException, ComponentException {
    // Graph
    XmlElement graphElement = workflowElement.element(GraphSchema.GRAPH_TAG);
    this.graph = WSGraphFactory.createGraph(graphElement);
    // WsdlDefinitions wsdl = null;
    // XmlElement wsdlsElement = workflowElement.element(WSDLS_TAG);
    // for (XmlElement wsdlElement : wsdlsElement.elements(null, WSDL_TAG)) {
    // String wsdlText = wsdlElement.requiredText();
    // try {
    // wsdl = WSDLUtil.stringToWSDL(wsdlText);
    // } catch (UtilsException e) {
    // logger.error(e.getMessage(), e);
    // }
    // String id = wsdlElement.attributeValue(NS_XWF, ID_ATTRIBUTE);
    // if (id == null || id.length() == 0) {
    // // xwf up to 2.2.6_2 doesn't have ID.
    // id = WSDLUtil.getWSDLQName(wsdl).toString();
    // }
    // addWSDL(id, wsdl);
    // }
    bindComponents();
    // Image
    XmlElement imageElement = workflowElement.element(IMAGE_TAG);
    if (imageElement != null) {
        String base64 = imageElement.requiredText();
        byte[] bytes = Base64.decodeBase64(base64.getBytes());
        try {
            this.image = ImageIO.read(new ByteArrayInputStream(bytes));
        } catch (IOException e) {
            // This should not happen and it's OK that image is broken. We
            // can reproduce it anytime.
            logger.error(e.getMessage(), e);
        }
    }
    XmlElement bpelElement = workflowElement.element(BPEL_TAG);
    if (bpelElement != null) {
        try {
            String bpelString = bpelElement.requiredText();
            XmlNamespace gpelNS = XmlInfosetBuilder.newInstance().newNamespace(BPELScript.GPEL, BPELScript.GPELNS);
        // GpelConstants.GPEL_NS = gpelNS;
        // this.gpelProcess = new GpelProcess(XMLUtil.stringToXmlElement(bpelString));
        } catch (RuntimeException e) {
            String error = "Failed to parse the BPEL document.";
            throw new GraphException(error, e);
        }
    }
    XmlElement workflowWSDLElement = workflowElement.element(WORKFLOW_WSDL_TAG);
    if (workflowWSDLElement != null) {
        try {
            String wsdlText = workflowWSDLElement.requiredText();
        // this.workflowWSDL = new WsdlDefinitions(XMLUtil.stringToXmlElement(wsdlText));
        } catch (RuntimeException e) {
            String error = "Failed to parse the workflow WSDL.";
            throw new GraphException(error, e);
        }
    }
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlNamespace(org.xmlpull.infoset.XmlNamespace) XmlElement(org.xmlpull.infoset.XmlElement) IOException(java.io.IOException)

Aggregations

XmlElement (org.xmlpull.infoset.XmlElement)79 AiravataException (org.apache.airavata.common.exception.AiravataException)5 GraphException (org.apache.airavata.workflow.model.graph.GraphException)5 IOException (java.io.IOException)4 Iterator (java.util.Iterator)4 DataType (org.apache.airavata.model.appcatalog.appinterface.DataType)4 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)4 InputNode (org.apache.airavata.workflow.model.graph.system.InputNode)4 LinkedList (java.util.LinkedList)3 ComponentException (org.apache.airavata.workflow.model.component.ComponentException)3 Workflow (org.apache.airavata.workflow.model.wf.Workflow)3 XmlAttribute (org.xmlpull.infoset.XmlAttribute)3 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 AiravataClientException (org.apache.airavata.model.error.AiravataClientException)2 AiravataSystemException (org.apache.airavata.model.error.AiravataSystemException)2 InvalidRequestException (org.apache.airavata.model.error.InvalidRequestException)2 WSComponent (org.apache.airavata.workflow.model.component.ws.WSComponent)2 WorkflowException (org.apache.airavata.workflow.model.exceptions.WorkflowException)2 OutputNode (org.apache.airavata.workflow.model.graph.system.OutputNode)2