View Javadoc

1   /* -*- mode: JDE; c-basic-offset: 2; indent-tabs-mode: nil -*-
2    *
3    * $Id: FileSpec.java,v 1.2 2003/07/10 19:48:13 ljnelson Exp $
4    *
5    * Copyright (c) 2003 Laird Jarrett Nelson.
6    *
7    * Permission is hereby granted, free of charge, to any person obtaining a copy
8    * of this software and associated documentation files (the "Software"), to deal
9    * in the Software without restriction, including without limitation the rights
10   * to use, copy, modify, merge, publish, distribute, sublicense and/or sell 
11   * copies of the Software, and to permit persons to whom the Software is 
12   * furnished to do so, subject to the following conditions:
13   * 
14   * The above copyright notice and this permission notice shall be included in 
15   * all copies or substantial portions of the Software.
16   * 
17   * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
19   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
20   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
21   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23   * SOFTWARE.
24   *
25   * The original copy of this license is available at
26   * http://www.opensource.org/license/mit-license.html.
27   */
28  package org.apache.tools.ant.taskdefs.optional.sourceforge;
29  
30  import java.io.File;
31  import java.io.Serializable;
32  
33  import java.util.Date;
34  
35  import org.apache.tools.ant.BuildException;
36  
37  import sfutils.frs.FileSpecification;
38  
39  /***
40   * A simple adapter class that allows <a href="http://ant.apache.org/">Ant</a>
41   * to create and set the attributes of a {@link FileSpecification}.
42   *
43   * @author     <a href="mailto:ljnelson94@alumni.amherst.edu">Laird Nelson</a>
44   * @version    $Revision: 1.2 $ $Date: 2003/07/10 19:48:13 $
45   * @since      July 2, 2003
46   */
47  public final class FileSpec implements Serializable {
48  
49    /***
50     * The {@link FileSpecification} being adapted.  This field is never
51     * <code>null</code>.
52     */
53    private final FileSpecification spec;
54  
55    /***
56     * Creates a new {@link FileSpec}.
57     */
58    public FileSpec() {
59      super();
60      this.spec = new FileSpecification();
61    }
62    
63    /***
64     * Sets the {@link File} for the underlying {@link FileSpecification}.
65     *
66     * @param      file
67     *               the {@link File} to install; must not be <code>null</code>
68     * @exception  BuildException
69     *               if an error occurs
70     */
71    public final void setFile(final File file) 
72      throws BuildException {
73      try {
74        this.spec.setFile(file);
75      } catch (final Exception anything) {
76        throw new BuildException(anything);
77      }
78    }
79  
80    /***
81     * Sets the {@linkplain FileSpecification#setReleaseDate(Date) release date}
82     * for the underlying {@link FileSpecification}.
83     *
84     * @param      date
85     *               the release {@link Date}; must not be <code>null</code>
86     * @exception  BuildException
87     *               if an error occurs
88     */
89    public final void setReleaseDate(final Date date) 
90      throws BuildException {
91      try {
92        this.spec.setReleaseDate(date);
93      } catch (final Exception anything) {
94        throw new BuildException(anything);
95      }
96    }
97  
98    /***
99     * Sets the {@linkplain FileSpecification#setProcessorType(int) processor
100    * type} on the underlying {@link FileSpecification}.
101    *
102    * @param      type
103    *               the processor type; must not be <code>null</code>
104    * @exception  BuildException
105    *               if an error occurs
106    */
107   public final void setProcessorType(final String type) 
108     throws BuildException {
109     try {
110       this.spec.setProcessorTypeString(type);
111     } catch (final Exception anything) {
112       throw new BuildException(anything);
113     }
114   }
115 
116   /***
117    * Sets the {@linkplain FileSpecification#setFileType(int) file type} on the
118    * underlying {@link FileSpecification}.
119    *
120    * @param      type
121    *               the file type; must not be <code>null</code>
122    * @exception  BuildException
123    *               if an error occurs
124    */
125   public final void setFileType(final String type) 
126     throws BuildException {
127     try {
128       this.spec.setFileTypeString(type);
129     } catch (final Exception anything) {
130       throw new BuildException(anything);
131     }
132   }
133 
134   /***
135    * Returns the underlying {@link FileSpecification}.  This method never
136    * returns <code>null</code>.
137    *
138    * @return     the underlying {@link FileSpecification}; never
139    *               <code>null</code>
140    */
141   public final FileSpecification getFileSpecification() {
142     return this.spec;
143   }
144 
145 }