org/objectweb/proactive/core/descriptor/xml/FileTransferDefinitionsHandler.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.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             //This will be initalized once we have the ID in in the startContextElement(...)
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             /* We get a reference on the FileTransfer object with this ID.
00092              * If this object doesn't exist the createFileTransfer will create
00093              * one. All future calls on this method will then return this same
00094              * instance for this ID.
00095              */
00096             fileTransfer = proActiveDescriptor.getFileTransfer(fileTransferId);
00097         }
00098 
00099         public Object getResultObject() throws SAXException {
00100             return fileTransfer; //not really used for now
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                 //fileTransfer variable is in the parent class
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                 //fileTransfer variable is in the parent class
00149                 fileTransfer.addDir(source, dest, include, exclude);
00150             }
00151         }
00152     }
00153 }

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