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