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 org.apache.commons.betwixt.AttributeDescriptor;
021    
022    
023    /**
024     * Models the attribute element in an XML schema.
025     * @author <a href='http://commons.apache.org/'>Apache Commons Team</a>
026     * @version $Revision: 561314 $
027     */
028    public class Attribute {
029    
030            private String name;
031            private String type;
032    
033    
034            public Attribute() {}
035            
036            public Attribute(String name, String type) {
037                    setName(name);
038                    setType(type);
039            }
040        
041        public Attribute(AttributeDescriptor attributeDescriptor) {
042            this(attributeDescriptor.getQualifiedName(),"xsd:string");
043        }
044            
045    
046        /**
047         * Gets the attribute name
048         * @return name of this attribute, not null
049         */
050        public String getName() {
051            return name;
052        }
053    
054        /**
055         * Sets the attribute name
056         * @param string the name for this attribute, not null
057         */
058        public void setName(String string) {
059            name = string;
060        }
061    
062            /**
063             * Gets the attribute type
064             * @return the type of this attribute
065             */
066            public String getType() {
067                    return type;
068            }
069    
070        /**
071         * Sets the attribute type
072         * @param string the attribute type
073         */
074        public void setType(String string) {
075            type = string;
076        }
077    
078        public int hashCode() {
079            return 0;
080        }
081    
082        public boolean equals(Object obj) {
083            boolean result = false;
084            if (obj instanceof Attribute) {
085                Attribute attribute = (Attribute) obj;
086                result = isEqual(type, attribute.type) &&
087                         isEqual(name, attribute.name);           
088            }
089            return result;
090        }
091    
092        /**
093         * Null safe equals method
094         * @param one
095         * @param two
096         * @return
097         */
098        private boolean isEqual(String one, String two) {
099            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    }