1 18 package org.objectweb.kilim.description; 19 20 import java.util.LinkedHashMap ; 21 import java.util.Iterator ; 22 23 import org.objectweb.kilim.KilimException; 24 25 29 public class Plug extends TemplateElementImpl { 30 private static String [][] msgTexts = { 31 { "attempt to create a plug with a null slot name", "" }, { "attempt to plug a null instance name ", "" }, { "attempt to define a plug to a slot ", " in a null template" }, { "attempt to add a mapping with a null external name in plug of slot ", "" }, { "attempt to add an already added name mapping : ", " in slot " }, { "attempt to remove a null nam mapping from a plug to slot ", "" }, { "attempt to remove a name mapping from a plug to ", " without name mapping in template " } }; 39 40 private String slotName; 41 private String instanceName; 42 private LinkedHashMap mappings; 43 44 51 public Plug(String aSlotName, String aInstanceName, TemplateDescription aTemplate) throws KilimException { 52 if (aSlotName == null) { 53 throw new KilimException(msgTexts[0][0]); 54 } 55 if (aInstanceName == null) { 56 throw new KilimException(msgTexts[1][0] + msgSuffix1()); 57 } 58 if (aTemplate == null) { 59 throw new KilimException(msgTexts[2][0] + aSlotName + msgTexts[2][1]); 60 } 61 62 slotName = aSlotName; 63 instanceName = aInstanceName; 64 setContainingTemplate(aTemplate); 65 } 66 67 71 public String getSlotName() { 72 return slotName; 73 } 74 75 79 public String getInstanceName() { 80 return instanceName; 81 } 82 83 90 public String getNameMapping(String aName) { 91 if (mappings == null) { 92 return aName; 93 } 94 95 Object name1 = mappings.get(aName); 96 if (name1 == null) { 97 return aName; 98 } else { 99 return (String ) name1; 100 } 101 } 102 103 109 public Iterator getNameMappings() { 110 if (mappings == null) { 111 return KILIM.EMPTY_ITERATOR; 112 } 113 return mappings.values().iterator(); 114 } 115 116 124 public void addNameMapping(String aExternal, String aInternal) throws KilimException { 125 if (aExternal == null) { 126 throw new KilimException(msgTexts[3][0] + msgSuffix1()); 127 } 128 if (mappings == null) { 129 mappings = new LinkedHashMap (); 130 } 131 132 if (mappings.containsKey(aExternal)) { 133 throw new KilimException(msgTexts[4][0] + aExternal + " to " + aInternal + msgTexts[4][1] + msgSuffix1()); 134 } 135 mappings.put(aExternal, aInternal); 136 } 137 138 145 public void removeNameMapping(String aExternal) throws KilimException { 146 if (aExternal == null) { 147 throw new KilimException(msgTexts[5][0] + msgSuffix1()); 148 } 149 150 if (mappings == null) { 151 throw new KilimException(msgTexts[6][0] + slotName + msgTexts[6][1] + msgSuffix1()); 152 } 153 mappings.remove(aExternal); 154 } 155 156 private String msgSuffix1() { 157 return slotName + " in template " + getContainingTemplate(); 158 } 159 } | Popular Tags |