1 23 24 package org.objectweb.fractal.julia.control.content; 25 26 import org.objectweb.fractal.api.Component; 27 import org.objectweb.fractal.api.NoSuchInterfaceException; 28 import org.objectweb.fractal.api.control.ContentController; 29 import org.objectweb.fractal.api.control.IllegalContentException; 30 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 31 32 import java.util.List ; 33 34 44 45 public abstract class CheckContentMixin implements ContentController { 46 47 51 private CheckContentMixin () { 52 } 53 54 58 70 71 public void addFcSubComponent (final Component subComponent) 72 throws IllegalContentException, IllegalLifeCycleException 73 { 74 if (containsFcSubComponent(subComponent)) { 75 throw new ChainedIllegalContentException( 76 null, _this_weaveableC, subComponent, "Already a sub component"); 77 } 78 79 Component thisComponent; 82 try { 83 thisComponent = (Component)_this_weaveableC.getFcInterface("component"); 84 } catch (NoSuchInterfaceException e) { 85 throw new ChainedIllegalContentException( 86 e, _this_weaveableC, subComponent, "Cannot check this operation"); 87 } 88 if (subComponent.equals(thisComponent)) { 89 throw new ChainedIllegalContentException( 90 null, 91 _this_weaveableC, 92 subComponent, 93 "A component cannot be a sub component of itself"); 94 } 95 96 List allSubComponents = Util.getAllSubComponents(subComponent); 99 for (int i = 0; i < allSubComponents.size(); ++i) { 100 if (allSubComponents.get(i).equals(thisComponent)) { 101 throw new ChainedIllegalContentException( 102 null, 103 _this_weaveableC, 104 subComponent, 105 "Would create a cycle in the component hierarchy"); 106 } 107 } 108 109 _super_addFcSubComponent(subComponent); 111 } 112 113 124 125 public void removeFcSubComponent (final Component subComponent) 126 throws IllegalContentException, IllegalLifeCycleException 127 { 128 if (!containsFcSubComponent(subComponent)) { 129 throw new ChainedIllegalContentException( 130 null, _this_weaveableC, subComponent, "Not a sub component"); 131 } 132 _super_removeFcSubComponent(subComponent); 133 } 134 135 142 143 public boolean containsFcSubComponent (final Component subComponent) { 144 Component[] subComponents = _this_getFcSubComponents(); 145 for (int i = 0; i < subComponents.length; ++i) { 146 if (subComponents[i].equals(subComponent)) { 147 return true; 148 } 149 } 150 return false; 151 } 152 153 157 162 163 public Component _this_weaveableC; 164 165 172 173 public abstract Component[] _this_getFcSubComponents (); 174 175 186 187 public abstract void _super_addFcSubComponent (Component subComponent) 188 throws IllegalContentException, IllegalLifeCycleException; 189 190 201 202 public abstract void _super_removeFcSubComponent (Component subComponent) 203 throws IllegalContentException, IllegalLifeCycleException; 204 } 205 | Popular Tags |