00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.descriptor.xml;
00032
00033 import java.util.Hashtable;
00034 import java.util.Map;
00035
00036 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00037 import org.objectweb.proactive.core.descriptor.services.TechnicalServiceXmlType;
00038 import org.objectweb.proactive.core.xml.handler.BasicUnmarshaller;
00039 import org.objectweb.proactive.core.xml.handler.PassiveCompositeUnmarshaller;
00040 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler;
00041 import org.objectweb.proactive.core.xml.io.Attributes;
00042 import org.xml.sax.SAXException;
00043
00044
00045 public class TechnicalServicesHandler extends PassiveCompositeUnmarshaller
00046 implements ProActiveDescriptorConstants {
00047 protected ProActiveDescriptor proActiveDescriptor;
00048
00049 public TechnicalServicesHandler(ProActiveDescriptor proActiveDescriptor) {
00050 super(false);
00051 this.proActiveDescriptor = proActiveDescriptor;
00052 addHandler(TECHNICAL_SERVICES_DEF_TAG,
00053 new TechnicalServiceDefinitionHandler());
00054 }
00055
00059 protected void notifyEndActiveHandler(String name,
00060 UnmarshallerHandler activeHandler) throws SAXException {
00061 try {
00062 proActiveDescriptor.addTechnicalService((TechnicalServiceXmlType) activeHandler.getResultObject());
00063 } catch (Exception e) {
00064 throw new SAXException("Technical service class not instanciable", e);
00065 }
00066 }
00067
00068
00069 public class TechnicalServiceDefinitionHandler
00070 extends PassiveCompositeUnmarshaller {
00071 private Map<String, String> argsMap = new Hashtable<String, String>();
00072 private TechnicalServiceXmlType technicalService = new TechnicalServiceXmlType();
00073
00074 public TechnicalServiceDefinitionHandler() {
00075 addHandler(TECHNICAL_SERVICE_ARG_TAG,
00076 new TechnicalServiceArgHandler());
00077 }
00078
00082 public void startContextElement(String name, Attributes attributes)
00083 throws SAXException {
00084 this.technicalService.setId(attributes.getValue("id"));
00085 try {
00086 this.technicalService.setType(Class.forName(attributes.getValue(
00087 "class")));
00088 } catch (ClassNotFoundException e) {
00089 throw new SAXException("Technical Service not found", e);
00090 }
00091 }
00092
00096 protected void notifyEndActiveHandler(String name,
00097 UnmarshallerHandler activeHandler) throws SAXException {
00098 this.technicalService.setArgs(this.argsMap);
00099 }
00100
00104 public Object getResultObject() throws SAXException {
00105 return this.technicalService;
00106 }
00107
00108
00109 public class TechnicalServiceArgHandler extends BasicUnmarshaller {
00110 public void startContextElement(String name, Attributes attributes)
00111 throws SAXException {
00112 String argName = attributes.getValue("name");
00113 String argValue = attributes.getValue("value");
00114 argsMap.put(argName, argValue);
00115 }
00116 }
00117 }
00118 }