org/objectweb/proactive/core/descriptor/xml/MainDefinitionHandler.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 org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00034 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00035 import org.objectweb.proactive.core.xml.handler.BasicUnmarshaller;
00036 import org.objectweb.proactive.core.xml.handler.CollectionUnmarshaller;
00037 import org.objectweb.proactive.core.xml.handler.PassiveCompositeUnmarshaller;
00038 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler;
00039 import org.objectweb.proactive.core.xml.io.Attributes;
00040 import org.objectweb.proactive.scheduler.GenericJob;
00041 import org.objectweb.proactive.scheduler.Scheduler;
00042 import org.objectweb.proactive.scheduler.SchedulerConstants;
00043 
00044 
00052 class MainDefinitionHandler extends PassiveCompositeUnmarshaller
00053     implements ProActiveDescriptorConstants, SchedulerConstants {
00054     private ProActiveDescriptor proActiveDescriptor;
00055     private Scheduler scheduler;
00056     private String jobId;
00057 
00058     //
00059     //  ----- PRIVATE MEMBERS -----------------------------------------------------------------------------------
00060     //
00061     //
00062     //  ----- CONSTRUCTORS -----------------------------------------------------------------------------------
00063     //
00064     public MainDefinitionHandler() {
00065     }
00066 
00067     public MainDefinitionHandler(ProActiveDescriptor proActiveDescriptor) {
00068         super();
00069         this.proActiveDescriptor = proActiveDescriptor;
00070         this.addHandler(ARG_TAG, new ArgHandler(proActiveDescriptor));
00071         this.addHandler(MAP_TO_VIRTUAL_NODE_TAG,
00072             new MapToVirtualNodeHandler(proActiveDescriptor));
00073     }
00074 
00075     public MainDefinitionHandler(Scheduler scheduler, String jobId,
00076         ProActiveDescriptor proActiveDescriptor) {
00077         this.proActiveDescriptor = proActiveDescriptor;
00078         UnmarshallerHandler pathHandler = new PathHandler();
00079         CollectionUnmarshaller classPath_Handler = new CollectionUnmarshaller(String.class);
00080         classPath_Handler.addHandler(ABS_PATH_TAG, pathHandler);
00081         this.scheduler = scheduler;
00082         this.jobId = jobId;
00083         this.addHandler(ARG_TAG, new ArgHandler(proActiveDescriptor));
00084         this.addHandler(MAP_TO_VIRTUAL_NODE_TAG,
00085             new MapToVirtualNodeHandler(proActiveDescriptor));
00086         this.addHandler(CLASSPATH_TAG, classPath_Handler);
00087     }
00088 
00089     public void startContextElement(String name, Attributes attributes)
00090         throws org.xml.sax.SAXException {
00091         String id = attributes.getValue("id");
00092         String className = attributes.getValue("class");
00093 
00094         if (!checkNonEmpty(className)) {
00095             throw new org.xml.sax.SAXException(
00096                 "class Tag without any mainDefinition defined");
00097         }
00098 
00099         if (scheduler != null) {
00100             GenericJob tmpJob = scheduler.getTmpJob(this.jobId);
00101             tmpJob.setClassName(className);
00102         }
00103 
00104         proActiveDescriptor.createMainDefinition(id);
00105 
00106         proActiveDescriptor.setMainDefined(true);
00107         proActiveDescriptor.mainDefinitionSetMainClass(className);
00108     }
00109 
00110     protected void notifyEndActiveHandler(String name,
00111         UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException {
00112         if (name.equals(ARG_TAG)) {
00113             //System.out.println("end of a arg tag") ;
00114         }
00115 
00116         if (name.equals(MAP_TO_VIRTUAL_NODE_TAG)) {
00117             //System.out.println("end of a mapToVirtualNode tag") ;
00118         }
00119 
00120         if (name.equals(CLASSPATH_TAG)) {
00121             //System.out.println("end of a classpath tag") ;
00122             if (scheduler != null) {
00123                 String[] result = (String[]) activeHandler.getResultObject();
00124                 GenericJob job = scheduler.getTmpJob(this.jobId);
00125                 job.setClassPath(result);
00126                 //                      for (int i=0; i<result.length; ++i) {
00127                 //                              System.out.println("------------" + result[i]);
00128                 //                      }
00129             }
00130         }
00131     }
00132 
00133     //
00134     //  ----- PUBLIC METHODS -----------------------------------------------------------------------------------
00135     //
00136     //
00137     // -- implements UnmarshallerHandler ------------------------------------------------------
00138     //
00139     //
00140     //  ----- PRIVATE METHODS -----------------------------------------------------------------------------------
00141     //
00142     //
00143     //  ----- INNER CLASSES -----------------------------------------------------------------------------------
00144     //  
00145     private class ArgHandler extends BasicUnmarshaller {
00146         ProActiveDescriptor proActiveDescriptor;
00147 
00148         private ArgHandler(ProActiveDescriptor proActiveDescriptor) {
00149             this.proActiveDescriptor = proActiveDescriptor;
00150         }
00151 
00152         public void startContextElement(String name, Attributes attributes)
00153             throws org.xml.sax.SAXException {
00154             String arg = attributes.getValue("value");
00155 
00156             //System.out.println("enter in a arg node : " + arg);
00157             if (!checkNonEmpty(arg)) {
00158                 throw new org.xml.sax.SAXException(
00159                     "value Tag without any arg defined");
00160             }
00161 
00162             if (scheduler != null) {
00163                 GenericJob job = scheduler.getTmpJob(jobId);
00164                 job.addMainParameter(arg);
00165             }
00166 
00167             proActiveDescriptor.mainDefinitionAddParameter(arg);
00168         }
00169     }
00170 
00171     private class MapToVirtualNodeHandler extends BasicUnmarshaller {
00172         ProActiveDescriptor proActiveDescriptor;
00173 
00174         private MapToVirtualNodeHandler(ProActiveDescriptor proActiveDescriptor) {
00175             this.proActiveDescriptor = proActiveDescriptor;
00176         }
00177 
00178         public void startContextElement(String name, Attributes attributes)
00179             throws org.xml.sax.SAXException {
00180             String virtualNode = attributes.getValue("value");
00181 
00182             if (!checkNonEmpty(virtualNode)) {
00183                 throw new org.xml.sax.SAXException(
00184                     "value Tag without any mapToVirtualNode defined");
00185             }
00186 
00187             VirtualNode vn = (VirtualNode) proActiveDescriptor.createVirtualNode(virtualNode,
00188                     false, true);
00189 
00190             proActiveDescriptor.mainDefinitionAddVirtualNode(vn);
00191         }
00192     }
00193 }

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