Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1686664&r1=1686663&r2=1686664&view=diff ============================================================================== --- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java (original) +++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java Sat Jun 20 19:09:06 2015 @@ -21,13 +21,16 @@ package org.apache.axiom.om.impl.dom; import static org.apache.axiom.dom.DOMExceptionUtil.newDOMException; +import org.apache.axiom.core.AttributeMatcher; +import org.apache.axiom.core.NodeMigrationException; +import org.apache.axiom.core.NodeMigrationPolicy; +import org.apache.axiom.dom.DOMAttribute; import org.apache.axiom.dom.DOMConfigurationImpl; import org.apache.axiom.dom.DOMElement; -import org.apache.axiom.om.OMAttribute; +import org.apache.axiom.dom.DOMExceptionUtil; import org.apache.axiom.om.OMCloneOptions; import org.apache.axiom.om.OMConstants; import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.OMException; import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMNamespace; import org.apache.axiom.om.OMNode; @@ -35,37 +38,24 @@ import org.apache.axiom.om.OMOutputForma import org.apache.axiom.om.OMXMLParserWrapper; import org.apache.axiom.om.impl.common.AxiomContainer; import org.apache.axiom.om.impl.common.AxiomElement; -import org.apache.axiom.om.impl.common.OMNamespaceImpl; import org.apache.axiom.om.impl.common.serializer.push.OutputException; import org.apache.axiom.om.impl.common.serializer.push.Serializer; -import org.apache.axiom.om.impl.util.EmptyIterator; import org.apache.axiom.om.impl.util.OMSerializerUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.w3c.dom.Attr; import org.w3c.dom.DOMException; import org.w3c.dom.NamedNodeMap; -import javax.xml.XMLConstants; -import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import java.io.ByteArrayOutputStream; -import java.util.ArrayList; import java.util.Iterator; /** Implementation of the org.w3c.dom.Element and org.apache.axiom.om.Element interfaces. */ public class ElementImpl extends ParentNode implements DOMElement, AxiomElement, NamedNode, OMConstants { - private static final Log log = LogFactory.getLog(ElementImpl.class); - private int lineNumber; - private AttributeMap attributes; - - private static final EmptyIterator EMPTY_ITERATOR = new EmptyIterator(); - public ElementImpl(ParentNode parentNode, String localName, OMNamespace ns, OMXMLParserWrapper builder, OMFactory factory, boolean generateNSDecl) { super(factory); @@ -80,10 +70,32 @@ public class ElementImpl extends ParentN parentNode.coreAppendChild(this, builder != null); } } - this.attributes = new AttributeMap(this); internalSetNamespace(generateNSDecl ? handleNamespace(this, ns, false, true) : ns); } + private final String checkNamespaceIsDeclared(String prefix, String namespaceURI, boolean allowDefaultNamespace, boolean declare) { + if (prefix == null) { + if (namespaceURI.length() == 0) { + prefix = ""; + declare = false; + } else { + prefix = coreLookupPrefix(namespaceURI, true); + if (prefix != null && (allowDefaultNamespace || prefix.length() != 0)) { + declare = false; + } else { + prefix = OMSerializerUtil.getNextNSPrefix(); + } + } + } else { + String existingNamespaceURI = coreLookupNamespaceURI(prefix, true); + declare = declare && !namespaceURI.equals(existingNamespaceURI); + } + if (declare) { + coreSetAttribute(AttributeMatcher.NAMESPACE_DECLARATION, null, prefix, null, namespaceURI); + } + return prefix; + } + // / // /org.w3c.dom.Node methods // / @@ -104,451 +116,9 @@ public class ElementImpl extends ParentN } // / - // / org.w3c.dom.Element methods - // / - - /** - * Removes an attribute by name. - * - * @param name The name of the attribute to remove - * @see org.w3c.dom.Element#removeAttribute(String) - */ - public void removeAttribute(String name) throws DOMException { - if (this.attributes != null) { - this.attributes.removeNamedItem(name); - } - } - - /* - * (non-Javadoc) - * - * @see org.w3c.dom.Element#removeAttributeNS(java.lang.String, - * java.lang.String) - */ - public void removeAttributeNS(String namespaceURI, String localName) - throws DOMException { - if (this.attributes != null) { - this.attributes.removeNamedItemNS(namespaceURI, localName); - } - } - - /** - * Removes the specified attribute node. - * - * @see org.w3c.dom.Element#removeAttributeNode(org.w3c.dom.Attr) - */ - public Attr removeAttributeNode(Attr oldAttr) throws DOMException { - if (oldAttr.getOwnerElement() != this) { - throw newDOMException(DOMException.NOT_FOUND_ERR); - } - attributes.remove((AttrImpl)oldAttr, true); - return oldAttr; - } - - /** - * Retrieves an attribute node by name. - * - * @see org.w3c.dom.Element#getAttributeNode(String) - */ - public Attr getAttributeNode(String name) { - return (this.attributes == null) ? null : (AttrImpl) this.attributes - .getNamedItem(name); - } - - /** - * Retrieves an attribute node by local name and namespace URI. - * - * @see org.w3c.dom.Element#getAttributeNodeNS(String, String) - */ - public Attr getAttributeNodeNS(String namespaceURI, String localName) { - return (this.attributes == null) ? null : (Attr) this.attributes - .getNamedItemNS(namespaceURI, localName); - } - - /** - * Adds a new attribute node. - * - * @see org.w3c.dom.Element#setAttributeNode(org.w3c.dom.Attr) - */ - public Attr setAttributeNode(Attr attr) throws DOMException { - AttrImpl attrImpl = (AttrImpl) attr; - - checkSameOwnerDocument(attr); - - // check whether the attr is in use - attrImpl.checkInUse(); - - if (attr.getNodeName().startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")) { - // This is a ns declaration - this.declareNamespace(attr.getNodeValue(), DOMUtil - .getLocalName(attr.getName())); - - //Don't add this to attr list, since its a namespace - return attr; - } else if (attr.getNodeName().equals(XMLConstants.XMLNS_ATTRIBUTE)) { - this.declareDefaultNamespace(attr.getValue()); - - //Don't add this to attr list, since its a namespace - return attr; - } - if (this.attributes == null) { - this.attributes = new AttributeMap(this); - } - - return (Attr) this.attributes.setNamedItem(attr); - - } - - /* - * (non-Javadoc) - * - * @see org.w3c.dom.Element#setAttribute(java.lang.String, java.lang.String) - */ - public void setAttribute(String name, String value) throws DOMException { - // Check for invalid charaters - if (!DOMUtil.isQualifiedName(name)) { - throw newDOMException(DOMException.INVALID_CHARACTER_ERR); - } - if (name.startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")) { - // This is a ns declaration - this.declareNamespace(value, DOMUtil.getLocalName(name)); - } else if (name.equals(XMLConstants.XMLNS_ATTRIBUTE)) { - this.declareDefaultNamespace(value); - } else { - this.setAttributeNode(new AttrImpl(ownerDocument(), name, value, - getOMFactory())); - } - - } - - public Attr setAttributeNodeNS(Attr attr) throws DOMException { - return setAttributeNodeNS(attr, true, false); - } - - private Attr setAttributeNodeNS(Attr attr, boolean useDomSemantics, boolean generateNSDecl) throws DOMException { - AttrImpl attrImpl = (AttrImpl) attr; - - if (useDomSemantics) { - checkSameOwnerDocument(attr); - } - - // check whether the attr is in use - attrImpl.checkInUse(); - - if (this.attributes == null) { - this.attributes = new AttributeMap(this); - } - - // handle the namespaces - if (generateNSDecl && attr.getNamespaceURI() != null - && findNamespace(attr.getNamespaceURI(), attr.getPrefix()) - == null) { - // TODO checkwhether the same ns is declared with a different - // prefix and remove it - this.declareNamespace(new OMNamespaceImpl(attr.getNamespaceURI(), - attr.getPrefix())); - } - - return (Attr) this.attributes.setAttribute(attr, useDomSemantics); - } - - /** - * Adds a new attribute. - * - * @see org.w3c.dom.Element#setAttributeNS(String, String, String) - */ - public void setAttributeNS(String namespaceURI, String qualifiedName, - String value) throws DOMException { - - if (namespaceURI != null && namespaceURI.length() == 0) { - namespaceURI = null; - } - String localName = DOMUtil.getLocalName(qualifiedName); - String prefix = DOMUtil.getPrefix(qualifiedName); - DOMUtil.validateAttrName(namespaceURI, localName, prefix); - - AttrImpl attr = (AttrImpl)getAttributeNodeNS(namespaceURI, localName); - if (attr != null) { - attr.setPrefix(prefix); - attr.setValue(value); - } else { - if (namespaceURI != null) { - attr = new AttrImpl(ownerDocument(), localName, value, getOMFactory()); - attr.internalSetNamespace(new OMNamespaceImpl(namespaceURI, prefix == null ? "" : prefix)); - - this.setAttributeNodeNS(attr); - } else { - // When the namespace is null, the attr name given better not be - // a qualified name - // But anyway check and set it - this.setAttribute(localName, value); - } - } - - } - - /** Returns whether this element contains any attribute or not. */ - public boolean hasAttributes() { - return attributes != null && attributes.getLength() > 0; - } - - // / // /OmElement methods // / - /** @see org.apache.axiom.om.OMElement#addAttribute (org.apache.axiom.om.OMAttribute) */ - public OMAttribute addAttribute(OMAttribute attr) { - // If the attribute already has an owner element then clone the attribute (except if it is owned - // by the this element) - OMElement owner = attr.getOwner(); - if (owner != null) { - if (owner == this) { - return attr; - } - attr = new AttrImpl(null, attr.getLocalName(), attr.getNamespace(), - attr.getAttributeValue(), attr.getOMFactory()); - } - - OMNamespace namespace = attr.getNamespace(); - if (namespace != null) { - String uri = namespace.getNamespaceURI(); - if (uri.length() > 0) { - String prefix = namespace.getPrefix(); - OMNamespace ns2 = findNamespaceURI(prefix); - if (ns2 == null || !uri.equals(ns2.getNamespaceURI())) { - declareNamespace(uri, prefix); - } - } - } - - this.setAttributeNodeNS((Attr) attr, false, true); - return attr; - } - - public OMAttribute addAttribute(String localName, String value, - OMNamespace ns) { - OMNamespace namespace = null; - if (ns != null) { - String namespaceURI = ns.getNamespaceURI(); - String prefix = ns.getPrefix(); - if (namespaceURI.length() > 0 || prefix != null) { - namespace = findNamespace(namespaceURI, prefix); - if (namespace == null || prefix == null && namespace.getPrefix().length() == 0) { - namespace = new OMNamespaceImpl(namespaceURI, prefix != null ? prefix : OMSerializerUtil.getNextNSPrefix()); - } - } - } - return addAttribute(new AttrImpl(null, localName, namespace, value, getOMFactory())); - } - - public OMNamespace addNamespaceDeclaration(String uri, String prefix) { - OMNamespace ns = new OMNamespaceImpl(uri, prefix); - addNamespaceDeclaration(ns); - return ns; - } - - public void addNamespaceDeclaration(OMNamespace ns) { - String prefix = ns.getPrefix(); - setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix.length() == 0 ? XMLConstants.XMLNS_ATTRIBUTE : XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix, ns.getNamespaceURI()); - } - - /** - * Allows overriding an existing declaration if the same prefix was used. - * - * @see org.apache.axiom.om.OMElement#declareNamespace (org.apache.axiom.om.OMNamespace) - */ - public OMNamespace declareNamespace(OMNamespace namespace) { - if (namespace != null) { - String prefix = namespace.getPrefix(); - if (prefix == null) { - prefix = OMSerializerUtil.getNextNSPrefix(); - namespace = new OMNamespaceImpl(namespace.getNamespaceURI(), prefix); - } - if (prefix.length() > 0 && namespace.getNamespaceURI().length() == 0) { - throw new IllegalArgumentException("Cannot bind a prefix to the empty namespace name"); - } - - if (!namespace.getPrefix().startsWith(XMLConstants.XMLNS_ATTRIBUTE)) { - setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix.length() == 0 ? XMLConstants.XMLNS_ATTRIBUTE : XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix, namespace.getNamespaceURI()); - } - } - return namespace; - } - - public void undeclarePrefix(String prefix) { - setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix.length() == 0 ? XMLConstants.XMLNS_ATTRIBUTE : XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix, ""); - } - - public OMNamespace declareNamespace(String uri, String prefix) { - if ("".equals(prefix)) { - log.warn("Deprecated usage of OMElement#declareNamespace(String,String) with empty prefix"); - prefix = OMSerializerUtil.getNextNSPrefix(); - } - - OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix); - return declareNamespace(ns); - } - - public OMNamespace declareDefaultNamespace(String uri) { - OMNamespace namespace = getNamespace(); - if (namespace == null && uri.length() > 0 - || namespace != null && namespace.getPrefix().length() == 0 && !namespace.getNamespaceURI().equals(uri)) { - throw new OMException("Attempt to add a namespace declaration that conflicts with " + - "the namespace information of the element"); - } - - setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE, uri); - return new OMNamespaceImpl(uri, ""); - } - - public OMNamespace getDefaultNamespace() { - Attr decl = (Attr)attributes.getNamedItemNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE); - if (decl != null) { - String uri = decl.getValue(); - return uri.length() == 0 ? null : new OMNamespaceImpl(uri, ""); - } - - ParentNode parentNode = (ParentNode)coreGetParent(); - if (parentNode instanceof ElementImpl) { - ElementImpl element = (ElementImpl) parentNode; - return element.getDefaultNamespace(); - } - return null; - } - - /** @see org.apache.axiom.om.OMElement#findNamespace(String, String) */ - public OMNamespace findNamespace(String uri, String prefix) { - - // check in the current element - OMNamespace namespace = findDeclaredNamespace(uri, prefix); - if (namespace != null) { - return namespace; - } - - // go up to check with ancestors - ParentNode parentNode = (ParentNode)coreGetParent(); - if (parentNode != null) { - // For the OMDocumentImpl there won't be any explicit namespace - // declarations, so going up the parent chain till the document - // element should be enough. - if (parentNode instanceof OMElement) { - namespace = ((ElementImpl) parentNode).findNamespace(uri, - prefix); - // If the prefix has been redeclared, then ignore the binding found on the ancestors - if (prefix == null && namespace != null && findDeclaredNamespace(null, namespace.getPrefix()) != null) { - namespace = null; - } - } - } - - if (namespace == null && uri != null && prefix != null - && prefix.equals(OMConstants.XMLNS_PREFIX) - && uri.equals(OMConstants.XMLNS_URI)) { - declareNamespace(OMConstants.XMLNS_URI, OMConstants.XMLNS_PREFIX); - namespace = findNamespace(uri, prefix); - } - return namespace; - } - - public OMNamespace findNamespaceURI(String prefix) { - if (attributes != null) { - Attr decl = (Attr)attributes.getNamedItemNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix.length() == 0 ? XMLConstants.XMLNS_ATTRIBUTE : prefix); - if (decl != null) { - String namespaceURI = decl.getValue(); - if (prefix != null && prefix.length() > 0 && namespaceURI.length() == 0) { - // Prefix undeclaring case (XML 1.1 only) - return null; - } else { - return new OMNamespaceImpl(namespaceURI, prefix); - } - } - } - ParentNode parentNode = (ParentNode)coreGetParent(); - if (parentNode instanceof OMElement) { - // try with the parent - return ((OMElement)parentNode).findNamespaceURI(prefix); - } else { - return null; - } - } - - /** - * Checks for the namespace <B>only</B> in the current Element. This can also be used to - * retrieve the prefix of a known namespace URI. - */ - private OMNamespace findDeclaredNamespace(String uri, String prefix) { - - if (uri == null) { - Attr decl = (Attr)attributes.getNamedItemNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, - prefix.length() == 0 ? XMLConstants.XMLNS_ATTRIBUTE : prefix); - return decl == null ? null : new OMNamespaceImpl(decl.getValue(), prefix); - } - // If the prefix is available and uri is available and its the xml - // namespace - if (prefix != null && prefix.equals(OMConstants.XMLNS_PREFIX) - && uri.equals(OMConstants.XMLNS_URI)) { - return new OMNamespaceImpl(uri, prefix); - } - - if (prefix == null || "".equals(prefix)) { - for (int i=0; i<attributes.getLength(); i++) { - Attr attr = (Attr)attributes.item(i); - if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI())) { - String declaredUri = attr.getValue(); - if (declaredUri.equals(uri)) { - return new OMNamespaceImpl(uri, attr.getPrefix() == null ? "" : attr.getLocalName()); - } - } - } - } else { - Attr decl = (Attr)attributes.getNamedItemNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix); - if (decl != null) { - String declaredUri = decl.getValue(); - if (declaredUri.equals(uri)) { - return new OMNamespaceImpl(uri, prefix); - } - } - } - - return null; - } - - /** - * Returns a named attribute if present. - * - * @see org.apache.axiom.om.OMElement#getAttribute (javax.xml.namespace.QName) - */ - public OMAttribute getAttribute(QName qname) { - if (this.attributes == null) { - return null; - } - - if (qname.getNamespaceURI().equals("")) { - return (AttrImpl) this.getAttributeNode(qname.getLocalPart()); - } else { - return (AttrImpl) this.getAttributeNodeNS(qname.getNamespaceURI(), - qname.getLocalPart()); - } - } - - /** - * Returns a named attribute's value, if present. - * - * @param qname the qualified name to search for - * @return Returns a String containing the attribute value, or null. - */ - public String getAttributeValue(QName qname) { - OMAttribute attr = getAttribute(qname); - return (attr == null) ? null : attr.getAttributeValue(); - } - - public void removeAttribute(OMAttribute attr) { - if (attr.getOwner() != this) { - throw new OMException("The attribute is not owned by this element"); - } - attributes.remove((AttrImpl)attr, false); - } - public void setNamespace(OMNamespace namespace) { setNamespace(namespace, true); } @@ -583,29 +153,6 @@ public class ElementImpl extends ParentN return new String(baos.toByteArray()); } - /** @see org.apache.axiom.om.OMElement#getAllDeclaredNamespaces() */ - public Iterator getAllDeclaredNamespaces() throws OMException { - return new NSDeclIterator(attributes); - } - - /** @see org.apache.axiom.om.OMElement#getAllAttributes() */ - public Iterator getAllAttributes() { - if (attributes == null) { - return EMPTY_ITERATOR; - } - ArrayList list = new ArrayList(); - for (int i = 0; i < attributes.getLength(); i++) { - OMAttribute item = (OMAttribute) attributes.getItem(i); - if (item.getNamespace() == null - || !(item.getNamespace() != null && XMLConstants.XMLNS_ATTRIBUTE_NS_URI - .equals(item.getNamespace().getNamespaceURI()))) { - list.add(item); - } - } - - return list.iterator(); - } - public OMElement cloneOMElement() { return (OMElement)clone(new OMCloneOptions()); } @@ -617,11 +164,23 @@ public class ElementImpl extends ParentN } else { clone = new ElementImpl(targetParent, getLocalName(), getNamespace(), null, getOMFactory(), namespaceRepairing); } + NamedNodeMap attributes = getAttributes(); for (int i=0, l=attributes.getLength(); i<l; i++) { AttrImpl attr = (AttrImpl)attributes.item(i); AttrImpl clonedAttr = (AttrImpl)attr.clone(options, null, true, false); clonedAttr.setSpecified(attr.getSpecified()); - clone.setAttributeNodeNS(clonedAttr, false, namespaceRepairing && !XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI())); + if (namespaceRepairing && attr instanceof NSAwareAttribute) { + NSAwareAttribute nsAwareAttr = (NSAwareAttribute)attr; + String namespaceURI = nsAwareAttr.coreGetNamespaceURI(); + if (namespaceURI.length() != 0) { + clone.checkNamespaceIsDeclared(nsAwareAttr.coreGetPrefix(), namespaceURI, false, true); + } + } + try { + clone.coreAppendAttribute(clonedAttr, NodeMigrationPolicy.MOVE_ALWAYS); + } catch (NodeMigrationException ex) { + DOMExceptionUtil.translate(ex); + } } return clone; } @@ -638,11 +197,6 @@ public class ElementImpl extends ParentN return lineNumber; } - /** Returns the set of attributes of this node and the namespace declarations available. */ - public NamedNodeMap getAttributes() { - return attributes; - } - /** * Returns the namespace uri, given the prefix. If it is not found at this element, searches the * parent. @@ -682,21 +236,10 @@ public class ElementImpl extends ParentN public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException { //find the attr - Iterator attrIter = this.getAllAttributes(); - AttrImpl tempAttr = null; - while (attrIter.hasNext()) { - AttrImpl attr = (AttrImpl) attrIter.next(); - if (attr.equals(idAttr)) { - tempAttr = attr; - break; - } - } - - if (tempAttr == null) { + if (((DOMAttribute)idAttr).coreGetOwnerElement() != this) { throw newDOMException(DOMException.NOT_FOUND_ERR); } - - this.updateIsId(isId, tempAttr); + this.updateIsId(isId, (AttrImpl)idAttr); } /**
Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeSupport.aj URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeSupport.aj?rev=1686664&r1=1686663&r2=1686664&view=diff ============================================================================== --- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeSupport.aj (original) +++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeSupport.aj Sat Jun 20 19:09:06 2015 @@ -25,6 +25,7 @@ import org.apache.axiom.om.impl.common.O import org.w3c.dom.DOMException; aspect NamedNodeSupport { + // TODO: rewrite this using coreSetPrefix public final void NamedNode.setPrefix(String prefix) throws DOMException { if (prefix == null) { prefix = ""; Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?rev=1686664&r1=1686663&r2=1686664&view=diff ============================================================================== --- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java (original) +++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java Sat Jun 20 19:09:06 2015 @@ -22,6 +22,9 @@ package org.apache.axiom.om.impl.dom.fac import org.apache.axiom.core.CoreCDATASection; import org.apache.axiom.core.CoreCharacterData; import org.apache.axiom.core.CoreDocument; +import org.apache.axiom.core.CoreNSAwareAttribute; +import org.apache.axiom.core.CoreNSUnawareAttribute; +import org.apache.axiom.core.CoreNamespaceDeclaration; import org.apache.axiom.om.OMAttribute; import org.apache.axiom.om.OMComment; import org.apache.axiom.om.OMContainer; @@ -41,15 +44,18 @@ import org.apache.axiom.om.OMText; import org.apache.axiom.om.OMXMLParserWrapper; import org.apache.axiom.om.impl.OMContainerEx; import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.axiom.om.impl.common.AxiomNamespaceDeclaration; import org.apache.axiom.om.impl.common.OMNamespaceImpl; import org.apache.axiom.om.impl.common.factory.AxiomNodeFactory; -import org.apache.axiom.om.impl.dom.AttrImpl; import org.apache.axiom.om.impl.dom.CDATASectionImpl; import org.apache.axiom.om.impl.dom.CommentImpl; import org.apache.axiom.om.impl.dom.DocumentImpl; import org.apache.axiom.om.impl.dom.DocumentTypeImpl; import org.apache.axiom.om.impl.dom.ElementImpl; import org.apache.axiom.om.impl.dom.EntityReferenceImpl; +import org.apache.axiom.om.impl.dom.NamespaceDeclaration; +import org.apache.axiom.om.impl.dom.NSAwareAttribute; +import org.apache.axiom.om.impl.dom.NSUnawareAttribute; import org.apache.axiom.om.impl.dom.OMDOMException; import org.apache.axiom.om.impl.dom.ParentNode; import org.apache.axiom.om.impl.dom.ProcessingInstructionImpl; @@ -193,7 +199,18 @@ public class OMDOMFactory implements Axi ns = new OMNamespaceImpl(namespaceURI, OMSerializerUtil.getNextNSPrefix()); } } - return new AttrImpl(null, localName, ns, value, this); + if (ns != null) { + if (ns.getNamespaceURI().length() == 0) { + if (ns.getPrefix().length() > 0) { + throw new IllegalArgumentException("Cannot create a prefixed attribute with an empty namespace name"); + } else { + ns = null; + } + } else if (ns.getPrefix().length() == 0) { + throw new IllegalArgumentException("Cannot create an unprefixed attribute with a namespace"); + } + } + return new NSAwareAttribute(null, localName, ns, value, this); } public OMDocType createOMDocType(OMContainer parent, String rootName, String publicId, @@ -322,4 +339,26 @@ public class OMDOMFactory implements Axi public CoreCDATASection createCDATASection() { return new CDATASectionImpl(this); } + + public final CoreNSUnawareAttribute createAttribute(CoreDocument document, String name, String value, String type) { + NSUnawareAttribute attr = new NSUnawareAttribute((DocumentImpl)document, this); + attr.coreSetName(name); + attr.coreSetValue(value); +// attr.coreSetType(type); + return attr; + } + + public final CoreNSAwareAttribute createAttribute(CoreDocument document, String namespaceURI, + String localName, String prefix, String value, String type) { + return new NSAwareAttribute((DocumentImpl)document, localName, namespaceURI.length() == 0 ? null : new OMNamespaceImpl(namespaceURI, prefix), value, this); + } + + public final CoreNamespaceDeclaration createNamespaceDeclaration(CoreDocument document, + String prefix, String namespaceURI) { + return new NamespaceDeclaration((DocumentImpl)document, new OMNamespaceImpl(namespaceURI == null ? "" : namespaceURI, prefix), this); + } + + public final AxiomNamespaceDeclaration createNamespaceDeclaration(OMNamespace namespace) { + return new NamespaceDeclaration(null, namespace, this); + } } Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderBlockImpl.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderBlockImpl.java?rev=1686664&r1=1686663&r2=1686664&view=diff ============================================================================== --- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderBlockImpl.java (original) +++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderBlockImpl.java Sat Jun 20 19:09:06 2015 @@ -30,6 +30,7 @@ import org.apache.axiom.om.impl.common.O import org.apache.axiom.om.impl.dom.AttrImpl; import org.apache.axiom.om.impl.dom.DocumentImpl; import org.apache.axiom.om.impl.dom.ElementImpl; +import org.apache.axiom.om.impl.dom.NSAwareAttribute; import org.apache.axiom.om.impl.dom.ParentNode; import org.apache.axiom.soap.SOAPCloneOptions; import org.apache.axiom.soap.SOAPConstants; @@ -61,7 +62,7 @@ public abstract class SOAPHeaderBlockImp if (omAttribute != null) { omAttribute.setAttributeValue(attrValue); } else { - OMAttribute attribute = new AttrImpl((DocumentImpl)getOwnerDocument(), attributeName, + OMAttribute attribute = new NSAwareAttribute((DocumentImpl)getOwnerDocument(), attributeName, new OMNamespaceImpl(soapEnvelopeNamespaceURI, SOAPConstants.SOAP_DEFAULT_NAMESPACE_PREFIX), attrValue, getOMFactory()); Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultTextImpl.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultTextImpl.java?rev=1686664&r1=1686663&r2=1686664&view=diff ============================================================================== --- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultTextImpl.java (original) +++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultTextImpl.java Sat Jun 20 19:09:06 2015 @@ -29,6 +29,7 @@ import org.apache.axiom.om.OMNamespace; import org.apache.axiom.om.OMXMLParserWrapper; import org.apache.axiom.om.impl.dom.AttrImpl; import org.apache.axiom.om.impl.dom.DocumentImpl; +import org.apache.axiom.om.impl.dom.NSAwareAttribute; import org.apache.axiom.om.impl.dom.ParentNode; import org.apache.axiom.soap.SOAP12Constants; import org.apache.axiom.soap.SOAPFactory; @@ -67,7 +68,7 @@ public class SOAP12FaultTextImpl extends public void setLang(String lang) { langAttr = - new AttrImpl((DocumentImpl)getOwnerDocument(), + new NSAwareAttribute((DocumentImpl)getOwnerDocument(), SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME, langNamespace, lang, getOMFactory()); Modified: webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java?rev=1686664&r1=1686663&r2=1686664&view=diff ============================================================================== --- webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java (original) +++ webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java Sat Jun 20 19:09:06 2015 @@ -42,30 +42,21 @@ public class DOMImplementationTest exten builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/attrspecifiedvalueremove)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentcreateelementdefaultattr)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentgetelementsbytagnametotallength)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreateattribute)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreateelement)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreateentref)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreateentref1)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreatepi)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreatepi1)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/elementinvalidcharacterexception)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/elementremoveattribute)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/elementremoveattributerestoredefaultvalue)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/elementreplaceattributewithself)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/elementsetattributenomodificationallowederr)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/namednodemapremovenameditem)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/namednodemapremovenameditemgetvalue)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/processinginstructionsetdatanomodificationallowederr)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_documentinvalidcharacterexceptioncreateattribute)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_documentinvalidcharacterexceptioncreateattribute1)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_documentinvalidcharacterexceptioncreateelement)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_documentinvalidcharacterexceptioncreateelement1)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_elementinvalidcharacterexception)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_elementinvalidcharacterexception1)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_elementnormalize)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_elementnormalize2)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_elementremoveattributeaftercreate)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_elementreplaceattributewithself)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild2)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild4)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrgetvalue2)"); @@ -148,12 +139,10 @@ public class DOMImplementationTest exten builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/nodesetprefix05)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/nodesetprefix06)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/nodesetprefix07)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/nodesetprefix08)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/nodesetprefix09)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/prefix05)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/prefix06)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/prefix07)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/prefix09)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/removeAttributeNS02)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/attrisid04)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/attrisid05)"); @@ -263,8 +252,6 @@ public class DOMImplementationTest exten builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/domstringlistitem01)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/domstringlistitem02)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementcontentwhitespace01)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributenode01)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributenode04)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributenode08)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributenode09)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributenode10)"); @@ -364,18 +351,15 @@ public class DOMImplementationTest exten builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisequalnode10)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisequalnode11)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisequalnode13)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisequalnode14)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisequalnode22)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodelookupprefix12)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/noderemovechild19)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild13)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild20)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild27)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild28)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild30)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild31)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild32)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild35)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild40)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodesettextcontent02)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodesettextcontent12)"); @@ -384,8 +368,6 @@ public class DOMImplementationTest exten builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/normalizecharacters01)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/normalizecharacters03)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/normalizecharacters05)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/textiselementcontentwhitespace01)"); - builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/textiselementcontentwhitespace02)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/textiselementcontentwhitespace03)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/textreplacewholetext06)"); builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/textreplacewholetext08)"); Modified: webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java?rev=1686664&r1=1686663&r2=1686664&view=diff ============================================================================== --- webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java (original) +++ webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java Sat Jun 20 19:09:06 2015 @@ -28,7 +28,6 @@ import org.apache.axiom.ts.om.container. import org.apache.axiom.ts.om.container.TestSerialize; import org.apache.axiom.ts.om.document.TestClone; import org.apache.axiom.ts.om.document.TestDigest; -import org.apache.axiom.ts.om.element.TestGetAllDeclaredNamespacesRemove; import org.apache.axiom.ts.om.element.TestGetChildrenWithName4; import org.apache.axiom.ts.om.element.TestSerializationWithTwoNonBuiltOMElements; import org.apache.axiom.ts.om.element.sr.TestClose; @@ -68,9 +67,6 @@ public class OMImplementationTest extend // TODO: test issue: DOOM doesn't preserve attribute order builder.exclude(TestGetXMLStreamReader.class, "(&(file=large.xml))"); - // TODO: will be fixed by merging the attrs-aspects branch - builder.exclude(TestGetAllDeclaredNamespacesRemove.class); - return builder.build(); } } Modified: webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java?rev=1686664&r1=1686663&r2=1686664&view=diff ============================================================================== --- webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java (original) +++ webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java Sat Jun 20 19:09:06 2015 @@ -19,7 +19,6 @@ package org.apache.axiom.om.impl.llom; -import org.apache.axiom.om.OMAttribute; import org.apache.axiom.om.OMCloneOptions; import org.apache.axiom.om.OMConstants; import org.apache.axiom.om.OMFactory; @@ -28,14 +27,7 @@ import org.apache.axiom.om.OMNamespace; import org.apache.axiom.om.impl.common.AxiomAttribute; /** Class OMAttributeImpl */ -public class OMAttributeImpl extends OMInformationItemImpl implements AxiomAttribute { - private String value; - - private String type; - - /** <code>OMFactory</code> that created this <code>OMAttribute</code> */ - private OMFactory factory; - +public class OMAttributeImpl extends Attribute implements AxiomAttribute { /** * Constructor OMAttributeImpl. * @@ -45,6 +37,7 @@ public class OMAttributeImpl extends OMI */ public OMAttributeImpl(String localName, OMNamespace ns, String value, OMFactory factory) { + super(factory); if (localName == null || localName.trim().length() == 0) throw new IllegalArgumentException("Local name may not be null or empty"); @@ -61,45 +54,12 @@ public class OMAttributeImpl extends OMI } internalSetLocalName(localName); - this.value = value; + coreSetValue(value); internalSetNamespace(ns); - this.type = OMConstants.XMLATTRTYPE_CDATA; - this.factory = factory; - } - - // -------- Getters and Setters - - public String getAttributeValue() { - return value; - } - - /** - * Method setAttributeValue. - * - * @param value - */ - public void setAttributeValue(String value) { - this.value = value; - } - - public String getAttributeType() { - return type; - } - - /** - * Method setAttributeType. - * - * @param type - */ - public void setAttributeType(String type) { - this.type = type; - } - - public OMFactory getOMFactory() { - return this.factory; + coreSetType(OMConstants.XMLATTRTYPE_CDATA); } public OMInformationItem clone(OMCloneOptions options) { - return new OMAttributeImpl(getLocalName(), getNamespace(), value, factory); + return new OMAttributeImpl(getLocalName(), getNamespace(), getAttributeValue(), getOMFactory()); } } Modified: webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1686664&r1=1686663&r2=1686664&view=diff ============================================================================== --- webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java (original) +++ webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java Sat Jun 20 19:09:06 2015 @@ -32,10 +32,8 @@ import org.apache.axiom.om.OMOutputForma import org.apache.axiom.om.OMXMLParserWrapper; import org.apache.axiom.om.impl.common.AxiomContainer; import org.apache.axiom.om.impl.common.AxiomElement; -import org.apache.axiom.om.impl.common.OMNamespaceImpl; import org.apache.axiom.om.impl.common.serializer.push.OutputException; import org.apache.axiom.om.impl.common.serializer.push.Serializer; -import org.apache.axiom.om.impl.util.EmptyIterator; import org.apache.axiom.om.impl.util.OMSerializerUtil; import org.apache.axiom.om.util.StAXUtils; import org.apache.commons.logging.Log; @@ -46,9 +44,7 @@ import javax.xml.stream.XMLStreamExcepti import javax.xml.stream.XMLStreamWriter; import java.io.StringWriter; -import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashMap; /** Class OMElementImpl */ public class OMElementImpl extends OMNodeImpl @@ -56,14 +52,7 @@ public class OMElementImpl extends OMNod private static final Log log = LogFactory.getLog(OMElementImpl.class); - /** Field namespaces */ - protected HashMap namespaces = null; - - /** Field attributes */ - protected HashMap attributes = null; - private int lineNumber; - private static final EmptyIterator EMPTY_ITERATOR = new EmptyIterator(); public OMElementImpl(OMContainer parent, String localName, OMNamespace ns, OMXMLParserWrapper builder, OMFactory factory, boolean generateNSDecl) { @@ -137,314 +126,6 @@ public class OMElementImpl extends OMNod public void checkChild(OMNode child) { } - public OMNamespace declareNamespace(String uri, String prefix) { - if ("".equals(prefix)) { - log.warn("Deprecated usage of OMElement#declareNamespace(String,String) with empty prefix"); - prefix = OMSerializerUtil.getNextNSPrefix(); - } - OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix); - return declareNamespace(ns); - } - - public OMNamespace declareDefaultNamespace(String uri) { - OMNamespace elementNamespace = getNamespace(); - if (elementNamespace == null && uri.length() > 0 - || elementNamespace != null && elementNamespace.getPrefix().length() == 0 && !elementNamespace.getNamespaceURI().equals(uri)) { - throw new OMException("Attempt to add a namespace declaration that conflicts with " + - "the namespace information of the element"); - } - - OMNamespaceImpl namespace = new OMNamespaceImpl(uri == null ? "" : uri, ""); - - if (namespaces == null) { - this.namespaces = new HashMap(5); - } - namespaces.put("", namespace); - return namespace; - } - - public OMNamespace getDefaultNamespace() { - OMNamespace defaultNS; - if (namespaces != null && (defaultNS = (OMNamespace) namespaces.get("")) != null) { - return defaultNS.getNamespaceURI().length() == 0 ? null : defaultNS; - } - OMContainer parent = getParent(); - if (parent instanceof OMElementImpl) { - return ((OMElementImpl) parent).getDefaultNamespace(); - - } - return null; - } - - public OMNamespace addNamespaceDeclaration(String uri, String prefix) { - OMNamespace ns = new OMNamespaceImpl(uri, prefix); - addNamespaceDeclaration(ns); - return ns; - } - - public void addNamespaceDeclaration(OMNamespace ns) { - if (namespaces == null) { - this.namespaces = new HashMap(5); - } - namespaces.put(ns.getPrefix(), ns); - } - - /** @return Returns namespace. */ - public OMNamespace declareNamespace(OMNamespace namespace) { - if (namespaces == null) { - this.namespaces = new HashMap(5); - } - String prefix = namespace.getPrefix(); - if (prefix == null) { - prefix = OMSerializerUtil.getNextNSPrefix(); - namespace = new OMNamespaceImpl(namespace.getNamespaceURI(), prefix); - } - if (prefix.length() > 0 && namespace.getNamespaceURI().length() == 0) { - throw new IllegalArgumentException("Cannot bind a prefix to the empty namespace name"); - } - namespaces.put(prefix, namespace); - return namespace; - } - - public void undeclarePrefix(String prefix) { - if (namespaces == null) { - this.namespaces = new HashMap(5); - } - namespaces.put(prefix, new OMNamespaceImpl("", prefix)); - } - - /** - * Finds a namespace with the given uri and prefix, in the scope of the document. Starts to find - * from the current element and goes up in the hiararchy until one is found. If none is found, - * returns null. - */ - public OMNamespace findNamespace(String uri, String prefix) { - - // check in the current element - OMNamespace namespace = findDeclaredNamespace(uri, prefix); - if (namespace != null) { - return namespace; - } - - // go up to check with ancestors - OMContainer parent = getParent(); - if (parent != null) { - //For the OMDocumentImpl there won't be any explicit namespace - //declarations, so going up the parent chain till the document - //element should be enough. - if (parent instanceof OMElement) { - namespace = ((OMElementImpl) parent).findNamespace(uri, prefix); - // If the prefix has been redeclared, then ignore the binding found on the ancestors - if (prefix == null && namespace != null && findDeclaredNamespace(null, namespace.getPrefix()) != null) { - namespace = null; - } - } - } - - return namespace; - } - - public OMNamespace findNamespaceURI(String prefix) { - OMNamespace ns = this.namespaces == null ? - null : - (OMNamespace) this.namespaces.get(prefix); - - if (ns == null) { - OMContainer parent = getParent(); - if (parent instanceof OMElement) { - // try with the parent - return ((OMElement)parent).findNamespaceURI(prefix); - } else { - return null; - } - } else if (prefix != null && prefix.length() > 0 && ns.getNamespaceURI().length() == 0) { - // Prefix undeclaring case (XML 1.1 only) - return null; - } else { - return ns; - } - } - - // Constant - static final OMNamespaceImpl xmlns = - new OMNamespaceImpl(OMConstants.XMLNS_URI, - OMConstants.XMLNS_PREFIX); - - /** - * Checks for the namespace <B>only</B> in the current Element. This is also used to retrieve - * the prefix of a known namespace URI. - */ - private OMNamespace findDeclaredNamespace(String uri, String prefix) { - if (uri == null) { - return namespaces == null ? null : (OMNamespace)namespaces.get(prefix); - } - - //If the prefix is available and uri is available and its the xml namespace - if (prefix != null && prefix.equals(OMConstants.XMLNS_PREFIX) && - uri.equals(OMConstants.XMLNS_URI)) { - return xmlns; - } - - if (namespaces == null) { - return null; - } - - if (prefix == null || "".equals(prefix)) { - - OMNamespace defaultNamespace = this.getDefaultNamespace(); - if (defaultNamespace != null && uri.equals(defaultNamespace.getNamespaceURI())) { - return defaultNamespace; - } - Iterator namespaceListIterator = namespaces.values().iterator(); - - String nsUri; - - while (namespaceListIterator.hasNext()) { - OMNamespace omNamespace = - (OMNamespace) namespaceListIterator.next(); - nsUri = omNamespace.getNamespaceURI(); - if (nsUri != null && - nsUri.equals(uri)) { - return omNamespace; - } - } - } else { - OMNamespace namespace = (OMNamespace) namespaces.get(prefix); - if (namespace != null && uri.equals(namespace.getNamespaceURI())) { - return namespace; - } - } - return null; - } - - - /** - * Method getAllDeclaredNamespaces. - * - * @return Returns Iterator. - */ - public Iterator getAllDeclaredNamespaces() { - if (namespaces == null) { - return EMPTY_ITERATOR; - } - return namespaces.values().iterator(); - } - - /** - * Returns a List of OMAttributes. - * - * @return Returns iterator. - */ - public Iterator getAllAttributes() { - if (attributes == null) { - return EMPTY_ITERATOR; - } - return attributes.values().iterator(); - } - - /** - * Returns a named attribute if present. - * - * @param qname the qualified name to search for - * @return Returns an OMAttribute with the given name if found, or null - */ - public OMAttribute getAttribute(QName qname) { - return attributes == null ? null : (OMAttribute) attributes.get(qname); - } - - /** - * Returns a named attribute's value, if present. - * - * @param qname the qualified name to search for - * @return Returns a String containing the attribute value, or null. - */ - public String getAttributeValue(QName qname) { - OMAttribute attr = getAttribute(qname); - return (attr == null) ? null : attr.getAttributeValue(); - } - - /** - * Inserts an attribute to this element. Implementor can decide as to insert this in the front - * or at the end of set of attributes. - * - * <p>The owner of the attribute is set to be the particular <code>OMElement</code>. - * If the attribute already has an owner then the attribute is cloned (i.e. its name, - * value and namespace are copied to a new attribute) and the new attribute is added - * to the element. It's owner is then set to be the particular <code>OMElement</code>. - * - * @return The attribute that was added to the element. Note: The added attribute - * may not be the same instance that was given to add. This can happen if the given - * attribute already has an owner. In such case the returned attribute and the given - * attribute are <i>equal</i> but not the same instance. - * - * @see OMAttributeImpl#equals(Object) - */ - public OMAttribute addAttribute(OMAttribute attr){ - // If the attribute already has an owner element then clone the attribute (except if it is owned - // by the this element) - OMElement owner = attr.getOwner(); - if (owner != null) { - if (owner == this) { - return attr; - } - attr = new OMAttributeImpl( - attr.getLocalName(), attr.getNamespace(), attr.getAttributeValue(), attr.getOMFactory()); - } - - OMNamespace namespace = attr.getNamespace(); - if (namespace != null) { - String uri = namespace.getNamespaceURI(); - if (uri.length() > 0) { - String prefix = namespace.getPrefix(); - OMNamespace ns2 = findNamespaceURI(prefix); - if (ns2 == null || !uri.equals(ns2.getNamespaceURI())) { - declareNamespace(uri, prefix); - } - } - } - - appendAttribute(attr); - return attr; - } - - void appendAttribute(OMAttribute attr) { - if (attributes == null) { - this.attributes = new LinkedHashMap(5); - } - // Set the owner element of the attribute - ((OMAttributeImpl)attr).internalSetOwnerElement(this); - OMAttributeImpl oldAttr = (OMAttributeImpl)attributes.put(attr.getQName(), attr); - // Did we replace an existing attribute? - if (oldAttr != null) { - oldAttr.internalUnsetOwnerElement(null); - } - } - - public void removeAttribute(OMAttribute attr) { - if (attr.getOwner() != this) { - throw new OMException("The attribute is not owned by this element"); - } - // Remove the owner from this attribute - ((OMAttributeImpl)attr).internalUnsetOwnerElement(null); - attributes.remove(attr.getQName()); - } - - public OMAttribute addAttribute(String localName, String value, - OMNamespace ns) { - OMNamespace namespace = null; - if (ns != null) { - String namespaceURI = ns.getNamespaceURI(); - String prefix = ns.getPrefix(); - if (namespaceURI.length() > 0 || prefix != null) { - namespace = findNamespace(namespaceURI, prefix); - if (namespace == null || prefix == null && namespace.getPrefix().length() == 0) { - namespace = new OMNamespaceImpl(namespaceURI, prefix != null ? prefix : OMSerializerUtil.getNextNSPrefix()); - } - } - } - return addAttribute(new OMAttributeImpl(localName, namespace, value, getOMFactory())); - } - public void build() throws OMException { /** * builder is null. Meaning this is a programatical created element but it has children which are not completed Modified: webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1686664&r1=1686663&r2=1686664&view=diff ============================================================================== --- webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java (original) +++ webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java Sat Jun 20 19:09:06 2015 @@ -20,7 +20,6 @@ package org.apache.axiom.om.impl.llom; import org.apache.axiom.core.CoreChildNode; -import org.apache.axiom.om.OMAttribute; import org.apache.axiom.om.OMCloneOptions; import org.apache.axiom.om.OMContainer; import org.apache.axiom.om.OMDataSource; @@ -335,88 +334,6 @@ public class OMSourcedElementImpl extend return isExpanded; } - public OMNamespace declareNamespace(String uri, String prefix) { - forceExpand(); - return super.declareNamespace(uri, prefix); - } - - public OMNamespace declareDefaultNamespace(String uri) { - forceExpand(); - return super.declareDefaultNamespace(uri); - } - - public OMNamespace getDefaultNamespace() { - forceExpand(); - return super.getDefaultNamespace(); - } - - public OMNamespace declareNamespace(OMNamespace namespace) { - forceExpand(); - return super.declareNamespace(namespace); - } - - public OMNamespace addNamespaceDeclaration(String uri, String prefix) { - return super.addNamespaceDeclaration(uri, prefix); - } - - public void addNamespaceDeclaration(OMNamespace ns) { - super.addNamespaceDeclaration(ns); - } - - public void undeclarePrefix(String prefix) { - forceExpand(); - super.undeclarePrefix(prefix); - } - - public OMNamespace findNamespace(String uri, String prefix) { - forceExpand(); - return super.findNamespace(uri, prefix); - } - - public OMNamespace findNamespaceURI(String prefix) { - forceExpand(); - return super.findNamespaceURI(prefix); - } - - public Iterator getAllDeclaredNamespaces() throws OMException { - forceExpand(); - return super.getAllDeclaredNamespaces(); - } - - public Iterator getAllAttributes() { - forceExpand(); - return super.getAllAttributes(); - } - - public OMAttribute getAttribute(QName qname) { - forceExpand(); - return super.getAttribute(qname); - } - - public String getAttributeValue(QName qname) { - forceExpand(); - return super.getAttributeValue(qname); - } - - public OMAttribute addAttribute(OMAttribute attr) { - forceExpand(); - return super.addAttribute(attr); - } - - public OMAttribute addAttribute(String attributeName, String value, OMNamespace namespace) { - forceExpand(); - return super.addAttribute(attributeName, value, namespace); - } - - void appendAttribute(OMAttribute attr) { - super.appendAttribute(attr); - } - - public void removeAttribute(OMAttribute attr) { - forceExpand(); - super.removeAttribute(attr); - } - public XMLStreamReader getXMLStreamReader(boolean cache) { return getXMLStreamReader(cache, new OMXMLStreamReaderConfiguration()); } @@ -524,11 +441,6 @@ public class OMSourcedElementImpl extend super.setNamespaceWithNoFindInCurrentScope(namespace); } - public void setNamespace(OMNamespace namespace, boolean declare) { - forceExpand(); - super.setNamespace(namespace, declare); - } - public QName getQName() { if (isExpanded()) { return super.getQName(); Modified: webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java?rev=1686664&r1=1686663&r2=1686664&view=diff ============================================================================== --- webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java (original) +++ webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java Sat Jun 20 19:09:06 2015 @@ -148,7 +148,7 @@ public class PushOMBuilder extends Abstr // 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); + ((OMElementImpl)parent).internalAppendAttribute(attr); } protected void doWriteAttribute(String localName, String value) throws XMLStreamException { Modified: webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java?rev=1686664&r1=1686663&r2=1686664&view=diff ============================================================================== --- webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java (original) +++ webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java Sat Jun 20 19:09:06 2015 @@ -22,6 +22,9 @@ package org.apache.axiom.om.impl.llom.fa import org.apache.axiom.core.CoreCDATASection; import org.apache.axiom.core.CoreCharacterData; import org.apache.axiom.core.CoreDocument; +import org.apache.axiom.core.CoreNSAwareAttribute; +import org.apache.axiom.core.CoreNSUnawareAttribute; +import org.apache.axiom.core.CoreNamespaceDeclaration; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMAttribute; import org.apache.axiom.om.OMComment; @@ -40,10 +43,13 @@ import org.apache.axiom.om.OMSourcedElem import org.apache.axiom.om.OMText; import org.apache.axiom.om.OMXMLParserWrapper; import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.axiom.om.impl.common.AxiomAttribute; +import org.apache.axiom.om.impl.common.AxiomNamespaceDeclaration; import org.apache.axiom.om.impl.common.OMNamespaceImpl; import org.apache.axiom.om.impl.common.factory.AxiomNodeFactory; import org.apache.axiom.om.impl.llom.CDATASectionImpl; import org.apache.axiom.om.impl.llom.CharacterDataImpl; +import org.apache.axiom.om.impl.llom.NamespaceDeclaration; import org.apache.axiom.om.impl.llom.OMAttributeImpl; import org.apache.axiom.om.impl.llom.OMCommentImpl; import org.apache.axiom.om.impl.llom.OMDocTypeImpl; @@ -343,4 +349,28 @@ public class OMLinkedListImplFactory imp public CoreCDATASection createCDATASection() { return new CDATASectionImpl(this); } + + public CoreNSUnawareAttribute createAttribute(CoreDocument document, String name, String value, + String type) { + // TODO + throw new UnsupportedOperationException(); + } + + public CoreNSAwareAttribute createAttribute(CoreDocument document, String namespaceURI, + String localName, String prefix, String value, String type) { + // TODO + throw new UnsupportedOperationException(); + } + + public final CoreNamespaceDeclaration createNamespaceDeclaration(CoreDocument document, + String prefix, String namespaceURI) { + // TODO + throw new UnsupportedOperationException(); + } + + public final AxiomNamespaceDeclaration createNamespaceDeclaration(OMNamespace namespace) { + NamespaceDeclaration decl = new NamespaceDeclaration(this); + decl.setDeclaredNamespace(namespace); + return decl; + } }
