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 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     
00060     
00061     
00062     
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             
00114         }
00115 
00116         if (name.equals(MAP_TO_VIRTUAL_NODE_TAG)) {
00117             
00118         }
00119 
00120         if (name.equals(CLASSPATH_TAG)) {
00121             
00122             if (scheduler != null) {
00123                 String[] result = (String[]) activeHandler.getResultObject();
00124                 GenericJob job = scheduler.getTmpJob(this.jobId);
00125                 job.setClassPath(result);
00126                 
00127                 
00128                 
00129             }
00130         }
00131     }
00132 
00133     
00134     
00135     
00136     
00137     
00138     
00139     
00140     
00141     
00142     
00143     
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             
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 }