View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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://commons.apache.org/'>Apache Commons Team</a>
26   * @version $Revision: 561314 $
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 }