Search in sources :

Example 1 with XmlAttribute

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

the class WSDLUtil method replaceAttributeValue.

/**
 * @param element
 * @param name
 * @param oldValue
 * @param newValue
 */
public static void replaceAttributeValue(XmlElement element, String name, String oldValue, String newValue) {
    XmlAttribute attribute = element.attribute(name);
    if (null != attribute && oldValue.equals(attribute.getValue())) {
        element.removeAttribute(attribute);
        element.setAttributeValue(name, newValue);
    }
    Iterable iterator = element.children();
    for (Object object : iterator) {
        if (object instanceof XmlElement) {
            replaceAttributeValue((XmlElement) object, name, oldValue, newValue);
        }
    }
}
Also used : XmlAttribute(org.xmlpull.infoset.XmlAttribute) XmlElement(org.xmlpull.infoset.XmlElement)

Example 2 with XmlAttribute

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

the class WSDLUtil method attributeExist.

public static boolean attributeExist(XmlElement element, String name, String value) {
    XmlAttribute attribute = element.attribute(name);
    if (null != attribute && value.equals(attribute.getValue())) {
        return true;
    }
    Iterable iterator = element.children();
    boolean ret = false;
    for (Object object : iterator) {
        if (object instanceof XmlElement) {
            ret = ret || attributeExist((XmlElement) object, name, value);
        }
    }
    return ret;
}
Also used : XmlAttribute(org.xmlpull.infoset.XmlAttribute) XmlElement(org.xmlpull.infoset.XmlElement)

Example 3 with XmlAttribute

use of org.xmlpull.infoset.XmlAttribute 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 4 with XmlAttribute

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

Aggregations

XmlAttribute (org.xmlpull.infoset.XmlAttribute)4 XmlElement (org.xmlpull.infoset.XmlElement)3 XmlNamespace (org.xmlpull.infoset.XmlNamespace)2 LinkedList (java.util.LinkedList)1 QName (javax.xml.namespace.QName)1