1 18 package org.objectweb.kilim.description; 19 20 import java.util.Iterator ; 21 import java.util.List ; 22 import java.util.ArrayList ; 23 24 import org.objectweb.kilim.KilimException; 25 26 30 public class Slot extends TemplateElementImpl implements NamedElement { 31 32 private static String [][] msgTexts = { 33 { "attempt to create a slot with a null name in template ", "" }, { "attempt to create a slot ", " in a null template" }, { "attempt to set a null name to a slot in template ", "" }, { "attempt to use an undefined status ", " for a slot " }, { "attempt to set a null name to a slot in template ", "" }, { "attempt ot add a null port in slot ", "" }, { "attempt to add an already added port ", " in slot " }, { "attempt to remove a null port from a slot ", "" }, { "attempt to remove a port from an empty slot ", "" }, { "attempt to add a null binding frin slot ", "" }, { "attempt to remove a null binding from a slot ", "" }, { "attempt to add an already added binding ", " in slot " }, { "attempt to remove a binding from an empty slot ", "" } }; 47 48 private String slotName; 49 private int status; 50 private List ports; 51 52 59 public Slot(String aSlotName, int aStatus, TemplateDescription aTemplate) throws KilimException { 60 if (aSlotName == null) { 61 throw new KilimException(msgTexts[0][0] + aTemplate); 62 } 63 if (aTemplate == null) { 64 throw new KilimException(msgTexts[1][0] + aSlotName + msgTexts[1][1]); 65 } 66 checkStatus(aStatus); 67 slotName = aSlotName; 68 status = aStatus; 69 setContainingTemplate(aTemplate); 70 } 71 72 75 public String getLocalName() { 76 return slotName; 77 } 78 79 82 public void setLocalName(String aName) throws KilimException { 83 if (aName == null) { 84 throw new KilimException(msgTexts[2][0] + getContainingTemplate()); 85 } 86 87 slotName = aName; 88 } 89 90 93 public int getStatus() { 94 return status; 95 } 96 97 100 public void setStatus(int aStatus) throws KilimException { 101 checkStatus(aStatus); 102 status = aStatus; 103 } 104 105 110 private void checkStatus(int aStatus) throws KilimException { 111 if (aStatus < 1 || aStatus > 3) { 112 throw new KilimException(msgTexts[3][0] + aStatus + msgTexts[3][1] + msgSuffix1()); 113 } 114 } 115 116 120 public Iterator getPorts() { 121 if (ports == null) { 122 return KILIM.EMPTY_ITERATOR; 123 } 124 return ports.listIterator(); 125 } 126 127 132 public void addPort(Port aPort) throws KilimException { 133 if (aPort == null) { 134 throw new KilimException(msgTexts[4][0] + msgSuffix1()); 135 } 136 if (ports == null) { 137 ports = new ArrayList (); 138 } 139 140 if (ports.contains(aPort)) { 141 throw new KilimException(msgTexts[6][0] + aPort.getLocalName() + msgTexts[6][1] + msgSuffix1()); 142 } 143 ports.add(aPort); 144 } 145 146 151 public void removePort(Port aPort) throws KilimException { 152 if (aPort == null) { 153 throw new KilimException(msgTexts[7][0] + msgSuffix1()); 154 } 155 156 if (ports == null) { 157 throw new KilimException(msgTexts[8][0] + msgSuffix1()); 158 } 159 ports.remove(aPort); 160 } 161 162 private String msgSuffix1() { 163 return slotName + " in template " + getContainingTemplate().getName(); 164 } 165 } | Popular Tags |