001    /* ========================================================================
002     * JCommon : a free general purpose class library for the Java(tm) platform
003     * ========================================================================
004     *
005     * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006     * 
007     * Project Info:  http://www.jfree.org/jcommon/index.html
008     *
009     * This library is free software; you can redistribute it and/or modify it 
010     * under the terms of the GNU Lesser General Public License as published by 
011     * the Free Software Foundation; either version 2.1 of the License, or 
012     * (at your option) any later version.
013     *
014     * This library is distributed in the hope that it will be useful, but 
015     * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016     * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017     * License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this library; if not, write to the Free Software
021     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022     * USA.  
023     *
024     * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025     * in the United States and other countries.]
026     * 
027     * -------------------------
028     * MultiplexMappingInfo.java
029     * -------------------------
030     * (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
031     *
032     * Original Author:  Thomas Morgner;
033     * Contributor(s):   David Gilbert (for Object Refinery Limited);
034     *
035     * $Id: MultiplexMappingInfo.java,v 1.2 2005/10/18 13:32:37 mungady Exp $
036     *
037     * Changes 
038     * -------
039     * 16-Nov-2003 : Initial version
040     *  
041     */
042    
043    package org.jfree.xml.generator.model;
044    
045    import java.util.Arrays;
046    
047    /**
048     * Defines the multiplex entries for a certain base class. Multiplexers are
049     * used to select a specific handler if more than one class will match the
050     * property type.
051     * <p>
052     * Multiplexers override automatic mappings and can be redefined using manual
053     * mappings.
054     */
055    public class MultiplexMappingInfo {
056        
057        /** The base class. */
058        private Class baseClass;
059        
060        /** The type attribute. */
061        private String typeAttribute;
062        
063        /** The child classes. */
064        private TypeInfo[] childClasses;
065        
066        /** The comments. */
067        private Comments comments;
068        
069        /** The source. */
070        private String source;
071    
072        /**
073         * Creates a new instance for the specified class.
074         * 
075         * @param baseClass  the base class.
076         */
077        public MultiplexMappingInfo(final Class baseClass) {
078            this(baseClass, "type");
079        }
080    
081        /**
082         * Creates a new instance for the specified class.
083         * 
084         * @param baseClass  the base class (<code>null</code> not permitted).
085         * @param typeAttribute  the type attribute (<code>null</code> not permitted).
086         */
087        public MultiplexMappingInfo(final Class baseClass, final String typeAttribute) {
088            if (baseClass == null) {
089                throw new NullPointerException("BaseClass");
090            }
091            if (typeAttribute == null) {
092                throw new NullPointerException("TypeAttribute");
093            }
094            this.baseClass = baseClass;
095            this.typeAttribute = typeAttribute;
096        }
097    
098        /**
099         * Returns the base class.
100         * 
101         * @return The base class.
102         */
103        public Class getBaseClass() {
104            return this.baseClass;
105        }
106    
107        /**
108         * Returns the type attribute.
109         * 
110         * @return The type attribute.
111         */
112        public String getTypeAttribute() {
113            return this.typeAttribute;
114        }
115    
116        /**
117         * Returns the child classes.
118         * 
119         * @return The child classes.
120         */
121        public TypeInfo[] getChildClasses() {
122            return this.childClasses;
123        }
124    
125        /**
126         * Sets the child classes.
127         * 
128         * @param childClasses  the child classes.
129         */
130        public void setChildClasses(final TypeInfo[] childClasses) {
131            this.childClasses = childClasses;
132        }
133    
134        /**
135         * Returns the comments.
136         * 
137         * @return The comments.
138         */
139        public Comments getComments() {
140            return this.comments;
141        }
142    
143        /**
144         * Sets the comments.
145         * 
146         * @param comments  the comments.
147         */
148        public void setComments(final Comments comments) {
149            this.comments = comments;
150        }
151    
152        /**
153         * Returns the source.
154         * 
155         * @return The source.
156         */
157        public String getSource() {
158            return this.source;
159        }
160    
161        /**
162         * Sets the source.
163         * 
164         * @param source  the source.
165         */
166        public void setSource(final String source) {
167            this.source = source;
168        }
169    
170        /**
171         * Tests this object for equality with another object.
172         * 
173         * @param o  the other object.
174         * 
175         * @return A boolean.
176         */
177        public boolean equals(final Object o) {
178            if (this == o) {
179                return true;
180            }
181            if (!(o instanceof MultiplexMappingInfo)) {
182                return false;
183            }
184    
185            final MultiplexMappingInfo multiplexMappingInfo = (MultiplexMappingInfo) o;
186    
187            if (!this.baseClass.equals(multiplexMappingInfo.baseClass)) {
188                return false;
189            }
190            if (!Arrays.equals(this.childClasses, multiplexMappingInfo.childClasses)) {
191                return false;
192            }
193            if (!this.typeAttribute.equals(multiplexMappingInfo.typeAttribute)) {
194                return false;
195            }
196    
197            return true;
198        }
199    
200        /**
201         * Returns a hash code for this object.
202         * 
203         * @return A hash code.
204         */
205        public int hashCode() {
206            int result;
207            result = this.baseClass.hashCode();
208            result = 29 * result + this.typeAttribute.hashCode();
209            return result;
210        }
211    
212    }