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: * MappingModel.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: MappingModel.java,v 1.3 2005/10/18 13:32:37 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 20-Nov-2003 : Initial version
040: *
041: */
042:
043: package org.jfree.xml.generator.model;
044:
045: import java.util.ArrayList;
046: import java.util.HashMap;
047:
048: import org.jfree.util.Log;
049:
050: /**
051: * A mapping model.
052: */
053: public class MappingModel {
054:
055: /** Mapping infos. */
056: private HashMap mappingInfos;
057:
058: /** The manual mappings. */
059: private ArrayList manualMappings;
060:
061: /** The multiplex mappings. */
062: private ArrayList multiplexMappings;
063:
064: /**
065: * Creates a new instance.
066: */
067: public MappingModel() {
068: this .mappingInfos = new HashMap();
069: this .manualMappings = new ArrayList();
070: this .multiplexMappings = new ArrayList();
071: }
072:
073: /**
074: * Returns the multiplex mapping info.
075: *
076: * @return The multiplex mapping info.
077: */
078: public MultiplexMappingInfo[] getMultiplexMapping() {
079: return (MultiplexMappingInfo[]) this .multiplexMappings
080: .toArray(new MultiplexMappingInfo[this .multiplexMappings
081: .size()]);
082: }
083:
084: /**
085: * Returns the manual mapping info.
086: *
087: * @return The manual mapping info.
088: */
089: public ManualMappingInfo[] getManualMapping() {
090: return (ManualMappingInfo[]) this .manualMappings
091: .toArray(new ManualMappingInfo[this .manualMappings
092: .size()]);
093: }
094:
095: /**
096: * Adds a manual mapping.
097: *
098: * @param mappingInfo the mapping.
099: */
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(),
104: mappingInfo);
105: } else {
106: final Object o = this .mappingInfos.get(mappingInfo
107: .getBaseClass());
108: if (o instanceof ManualMappingInfo) {
109: Log.info("Duplicate manual mapping: "
110: + mappingInfo.getBaseClass());
111: } else {
112: throw new IllegalArgumentException(
113: "This mapping is already a multiplex mapping.");
114: }
115: }
116: }
117:
118: /**
119: * Adds a multiplex mapping.
120: *
121: * @param mappingInfo the mapping.
122: */
123: public void addMultiplexMapping(
124: final MultiplexMappingInfo mappingInfo) {
125: if (!this .mappingInfos.containsKey(mappingInfo.getBaseClass())) {
126: this .multiplexMappings.add(mappingInfo);
127: this .mappingInfos.put(mappingInfo.getBaseClass(),
128: mappingInfo);
129: } else {
130: final Object o = this .mappingInfos.get(mappingInfo
131: .getBaseClass());
132: if (o instanceof ManualMappingInfo) {
133: throw new IllegalArgumentException(
134: "This mapping is already a manual mapping.");
135: } else {
136: Log.info("Duplicate Multiplex mapping: "
137: + mappingInfo.getBaseClass(), new Exception());
138: }
139: }
140:
141: }
142:
143: /**
144: * Returns a multiplex mapping for the specified class.
145: *
146: * @param baseClass the base class.
147: *
148: * @return The mapping.
149: */
150: public MultiplexMappingInfo lookupMultiplexMapping(
151: final Class baseClass) {
152: final Object o = this .mappingInfos.get(baseClass);
153: if (o instanceof MultiplexMappingInfo) {
154: return (MultiplexMappingInfo) o;
155: }
156: return null;
157: }
158:
159: }
|