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