1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.betwixt.schema;
19
20 import org.apache.commons.betwixt.AttributeDescriptor;
21
22
23 /***
24 * Models the attribute element in an XML schema.
25 * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
26 * @version $Revision: 438373 $
27 */
28 public class Attribute {
29
30 private String name;
31 private String type;
32
33
34 public Attribute() {}
35
36 public Attribute(String name, String type) {
37 setName(name);
38 setType(type);
39 }
40
41 public Attribute(AttributeDescriptor attributeDescriptor) {
42 this(attributeDescriptor.getQualifiedName(),"xsd:string");
43 }
44
45
46 /***
47 * Gets the attribute name
48 * @return name of this attribute, not null
49 */
50 public String getName() {
51 return name;
52 }
53
54 /***
55 * Sets the attribute name
56 * @param string the name for this attribute, not null
57 */
58 public void setName(String string) {
59 name = string;
60 }
61
62 /***
63 * Gets the attribute type
64 * @return the type of this attribute
65 */
66 public String getType() {
67 return type;
68 }
69
70 /***
71 * Sets the attribute type
72 * @param string the attribute type
73 */
74 public void setType(String string) {
75 type = string;
76 }
77
78 public int hashCode() {
79 return 0;
80 }
81
82 public boolean equals(Object obj) {
83 boolean result = false;
84 if (obj instanceof Attribute) {
85 Attribute attribute = (Attribute) obj;
86 result = isEqual(type, attribute.type) &&
87 isEqual(name, attribute.name);
88 }
89 return result;
90 }
91
92 /***
93 * Null safe equals method
94 * @param one
95 * @param two
96 * @return
97 */
98 private boolean isEqual(String one, String two) {
99 boolean result = false;
100 if (one == null) {
101 result = (two == null);
102 }
103 else
104 {
105 result = one.equals(two);
106 }
107
108 return result;
109 }
110
111 public String toString() {
112 return "<xsd:attribute name='" + name + "' type='" + type + "'/>";
113 }
114
115 }