1 31 package org.objectweb.proactive.core.descriptor.xml; 32 33 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor; 34 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptorImpl; 35 import org.objectweb.proactive.core.descriptor.data.VirtualNode; 36 import org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator; 37 import org.objectweb.proactive.core.xml.handler.BasicUnmarshaller; 38 import org.objectweb.proactive.core.xml.handler.PassiveCompositeUnmarshaller; 39 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler; 40 import org.objectweb.proactive.core.xml.io.Attributes; 41 42 49 50 public class ProActiveDescriptorHandler extends AbstractUnmarshallerDecorator implements ProActiveDescriptorConstants { 51 52 private ProActiveDescriptor proActiveDescriptor; 53 54 58 public ProActiveDescriptorHandler(String xmlDescriptorUrl) { 59 super(false); 60 proActiveDescriptor = new ProActiveDescriptorImpl(xmlDescriptorUrl); 61 addHandler(DEPLOYMENT_TAG, new DeploymentHandler(proActiveDescriptor)); 62 addHandler(INFRASTRUCTURE_TAG, new InfrastructureHandler(proActiveDescriptor)); 63 addHandler(SECURITY_TAG, new SecurityHandler(proActiveDescriptor)); 64 { 65 PassiveCompositeUnmarshaller compDefHandler = new PassiveCompositeUnmarshaller(); 66 PassiveCompositeUnmarshaller vNodesDefHandler = new PassiveCompositeUnmarshaller(); 67 PassiveCompositeUnmarshaller vNodesAcqHandler = new PassiveCompositeUnmarshaller(); 68 vNodesDefHandler.addHandler(VIRTUAL_NODE_TAG, new VirtualNodeHandler()); 69 vNodesAcqHandler.addHandler(VIRTUAL_NODE_TAG, new VirtualNodeLookupHandler()); 70 compDefHandler.addHandler(VIRTUAL_NODES_DEFINITION_TAG, vNodesDefHandler); 71 compDefHandler.addHandler(VIRTUAL_NODES_ACQUISITION_TAG, vNodesAcqHandler); 72 this.addHandler(COMPONENT_DEFINITION_TAG, compDefHandler); 73 } 74 } 75 76 77 78 82 83 public static void main(String [] args) throws java.io.IOException { 84 85 String uri = "Z:\\ProActive\\descriptors\\C3D_Dispatcher_Renderer.xml"; 86 InitialHandler h = new InitialHandler(uri); 87 89 org.objectweb.proactive.core.xml.io.StreamReader sr = new org.objectweb.proactive.core.xml.io.StreamReader(new org.xml.sax.InputSource (uri), h); 90 sr.read(); 91 } 92 93 97 public static ProActiveDescriptorHandler createProActiveDescriptor(String xmlDescriptorUrl) throws java.io.IOException ,org.xml.sax.SAXException { 98 try { 100 InitialHandler h = new InitialHandler(xmlDescriptorUrl); 101 String uri = xmlDescriptorUrl; 102 org.objectweb.proactive.core.xml.io.StreamReader sr = 103 new org.objectweb.proactive.core.xml.io.StreamReader(new org.xml.sax.InputSource (uri), h); 104 sr.read(); 105 return(ProActiveDescriptorHandler)h.getResultObject(); 106 } 107 catch (org.xml.sax.SAXException e){ 108 e.printStackTrace(); 109 logger.fatal("a problem occurs when getting the ProActiveDescriptorHandler"); 110 throw e; 111 } 112 } 113 114 115 119 120 public Object getResultObject() throws org.xml.sax.SAXException { 121 return proActiveDescriptor; 122 } 123 124 public void startContextElement(String name, Attributes attributes) throws org.xml.sax.SAXException { 125 } 126 127 128 132 protected void notifyEndActiveHandler(String name, UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException { 133 } 134 135 136 140 141 145 146 149 private static class InitialHandler extends AbstractUnmarshallerDecorator { 150 private ProActiveDescriptorHandler proActiveDescriptorHandler; 152 private InitialHandler(String xmlDescriptorUrl) { 153 super(); 154 proActiveDescriptorHandler = new ProActiveDescriptorHandler(xmlDescriptorUrl); 155 this.addHandler(PROACTIVE_DESCRIPTOR_TAG, proActiveDescriptorHandler); 156 } 157 public Object getResultObject() throws org.xml.sax.SAXException { 158 return proActiveDescriptorHandler; 159 } 160 public void startContextElement(String name, Attributes attributes) throws org.xml.sax.SAXException { 161 } 162 protected void notifyEndActiveHandler(String name, UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException { 163 } 164 } 165 166 169 private class VirtualNodeHandler extends BasicUnmarshaller { 170 private VirtualNodeHandler() { 171 } 172 public void startContextElement(String name, Attributes attributes) throws org.xml.sax.SAXException { 173 String vnName = attributes.getValue("name"); 175 if (! checkNonEmpty(vnName)) throw new org.xml.sax.SAXException ("VirtualNode defined without name"); 176 VirtualNode vn = proActiveDescriptor.createVirtualNode(vnName,false); 177 String property = attributes.getValue("property"); 179 if (checkNonEmpty(property)) { 180 vn.setProperty(property); 181 } 182 String timeout = attributes.getValue("timeout"); 183 String waitForTimeoutAsString = attributes.getValue("waitForTimeout"); 184 boolean waitForTimeout = false; 185 if (checkNonEmpty(waitForTimeoutAsString)){ 186 waitForTimeout = new Boolean (waitForTimeoutAsString).booleanValue(); 187 } 188 if (checkNonEmpty(timeout)) { 189 vn.setTimeout(timeout, waitForTimeout); 190 } 191 192 } 193 } 195 198 private class VirtualNodeLookupHandler extends BasicUnmarshaller { 199 private VirtualNodeLookupHandler() { 200 } 201 public void startContextElement(String name, Attributes attributes) throws org.xml.sax.SAXException { 202 String vnName = attributes.getValue("name"); 204 if (! checkNonEmpty(vnName)) throw new org.xml.sax.SAXException ("VirtualNode defined without name"); 205 VirtualNode vn = proActiveDescriptor.createVirtualNode(vnName,true); 206 } 207 } 209 213 private class SecurityHandler extends BasicUnmarshaller { 214 private ProActiveDescriptor proActiveDescriptor; 215 216 public SecurityHandler(ProActiveDescriptor proActiveDescriptor) { 217 super(); 218 this.proActiveDescriptor = proActiveDescriptor; 219 } 220 221 public void startContextElement(String name, Attributes attributes) 222 throws org.xml.sax.SAXException { 223 String file = attributes.getValue("file"); 225 226 227 if (!checkNonEmpty(file)) { 228 throw new org.xml.sax.SAXException ("Empty security file"); 229 } 230 logger.debug("creating PolicyServer : " + file); 231 proActiveDescriptor.createPolicyServer(file); 232 } 233 } 234 } 236 | Popular Tags |