Frames | No Frames |
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: * MappingModel.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: MappingModel.java,v 1.3 2005/10/18 13:32:37 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 20-Nov-2003 : Initial version 40: * 41: */ 42: 43: package org.jfree.xml.generator.model; 44: 45: import java.util.ArrayList; 46: import java.util.HashMap; 47: 48: import org.jfree.util.Log; 49: 50: /** 51: * A mapping model. 52: */ 53: public class MappingModel { 54: 55: /** Mapping infos. */ 56: private HashMap mappingInfos; 57: 58: /** The manual mappings. */ 59: private ArrayList manualMappings; 60: 61: /** The multiplex mappings. */ 62: private ArrayList multiplexMappings; 63: 64: /** 65: * Creates a new instance. 66: */ 67: public MappingModel() { 68: this.mappingInfos = new HashMap(); 69: this.manualMappings = new ArrayList(); 70: this.multiplexMappings = new ArrayList(); 71: } 72: 73: /** 74: * Returns the multiplex mapping info. 75: * 76: * @return The multiplex mapping info. 77: */ 78: public MultiplexMappingInfo[] getMultiplexMapping() { 79: return (MultiplexMappingInfo[]) this.multiplexMappings.toArray( 80: new MultiplexMappingInfo[this.multiplexMappings.size()] 81: ); 82: } 83: 84: /** 85: * Returns the manual mapping info. 86: * 87: * @return The manual mapping info. 88: */ 89: public ManualMappingInfo[] getManualMapping() { 90: return (ManualMappingInfo[]) this.manualMappings.toArray( 91: new ManualMappingInfo[this.manualMappings.size()] 92: ); 93: } 94: 95: /** 96: * Adds a manual mapping. 97: * 98: * @param mappingInfo the mapping. 99: */ 100: public void addManualMapping(final ManualMappingInfo mappingInfo) { 101: if (!this.mappingInfos.containsKey(mappingInfo.getBaseClass())) { 102: this.manualMappings.add(mappingInfo); 103: this.mappingInfos.put(mappingInfo.getBaseClass(), mappingInfo); 104: } 105: else { 106: final Object o = this.mappingInfos.get(mappingInfo.getBaseClass()); 107: if (o instanceof ManualMappingInfo) { 108: Log.info ("Duplicate manual mapping: " + mappingInfo.getBaseClass()); 109: } 110: else { 111: throw new IllegalArgumentException 112: ("This mapping is already a multiplex mapping."); 113: } 114: } 115: } 116: 117: /** 118: * Adds a multiplex mapping. 119: * 120: * @param mappingInfo the mapping. 121: */ 122: public void addMultiplexMapping(final MultiplexMappingInfo mappingInfo) { 123: if (!this.mappingInfos.containsKey(mappingInfo.getBaseClass())) { 124: this.multiplexMappings.add(mappingInfo); 125: this.mappingInfos.put(mappingInfo.getBaseClass(), mappingInfo); 126: } 127: else { 128: final Object o = this.mappingInfos.get(mappingInfo.getBaseClass()); 129: if (o instanceof ManualMappingInfo) { 130: throw new IllegalArgumentException 131: ("This mapping is already a manual mapping."); 132: } 133: else { 134: Log.info( 135: "Duplicate Multiplex mapping: " + mappingInfo.getBaseClass(), new Exception() 136: ); 137: } 138: } 139: 140: } 141: 142: /** 143: * Returns a multiplex mapping for the specified class. 144: * 145: * @param baseClass the base class. 146: * 147: * @return The mapping. 148: */ 149: public MultiplexMappingInfo lookupMultiplexMapping(final Class baseClass) { 150: final Object o = this.mappingInfos.get(baseClass); 151: if (o instanceof MultiplexMappingInfo) { 152: return (MultiplexMappingInfo) o; 153: } 154: return null; 155: } 156: 157: }