001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     * 
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */ 
017    
018    package org.apache.commons.betwixt.schema;
019    
020    import java.beans.IntrospectionException;
021    
022    import org.apache.commons.betwixt.ElementDescriptor;
023    
024    /**
025     * @author <a href='http://commons.apache.org/'>Apache Commons Team</a>
026     * @version $Revision: 561314 $
027     */
028    public class SimpleLocalElement extends LocalElement {
029        
030        private String type;
031        
032        public SimpleLocalElement(String name, String type) {
033            super(name);
034            setType(type);
035        }
036        
037        public SimpleLocalElement(
038                                    TranscriptionConfiguration configuration, 
039                                    ElementDescriptor descriptor, 
040                                    Schema schema) 
041                                        throws IntrospectionException {
042            super(descriptor, schema);
043            setType(configuration.getDataTypeMapper().toXMLSchemaDataType(descriptor.getPropertyType()));
044        }
045        
046        public String getType() {
047            return type;
048        }
049    
050        public void setType(String string) {
051            type = string;
052        }
053    
054        public int hashCode() {
055            return getName().hashCode();
056        }
057        
058        public boolean equals(Object obj) {
059            boolean result = false;
060            if (obj instanceof SimpleLocalElement) {
061                SimpleLocalElement simpleLocalElement = (SimpleLocalElement) obj;
062                result = 
063                    isEqual(getName(), simpleLocalElement.getName()) &&
064                    isEqual(getType(), simpleLocalElement.getType());    
065            }
066            return result;
067        }
068        
069        private boolean isEqual(String one, String two) {
070            if (one == null) {
071               return (two == null); 
072            }
073            
074            return one.equals(two);
075        }
076        
077        public String toString() {
078            StringBuffer buffer = new StringBuffer();
079            buffer.append("<element name='");
080            buffer.append(getName());
081            buffer.append("' type='");
082            buffer.append(getType());
083            buffer.append("'/>"); 
084            return buffer.toString();
085        }
086    }