1 31 package org.objectweb.proactive.core.component.xml; 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.IllegalContentException; 39 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 40 import org.objectweb.fractal.api.factory.InstantiationException; 41 42 import org.objectweb.proactive.core.component.Constants; 43 import org.objectweb.proactive.core.component.ContentDescription; 44 import org.objectweb.proactive.core.component.ControllerDescription; 45 import org.objectweb.proactive.core.component.type.Composite; 46 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor; 47 import org.objectweb.proactive.core.descriptor.data.VirtualNode; 48 import org.objectweb.proactive.core.node.Node; 49 import org.objectweb.proactive.core.node.NodeException; 50 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler; 51 import org.objectweb.proactive.core.xml.io.Attributes; 52 53 import org.xml.sax.SAXException ; 54 55 import java.util.HashMap ; 56 import java.util.Iterator ; 57 import java.util.List ; 58 59 60 63 public class CompositeComponentHandler extends AbstractContainerComponentHandler { 64 public static Logger logger = Logger.getLogger(CompositeComponentHandler.class.getName()); 65 private List subComponents; 66 67 71 public CompositeComponentHandler(ProActiveDescriptor deploymentDescriptor, 72 ComponentsCache componentsCache, HashMap componentTypes, 73 ComponentsHandler fatherHandler) { 74 super(deploymentDescriptor, componentsCache, componentTypes, 75 fatherHandler); 76 controllerDescription.setHierarchicalType(Constants.COMPOSITE); 77 addHandler(ComponentsDescriptorConstants.BINDINGS_TAG, 78 new BindingsHandler(componentsCache)); 79 } 80 81 84 protected void notifyEndActiveHandler(String name, 85 UnmarshallerHandler activeHandler) throws SAXException { 86 if (getContainerElementHierarchy().containsChild(activeHandler)) { 87 enable(); 88 } 89 if (isEnabled()) { 90 Component composite; 91 if (name.equals(ComponentsDescriptorConstants.COMPONENTS_TAG)) { 92 try { 94 if (virtualNode.equals(ComponentsDescriptorConstants.NULL)) { 95 composite = cf.newFcInstance(componentType, 96 new ControllerDescription(controllerDescription.getName(), 97 controllerDescription.getHierarchicalType()), 98 new ContentDescription(Composite.class.getName(), 99 new Object [] { })); 100 componentsCache.addComponent(controllerDescription.getName(), 101 composite); 102 } else { 103 VirtualNode vn = deploymentDescriptor.getVirtualNode(virtualNode); 104 vn.activate(); 105 if (vn.getNodeCount() == 0) { 106 throw new NodeException( 107 "no node defined for the virtual node " + 108 vn.getName()); 109 } 110 if (logger.isDebugEnabled()) { 111 if (vn.getNodeCount() > 1) { 112 if (logger.isDebugEnabled()) { 113 logger.debug( 114 "creating a composite component on a virtual node mapped onto several nodes will actually create the component on the first retreived node"); 115 } 116 } 117 } 118 119 Node targeted_node = vn.getNode(); 121 composite = cf.newFcInstance(componentType, 122 new ControllerDescription(controllerDescription.getName(), 123 controllerDescription.getHierarchicalType()), 124 new ContentDescription(Composite.class.getName(), 125 new Object [] { }, targeted_node)); 126 componentsCache.addComponent(controllerDescription.getName(), 127 composite); 128 } 129 130 List sub_components = (List ) getHandler(name) 132 .getResultObject(); 133 Iterator iterator = sub_components.iterator(); 134 while (iterator.hasNext()) { 135 String sub_component_name = (String ) iterator.next(); 136 if (logger.isDebugEnabled()) { 137 logger.debug("adding sub component : " + 138 sub_component_name); 139 } 140 ((ContentController) composite.getFcInterface(Constants.CONTENT_CONTROLLER)).addFcSubComponent(componentsCache.getComponent( 141 sub_component_name)); 142 } 143 } catch (InstantiationException e) { 144 logger.error("cannot instantiate component"); 145 throw new SAXException (e); 146 } catch (NodeException ne) { 147 logger.error( 148 "cannot create active component: node exception"); 149 throw new SAXException (ne); 150 } catch (NoSuchInterfaceException nsie) { 151 logger.error( 152 "cannot create active component : interface not found"); 153 throw new SAXException (nsie); 154 } catch (IllegalLifeCycleException ilce) { 155 logger.error( 156 "cannot create active component : illegal life cycle operation"); 157 throw new SAXException (ilce); 158 } catch (IllegalContentException ice) { 159 logger.error( 160 "cannot create active component : illegal content operation"); 161 throw new SAXException (ice); 162 } 163 logger.debug("created composite component : " + 164 controllerDescription.getName()); 165 } 166 } 167 } 168 169 172 public Object getResultObject() throws SAXException { 173 return new ComponentResultObject(controllerDescription.getName()); 174 } 175 176 179 public void startContextElement(String name, Attributes attributes) 180 throws SAXException { 181 if (isEnabled()) { 182 super.startContextElement(name, attributes); 183 } 184 } 185 } 186 | Popular Tags |