KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > schema > Attribute


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/'>Jakarta Commons Team</a>
25  * @version $Revision: 1.2 $
26  */

27 public class Attribute {
28
29     private String JavaDoc name;
30     private String JavaDoc type;
31
32
33     public Attribute() {}
34     
35     public Attribute(String JavaDoc name, String JavaDoc 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
48      */

49     public String JavaDoc getName() {
50         return name;
51     }
52
53     /**
54      * Sets the attribute name
55      * @param string
56      */

57     public void setName(String JavaDoc string) {
58         name = string;
59     }
60
61     /**
62      * Gets the attribute type
63      * @return
64      */

65     public String JavaDoc getType() {
66         return type;
67     }
68
69     /**
70      * Sets the attribute type
71      * @param string
72      */

73     public void setType(String JavaDoc string) {
74         type = string;
75     }
76
77     public int hashCode() {
78         return 0;
79     }
80
81     public boolean equals(Object JavaDoc 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 JavaDoc one, String JavaDoc 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 JavaDoc toString() {
111         return "<xsd:attribute name='" + name + "' type='" + type + "'/>";
112     }
113         
114 }
115
Popular Tags