1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
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.
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.
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,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
30
* (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
32
* Original Author: Thomas Morgner;
33
* Contributor(s): David Gilbert (for Object Refinery Limited);
35
* $Id: MappingModel.java,v 1.3 2005/10/18 13:32:37 mungady Exp $
39
* 20-Nov-2003 : Initial version
43
package org.jfree.xml.generator.model;
45
import java.util.ArrayList;
46
import java.util.HashMap;
48
import org.jfree.util.Log;
53
public class MappingModel {
56
private HashMap mappingInfos;
58
/** The manual mappings. */
59
private ArrayList manualMappings;
61
/** The multiplex mappings. */
62
private ArrayList multiplexMappings;
65
* Creates a new instance.
67
public MappingModel() {
68
this.mappingInfos = new HashMap();
69
this.manualMappings = new ArrayList();
70
this.multiplexMappings = new ArrayList();
74
* Returns the multiplex mapping info.
76
* @return The multiplex mapping info.
78
public MultiplexMappingInfo[] getMultiplexMapping() {
79
return (MultiplexMappingInfo[]) this.multiplexMappings.toArray(
80
new MultiplexMappingInfo[this.multiplexMappings.size()]
85
* Returns the manual mapping info.
87
* @return The manual mapping info.
89
public ManualMappingInfo[] getManualMapping() {
90
return (ManualMappingInfo[]) this.manualMappings.toArray(
91
new ManualMappingInfo[this.manualMappings.size()]
96
* Adds a manual mapping.
98
* @param mappingInfo the mapping.
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);
106
final Object o = this.mappingInfos.get(mappingInfo.getBaseClass());
107
if (o instanceof ManualMappingInfo) {
108
Log.info ("Duplicate manual mapping: " + mappingInfo.getBaseClass());
111
throw new IllegalArgumentException
112
("This mapping is already a multiplex mapping.");
118
* Adds a multiplex mapping.
120
* @param mappingInfo the mapping.
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);
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.");
135
"Duplicate Multiplex mapping: " + mappingInfo.getBaseClass(), new Exception()
143
* Returns a multiplex mapping for the specified class.
145
* @param baseClass the base class.
147
* @return The mapping.
149
public MultiplexMappingInfo lookupMultiplexMapping(final Class baseClass) {
150
final Object o = this.mappingInfos.get(baseClass);
151
if (o instanceof MultiplexMappingInfo) {
152
return (MultiplexMappingInfo) o;