1 31 package org.objectweb.proactive.core.component.controller; 32 33 import org.apache.log4j.Logger; 34 35 import org.objectweb.fractal.api.Component; 36 import org.objectweb.fractal.api.NoSuchInterfaceException; 37 import org.objectweb.fractal.api.control.ContentController; 38 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 39 40 import org.objectweb.proactive.core.ProActiveRuntimeException; 41 import org.objectweb.proactive.core.component.Constants; 42 import org.objectweb.proactive.core.component.Fractive; 43 import org.objectweb.proactive.core.component.identity.ProActiveComponent; 44 45 import java.io.Serializable ; 46 47 import java.util.Vector ; 48 49 50 56 public class ProActiveContentController extends ProActiveController 57 implements ContentController, Serializable { 58 protected static Logger logger = Logger.getLogger(ProActiveContentController.class.getName()); 59 Vector fcSubComponents; 60 61 64 public ProActiveContentController(Component owner) { 65 super(owner, Constants.CONTENT_CONTROLLER); 66 fcSubComponents = new Vector (); 67 } 68 69 74 public Object [] getFcInternalInterfaces() { 75 logger.error( 76 "Internal interfaces are only accessible from the stub, i.e. from outside of this component"); 77 return null; 78 } 79 80 85 public Object getFcInternalInterface(String interfaceName) 86 throws NoSuchInterfaceException { 87 throw new NoSuchInterfaceException( 88 "Internal interfaces are only accessible from the stub, i.e. from outside of this component"); 89 } 90 91 94 public Component[] getFcSubComponents() { 95 if (fcSubComponents.size() > 0) { 96 return (Component[]) fcSubComponents.toArray(new Component[fcSubComponents.size()]); 97 } else { 98 return null; 99 } 100 } 101 102 public boolean isSubComponent(Component component) { 103 return fcSubComponents.contains(component); 104 } 105 106 109 public void addFcSubComponent(Component subComponent) 110 throws IllegalLifeCycleException { 111 checkLifeCycleIsStopped(); 112 113 if (getFcItfOwner().equals((ProActiveComponent) subComponent)) { 115 try { 116 throw new IllegalArgumentException ("cannot add " + 117 Fractive.getComponentParametersController(getFcItfOwner()) 118 .getComponentParameters().getName() + 119 " component into itself "); 120 } catch (NoSuchInterfaceException e) { 121 logger.error(e.getMessage()); 122 } 123 } 124 125 if (fcSubComponents.contains(subComponent)) { 128 String name; 129 try { 130 name = ((ComponentParametersController) subComponent 131 .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters() 132 .getName(); 133 } catch (NoSuchInterfaceException nsie) { 134 throw new ProActiveRuntimeException( 135 "cannot access the component parameters controller"); 136 } 137 throw new IllegalArgumentException ("already a sub component : " + 138 name); 139 } else { 140 fcSubComponents.addElement(subComponent); 141 } 142 143 } 167 168 171 public void removeFcSubComponent(Component subComponent) 172 throws IllegalLifeCycleException { 173 checkLifeCycleIsStopped(); 174 if (!fcSubComponents.removeElement(subComponent)) { 175 throw new IllegalArgumentException ("not a sub component : " + 176 subComponent); 177 } 178 179 if (logger.isDebugEnabled()) { 180 logger.debug("TODO : check the bindings"); 181 } 182 } 183 } 184 | Popular Tags |