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