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.process.filetransfer.FileTransferDefinition;
00035 import org.objectweb.proactive.core.xml.handler.BasicUnmarshaller;
00036 import org.objectweb.proactive.core.xml.handler.PassiveCompositeUnmarshaller;
00037 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler;
00038 import org.objectweb.proactive.core.xml.io.Attributes;
00039 import org.xml.sax.SAXException;
00040 
00041 
00048 public class FileTransferDefinitionsHandler extends PassiveCompositeUnmarshaller
00049     implements ProActiveDescriptorConstants {
00050     protected ProActiveDescriptor proActiveDescriptor;
00051 
00052     public FileTransferDefinitionsHandler(
00053         ProActiveDescriptor proActiveDescriptor) {
00054         super(false);
00055         this.proActiveDescriptor = proActiveDescriptor;
00056         addHandler(FILE_TRANSFER_TAG, new FileTransferHandler());
00057     }
00058 
00059     protected void notifyEndActiveHandler(String name,
00060         UnmarshallerHandler activeHandler) throws SAXException {
00061     }
00062 
00063     public class FileTransferHandler extends PassiveCompositeUnmarshaller
00064         implements ProActiveDescriptorConstants {
00065         protected FileTransferDefinition fileTransfer;
00066 
00067         public FileTransferHandler() {
00068             super(false);
00069             addHandler(FILE_TRANSFER_FILE_TAG, new FileHandler());
00070             addHandler(FILE_TRANSFER_DIR_TAG, new DirHandler());
00071 
00072             
00073             fileTransfer = null;
00074         }
00075 
00076         public void startContextElement(String name, Attributes attributes)
00077             throws SAXException {
00078             String fileTransferId = attributes.getValue("id");
00079 
00080             if (!checkNonEmpty(fileTransferId)) {
00081                 throw new org.xml.sax.SAXException(
00082                     "FileTransfer defined without id");
00083             }
00084 
00085             if (fileTransferId.equalsIgnoreCase(FILE_TRANSFER_IMPLICT_KEYWORD)) {
00086                 throw new org.xml.sax.SAXException(
00087                     "FileTransferDefinition id attribute is using illegal keyword: " +
00088                     FILE_TRANSFER_IMPLICT_KEYWORD);
00089             }
00090 
00091             
00092 
00093 
00094 
00095 
00096             fileTransfer = proActiveDescriptor.getFileTransfer(fileTransferId);
00097         }
00098 
00099         public Object getResultObject() throws SAXException {
00100             return fileTransfer; 
00101         }
00102 
00103         public class FileHandler extends BasicUnmarshaller
00104             implements ProActiveDescriptorConstants {
00105             public void startContextElement(String name, Attributes attributes)
00106                 throws SAXException {
00107                 String source = attributes.getValue("src");
00108                 String dest = attributes.getValue("dest");
00109 
00110                 if (!checkNonEmpty(source)) {
00111                     throw new org.xml.sax.SAXException(
00112                         "Source filename not specified for file tag");
00113                 }
00114 
00115                 if (!checkNonEmpty(dest)) {
00116                     dest = source;
00117                 }
00118 
00119                 
00120                 fileTransfer.addFile(source, dest);
00121             }
00122         }
00123 
00124         public class DirHandler extends BasicUnmarshaller
00125             implements ProActiveDescriptorConstants {
00126             public void startContextElement(String name, Attributes attributes)
00127                 throws SAXException {
00128                 String source = attributes.getValue("src");
00129                 String dest = attributes.getValue("dest");
00130                 String include = attributes.getValue("include");
00131                 String exclude = attributes.getValue("exclude");
00132 
00133                 if (!checkNonEmpty(source)) {
00134                     throw new org.xml.sax.SAXException(
00135                         "Source filename not specified for file tag");
00136                 }
00137 
00138                 if (!checkNonEmpty(dest)) {
00139                     dest = source;
00140                 }
00141                 if (!checkNonEmpty(include)) {
00142                     include = "*";
00143                 }
00144                 if (!checkNonEmpty(exclude)) {
00145                     exclude = "";
00146                 }
00147 
00148                 
00149                 fileTransfer.addDir(source, dest, include, exclude);
00150             }
00151         }
00152     }
00153 }