1 18 19 package org.objectweb.kilim.model.mapping; 20 21 import java.util.HashMap ; 22 23 import org.objectweb.kilim.KilimException; 24 25 39 40 public class DefaultMappingStrategy implements MappingStrategy { 41 private Mapper defaultMapper = new JavaRuntimeMapper(); 42 private HashMap perTemplateMapper; 43 private HashMap perInstanceMapper; 44 45 48 public DefaultMappingStrategy() throws KilimException { 49 } 50 51 57 public DefaultMappingStrategy(Mapper aMapper) throws KilimException { 58 setDefaultMapper(aMapper); 59 } 60 61 64 public void setDefaultMapper(Mapper aMapper) throws KilimException { 65 if (aMapper == null) { 66 throw new KilimException("attempt to install a null mapper as default"); 67 } 68 defaultMapper = aMapper; 69 } 70 71 74 public Mapper getDefaultMapper() { 75 return defaultMapper; 76 } 77 78 81 public void setPerTemplateMapper(String aName, Mapper aMapper) throws KilimException { 82 if (aName == null) { 83 throw new KilimException("attempt to install a manager for template through a null name"); 84 } 85 86 if (perTemplateMapper == null) { 87 perTemplateMapper = new HashMap (); 88 } 89 perTemplateMapper.put(aName, aMapper); 90 } 91 92 95 public Mapper getPerTemplateMapper(String aName) throws KilimException { 96 if (aName == null) { 97 throw new KilimException("attempt to get a template manager through a null name "); 98 } 99 100 if (perTemplateMapper == null) { 101 return null; 102 } 103 return (Mapper) perTemplateMapper.get(aName); 104 } 105 106 109 public void setPerInstanceMapper(String aName, Mapper aMapper) throws KilimException { 110 if (aMapper == null) { 111 throw new KilimException("attempt to install a null mapper for template " + aName); 112 } 113 114 if (perInstanceMapper == null) { 115 perInstanceMapper = new HashMap (); 116 } 117 perInstanceMapper.put(aName, aMapper); 118 } 119 120 123 public Mapper getPerInstanceMapper(String aName) throws KilimException { 124 if (aName == null) { 125 throw new KilimException("attempt to get a instance manager through a null name "); 126 } 127 128 if (perInstanceMapper == null) { 129 return null; 130 } 131 return (Mapper) perInstanceMapper.get(aName); 132 } 133 } 134 | Popular Tags |