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.factory.InstantiationException; 37 38 import org.objectweb.proactive.core.component.Constants; 39 import org.objectweb.proactive.core.component.ContentDescription; 40 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor; 41 import org.objectweb.proactive.core.descriptor.data.VirtualNode; 42 import org.objectweb.proactive.core.group.ProActiveGroup; 43 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler; 44 import org.objectweb.proactive.core.xml.io.Attributes; 45 46 import org.xml.sax.SAXException ; 47 48 import java.util.HashMap ; 49 50 51 54 public class PrimitiveComponentHandler extends ComponentHandler { 55 public static Logger logger = Logger.getLogger(PrimitiveComponentHandler.class.getName()); 56 private String [] names; 58 61 public PrimitiveComponentHandler(ProActiveDescriptor deploymentDescriptor, 62 ComponentsCache componentsCache, HashMap componentTypes) { 63 super(deploymentDescriptor, componentsCache, componentTypes); 64 controllerDescription.setHierarchicalType(Constants.PRIMITIVE); 65 } 66 67 72 public void startContextElement(String name, Attributes attributes) 73 throws SAXException { 74 names = null; 75 if (logger.isDebugEnabled()) { 76 logger.debug("startContextElement : " + name + "of : " + 77 controllerDescription.getName()); 78 } 79 80 super.startContextElement(name, attributes); 84 85 String implementation = attributes.getValue(ComponentsDescriptorConstants.PRIMITIVE_COMPONENT_IMPLEMENTATION_TAG); 86 if (!checkNonEmpty(implementation)) { 87 throw new SAXException ("Component's implementation unspecified"); 88 } 89 90 try { 92 if (Class.forName(implementation).isInterface()) { 93 throw new SAXException (implementation + 94 " is an interface. You cannot specify an interface as the implementation of a component."); 95 } 96 } catch (ClassNotFoundException e) { 97 throw new SAXException ("Specified class for implementation of the component is not in the classpath ", 98 e); 99 } 100 101 try { 105 VirtualNode vn = null; 107 try { 108 if (virtualNode.equals(ComponentsDescriptorConstants.NULL)) { 109 componentsCache.addComponent(controllerDescription.getName(), 110 cf.newFcInstance(componentType, controllerDescription, 111 new ContentDescription(implementation, 112 new Object [] { }))); 113 return; 114 } 115 vn = deploymentDescriptor.getVirtualNode(virtualNode); 116 } catch (NullPointerException npe) { 117 logger.fatal( 118 "Could not find virtual node. Maybe virtual node names do not match between components descriptor and deployment descriptor"); 119 return; 120 } 121 Component components = cf.newFcInstance(componentType, 122 controllerDescription, 123 new ContentDescription(implementation, new Object [] { }, vn)); 124 125 if (!ProActiveGroup.isGroup(components)) { 126 componentsCache.addComponent(controllerDescription.getName(), 128 components); 129 } else { 130 Component[] components_table = (Component[]) (ProActiveGroup.getGroup(components) 132 .toArray(new Component[ProActiveGroup.getGroup( 133 components).size()])); 134 135 names = new String [components_table.length]; 137 for (int i = 0; i < components_table.length; i++) { 139 names[i] = controllerDescription.getName() + 140 Constants.CYCLIC_NODE_SUFFIX + i; 141 componentsCache.addComponent(names[i], components_table[i]); 142 } 143 } 144 } catch (InstantiationException e) { 145 logger.error("cannot create active component " + e.getMessage()); 146 throw new SAXException (e); 147 } 148 if (logger.isDebugEnabled()) { 149 logger.debug("created primitive component : " + 150 controllerDescription.getName()); 151 } 152 } 153 154 157 public Object getResultObject() throws SAXException { 158 if (names != null) { 159 return new ComponentResultObject(names); 161 } else { 162 return new ComponentResultObject(controllerDescription.getName()); 163 } 164 } 165 166 169 protected void notifyEndActiveHandler(String name, 170 UnmarshallerHandler activeHandler) throws SAXException { 171 } 172 } 173 | Popular Tags |