1 18 19 package org.objectweb.kilim.model.instanciation; 20 21 import java.util.Iterator ; 22 23 import org.objectweb.kilim.KilimException; 24 import org.objectweb.kilim.description.Trigger; 25 import org.objectweb.kilim.model.Component; 26 import org.objectweb.kilim.model.ComponentInterface; 27 import org.objectweb.kilim.model.ComponentSlot; 28 import org.objectweb.kilim.model.RtCollectionPort; 29 import org.objectweb.kilim.model.RtComponentInterface; 30 import org.objectweb.kilim.model.RtComponentSlot; 31 import org.objectweb.kilim.model.RuntimeAction; 32 import org.objectweb.kilim.model.RuntimeSource; 33 import org.objectweb.kilim.model.RuntimeTrigger; 34 import org.objectweb.kilim.model.mapping.MappingContext; 35 36 39 40 public class BDUInstanciationMger extends InstanciationMger { 41 42 45 public void finalizeInstanciation(Component aComponent, ComponentInterface aInterface, MappingContext aContext) throws KilimException { } 46 47 50 public void initializeInstanciation(Component aComponent, ComponentInterface aInterface, MappingContext aContext) throws KilimException { 51 doWhenInstanciate(aComponent, aInterface, aContext); 52 } 53 54 57 public void initializePlug(Component aComponent, ComponentSlot aSlot, MappingContext aContext) throws KilimException { 58 doWhenPlug(aComponent, aSlot, aContext); 59 } 60 61 64 public void finalizePlug(Component aComponent, ComponentSlot aSlot, MappingContext aContext) throws KilimException { } 65 66 76 77 public static void doWhenInstanciate(Component aComponent, ComponentInterface aInterface, MappingContext aContext) throws KilimException { 78 if (aComponent == null) { 79 throw new KilimException("attempt to invoke an instanciation manager on a null component"); 80 } 81 82 if (aComponent.isInitialized()) { 83 return; 84 } 85 aComponent.setInitialized(); 86 87 Component contain = aComponent.getContainingComponent(); 88 while (contain != null && !contain.isInitialized()) { 89 doWhenInstanciate(contain, null, aContext); 90 } 91 92 Iterator iter0 = aComponent.getInterfaces(); 93 while (iter0.hasNext()) { 94 RtComponentInterface interf = (RtComponentInterface) iter0.next(); 95 if (interf instanceof RtCollectionPort) { 96 doWhenInstanciate1((RtCollectionPort) interf, aContext); 97 } 98 } 99 100 Iterator iter1 = aComponent.getSlots(); 101 while (iter1.hasNext()) { 102 RtComponentSlot slot = (RtComponentSlot) iter1.next(); 103 doWhenPlug(aComponent, slot, aContext); 104 } 105 } 106 107 private static void doWhenInstanciate1(RtCollectionPort aInterface, MappingContext aContext) throws KilimException { 108 Iterator iter = aInterface.getBoundProviders(); 109 while (iter.hasNext()) { 110 ComponentInterface provider = (ComponentInterface) iter.next(); 111 if (provider instanceof RtCollectionPort) { 112 throw new KilimException("attempt to use a nary port " + provider.getQualifiedName() + " inside another nary port " + aInterface.getQualifiedName()); 114 } else { 115 RuntimeSource rtSource = (RuntimeSource) ((RuntimeSource) provider).getTarget(); 116 if (!aInterface.triggersDone(rtSource, Trigger.BIND)) { 117 aInterface.setTriggersDone(rtSource, Trigger.BIND, true); 118 Iterator iter2 = aInterface.getTriggers(Trigger.BIND); 119 Object resultValue = provider.getValue(); 120 while (iter2.hasNext()) { 121 RuntimeTrigger rtElem = (RuntimeTrigger) iter2.next(); 122 if (rtElem.getEventKind() == Trigger.BIND) { 123 Iterator iter3 = rtElem.getTransformers(); 124 while (iter3.hasNext()) { 125 RuntimeAction rtElem3 = (RuntimeAction) iter3.next(); 126 rtElem3.setEventSourceValue(resultValue); 127 128 rtElem3.execute(); 129 } 130 } 131 } 132 } 133 } 134 } 135 } 136 137 144 public static void doWhenPlug(Component aComponent, ComponentSlot aSlot, MappingContext aContext) throws KilimException { 145 if (aSlot.isInitialized()) { 146 return; 147 } 148 aSlot.setInitialized(); 149 150 Iterator iter0 = aSlot.getInterfaces(); 151 while (iter0.hasNext()) { 152 RtComponentInterface interf = (RtComponentInterface) iter0.next(); 153 if (interf instanceof RtCollectionPort) { 154 doWhenInstanciate1((RtCollectionPort) interf, aContext); 155 } 156 } 157 } 158 } | Popular Tags |