Package org.apache.axiom.om

Examples of org.apache.axiom.om.OMAttribute


        public String getLocalName(int index) {
            return ((OMAttribute)attributes.get(index)).getLocalName();
        }

        public String getQName(int index) {
            OMAttribute attribute = ((OMAttribute)attributes.get(index));
            OMNamespace ns = attribute.getNamespace();
            if (ns == null) {
                return attribute.getLocalName();
            } else {
                String prefix = ns.getPrefix();
                if (prefix == null || prefix.length() == 0) {
                    return attribute.getLocalName();
                } else {
                    return ns.getPrefix() + ":" + attribute.getLocalName();
                }
            }
        }
View Full Code Here


    protected void doWriteEmptyElement(String localName) throws XMLStreamException {
        throw new UnsupportedOperationException("OMDataSource#serialize(XMLStreamWriter) MUST NOT use XMLStreamWriter#writeEmptyElement(String)");
    }

    protected void doWriteAttribute(String prefix, String namespaceURI, String localName, String value) {
        OMAttribute attr = factory.createOMAttribute(localName, getOMNamespace(prefix, namespaceURI, false), value);
        // Use the internal appendAttribute method instead of addAttribute in order to avoid
        // automatic of a namespace declaration (the OMDataSource is required to produce well formed
        // XML with respect to namespaces, so it will take care of the namespace declarations).
        ((OMElementImpl)parent).appendAttribute(attr);
    }
View Full Code Here

            throws XMLComparisonException {
        int elementOneAtribCount = 0;
        int elementTwoAtribCount = 0;
        Iterator attributes = elementOne.getAllAttributes();
        while (attributes.hasNext()) {
            OMAttribute omAttribute = (OMAttribute) attributes.next();
            OMAttribute attr = elementTwo.getAttribute(
                    omAttribute.getQName());
            if (attr == null) {
                throw new XMLComparisonException(
                        "Attributes are not the same in two elements. Attribute " +
                                omAttribute.getLocalName() +
View Full Code Here

     * @return True if the two objects are equal or else false. The equality is checked as explained above.
     */
    public boolean equals(Object obj) {
        String attrValue = getValue();
        if (obj instanceof OMAttribute) { // Checks equality of an OMAttributeImpl or an AttrImpl with this instance
            OMAttribute other = (OMAttribute) obj;
            return (namespace == null ? other.getNamespace() == null :
                    namespace.equals(other.getNamespace()) &&
                    localName.equals(other.getLocalName()) &&
                    (attrValue == null ? other.getAttributeValue() == null :
                            attrValue.toString().equals(other.getAttributeValue())));
        } else if (obj instanceof Attr) {// Checks equality of an org.w3c.dom.Attr with this instance
            Attr other = (Attr)obj;
            String otherNs = other.getNamespaceURI();
            if (namespace == null) { // I don't have a namespace
                if (otherNs != null) {
                    return false; // I don't have a namespace and the other has. So return false
                } else {
                    // Both of us don't have namespaces. So check for name and value equality only
                    return (localName.equals(other.getLocalName()) &&
                            (attrValue == null ? other.getValue() == null :
                                    attrValue.toString().equals(other.getValue())));
                }
            } else { // Ok, now I've a namespace
                String ns = namespace.getNamespaceURI();
                String prefix = namespace.getPrefix();
                String otherPrefix = other.getPrefix();
                // First check for namespaceURI equality. Then check for prefix equality.
                // Then check for name and value equality
                return (ns.equals(otherNs) && (prefix == null ? otherPrefix == null : prefix.equals(otherPrefix)) &&
                        (localName.equals(other.getLocalName())) &&
                        (attrValue == null ? other.getValue() == null :
                                attrValue.toString().equals(other.getValue())));
            }
        }
        return false;
    }
View Full Code Here

     * @param obj The object to compare with this instance.
     * @return True if obj is equal to this or else false.
     */
    public boolean equals(Object obj) {
        if (! (obj instanceof OMAttribute)) return false;
        OMAttribute other = (OMAttribute)obj;
        //first check namespace then localName then value to improve performance
        return (namespace == null ? other.getNamespace() == null :
                namespace.equals(other.getNamespace()) &&
                localName.equals(other.getLocalName()) &&
                (value == null ? other.getAttributeValue() == null :
                        value.equals(other.getAttributeValue())));

    }
View Full Code Here

    }

    protected void runTest() throws Throwable {
        OMFactory factory = metaFactory.getOMFactory();
        OMElement element = factory.createOMElement("test", null);
        OMAttribute attr1 = factory.createOMAttribute("attr", null, "value1");
        OMAttribute attr2 = factory.createOMAttribute("attr", null, "value2");
        OMAttribute attr = element.addAttribute(attr1);
        assertSame(attr1, attr);
        attr = element.addAttribute(attr2);
        assertSame(attr2, attr);
        Iterator it = element.getAllAttributes();
        assertTrue(it.hasNext());
View Full Code Here

        SOAPHeaderBlock soapHeaderBlock = createSOAPHeaderBlock();
        soapHeaderBlock.setMustUnderstand(value);
        assertEquals("getMustUnderstand return value", value, soapHeaderBlock.getMustUnderstand());
        Iterator it = soapHeaderBlock.getAllAttributes();
        assertTrue(it.hasNext());
        OMAttribute att = (OMAttribute)it.next();
        OMNamespace ns = att.getNamespace();
        assertEquals(spec.getEnvelopeNamespaceURI(), ns.getNamespaceURI());
        assertEquals(SOAPConstants.ATTR_MUSTUNDERSTAND, att.getLocalName());
        assertEquals(stringValue, att.getAttributeValue());
        assertFalse(it.hasNext());
    }
View Full Code Here

        SOAPFaultText faultText = soapFactory.createSOAPFaultText();
        faultText.setLang("en");
        assertEquals(
                "SOAP Fault Text Test : - After calling setLang method, Lang attribute value mismatch",
                "en", faultText.getLang());
        OMAttribute langAttribute = (OMAttribute) faultText.getAllAttributes()
                .next();
        assertEquals(
                "SOAP Fault Text Test : - After calling setLang method, Lang attribute local name mismaatch",
                SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME, langAttribute.getLocalName());
        assertEquals(
                "SOAP Fault Text Test : - After calling setLang method, Lang attribute namespace prefix mismatch",
                SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_PREFIX, langAttribute.getNamespace().getPrefix());
        assertEquals(
                "SOAP Fault Text Test : - After calling setLang method, Lang attribute namespace uri mismatch",
                SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_URI, langAttribute.getNamespace().getNamespaceURI());
    }
View Full Code Here

    }

    public void testDefaultAttributeType() throws Exception {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMNamespace ns = factory.createOMNamespace("http://www.me.com", "axiom");
        OMAttribute at = factory.createOMAttribute("id", ns, "value");

        assertEquals(at.getAttributeType(), "CDATA");
    }
View Full Code Here

        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMNamespace ns = factory.createOMNamespace("http://www.me.com", "axiom");

        //code line to be tested
        OMAttribute at = factory.createOMAttribute("id", ns, "value");
        doc.addAttribute(at);

        return doc.toString();
    }
View Full Code Here

TOP

Related Classes of org.apache.axiom.om.OMAttribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.