Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
GlobalElement |
|
| 1.2307692307692308;1.231 |
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 | ||
20 | ||
21 | /** |
|
22 | * Models a global definition of an <code>element</code>. |
|
23 | * @author <a href='http://jakarta.apache.org/'>Apache Commons Team</a> |
|
24 | * @version $Revision: 190509 $ |
|
25 | */ |
|
26 | public class GlobalElement implements Element { |
|
27 | //TODO: going to ignore the issue of namespacing for the moment |
|
28 | public static final String STRING_SIMPLE_TYPE="xsd:string"; |
|
29 | ||
30 | private String name; |
|
31 | private String type; |
|
32 | ||
33 | private GlobalComplexType complexType; |
|
34 | ||
35 | 247 | public GlobalElement() {} |
36 | ||
37 | 325 | public GlobalElement(String name, String type) { |
38 | 325 | setName(name); |
39 | 325 | setType(type); |
40 | 325 | } |
41 | ||
42 | 52 | public GlobalElement(String name, GlobalComplexType complexType) { |
43 | 52 | setName(name); |
44 | 52 | setComplexType(complexType); |
45 | 52 | } |
46 | ||
47 | ||
48 | ||
49 | ||
50 | /** |
|
51 | * Gets the element name |
|
52 | * @return element name, not null |
|
53 | */ |
|
54 | public String getName() { |
|
55 | 364 | return name; |
56 | } |
|
57 | ||
58 | /** |
|
59 | * Sets the element name |
|
60 | * @param string not null |
|
61 | */ |
|
62 | public void setName(String string) { |
|
63 | 624 | name = string; |
64 | 624 | } |
65 | ||
66 | /** |
|
67 | * Gets the element type |
|
68 | * @return the type of the element |
|
69 | */ |
|
70 | public String getType() { |
|
71 | 364 | return type; |
72 | } |
|
73 | ||
74 | /** |
|
75 | * Sets the element type |
|
76 | * @param string |
|
77 | */ |
|
78 | public void setType(String string) { |
|
79 | 325 | type = string; |
80 | 325 | } |
81 | ||
82 | ||
83 | /** |
|
84 | * Gets the anonymous type definition for this element, if one exists. |
|
85 | * @return ComplexType, null if there is no associated anonymous type definition |
|
86 | */ |
|
87 | public GlobalComplexType getComplexType() { |
|
88 | 0 | return complexType; |
89 | } |
|
90 | ||
91 | /** |
|
92 | * Sets the anonymous type definition for this element |
|
93 | * @param type ComplexType to be set as the anonymous type definition, |
|
94 | * null if the type is to be referenced |
|
95 | */ |
|
96 | public void setComplexType(GlobalComplexType type) { |
|
97 | 299 | this.type = type.getName(); |
98 | 299 | complexType = type; |
99 | 299 | } |
100 | ||
101 | public boolean equals(Object obj) { |
|
102 | 2769 | boolean result = false; |
103 | 2769 | if (obj instanceof GlobalElement) { |
104 | 845 | GlobalElement element = (GlobalElement) obj; |
105 | 1690 | result = isEqual(type, element.type) && |
106 | 182 | isEqual(name, element.name); |
107 | } |
|
108 | 2769 | return result; |
109 | } |
|
110 | ||
111 | public int hashCode() { |
|
112 | 728 | return 0; |
113 | } |
|
114 | ||
115 | /** |
|
116 | * Null safe equals method |
|
117 | * @param one |
|
118 | * @param two |
|
119 | * @return |
|
120 | */ |
|
121 | private boolean isEqual(String one, String two) { |
|
122 | 1027 | boolean result = false; |
123 | 1027 | if (one == null) { |
124 | 0 | result = (two == null); |
125 | } |
|
126 | else |
|
127 | { |
|
128 | 1027 | result = one.equals(two); |
129 | } |
|
130 | ||
131 | 1027 | return result; |
132 | } |
|
133 | ||
134 | public String toString() { |
|
135 | 0 | StringBuffer buffer = new StringBuffer(); |
136 | 0 | buffer.append("<xsd:element name='"); |
137 | 0 | buffer.append(name); |
138 | 0 | buffer.append("' type='"); |
139 | 0 | buffer.append(type); |
140 | 0 | buffer.append("'>"); |
141 | ||
142 | 0 | if (complexType != null) { |
143 | 0 | buffer.append(complexType); |
144 | } |
|
145 | 0 | buffer.append("</xsd:element>"); |
146 | 0 | return buffer.toString(); |
147 | } |
|
148 | ||
149 | ||
150 | } |