Skip to content

Commit

Permalink
Remove NO_NAMESPACE and XML_NAMESPACE constants from JDOMConstants.
Browse files Browse the repository at this point in the history
These created a 'circular' construct issue on the Namespace class which implmented JDOMConstants. Issue identified by FindBugs, but I could not see any symptoms of an actual problem. Reverted JDOMConstant code just in case.
  • Loading branch information
rolfl committed Dec 7, 2011
1 parent 6e96bfd commit 70f9728
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
36 changes: 18 additions & 18 deletions core/src/java/org/jdom2/Element.java
Expand Up @@ -103,11 +103,11 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* can modify the set by adding and removing Attributes to the Element.
* <p>
* <b>NOTE:</b>
* The {@link Namespace#NO_NAMESPACE NO_NAMESPACE} Namespace is always the
* The {@link Namespace#NO_NAMESPACE Namespace.NO_NAMESPACE} Namespace is always the
* <i>default</i> Namespace for attributes (the Namespace that has no
* prefix). Thus there may be a special case with this Namespace, because
* if there is a different <i>default</i> Namespace for the Element, then
* the NO_NAMESPACE Namespace is not part of the Element's in-scope
* the Namespace.NO_NAMESPACE Namespace is not part of the Element's in-scope
* Namespace set (the Element cannot have two Namespaces in scope with the
* same prefix - "").
* </td>
Expand Down Expand Up @@ -135,7 +135,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* </table>
*
* <p>
* Since you cannot change the XML_NAMESPACE, and the 'inherited' Namespace set
* Since you cannot change the Namespace.XML_NAMESPACE, and the 'inherited' Namespace set
* is dynamic, the remaining Namespace sets are the most interesting from a JDOM
* perspective. JDOM validates all modifications that affect the Namespaces in
* scope for an Element. An IllegalAddException will be thrown if you attempt to
Expand Down Expand Up @@ -305,7 +305,7 @@ public Namespace getNamespace() {
*/
public Element setNamespace(Namespace namespace) {
if (namespace == null) {
namespace = NO_NAMESPACE;
namespace = Namespace.NO_NAMESPACE;
}

String reason = Verifier.checkNamespaceCollision(namespace,
Expand Down Expand Up @@ -363,7 +363,7 @@ public Namespace getNamespace(final String prefix) {

if (NS_PFX_XML.equals(prefix)) {
// Namespace "xml" is always bound.
return XML_NAMESPACE;
return Namespace.XML_NAMESPACE;
}

// Check if the prefix is the prefix for this element
Expand Down Expand Up @@ -1080,7 +1080,7 @@ public List<Attribute> getAttributes() {
* @return attribute for the element
*/
public Attribute getAttribute(final String attname) {
return getAttribute(attname, NO_NAMESPACE);
return getAttribute(attname, Namespace.NO_NAMESPACE);
}

/**
Expand Down Expand Up @@ -1108,7 +1108,7 @@ public Attribute getAttribute(final String attname, final Namespace ns) {
* @return the named attribute's value, or null if no such attribute
*/
public String getAttributeValue(final String attname) {
return getAttributeValue(attname, NO_NAMESPACE);
return getAttributeValue(attname, Namespace.NO_NAMESPACE);
}

/**
Expand All @@ -1123,7 +1123,7 @@ public String getAttributeValue(final String attname) {
* @return the named attribute's value, or the default if no such attribute
*/
public String getAttributeValue(final String attname, final String def) {
return getAttributeValue(attname, NO_NAMESPACE, def);
return getAttributeValue(attname, Namespace.NO_NAMESPACE, def);
}

/**
Expand Down Expand Up @@ -1295,7 +1295,7 @@ public Element setAttribute(final Attribute attribute) {
* @return whether the attribute was removed
*/
public boolean removeAttribute(final String attname) {
return removeAttribute(attname, NO_NAMESPACE);
return removeAttribute(attname, Namespace.NO_NAMESPACE);
}

/**
Expand Down Expand Up @@ -1533,7 +1533,7 @@ public List<Element> getChildren() {
* @return all matching child elements
*/
public List<Element> getChildren(final String cname) {
return getChildren(cname, NO_NAMESPACE);
return getChildren(cname, Namespace.NO_NAMESPACE);
}

/**
Expand Down Expand Up @@ -1586,7 +1586,7 @@ public Element getChild(final String cname, final Namespace ns) {
* @return the first matching child element, or null if not found
*/
public Element getChild(final String cname) {
return getChild(cname, NO_NAMESPACE);
return getChild(cname, Namespace.NO_NAMESPACE);
}

/**
Expand All @@ -1600,7 +1600,7 @@ public Element getChild(final String cname) {
* @return whether deletion occurred
*/
public boolean removeChild(final String cname) {
return removeChild(cname, NO_NAMESPACE);
return removeChild(cname, Namespace.NO_NAMESPACE);
}

/**
Expand Down Expand Up @@ -1638,7 +1638,7 @@ public boolean removeChild(final String cname, final Namespace ns) {
* @return whether deletion occurred
*/
public boolean removeChildren(final String cname) {
return removeChildren(cname, NO_NAMESPACE);
return removeChildren(cname, Namespace.NO_NAMESPACE);
}

/**
Expand Down Expand Up @@ -1677,7 +1677,7 @@ public List<Namespace> getNamespacesInScope() {
// getNamespace*() methods

TreeMap<String,Namespace> namespaces = new TreeMap<String, Namespace>();
namespaces.put(XML_NAMESPACE.getPrefix(), XML_NAMESPACE);
namespaces.put(Namespace.XML_NAMESPACE.getPrefix(), Namespace.XML_NAMESPACE);
namespaces.put(getNamespacePrefix(), getNamespace());
for (Namespace ns : getAdditionalNamespaces()) {
if (!namespaces.containsKey(ns.getPrefix())) {
Expand All @@ -1703,7 +1703,7 @@ public List<Namespace> getNamespacesInScope() {

if (getParentElement() == null && !namespaces.containsKey("")) {
// we are the root element, and there is no 'default' namespace.
namespaces.put(NO_NAMESPACE.getPrefix(), NO_NAMESPACE);
namespaces.put(Namespace.NO_NAMESPACE.getPrefix(), Namespace.NO_NAMESPACE);
}

ArrayList<Namespace> al = new ArrayList<Namespace>(namespaces.size());
Expand All @@ -1720,7 +1720,7 @@ public List<Namespace> getNamespacesInherited() {
ArrayList<Namespace> ret = new ArrayList<Namespace>(getNamespacesInScope());
for (Iterator<Namespace> it = ret.iterator(); it.hasNext();) {
Namespace ns = it.next();
if (ns == NO_NAMESPACE || ns == XML_NAMESPACE) {
if (ns == Namespace.NO_NAMESPACE || ns == Namespace.XML_NAMESPACE) {
continue;
}
it.remove();
Expand Down Expand Up @@ -1749,11 +1749,11 @@ public List<Namespace> getNamespacesInherited() {
@Override
public List<Namespace> getNamespacesIntroduced() {
if (getParentElement() == null) {
// we introduce everything... except XML_NAMESPACE
// we introduce everything... except Namespace.XML_NAMESPACE
List<Namespace> ret = new ArrayList<Namespace>(getNamespacesInScope());
for (Iterator<Namespace> it = ret.iterator(); it.hasNext(); ) {
Namespace ns = it.next();
if (ns == XML_NAMESPACE || ns == NO_NAMESPACE) {
if (ns == Namespace.XML_NAMESPACE || ns == Namespace.NO_NAMESPACE) {
it.remove();
}
}
Expand Down
6 changes: 0 additions & 6 deletions core/src/java/org/jdom2/JDOMConstants.java
Expand Up @@ -43,12 +43,6 @@ public interface JDOMConstants {
/** Defined as '{@value}' */
public static final String NS_URI_XMLNS = "http://www.w3.org/XML/1998/namespace";

/** Defined as {@link Namespace#NO_NAMESPACE} */
public static final Namespace NO_NAMESPACE = Namespace.NO_NAMESPACE;
/** Defined as {@link Namespace#XML_NAMESPACE} */
public static final Namespace XML_NAMESPACE = Namespace.XML_NAMESPACE;



/** Defined as '{@value}' */
public static final String SAX_PROPERTY_DECLARATION_HANDLER =
Expand Down
4 changes: 2 additions & 2 deletions core/src/java/org/jdom2/input/DOMBuilder.java
Expand Up @@ -176,7 +176,7 @@ private void buildTree(Node node,
Namespace ns = null;
String uri = node.getNamespaceURI();
if (uri == null) {
ns = (current == null) ? NO_NAMESPACE
ns = (current == null) ? Namespace.NO_NAMESPACE
: current.getNamespace(prefix);
}
else {
Expand Down Expand Up @@ -252,7 +252,7 @@ private void buildTree(Node node,
Namespace attNS = null;
String attURI = att.getNamespaceURI();
if (attURI == null || NS_URI_DEFAULT.equals(attURI)) {
attNS = NO_NAMESPACE;
attNS = Namespace.NO_NAMESPACE;
} else {
// various conditions can lead here.
// the logical one is that we have a prefix for the
Expand Down

0 comments on commit 70f9728

Please sign in to comment.