1 18 19 package org.objectweb.kilim.model; 20 21 import java.util.HashMap ; 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.Stack ; 26 27 import org.objectweb.kilim.KilimConfiguration; 28 import org.objectweb.kilim.KilimException; 29 import org.objectweb.kilim.description.KILIM; 30 import org.objectweb.kilim.description.TemplateElementImpl; 31 import org.objectweb.kilim.model.mapping.Mapper; 32 import org.objectweb.kilim.model.mapping.MappingContext; 33 34 37 38 public abstract class RtComponentSource extends RtComponentElement implements RuntimeSource { 39 protected static Stack svpStack = new Stack (); 43 protected static HashMap knownValues = new HashMap (); 44 45 protected Mapper mapper; 46 protected MappingContext mappingContext; 47 48 private List nAryListeners; 50 51 protected RtComponentSource(TemplateElementImpl aElement, ContainerElement aComponent) { 52 super(aElement, aComponent); 53 mapper = KilimConfiguration.getMappingStrategy().getDefaultMapper(); 54 mappingContext = KilimConfiguration.getMappingContext(); 55 } 56 57 61 public static RtSingleValuePort getCurrentSVP() { 62 int svpSize = svpStack.size(); 63 if (svpSize == 0) { 64 return null; 65 } else { 66 return (RtSingleValuePort) svpStack.get(svpSize - 1); 67 } 68 } 69 70 75 public static boolean evaluationPerformed(RtSingleValuePort aPort) { 76 if (knownValues.containsKey(aPort)) { 77 return true; 78 } else { 79 return false; 80 } 81 } 82 83 86 public void addInterfaceListener(RtCollectionPort aInterface) throws KilimException { 87 if (aInterface == null) { 88 throw new KilimException("attempt to add a null nary port listener to an interface " + getQualifiedName()); 89 } 90 91 if (nAryListeners == null) { 92 nAryListeners = new ArrayList (); 93 } 94 95 if (nAryListeners.contains(aInterface)) { 96 throw new KilimException("attempt to add an already known nary port listener to an interface " + getQualifiedName()); 97 } 98 nAryListeners.add(aInterface); 99 } 100 101 104 public void removeInterfaceListener(RtCollectionPort aInterface) throws KilimException { 105 if (aInterface == null) { 106 throw new KilimException("attempt to remove a null nary port listener from an interface " + getQualifiedName()); 107 } 108 if (nAryListeners == null) { 109 throw new KilimException("attempt to remove a nary port listener from an interface " + getQualifiedName() + " without listeners"); 110 } 111 112 boolean result = nAryListeners.remove(aInterface); 113 if (!result) { 114 throw new KilimException("attempt to remove a unknown nary port listener from an interface " + getQualifiedName()); 115 } 116 } 117 118 122 public Iterator getInterfaceListeners() { 123 if (nAryListeners == null) { 124 return KILIM.EMPTY_ITERATOR; 125 } 126 127 return nAryListeners.iterator(); 128 } 129 } 130 | Popular Tags |