KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > mktemp > MkTempFile


1 /**
2  * $Id: MkTempFile.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2005 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2 of the License, or (at your option) any later
9  * version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL (GNU Lesser General Public License) for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.mktemp;
30
31 import java.io.File JavaDoc;
32
33 import org.apache.tools.ant.BuildException;
34 import org.apache.tools.ant.types.PropertySet;
35 import org.apache.tools.ant.types.Reference;
36
37 import com.idaremedia.antx.helpers.InnerString;
38 import com.idaremedia.antx.starters.StringItemListHandle;
39
40 /**
41  * Instance of MkTempObject that only produces actual temporary files. Note temporary
42  * files <em>are</em> marked for automatic deletion when the VM exits. Unlike the
43  * builtin Ant '<i>tempfile</i>' task, this command produces a real file-system entity.
44  * Prototype lines (as specified with the &lt;line&gt; or &lt;lines&gt; elements) are
45  * only applied to new empty files. If a prototype copy file (or resource) has been
46  * defined, these lines are <em>not</em> included to the new file.
47  * <p>
48  * <b> Examples:</b><pre>
49  * &lt;<b>newtempfile</b> prefix="sot" copyresource="antx/testfiles/broken-build.xml"
50  * pathproperty="scratch.file0"/&gt;
51  *
52  * &lt;<b>newtempfile</b> prefix="corn-" suffix=".sql" copyresource="build/getcorn.sql"
53  * pathproperty="corn.sql.file"&gt;
54  * &lt;filterset refid="corn.sql.copyfilters"/&gt;
55  * &lt;/newtempfile&gt;
56  *
57  * &lt;<b>newtempfile</b> pathproperty="sillyfile"&gt;
58  * &lt;line value="hello"/&gt;
59  * &lt;line value="there"/&gt;
60  * &lt;line value="world"/&gt;
61  * &lt;/newtempfile&gt;
62  * </pre>
63  *
64  * @since JWare/AntX 0.1
65  * @author ssmc, &copy;2002-2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
66  * @version 0.5
67  * @.safety single
68  * @.group api,helper
69  **/

70
71 public final class MkTempFile extends MkTempObject
72 {
73     /**
74      * Create a new mktempfile task.
75      **/

76     public MkTempFile()
77     {
78         super();
79     }
80
81
82     /**
83      * Adds a new prototype line to include in new file.
84      * @param line the line information (non-null)
85      * @since JWare/AntX 0.3
86      **/

87     public void addLine(InnerString line)
88     {
89         require_(line!=null,"addLn- nonzro ln");
90         getPrototypeLinesNoNull().add(line);
91     }
92
93
94     /**
95      * Adds a reference to prototype lines to include in new file.
96      * @param lines the line information (non-null)
97      * @since JWare/AntX 0.3
98      **/

99     public void addLines(StringItemListHandle lines)
100     {
101         require_(lines!=null,"addLns- nonzro lns");
102         getPrototypeLinesNoNull().add(lines);
103     }
104
105
106     /**
107      * Shortcut for {@linkplain #addLines addLines()}. The
108      * refered-to list is <em>added</em> to this task's prototype
109      * lines.
110      * @param ref the itemlist's reference (non-null)
111      * @since JWare/AntX 0.3
112      **/

113     public final void setLines(Reference ref)
114     {
115         StringItemListHandle lines = new StringItemListHandle(ref);
116         getPrototypeLinesNoNull().add(lines);
117     }
118
119
120     /**
121      * Adds a new property set to include in new temporary file.
122      * @param propertyset new propertyset line (non-null)
123      * @since JWare/AntX 0.4
124      **/

125     public void addConfiguredPropertySet(PropertySet propertyset)
126     {
127         require_(propertyset!=null,"addPropSet- nonzro pset");
128         getPrototypeLinesNoNull().add(propertyset);
129     }
130
131
132     /**
133      * Creates a new temporary file. If executed multiple times, will not
134      * produce the same named file within a single VM instance. If either a prototype
135      * source or prototype lines were defined, the new file's contents will
136      * match the prototype information.
137      **/

138     public void execute() throws BuildException
139     {
140         verifyInProject_("exec");
141
142         File JavaDoc newFile = createFile(getInDir());
143
144         saveFinalPath(newFile,true);
145     }
146 }
147
148 /* end-of-MkTempFile.java */
149
Popular Tags