Search in sources :

Example 1 with XmlNamespace

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

the class XMLUtil method declareNamespace.

/**
 * @param prefixCandidate
 * @param uri
 * @param alwaysUseSuffix
 * @param element
 * @return The namespace declared.
 */
public static XmlNamespace declareNamespace(String prefixCandidate, String uri, boolean alwaysUseSuffix, XmlElement element) {
    if (prefixCandidate == null || prefixCandidate.length() == 0) {
        prefixCandidate = "a";
    }
    String prefix = prefixCandidate;
    if (alwaysUseSuffix) {
        prefix += "0";
    }
    if (element.lookupNamespaceByPrefix(prefix) != null) {
        int i = 1;
        prefix = prefixCandidate + i;
        while (element.lookupNamespaceByPrefix(prefix) != null) {
            i++;
        }
    }
    XmlNamespace namespace = element.declareNamespace(prefix, uri);
    return namespace;
}
Also used : XmlNamespace(org.xmlpull.infoset.XmlNamespace)

Example 2 with XmlNamespace

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

the class BasicTypeMapping method getSimpleTypeIndex.

public static int getSimpleTypeIndex(XmlElement element) {
    XmlAttribute type = element.attribute(STR_TYPE);
    if (null == type) {
        return -1;
    }
    String typeQNameString = type.getValue();
    String typeName = XMLUtil.getLocalPartOfQName(typeQNameString);
    String prefix = XMLUtil.getPrefixOfQName(typeQNameString);
    XmlNamespace namespace = element.lookupNamespaceByPrefix(prefix);
    if (namespace == null) {
        return -1;
    }
    QName typeQname = new QName(namespace.getName(), typeName, prefix);
    int simpleTypeIndex = getSimpleTypeIndex(typeQname);
    if (-1 == simpleTypeIndex) {
        return -1;
    }
    XmlAttribute maxOccurs = element.attribute(STR_MAX_OCCURS);
    if (maxOccurs != null && STR_UNBOUNDED.equals(maxOccurs.getValue())) {
        // this is the comvention the arraytype index is simplextye index + NUM
        return NUM + simpleTypeIndex;
    } else {
        return simpleTypeIndex;
    }
}
Also used : XmlAttribute(org.xmlpull.infoset.XmlAttribute) XmlNamespace(org.xmlpull.infoset.XmlNamespace) QName(javax.xml.namespace.QName)

Example 3 with XmlNamespace

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

the class WorkflowWSDL method setTypeAttribute.

private void setTypeAttribute(XmlElement element, QName type) {
    String namespaceURI = type.getNamespaceURI();
    XmlNamespace namespace = element.lookupNamespaceByName(namespaceURI);
    element.setAttributeValue(WSConstants.TYPE_ATTRIBUTE, namespace.getPrefix() + ":" + type.getLocalPart());
}
Also used : XmlNamespace(org.xmlpull.infoset.XmlNamespace)

Example 4 with XmlNamespace

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

the class WSDLUtil method getNamespaces.

public static List<XmlNamespace> getNamespaces(XmlElement element) {
    LinkedList<XmlNamespace> namespaces = new LinkedList<XmlNamespace>();
    namespaces.add(element.getNamespace());
    Iterable<XmlAttribute> attributes = element.attributes();
    for (XmlAttribute xmlAttribute : attributes) {
        if (xmlAttribute.getNamespace() != null && !namespaces.contains(xmlAttribute.getNamespace())) {
            namespaces.add(xmlAttribute.getNamespace());
        }
        int index = xmlAttribute.getValue().indexOf(':');
        if (-1 != index) {
            String prefix = xmlAttribute.getValue().substring(0, index);
            if (element.lookupNamespaceByPrefix(prefix) != null) {
                namespaces.add(element.lookupNamespaceByPrefix(prefix));
            }
        }
    }
    Iterable children = element.children();
    for (Object object : children) {
        if (object instanceof XmlElement) {
            List<XmlNamespace> newNSs = getNamespaces((XmlElement) object);
            for (XmlNamespace xmlNamespace : newNSs) {
                if (!namespaces.contains(xmlNamespace)) {
                    namespaces.add(xmlNamespace);
                }
            }
        }
    }
    return namespaces;
}
Also used : XmlAttribute(org.xmlpull.infoset.XmlAttribute) XmlNamespace(org.xmlpull.infoset.XmlNamespace) XmlElement(org.xmlpull.infoset.XmlElement) LinkedList(java.util.LinkedList)

Example 5 with XmlNamespace

use of org.xmlpull.infoset.XmlNamespace 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

XmlNamespace (org.xmlpull.infoset.XmlNamespace)5 XmlAttribute (org.xmlpull.infoset.XmlAttribute)2 XmlElement (org.xmlpull.infoset.XmlElement)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 QName (javax.xml.namespace.QName)1 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)1 GraphException (org.apache.airavata.workflow.model.graph.GraphException)1