Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
Attribute |
|
| 1.1818181818181819;1.182 |
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 | ||
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/'>Apache Commons Team</a> |
|
25 | * @version $Revision: 190509 $ |
|
26 | */ |
|
27 | public class Attribute { |
|
28 | ||
29 | private String name; |
|
30 | private String type; |
|
31 | ||
32 | ||
33 | 0 | public Attribute() {} |
34 | ||
35 | 1105 | public Attribute(String name, String type) { |
36 | 1105 | setName(name); |
37 | 1105 | setType(type); |
38 | 1105 | } |
39 | ||
40 | public Attribute(AttributeDescriptor attributeDescriptor) { |
|
41 | 845 | this(attributeDescriptor.getQualifiedName(),"xsd:string"); |
42 | 845 | } |
43 | ||
44 | ||
45 | /** |
|
46 | * Gets the attribute name |
|
47 | * @return name of this attribute, not null |
|
48 | */ |
|
49 | public String getName() { |
|
50 | 585 | 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 | 1105 | name = string; |
59 | 1105 | } |
60 | ||
61 | /** |
|
62 | * Gets the attribute type |
|
63 | * @return the type of this attribute |
|
64 | */ |
|
65 | public String getType() { |
|
66 | 585 | return type; |
67 | } |
|
68 | ||
69 | /** |
|
70 | * Sets the attribute type |
|
71 | * @param string the attribute type |
|
72 | */ |
|
73 | public void setType(String string) { |
|
74 | 1105 | type = string; |
75 | 1105 | } |
76 | ||
77 | public int hashCode() { |
|
78 | 1066 | return 0; |
79 | } |
|
80 | ||
81 | public boolean equals(Object obj) { |
|
82 | 9230 | boolean result = false; |
83 | 9230 | if (obj instanceof Attribute) { |
84 | 3354 | Attribute attribute = (Attribute) obj; |
85 | 6708 | result = isEqual(type, attribute.type) && |
86 | 3354 | isEqual(name, attribute.name); |
87 | } |
|
88 | 9230 | 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 | 6708 | boolean result = false; |
99 | 6708 | if (one == null) { |
100 | 0 | result = (two == null); |
101 | } |
|
102 | else |
|
103 | { |
|
104 | 6708 | result = one.equals(two); |
105 | } |
|
106 | ||
107 | 6708 | return result; |
108 | } |
|
109 | ||
110 | public String toString() { |
|
111 | 0 | return "<xsd:attribute name='" + name + "' type='" + type + "'/>"; |
112 | } |
|
113 | ||
114 | } |