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.mojo;
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   * @since 1.2
41   */
42  public class ResourceType implements Cloneable
43  {
44  
45      /** The location of the resource. */
46      private String location;
47  
48      /** Flag indicating the resource is optional. */
49      private boolean optional;
50  
51      /** Timeout value, in milliseconds, to be used when opening communications links to the resource. */
52      private int connectTimeout = 60000;
53  
54      /** Timeout value, in milliseconds, to be used when reading the resource. */
55      private int readTimeout = 60000;
56  
57      /** Creates a new {@code ResourceType} instance. */
58      public ResourceType()
59      {
60          super();
61      }
62  
63      /**
64       * Gets the value of the {@code location} property.
65       *
66       * @return The value of the {@code location} property.
67       */
68      public final String getLocation()
69      {
70          return this.location;
71      }
72  
73      /**
74       * Sets the value of the {@code location} property.
75       *
76       * @param value The value of the {@code location} property.
77       */
78      public final void setLocation( final String value )
79      {
80          this.location = value;
81      }
82  
83      /**
84       * Gets a flag indicating the resource is optional.
85       *
86       * @return {@code true}, if the resource is optional; {@code false}, if the build fails when the resource is not
87       * found.
88       */
89      public final boolean isOptional()
90      {
91          return this.optional;
92      }
93  
94      /**
95       * Sets the flag indicating the resource is optional.
96       *
97       * @param value {@code true}, to flag the resource optional; {@code false}, to fail the build when the resource is
98       * not found.
99       */
100     public final void setOptional( final boolean value )
101     {
102         this.optional = value;
103     }
104 
105     /**
106      * Gets the timeout value, in milliseconds, to be used when opening communications links to the resource.
107      * A timeout of zero is interpreted as an infinite timeout.
108      *
109      * @return The timeout value, in milliseconds, to be used when opening communications links to the resource.
110      */
111     public final int getConnectTimeout()
112     {
113         return this.connectTimeout;
114     }
115 
116     /**
117      * Sets the timeout value, in milliseconds, to be used when opening communications links to the resource.
118      * A timeout of zero is interpreted as an infinite timeout.
119      *
120      * @param value The new timeout value, in milliseconds, to be used when opening communications links to the
121      * resource.
122      */
123     public final void setConnectTimeout( final int value )
124     {
125         this.connectTimeout = value;
126     }
127 
128     /**
129      * Gets the timeout value, in milliseconds, to be used when reading the resource. A timeout of zero is interpreted
130      * as an infinite timeout.
131      *
132      * @return The timeout value, in milliseconds, to be used when reading the resource.
133      */
134     public final int getReadTimeout()
135     {
136         return this.readTimeout;
137     }
138 
139     /**
140      * Sets 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      * @param value The new timeout value, in milliseconds, to be used when reading the resource.
144      */
145     public final void setReadTimeout( final int value )
146     {
147         this.readTimeout = value;
148     }
149 
150     /**
151      * Creates and returns a copy of this object.
152      *
153      * @return A copy of this object.
154      */
155     @Override
156     public ResourceType clone()
157     {
158         try
159         {
160             return (ResourceType) super.clone();
161         }
162         catch ( final CloneNotSupportedException e )
163         {
164             throw new AssertionError( e );
165         }
166     }
167 
168     /**
169      * Creates and returns a string representation of the object.
170      *
171      * @return A string representation of the object.
172      */
173     @Override
174     public String toString()
175     {
176         return ToStringBuilder.reflectionToString( this );
177     }
178 
179 }