1 31 package org.objectweb.proactive.core.component.xml; 32 33 import org.apache.log4j.Logger; 34 35 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor; 36 import org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator; 37 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler; 38 import org.objectweb.proactive.core.xml.io.Attributes; 39 40 import org.xml.sax.SAXException ; 41 42 import java.util.ArrayList ; 43 import java.util.HashMap ; 44 import java.util.List ; 45 46 47 50 public class ComponentsHandler extends AbstractUnmarshallerDecorator 51 implements ContainerHandlerMarker { 52 public static Logger logger = Logger.getLogger(ComponentsHandler.class.getName()); 53 private ProActiveDescriptor deploymentDescriptor; 54 private ComponentsCache componentsCache; 55 private HashMap componentTypes; 56 private List subComponents; 57 private boolean enabled; 58 private ContainerElementHierarchy containersHierarchy; 59 60 public ComponentsHandler(ProActiveDescriptor deploymentDescriptor, 61 ComponentsCache componentsCache, HashMap componentTypes, 62 AbstractContainerComponentHandler fatherHandler) { 63 enable(); 64 containersHierarchy = new ContainerElementHierarchy(); 65 containersHierarchy.addFatherHandler(fatherHandler); 66 this.deploymentDescriptor = deploymentDescriptor; 67 this.componentsCache = componentsCache; 68 this.componentTypes = componentTypes; 69 70 BindingsHandler bindings_handler = new BindingsHandler(componentsCache); 73 addHandler(ComponentsDescriptorConstants.BINDINGS_TAG, bindings_handler); 74 subComponents = new ArrayList (); 75 getContainerElementHierarchy().disableGrandFatherHandler(); 76 } 77 78 81 protected void notifyEndActiveHandler(String name, 82 UnmarshallerHandler activeHandler) throws SAXException { 83 if (isEnabled() || 84 getContainerElementHierarchy().containsChild(activeHandler)) { 85 enable(); if (name.equals( 87 ComponentsDescriptorConstants.PRIMITIVE_COMPONENT_TAG) || 88 name.equals( 89 ComponentsDescriptorConstants.COMPOSITE_COMPONENT_TAG) || 90 name.equals( 91 ComponentsDescriptorConstants.PARALLEL_COMPOSITE_COMPONENT_TAG)) { 92 ComponentResultObject result = (ComponentResultObject) activeHandler.getResultObject(); 94 if (result.componentsAreParallelized()) { 95 String [] component_names = result.getNames(); 96 for (int i = 0; i < component_names.length; i++) { 97 subComponents.add(component_names[i]); 98 if (logger.isDebugEnabled()) { 99 logger.debug("adding component's name : " + 100 component_names[i]); 101 } 102 } 103 } else { 104 subComponents.add(result.getName()); 105 if (logger.isDebugEnabled()) { 106 logger.debug("adding component's name : " + 107 ((ComponentResultObject) activeHandler.getResultObject()).getName()); 108 } 109 } 110 } 111 } 112 } 113 114 117 public Object getResultObject() throws SAXException { 118 return subComponents; 119 } 120 121 124 public void readValue(String value) throws SAXException { 125 super.readValue(value); 126 } 127 128 131 public void startElement(String name, Attributes attributes) 132 throws SAXException { 133 if (isEnabled()) { 134 if (name.equals( 135 ComponentsDescriptorConstants.COMPOSITE_COMPONENT_TAG)) { 136 CompositeComponentHandler handler = new CompositeComponentHandler(deploymentDescriptor, 137 componentsCache, componentTypes, this); 138 getContainerElementHierarchy().addChildContainerHandler(handler); 139 addHandler(ComponentsDescriptorConstants.COMPOSITE_COMPONENT_TAG, 140 handler); 141 } 142 if (name.equals( 143 ComponentsDescriptorConstants.PRIMITIVE_COMPONENT_TAG)) { 144 addHandler(ComponentsDescriptorConstants.PRIMITIVE_COMPONENT_TAG, 145 new PrimitiveComponentHandler(deploymentDescriptor, 146 componentsCache, componentTypes)); 147 } 148 if (name.equals( 149 ComponentsDescriptorConstants.PARALLEL_COMPOSITE_COMPONENT_TAG)) { 150 ParallelCompositeComponentHandler handler = new ParallelCompositeComponentHandler(deploymentDescriptor, 151 componentsCache, componentTypes, this); 152 addHandler(ComponentsDescriptorConstants.PARALLEL_COMPOSITE_COMPONENT_TAG, 153 handler); 154 getContainerElementHierarchy().addChildContainerHandler(handler); 155 } 156 } 157 super.startElement(name, attributes); 158 } 159 160 public void enable() { 161 enabled = true; 162 } 163 164 public void disable() { 165 enabled = false; 166 } 167 168 public boolean isEnabled() { 169 return enabled; 170 } 171 172 175 public ContainerElementHierarchy getContainerElementHierarchy() { 176 return containersHierarchy; 177 } 178 179 182 public void startContextElement(String name, Attributes attributes) 183 throws SAXException { 184 } 186 } 187 | Popular Tags |