Source for org.jfree.xml.generator.model.MultiplexMappingInfo

   1: /* ========================================================================
   2:  * JCommon : a free general purpose class library for the Java(tm) platform
   3:  * ========================================================================
   4:  *
   5:  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
   6:  * 
   7:  * Project Info:  http://www.jfree.org/jcommon/index.html
   8:  *
   9:  * This library is free software; you can redistribute it and/or modify it 
  10:  * under the terms of the GNU Lesser General Public License as published by 
  11:  * the Free Software Foundation; either version 2.1 of the License, or 
  12:  * (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but 
  15:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  16:  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
  17:  * License for more details.
  18:  *
  19:  * You should have received a copy of the GNU Lesser General Public
  20:  * License along with this library; if not, write to the Free Software
  21:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
  22:  * USA.  
  23:  *
  24:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
  25:  * in the United States and other countries.]
  26:  * 
  27:  * -------------------------
  28:  * MultiplexMappingInfo.java
  29:  * -------------------------
  30:  * (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
  31:  *
  32:  * Original Author:  Thomas Morgner;
  33:  * Contributor(s):   David Gilbert (for Object Refinery Limited);
  34:  *
  35:  * $Id: MultiplexMappingInfo.java,v 1.2 2005/10/18 13:32:37 mungady Exp $
  36:  *
  37:  * Changes 
  38:  * -------
  39:  * 16-Nov-2003 : Initial version
  40:  *  
  41:  */
  42: 
  43: package org.jfree.xml.generator.model;
  44: 
  45: import java.util.Arrays;
  46: 
  47: /**
  48:  * Defines the multiplex entries for a certain base class. Multiplexers are
  49:  * used to select a specific handler if more than one class will match the
  50:  * property type.
  51:  * <p>
  52:  * Multiplexers override automatic mappings and can be redefined using manual
  53:  * mappings.
  54:  */
  55: public class MultiplexMappingInfo {
  56:     
  57:     /** The base class. */
  58:     private Class baseClass;
  59:     
  60:     /** The type attribute. */
  61:     private String typeAttribute;
  62:     
  63:     /** The child classes. */
  64:     private TypeInfo[] childClasses;
  65:     
  66:     /** The comments. */
  67:     private Comments comments;
  68:     
  69:     /** The source. */
  70:     private String source;
  71: 
  72:     /**
  73:      * Creates a new instance for the specified class.
  74:      * 
  75:      * @param baseClass  the base class.
  76:      */
  77:     public MultiplexMappingInfo(final Class baseClass) {
  78:         this(baseClass, "type");
  79:     }
  80: 
  81:     /**
  82:      * Creates a new instance for the specified class.
  83:      * 
  84:      * @param baseClass  the base class (<code>null</code> not permitted).
  85:      * @param typeAttribute  the type attribute (<code>null</code> not permitted).
  86:      */
  87:     public MultiplexMappingInfo(final Class baseClass, final String typeAttribute) {
  88:         if (baseClass == null) {
  89:             throw new NullPointerException("BaseClass");
  90:         }
  91:         if (typeAttribute == null) {
  92:             throw new NullPointerException("TypeAttribute");
  93:         }
  94:         this.baseClass = baseClass;
  95:         this.typeAttribute = typeAttribute;
  96:     }
  97: 
  98:     /**
  99:      * 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: }