1 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 53 public class MappingModel { 54 55 56 private HashMap mappingInfos; 57 58 59 private ArrayList manualMappings; 60 61 62 private ArrayList multiplexMappings; 63 64 67 public MappingModel() { 68 this.mappingInfos = new HashMap (); 69 this.manualMappings = new ArrayList (); 70 this.multiplexMappings = new ArrayList (); 71 } 72 73 78 public MultiplexMappingInfo[] getMultiplexMapping() { 79 return (MultiplexMappingInfo[]) this.multiplexMappings.toArray( 80 new MultiplexMappingInfo[this.multiplexMappings.size()] 81 ); 82 } 83 84 89 public ManualMappingInfo[] getManualMapping() { 90 return (ManualMappingInfo[]) this.manualMappings.toArray( 91 new ManualMappingInfo[this.manualMappings.size()] 92 ); 93 } 94 95 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 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 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 } 158 | Popular Tags |