View Javadoc

1   /*
2    *   Copyright (C) Christian Schulte, 2005-206
3    *   All rights reserved.
4    *
5    *   Redistribution and use in source and binary forms, with or without
6    *   modification, are permitted provided that the following conditions
7    *   are met:
8    *
9    *     o Redistributions of source code must retain the above copyright
10   *       notice, this list of conditions and the following disclaimer.
11   *
12   *     o Redistributions in binary form must reproduce the above copyright
13   *       notice, this list of conditions and the following disclaimer in
14   *       the documentation and/or other materials provided with the
15   *       distribution.
16   *
17   *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18   *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19   *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20   *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
21   *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22   *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23   *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24   *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25   *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26   *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27   *
28   *   $JOMC: ResourceType.java 3838 2011-10-08 20:15:41Z schulte2005 $
29   *
30   */
31  package org.jomc.ant.types;
32  
33  import org.apache.commons.lang.builder.ToStringBuilder;
34  
35  /**
36   * Datatype describing a resource.
37   *
38   * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a>
39   * @version $JOMC: ResourceType.java 3838 2011-10-08 20:15:41Z schulte2005 $
40   */
41  public class ResourceType implements Cloneable
42  {
43  
44      /** The location of the resource. */
45      private String location;
46  
47      /** Flag indicating the resource is optional. */
48      private boolean optional;
49  
50      /** Timeout value, in milliseconds, to be used when opening communications links to the resource. */
51      private int connectTimeout = 60000;
52  
53      /** Timeout value, in milliseconds, to be used when reading the resource. */
54      private int readTimeout = 60000;
55  
56      /** Creates a new {@code ResourceType} instance. */
57      public ResourceType()
58      {
59          super();
60      }
61  
62      /**
63       * Gets the value of the {@code location} property.
64       *
65       * @return The value of the {@code location} property.
66       *
67       * @see #setLocation(java.lang.String)
68       */
69      public final String getLocation()
70      {
71          return this.location;
72      }
73  
74      /**
75       * Sets the value of the {@code location} property.
76       *
77       * @param value The value of the {@code location} property.
78       *
79       * @see #getLocation()
80       */
81      public final void setLocation( final String value )
82      {
83          this.location = value;
84      }
85  
86      /**
87       * Gets a flag indicating the resource is optional.
88       *
89       * @return {@code true}, if the resource is optional; {@code false}, if the build fails when the resource is not
90       * found.
91       *
92       * @see #setOptional(boolean)
93       */
94      public final boolean isOptional()
95      {
96          return this.optional;
97      }
98  
99      /**
100      * Sets the flag indicating the resource is optional.
101      *
102      * @param value {@code true}, to flag the resource optional; {@code false}, to fail the build when the resource is
103      * not found.
104      *
105      * @see #isOptional()
106      */
107     public final void setOptional( final boolean value )
108     {
109         this.optional = value;
110     }
111 
112     /**
113      * Gets the timeout value, in milliseconds, to be used when opening communications links to the resource.
114      * A timeout of zero is interpreted as an infinite timeout.
115      *
116      * @return The timeout value, in milliseconds, to be used when opening communications links to the resource.
117      *
118      * @see #setConnectTimeout(int)
119      */
120     public final int getConnectTimeout()
121     {
122         return this.connectTimeout;
123     }
124 
125     /**
126      * Sets the timeout value, in milliseconds, to be used when opening communications links to the resource.
127      * A timeout of zero is interpreted as an infinite timeout.
128      *
129      * @param value The new timeout value, in milliseconds, to be used when opening communications links to the
130      * resource.
131      *
132      * @see #getConnectTimeout()
133      */
134     public final void setConnectTimeout( final int value )
135     {
136         this.connectTimeout = value;
137     }
138 
139     /**
140      * Gets the timeout value, in milliseconds, to be used when reading the resource. A timeout of zero is interpreted
141      * as an infinite timeout.
142      *
143      * @return The timeout value, in milliseconds, to be used when reading the resource.
144      *
145      * @see #setReadTimeout(int)
146      */
147     public final int getReadTimeout()
148     {
149         return this.readTimeout;
150     }
151 
152     /**
153      * Sets the timeout value, in milliseconds, to be used when reading the resource. A timeout of zero is interpreted
154      * as an infinite timeout.
155      *
156      * @param value The new timeout value, in milliseconds, to be used when reading the resource.
157      *
158      * @see #getReadTimeout()
159      */
160     public final void setReadTimeout( final int value )
161     {
162         this.readTimeout = value;
163     }
164 
165     /**
166      * Creates and returns a copy of this object.
167      *
168      * @return A copy of this object.
169      */
170     @Override
171     public ResourceType clone()
172     {
173         try
174         {
175             return (ResourceType) super.clone();
176         }
177         catch ( final CloneNotSupportedException e )
178         {
179             throw new AssertionError( e );
180         }
181     }
182 
183     /**
184      * Creates and returns a string representation of the object.
185      *
186      * @return A string representation of the object.
187      */
188     @Override
189     public String toString()
190     {
191         return ToStringBuilder.reflectionToString( this );
192     }
193 
194 }