View Javadoc

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 java.beans.IntrospectionException;
20  
21  import org.apache.commons.betwixt.ElementDescriptor;
22  
23  /***
24   * @author <a href='http://jakarta.apache.org/'>Apache Commons Team</a>
25   * @version $Revision: 1.2 $
26   */
27  public class SimpleLocalElement extends LocalElement {
28      
29      private String type;
30      
31      public SimpleLocalElement(String name, String type) {
32          super(name);
33          setType(type);
34      }
35      
36      public SimpleLocalElement(
37                                  TranscriptionConfiguration configuration, 
38                                  ElementDescriptor descriptor, 
39                                  Schema schema) 
40                                      throws IntrospectionException {
41          super(descriptor, schema);
42          setType(configuration.getDataTypeMapper().toXMLSchemaDataType(descriptor.getPropertyType()));
43      }
44      
45      public String getType() {
46          return type;
47      }
48  
49      public void setType(String string) {
50          type = string;
51      }
52  
53      public int hashCode() {
54          return getName().hashCode();
55      }
56      
57      public boolean equals(Object obj) {
58          boolean result = false;
59          if (obj instanceof SimpleLocalElement) {
60              SimpleLocalElement simpleLocalElement = (SimpleLocalElement) obj;
61              result = 
62                  isEqual(getName(), simpleLocalElement.getName()) &&
63                  isEqual(getType(), simpleLocalElement.getType());    
64          }
65          return result;
66      }
67      
68      private boolean isEqual(String one, String two) {
69          if (one == null) {
70             return (two == null); 
71          }
72          
73          return one.equals(two);
74      }
75      
76      public String toString() {
77          StringBuffer buffer = new StringBuffer();
78          buffer.append("<element name='");
79          buffer.append(getName());
80          buffer.append("' type='");
81          buffer.append(getType());
82          buffer.append("'/>"); 
83          return buffer.toString();
84      }
85  }