Source for org.jfree.xml.util.MultiplexMappingDefinition

   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:  * MultiplexMappingDefinition.java
  29:  * -------------------------------
  30:  * (C)opyright 2003-2005, by Thomas Morgner and Contributors.
  31:  *
  32:  * Original Author:  Thomas Morgner;
  33:  * Contributor(s):   David Gilbert (for Object Refinery Limited);
  34:  *
  35:  * $Id: MultiplexMappingDefinition.java,v 1.3 2005/10/18 13:33:53 mungady Exp $
  36:  *
  37:  * Changes 
  38:  * -------
  39:  * 22-Nov-2003 : Initial version
  40:  *  
  41:  */
  42: 
  43: package org.jfree.xml.util;
  44: 
  45: import java.util.HashMap;
  46: 
  47: /**
  48:  * Maps a class to ...
  49:  */
  50: public class MultiplexMappingDefinition {
  51: 
  52:     /** The class. */
  53:     private Class baseClass;
  54: 
  55:     /** The attribute name. */
  56:     private String attributeName;
  57:     
  58:     /** The forward mappings. */
  59:     private HashMap forwardMappings;
  60:     
  61:     /** The reverse mappings. */
  62:     private HashMap reverseMappings;
  63: 
  64:     /**
  65:      * Creates a new mapping definition.
  66:      * 
  67:      * @param baseClass  the class.
  68:      * @param attributeName  the attribute name.
  69:      * @param entries  the entries.
  70:      */
  71:     public MultiplexMappingDefinition(final Class baseClass,
  72:                                       final String attributeName,
  73:                                       final MultiplexMappingEntry[] entries) {
  74:         
  75:         this.attributeName = attributeName;
  76:         this.baseClass = baseClass;
  77:         this.forwardMappings = new HashMap();
  78:         this.reverseMappings = new HashMap();
  79: 
  80:         for (int i = 0; i < entries.length; i++) {
  81:             final MultiplexMappingEntry entry = entries[i];
  82:             this.forwardMappings.put(entry.getAttributeValue(), entry);
  83:             this.reverseMappings.put(entry.getTargetClass(), entry);
  84:         }
  85:     }
  86: 
  87:     /**
  88:      * Returns the attribute name.
  89:      * 
  90:      * @return The attribute name.
  91:      */
  92:     public String getAttributeName() {
  93:         return this.attributeName;
  94:     }
  95: 
  96:     /**
  97:      * Returns the class.
  98:      * 
  99:      * @return The class.
 100:      */
 101:     public Class getBaseClass() {
 102:         return this.baseClass;
 103:     }
 104: 
 105:     /**
 106:      * Returns a mapping entry for a type.
 107:      * 
 108:      * @param type  the type.
 109:      * 
 110:      * @return The mapping entry.
 111:      */
 112:     public MultiplexMappingEntry getEntryForType(final String type) {
 113:         return (MultiplexMappingEntry) this.forwardMappings.get(type);
 114:     }
 115: 
 116:     /**
 117:      * Returns a mapping entry for a class.
 118:      * 
 119:      * @param clazz  the class.
 120:      * 
 121:      * @return The mapping entry.
 122:      */
 123:     public MultiplexMappingEntry getEntryForClass(final String clazz) {
 124:         return (MultiplexMappingEntry) this.reverseMappings.get(clazz);
 125:     }
 126: }