1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.betwixt;
  17. /** <p> Common superclass for <code>ElementDescriptor</code>
  18. * and <code>AttributeDescriptor</code>.</p>
  19. *
  20. * <p> Nodes can have just a local name
  21. * or they can have a local name, qualified name and a namespace uri.</p>
  22. *
  23. * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  24. * @version $Revision: 1.10 $
  25. */
  26. public class NodeDescriptor extends Descriptor {
  27. /** The local name of this node without any namespace prefix */
  28. private String localName;
  29. /** The qualified name of the xml node associated with this descriptor. */
  30. private String qualifiedName;
  31. /** The namespace URI of this node */
  32. private String uri = "";
  33. /** Base constructor */
  34. public NodeDescriptor() {
  35. }
  36. /**
  37. * Creates a NodeDescriptor with no namespace URI or prefix.
  38. *
  39. * @param localName the (xml) local name of this node.
  40. * This will be used to set both qualified and local name for this name.
  41. */
  42. public NodeDescriptor(String localName) {
  43. this.localName = localName;
  44. this.qualifiedName = localName;
  45. }
  46. /**
  47. * Creates a NodeDescriptor with namespace URI and qualified name
  48. * @param localName the (xml) local name of this node
  49. * @param qualifiedName the (xml) qualified name of this node
  50. * @param uri the (xml) namespace prefix of this node
  51. */
  52. public NodeDescriptor(String localName, String qualifiedName, String uri) {
  53. this.localName = localName;
  54. this.qualifiedName = qualifiedName;
  55. this.uri = uri;
  56. }
  57. /**
  58. * Gets the local name, excluding any namespace prefix
  59. * @return the (xml) local name of this node
  60. */
  61. public String getLocalName() {
  62. return localName;
  63. }
  64. /**
  65. * Sets the local name
  66. * @param localName the (xml) local name of this node
  67. */
  68. public void setLocalName(String localName) {
  69. this.localName = localName;
  70. }
  71. /**
  72. * Gets the qualified name, including any namespace prefix
  73. * @return the (xml) qualified name of this node. This may be null.
  74. */
  75. public String getQualifiedName() {
  76. if ( qualifiedName == null ) {
  77. qualifiedName = localName;
  78. }
  79. return qualifiedName;
  80. }
  81. /**
  82. * Sets the qualified name
  83. * @param qualifiedName the new (xml) qualified name for this node
  84. */
  85. public void setQualifiedName(String qualifiedName) {
  86. this.qualifiedName = qualifiedName;
  87. }
  88. /**
  89. * Gets the (xml) namespace URI prefix for this node.
  90. * @return the namespace URI that this node belongs to
  91. * or "" if there is no namespace defined
  92. */
  93. public String getURI() {
  94. return uri;
  95. }
  96. /**
  97. * Sets the namespace URI that this node belongs to.
  98. * @param uri the new namespace uri for this node
  99. */
  100. public void setURI(String uri) {
  101. if ( uri == null ) {
  102. throw new IllegalArgumentException(
  103. "The namespace URI cannot be null. "
  104. + "No namespace URI is specified with the empty string"
  105. );
  106. }
  107. this.uri = uri;
  108. }
  109. }