org/objectweb/proactive/core/descriptor/xml/TechnicalServicesHandler.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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     // INNER
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         // INNNER INNER
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 }

Generated on Mon Jan 22 15:16:07 2007 for ProActive by  doxygen 1.5.1