1 /**
2 * This file is part of Waarp Project.
3 *
4 * Copyright 2009, Frederic Bregier, and individual contributors by the @author tags. See the
5 * COPYRIGHT.txt in the distribution for a full listing of individual contributors.
6 *
7 * All Waarp Project is free software: you can redistribute it and/or modify it under the terms of
8 * the GNU General Public License as published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 * Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along with Waarp . If not, see
16 * <http://www.gnu.org/licenses/>.
17 */
18 package org.waarp.ftp.core.data;
19
20 import java.util.List;
21
22 import org.waarp.common.command.exception.CommandAbstractException;
23 import org.waarp.common.logging.WaarpLogger;
24 import org.waarp.common.logging.WaarpLoggerFactory;
25 import org.waarp.ftp.core.command.FtpCommandCode;
26 import org.waarp.ftp.core.exception.FtpNoFileException;
27 import org.waarp.ftp.core.file.FtpFile;
28
29 /**
30 * Class that owns one transfer to be run
31 *
32 * @author Frederic Bregier
33 *
34 */
35 public class FtpTransfer {
36 private static final WaarpLogger logger = WaarpLoggerFactory.getLogger(FtpTransfer.class);
37
38 /**
39 * The command to execute
40 */
41 private final FtpCommandCode command;
42
43 /**
44 * The information (list) on which the command was executed
45 */
46 private final List<String> info;
47
48 /**
49 * The original path on which the command was executed
50 */
51 private String path = null;
52
53 /**
54 * Current Ftp FileInterface
55 */
56 private final FtpFile currentFile;
57
58 /**
59 * The status
60 */
61 private boolean status = false;
62
63 /**
64 * @param command
65 * @param fileOrInfo
66 * @param path
67 */
68 public FtpTransfer(FtpCommandCode command, List<String> fileOrInfo,
69 String path) {
70 this.command = command;
71 info = fileOrInfo;
72 this.path = path;
73 currentFile = null;
74 }
75
76 /**
77 * @param command
78 * @param file
79 */
80 public FtpTransfer(FtpCommandCode command, FtpFile file) {
81 this.command = command;
82 currentFile = file;
83 try {
84 path = file.getFile();
85 } catch (CommandAbstractException e) {
86 }
87 info = null;
88 }
89
90 /**
91 * @return the command
92 */
93 public FtpCommandCode getCommand() {
94 return command;
95 }
96
97 /**
98 * @return the file
99 * @throws FtpNoFileException
100 */
101 public FtpFile getFtpFile() throws FtpNoFileException {
102 if (currentFile == null) {
103 throw new FtpNoFileException("No file associated with the transfer");
104 }
105 return currentFile;
106 }
107
108 /**
109 * @return the Info
110 */
111 public List<String> getInfo() {
112 return info;
113 }
114
115 /**
116 * @return the path
117 */
118 public String getPath() {
119 return path;
120 }
121
122 /**
123 * @return the status
124 */
125 public boolean getStatus() {
126 return status;
127 }
128
129 /**
130 * @param status
131 */
132 public void setStatus(boolean status) {
133 if (!status) {
134 logger.debug("Status false", new Exception("Trace only exception"));
135 }
136 this.status = status;
137 }
138
139 /**
140 *
141 */
142 @Override
143 public String toString() {
144 return command.name() + " " + path;
145 }
146 }