Source code: joelib/process/types/CreateFileName.java
1 ///////////////////////////////////////////////////////////////////////////////
2 // Filename: $RCSfile: CreateFileName.java,v $
3 // Purpose: Counts the number of descriptors and molecules in a molecule file.
4 // Language: Java
5 // Compiler: JDK 1.4
6 // Authors: Joerg K. Wegner
7 // Version: $Revision: 1.5 $
8 // $Date: 2003/08/22 15:56:20 $
9 // $Author: wegner $
10 //
11 // Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
12 //
13 // This program is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation version 2 of the License.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 ///////////////////////////////////////////////////////////////////////////////
22 package joelib.process.types;
23
24 import joelib.molecule.JOEMol;
25
26 import joelib.process.JOEProcess;
27 import joelib.process.JOEProcessException;
28 import joelib.process.ProcessInfo;
29
30 import joelib.util.JHM;
31 import joelib.util.JOEProperty;
32 import joelib.util.JOEPropertyHelper;
33
34 import wsi.ra.io.FileUtilities;
35
36 /*==========================================================================*
37 * IMPORTS
38 *========================================================================== */
39 import java.util.Map;
40
41 import org.apache.log4j.Category;
42
43
44 /*==========================================================================*
45 * CLASS DECLARATION
46 *========================================================================== */
47
48 /**
49 * Calling processor classes if the filter rule fits.
50 *
51 * @author wegnerj
52 * @license GPL
53 * @cvsversion $Revision: 1.5 $, $Date: 2003/08/22 15:56:20 $
54 */
55 public class CreateFileName implements JOEProcess
56 {
57 //~ Static fields/initializers /////////////////////////////////////////////
58
59 /*-------------------------------------------------------------------------*
60 * public static member variables
61 *------------------------------------------------------------------------- */
62
63 /**
64 * Obtain a suitable logger.
65 */
66 private static Category logger = Category.getInstance(
67 "joelib.process.types.CreateFileName");
68 private final static JOEProperty[] ACCEPTED_PROPERTIES = new JOEProperty[]
69 {
70 new JOEProperty("FILE", "java.lang.String",
71 "Filename of the file that will be created in the temporary directory.",
72 false)
73 };
74
75 //~ Instance fields ////////////////////////////////////////////////////////
76
77 private ProcessInfo info;
78
79 //~ Constructors ///////////////////////////////////////////////////////////
80
81 /*-------------------------------------------------------------------------*
82 * constructor
83 *------------------------------------------------------------------------- */
84
85 /**
86 * Constructor for the DescSelectionWriter object
87 */
88 public CreateFileName()
89 {
90 }
91
92 //~ Methods ////////////////////////////////////////////////////////////////
93
94 /**
95 * Sets the processInfo attribute of the ProcessPipe object
96 *
97 * @param _info The new processInfo value
98 */
99 public void setProcessInfo(ProcessInfo _info)
100 {
101 info = _info;
102 }
103
104 /*-------------------------------------------------------------------------*
105 * public methods
106 *------------------------------------------------------------------------- */
107
108 /**
109 * Gets the processInfo attribute of the ProcessPipe object
110 *
111 * @return The processInfo value
112 */
113 public ProcessInfo getProcessInfo()
114 {
115 return info;
116 }
117
118 /**
119 * Description of the Method
120 *
121 * @return Description of the Return Value
122 */
123 public JOEProperty[] acceptedProperties()
124 {
125 return ACCEPTED_PROPERTIES;
126 }
127
128 /**
129 * Description of the Method
130 *
131 * @return Description of the Return Value
132 */
133 public boolean clear()
134 {
135 return true;
136 }
137
138 /**
139 * Description of the Method
140 *
141 * @param mol Description of the Parameter
142 * @param properties Description of the Parameter
143 * @return Description of the Return Value
144 * @exception JOEProcessException Description of the Exception
145 */
146 public boolean process(JOEMol mol, Map properties)
147 throws JOEProcessException
148 {
149 // check properties
150 if (!JOEPropertyHelper.checkProperties(this, properties))
151 {
152 throw new JOEProcessException(
153 "Empty property definition for process or missing property entry.");
154
155 //return false;
156 }
157
158 // get plain file name
159 String filename = (String) JOEPropertyHelper.getProperty(this, "FILE",
160 properties);
161
162 // create full path to file and create file
163 String fullFilename = JHM.getTempFileBase() + filename;
164
165 try
166 {
167 fullFilename = FileUtilities.instance().createNewFileName(fullFilename);
168 }
169 catch (Exception ex)
170 {
171 logger.error(ex.toString());
172
173 return false;
174 }
175
176 // store created file name in properties
177 JOEPropertyHelper.setProperty("FILE", properties, fullFilename);
178
179 if (logger.isDebugEnabled())
180 {
181 logger.debug("Filename '" + fullFilename + "' created.");
182 }
183
184 return true;
185 }
186
187 /*-------------------------------------------------------------------------*
188 * private methods
189 *------------------------------------------------------------------------- */
190 }
191 ///////////////////////////////////////////////////////////////////////////////
192 // END OF FILE.
193 ///////////////////////////////////////////////////////////////////////////////