1. /*
  2. * Copyright 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.schema;
  17. import org.apache.commons.betwixt.AttributeDescriptor;
  18. /**
  19. * Models the attribute element in an XML schema.
  20. * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
  21. * @version $Revision: 1.2 $
  22. */
  23. public class Attribute {
  24. private String name;
  25. private String type;
  26. public Attribute() {}
  27. public Attribute(String name, String type) {
  28. setName(name);
  29. setType(type);
  30. }
  31. public Attribute(AttributeDescriptor attributeDescriptor) {
  32. this(attributeDescriptor.getQualifiedName(),"xsd:string");
  33. }
  34. /**
  35. * Gets the attribute name
  36. * @return
  37. */
  38. public String getName() {
  39. return name;
  40. }
  41. /**
  42. * Sets the attribute name
  43. * @param string
  44. */
  45. public void setName(String string) {
  46. name = string;
  47. }
  48. /**
  49. * Gets the attribute type
  50. * @return
  51. */
  52. public String getType() {
  53. return type;
  54. }
  55. /**
  56. * Sets the attribute type
  57. * @param string
  58. */
  59. public void setType(String string) {
  60. type = string;
  61. }
  62. public int hashCode() {
  63. return 0;
  64. }
  65. public boolean equals(Object obj) {
  66. boolean result = false;
  67. if (obj instanceof Attribute) {
  68. Attribute attribute = (Attribute) obj;
  69. result = isEqual(type, attribute.type) &&
  70. isEqual(name, attribute.name);
  71. }
  72. return result;
  73. }
  74. /**
  75. * Null safe equals method
  76. * @param one
  77. * @param two
  78. * @return
  79. */
  80. private boolean isEqual(String one, String two) {
  81. boolean result = false;
  82. if (one == null) {
  83. result = (two == null);
  84. }
  85. else
  86. {
  87. result = one.equals(two);
  88. }
  89. return result;
  90. }
  91. public String toString() {
  92. return "<xsd:attribute name='" + name + "' type='" + type + "'/>";
  93. }
  94. }