[ https://issues.apache.org/jira/browse/WSCOMMONS-557?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12901290#action_12901290 ]
Amila Jayasekara edited comment on WSCOMMONS-557 at 8/23/10 3:30 AM: --------------------------------------------------------------------- Hi Andreas, It seems to be the way i understood org.apache.axiom.om.impl.dom.ElementImpl implementation is not quite correct. Also I am facing few difficulties, understanding org.apache.axiom.om.impl.dom.ElementImpl implementation. Let me explain my issue in detail. Assume i have following xml, <root><child xmlns=""/></root> According to above xml the element "child" is having an empty namespace. During a debug session i found following values of ElementImpl relevant to element "child", ElementImpl.namespace = null ElementImpl.namespaces = {java.util.hash...@965} size = 1 [0] = {java.util.hashmap$en...@980} -> org.apache.axiom.om.impl.dom.namespacei...@0 key: java.lang.String = {java.lang.str...@982}"" value: org.apache.axiom.om.impl.dom.NamespaceImpl = {org.apache.axiom.om.impl.dom.namespacei...@986} nsUri = {java.lang.str...@982}"" nsPrefix = {java.lang.str...@982}"" As per above values ElementImpl.namespaces is having an element. Thus the nsPrefix of that element is an empty string. This should be the namespace we defined for "child" element. (i.e. <child xmlns=""/>) So what is the convention here ? Are we assuming when the nsPrefix is null, it represents xmlns ? Also i found some code in ElementImpl.getAttributes() method which made me confuse, // Add the NS declarations if (this.namespaces != null) { Iterator nsDecls = this.namespaces.keySet().iterator(); while (nsDecls.hasNext()) { String prefix = (String) nsDecls.next(); if (prefix != null && !"".equals(prefix) && !prefix.equals(OMConstants.XMLNS_NS_PREFIX)) { <------------------------- Here we are checking whether prefix is not equal to "xmlns". If we are interpreting nsPrefix="" as xmlns we will never encounter this condition. Do we ? OMNamespace ns = (OMNamespace) this.namespaces.get(prefix); AttrImpl attr = new AttrImpl(this.ownerNode, prefix, ns .getNamespaceURI(), this.factory); attr.setOMNamespace(new NamespaceImpl( OMConstants.XMLNS_NS_URI, OMConstants.XMLNS_NS_PREFIX)); attributeMap.addItem(attr); } } ....... ..... ... According to the DOM API the ElementImpl.getAttributes() should return attributes and namespaces attached to an element. But ElementImpl.getAttributes() is checking ElementImpl.namespace varriable and does a traversal. I dont understand why we need this. Cos we are querying attributes and namespaces through ElementImpl.namespaces. Thanks AmilaJ was (Author: amilaj): Hi Andreas, It seems to be the way i understood org.apache.axiom.om.impl.dom.ElementImpl implementation is not quite correct. Also I am facing few difficulties, understanding org.apache.axiom.om.impl.dom.ElementImpl implementation. Let me explain my issue in detail. Assume i have following xml, <root><child xmlns=""/></root> According to above xml the element "child" is having an empty namespace. During a debug session i found following values of ElementImpl relevant to element "child", ElementImpl.namespace = null ElementImpl.namespaces = {java.util.hash...@965} size = 1 [0] = {java.util.hashmap$en...@980} -> org.apache.axiom.om.impl.dom.namespacei...@0 key: java.lang.String = {java.lang.str...@982}"" value: org.apache.axiom.om.impl.dom.NamespaceImpl = {org.apache.axiom.om.impl.dom.namespacei...@986} nsUri = {java.lang.str...@982}"" nsPrefix = {java.lang.str...@982}"" As per above values ElementImpl.namespaces is having an element. Thus the nsPrefix of that element is an empty string. This should be the namespace we defined for "child" element. (i.e. <child xmlns=""/>) So what is the convention here ? Are we assuming when the nsPrefix is null, it represents xmlns ? Also i found some code in ElementImpl.getAttributes() method which made me confuse, // Add the NS declarations if (this.namespaces != null) { Iterator nsDecls = this.namespaces.keySet().iterator(); while (nsDecls.hasNext()) { String prefix = (String) nsDecls.next(); if (prefix != null && !"".equals(prefix) && !prefix.equals(OMConstants.XMLNS_NS_PREFIX)) { <------------------------- Here we are checking whether prefix is not equal to "xmlns". If we are interpreting nsPrefix="" as xmlns we will never encounter this condition. Do we ? OMNamespace ns = (OMNamespace) this.namespaces.get(prefix); AttrImpl attr = new AttrImpl(this.ownerNode, prefix, ns .getNamespaceURI(), this.factory); attr.setOMNamespace(new NamespaceImpl( OMConstants.XMLNS_NS_URI, OMConstants.XMLNS_NS_PREFIX)); attributeMap.addItem(attr); } } ....... ..... ... According to the DOM API the ElementImpl.getAttributes() should return attributes and namespaces attached to an element. But ElementImpl.getAttributes() is checking ElementImpl.namespace varriable and does a traversal. I dont understand why we need this. Cos we are querying attributes and namespaces through ElementImpl.namespaces. > org.apache.axiom.om.impl.dom.ElementImpl class's hasAttributes() and > getAttributes() methods are not compatible with DOM interfaces. > ------------------------------------------------------------------------------------------------------------------------------------ > > Key: WSCOMMONS-557 > URL: https://issues.apache.org/jira/browse/WSCOMMONS-557 > Project: WS-Commons > Issue Type: Bug > Components: AXIOM > Affects Versions: Axiom 1.2.10 > Environment: Ubuntu, JDK 1.6 > Reporter: Amila Jayasekara > Assignee: Andreas Veithen > Attachments: WSCOMMONS-557.diff > > > The class org.apache.axiom.om.impl.dom.ElementImpl implements both DOM > Element and OMElement interfaces. According to DOM API the method > hasAttrbutes() should return true if there are attributes attached to current > node. Also this method will return true if there are namespaces attached to > current node. But according to current implementation the ElementImpl class > only checks for namespace nullability. This code will fail if we have a xml > like follows, > <?xml version='1.0' encoding='utf-8'?> > <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" > xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" > wsu:Id="Id-739587016"> > <GetDirectionsResponse xmlns="http://www.example.org/webservices/"> > <GetDirectionsResult> > <drivingdirections xmlns=""> > <route distanceToTravel="500m" finalStep="false" id="0">Head south on > Grove St</route> > </drivingdirections> > </GetDirectionsResult> > </GetDirectionsResponse> > </soapenv:Body> > In above xml the node "drivingdirections" is having an empty namespace. But > for "drivingdirections" node, the method "hasAttribute()" should return true, > as there is a namespace attached to it. But current implementation of > ElementImpl returns false. > Also getAttributes() method should return empty namespace ("xmlns=\"\"") for > "drivingdirections" node. Current implementation doesnt return empty > namespace as an attribute. Since namespace of drivingdirections is empty, > namespace of child elements of "drivingdirections" are also null. Therefore > hasAttribute() method will return false for even elements like "route". > ("route" element has attributes, therefore hasAttribute() should return true) > There are 2 rampart issues which depends on this. > [1] https://issues.apache.org/jira/browse/RAMPART-303 > [2] https://issues.apache.org/jira/browse/RAMPART-128 -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.