1 23 24 package org.objectweb.fractal.julia.control.lifecycle; 25 26 import org.objectweb.fractal.api.Component; 27 import org.objectweb.fractal.api.NoSuchInterfaceException; 28 import org.objectweb.fractal.api.control.BindingController; 29 import org.objectweb.fractal.api.control.IllegalBindingException; 30 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 31 import org.objectweb.fractal.api.control.LifeCycleController; 32 import org.objectweb.fractal.api.type.ComponentType; 33 import org.objectweb.fractal.api.type.InterfaceType; 34 35 import org.objectweb.fractal.julia.control.binding.ChainedIllegalBindingException; 36 import org.objectweb.fractal.julia.control.content.Util; 37 38 import java.util.List ; 39 40 51 52 public abstract class TypeLifeCycleMixin implements LifeCycleController { 53 54 58 private TypeLifeCycleMixin () { 59 } 60 61 65 71 72 public void startFc () throws IllegalLifeCycleException { 73 Component thisComponent; 75 try { 76 thisComponent = (Component)_this_weaveableC.getFcInterface("component"); 77 } catch (NoSuchInterfaceException e) { 78 throw new ChainedIllegalLifeCycleException( 79 e, _this_weaveableC, "Cannot start the component"); 80 } 81 List allSubComponents = Util.getAllSubComponents(thisComponent); 82 83 for (int i = 0; i < allSubComponents.size(); ++i) { 85 Component subComponent = (Component)allSubComponents.get(i); 86 try { 87 checkFcMandatoryInterfaces(subComponent); 88 } catch (IllegalBindingException e) { 89 throw new ChainedIllegalLifeCycleException( 90 e, _this_weaveableC, "Cannot start the component"); 91 } 92 } 93 94 _super_startFc(); 96 } 97 98 106 107 public void checkFcMandatoryInterfaces (final Component c) 108 throws IllegalBindingException 109 { 110 BindingController bc; 111 try { 112 bc = (BindingController)c.getFcInterface("binding-controller"); 113 } catch (NoSuchInterfaceException e) { 114 return; 115 } 116 ComponentType compType = (ComponentType)c.getFcType(); 117 String [] names = bc.listFc(); 118 for (int i = 0; i < names.length; ++i) { 119 InterfaceType itfType; 120 try { 121 itfType = compType.getFcInterfaceType(names[i]); 122 } catch (NoSuchInterfaceException e) { 123 continue; 124 } 125 if (itfType.isFcClientItf() && !itfType.isFcOptionalItf()) { 126 Object sItf; 127 try { 128 sItf = bc.lookupFc(names[i]); 129 } catch (NoSuchInterfaceException e) { 130 continue; 131 } 132 if (sItf == null) { 133 throw new ChainedIllegalBindingException( 134 null, 135 c, 136 null, 137 names[i], 138 null, 139 "Mandatory client interface unbound"); 140 } 141 } 142 } 143 } 144 145 149 154 155 public Component _this_weaveableC; 156 157 163 164 public abstract void _super_startFc () throws IllegalLifeCycleException; 165 } 166 | Popular Tags |