org/objectweb/proactive/core/process/filetransfer/AbstractCopyProtocol.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.process.filetransfer;
00032 
00033 import java.io.IOException;
00034 import java.io.InputStream;
00035 import java.util.ArrayList;
00036 
00037 import org.apache.log4j.Logger;
00038 import org.objectweb.proactive.core.process.filetransfer.FileTransferDefinition.DirectoryDescription;
00039 import org.objectweb.proactive.core.process.filetransfer.FileTransferDefinition.FileDescription;
00040 import org.objectweb.proactive.core.process.filetransfer.FileTransferWorkShop;
00041 import org.objectweb.proactive.core.process.filetransfer.FileTransferWorkShop.StructureInformation;
00042 import org.objectweb.proactive.core.util.log.Loggers;
00043 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00044 
00045 
00054 public abstract class AbstractCopyProtocol implements CopyProtocol {
00055     protected static Logger logger = ProActiveLogger.getLogger(Loggers.DEPLOYMENT_FILETRANSFER);
00056     protected boolean isDefaultProtocol = false;
00057     protected String name;
00058     protected FileTransferDefinition[] fileTransfer;
00059     protected StructureInformation srcInfoParams;
00060     protected StructureInformation dstInfoParams;
00061     protected boolean closeStream = false;
00062 
00063     public AbstractCopyProtocol(String name) {
00064         this.name = name;
00065     }
00066 
00067     public String getProtocolName() {
00068         return name;
00069     }
00070 
00071     public void setProtocolName(String name) {
00072         this.name = name;
00073     }
00074 
00075     public boolean isDefaultProtocol() {
00076         return isDefaultProtocol;
00077     }
00078 
00079     public void setDefaultProtocol(boolean isDefaultProtocol) {
00080         this.isDefaultProtocol = isDefaultProtocol;
00081     }
00082 
00083     public void setFileTransferDefinitions(FileTransferDefinition[] fileTransfer) {
00084         this.fileTransfer = fileTransfer;
00085     }
00086 
00087     public void setSrcInfo(
00088         FileTransferWorkShop.StructureInformation srcInfoParams) {
00089         this.srcInfoParams = srcInfoParams;
00090     }
00091 
00092     public void setDstInfo(
00093         FileTransferWorkShop.StructureInformation dstInfoParams) {
00094         this.dstInfoParams = dstInfoParams;
00095     }
00096 
00101     public boolean isDummyProtocol() {
00102         return false;
00103     }
00104 
00113     protected FileDescription[] getHomonymousFiles() {
00114         ArrayList<FileDescription> aList = new ArrayList<FileDescription>();
00115 
00116         for (int i = 0; i < fileTransfer.length; i++) {
00117             FileDescription[] fd = fileTransfer[i].getHomonymousFile();
00118             for (int j = 0; j < fd.length; j++)
00119                 aList.add(fd[j]);
00120         }
00121 
00122         return aList.toArray(new FileDescription[0]);
00123     }
00124 
00133     protected FileDescription[] getHeteronymousFiles() {
00134         ArrayList<FileDescription> aList = new ArrayList<FileDescription>();
00135 
00136         for (int i = 0; i < fileTransfer.length; i++) {
00137             FileDescription[] fd = fileTransfer[i].getHeteronymousFile();
00138             for (int j = 0; j < fd.length; j++)
00139                 aList.add(fd[j]);
00140         }
00141 
00142         return aList.toArray(new FileDescription[0]);
00143     }
00144 
00153     protected DirectoryDescription[] getHomonymousDirs() {
00154         ArrayList<FileDescription> aList = new ArrayList<FileDescription>();
00155 
00156         for (int i = 0; i < fileTransfer.length; i++) {
00157             FileDescription[] fd = fileTransfer[i].getHomonymousDir();
00158             for (int j = 0; j < fd.length; j++)
00159                 aList.add(fd[j]);
00160         }
00161 
00162         return (DirectoryDescription[]) aList.toArray(new DirectoryDescription[0]);
00163     }
00164 
00174     protected DirectoryDescription[] getHeteronymousDirs() {
00175         ArrayList<DirectoryDescription> aList = new ArrayList<DirectoryDescription>();
00176 
00177         for (int i = 0; i < fileTransfer.length; i++) {
00178             DirectoryDescription[] fd = fileTransfer[i].getHeteronymousDir();
00179             for (int j = 0; j < fd.length; j++)
00180                 aList.add(fd[j]);
00181         }
00182 
00183         return aList.toArray(new DirectoryDescription[0]);
00184     }
00185 
00186     protected FileDescription[] getHeteronymousAll() {
00187         FileDescription[] files = getHeteronymousFiles();
00188         FileDescription[] dirs = getHeteronymousDirs();
00189 
00190         FileDescription[] all = new FileDescription[files.length + dirs.length];
00191 
00192         for (int i = 0; i < files.length; i++) {
00193             all[i] = files[i];
00194         }
00195 
00196         for (int i = 0; i < dirs.length; i++) {
00197             all[files.length + i] = dirs[i];
00198         }
00199 
00200         return all;
00201     }
00202 
00203     protected FileDescription[] getHomonymousAll() {
00204         FileDescription[] files = getHomonymousFiles();
00205         FileDescription[] dirs = getHomonymousDirs();
00206 
00207         FileDescription[] all = new FileDescription[files.length + dirs.length];
00208 
00209         for (int i = 0; i < files.length; i++) {
00210             all[i] = files[i];
00211         }
00212 
00213         for (int i = 0; i < dirs.length; i++) {
00214             all[files.length + i] = dirs[i];
00215         }
00216 
00217         return all;
00218     }
00219 
00225     protected String getErrorMessage(InputStream in) {
00226         StringBuilder sb = new StringBuilder();
00227         byte[] b = new byte[1000];
00228         int read;
00229         while (true) {
00230             try {
00231                 read = in.read(b);
00232                 if (read < 0) {
00233                     break;
00234                 }
00235 
00236                 sb.append(new String(b, 0, read));
00237             } catch (IOException e1) {
00238                 e1.printStackTrace();
00239             }
00240         }
00241         return sb.toString();
00242     }
00243 }

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