1 31 package org.objectweb.proactive.core.component.xml; 32 33 import org.objectweb.fractal.api.Component; 34 import org.objectweb.fractal.api.NoSuchInterfaceException; 35 import org.objectweb.fractal.api.control.BindingController; 36 import org.objectweb.fractal.api.control.IllegalBindingException; 37 import org.objectweb.fractal.api.control.IllegalContentException; 38 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 39 import org.objectweb.fractal.api.factory.InstantiationException; 40 import org.objectweb.fractal.api.type.InterfaceType; 41 import org.objectweb.fractal.util.Fractal; 42 43 import org.objectweb.proactive.core.component.Constants; 44 import org.objectweb.proactive.core.component.ContentDescription; 45 import org.objectweb.proactive.core.component.ControllerDescription; 46 import org.objectweb.proactive.core.component.Fractive; 47 import org.objectweb.proactive.core.component.type.ParallelComposite; 48 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor; 49 import org.objectweb.proactive.core.descriptor.data.VirtualNode; 50 import org.objectweb.proactive.core.node.Node; 51 import org.objectweb.proactive.core.node.NodeException; 52 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler; 53 import org.objectweb.proactive.core.xml.io.Attributes; 54 55 import org.xml.sax.SAXException ; 56 57 import java.util.HashMap ; 58 import java.util.Iterator ; 59 import java.util.List ; 60 61 62 65 public class ParallelCompositeComponentHandler 66 extends AbstractContainerComponentHandler { 67 68 72 public ParallelCompositeComponentHandler( 73 ProActiveDescriptor deploymentDescriptor, 74 ComponentsCache componentsCache, HashMap componentTypes, 75 ComponentsHandler fatherHandler) { 76 super(deploymentDescriptor, componentsCache, componentTypes, 77 fatherHandler); 78 controllerDescription.setHierarchicalType(Constants.PARALLEL); 79 addHandler(ComponentsDescriptorConstants.BINDINGS_TAG, 81 new BindingsHandler(componentsCache)); 82 } 83 84 87 public Object getResultObject() throws SAXException { 88 return new ComponentResultObject(controllerDescription.getName()); 89 } 90 91 94 protected void notifyEndActiveHandler(String name, 95 UnmarshallerHandler activeHandler) throws SAXException { 96 if (getContainerElementHierarchy().containsChild(activeHandler)) { 97 enable(); 98 } 99 if (isEnabled()) { 100 Component parallel = null; 101 if (name.equals(ComponentsDescriptorConstants.COMPONENTS_TAG)) { 102 try { 103 if (virtualNode.equals(ComponentsDescriptorConstants.NULL)) { 104 parallel = cf.newFcInstance(componentType, 108 new ControllerDescription(controllerDescription), 109 new ContentDescription(ParallelComposite.class.getName(), 110 new Object [] { })); 111 componentsCache.addComponent(controllerDescription.getName(), 112 parallel); 113 } else { 115 VirtualNode vn = deploymentDescriptor.getVirtualNode(virtualNode); 118 119 if (vn.getNodeCount() == 0) { 120 throw new NodeException( 121 "no node defined for the virtual node " + vn.getName()); 122 } 123 if (logger.isDebugEnabled()) { 124 if (vn.getNodeCount() > 1) { 125 logger.debug("creating a parallel composite component on a virtual node mapped onto several nodes will actually create the component on the first retreived node"); 126 } 127 } 128 Node targeted_node = vn.getNode(); 130 parallel = cf.newFcInstance(componentType, 131 new ControllerDescription(controllerDescription.getName(), 132 controllerDescription.getHierarchicalType()), 133 new ContentDescription(ParallelComposite.class.getName(), 134 new Object [] { }, targeted_node)); 135 componentsCache.addComponent(controllerDescription.getName(), 136 parallel); 137 if (logger.isDebugEnabled()) { 138 logger.debug("created parallel component : " + 139 controllerDescription.getName()); 140 } 141 } 142 List sub_components_names = (List ) getHandler(name) 144 .getResultObject(); 145 Component[] sub_components = new Component[sub_components_names.size()]; 146 Iterator iterator = sub_components_names.iterator(); 147 int n = 0; 148 while (iterator.hasNext()) { 149 String sub_component_name = (String ) iterator.next(); 150 if (logger.isDebugEnabled()) { 151 logger.debug("adding sub component : " + 152 sub_component_name); 153 } 154 Fractal.getContentController(parallel) 155 .addFcSubComponent(componentsCache.getComponent( 156 sub_component_name)); 157 sub_components[n] = componentsCache.getComponent(sub_component_name); 158 n++; 159 } 160 161 170 InterfaceType[] current_component_interfaces = componentType.getFcInterfaceTypes(); 173 for (int i = 0; i < sub_components.length; i++) { 174 InterfaceType[] sub_component_interfaces = Fractive.getComponentParametersController(sub_components[i]) 177 .getComponentParameters() 178 .getInterfaceTypes(); 179 180 for (int j = 0; j < sub_component_interfaces.length; 182 j++) { 183 for (int k = 0; 189 k < current_component_interfaces.length; 190 k++) { 191 if (sub_component_interfaces[j].getFcItfName() 192 .equals(current_component_interfaces[k].getFcItfName())) { 193 String itf_name = current_component_interfaces[k].getFcItfName(); 195 if ((sub_component_interfaces[j].isFcClientItf() && 196 current_component_interfaces[k].isFcClientItf())) { 197 if (logger.isDebugEnabled()) { 198 logger.debug( 199 "BINDING INTERFACES OF SAME NAME " + 200 itf_name); 201 } 202 203 ((BindingController) sub_components[i].getFcInterface(Constants.BINDING_CONTROLLER)).bindFc(itf_name, 206 parallel.getFcInterface(itf_name)); 207 } else if ((!sub_component_interfaces[j].isFcClientItf() && 208 !current_component_interfaces[k].isFcClientItf())) { 209 if (logger.isDebugEnabled()) { 210 logger.debug( 211 "BINDING INTERFACES OF SAME NAME " + 212 itf_name); 213 } 214 215 ((BindingController) parallel.getFcInterface(Constants.BINDING_CONTROLLER)).bindFc(itf_name, 218 sub_components[i].getFcInterface( 219 itf_name)); 220 } 221 } 222 } 223 } 224 } 225 } catch (InstantiationException e) { 226 logger.error( 227 "cannot create active component: instantiation exception"); 228 throw new SAXException (e); 229 } catch (NodeException e) { 230 logger.error( 231 "cannot create active component: node exception"); 232 throw new SAXException (e); 233 } catch (IllegalContentException e) { 234 logger.error( 235 "cannot assemble active component : illegal content"); 236 throw new SAXException (e); 237 } catch (NoSuchInterfaceException e) { 238 logger.error("interface not found"); 239 throw new SAXException (e); 240 } catch (IllegalLifeCycleException e) { 241 logger.error( 242 "cannot bind active component : illegal life cycle operation"); 243 throw new SAXException (e); 244 } catch (IllegalBindingException e) { 245 logger.error( 246 "cannot bind active component : illegal binding operation"); 247 throw new SAXException (e); 248 } 249 } 250 } 251 } 252 253 256 public void startContextElement(String name, Attributes attributes) 257 throws SAXException { 258 if (isEnabled()) { 259 super.startContextElement(name, attributes); 260 } 261 } 262 } 263 | Popular Tags |