001    /*
002     *   Copyright (C) Christian Schulte, 2005-206
003     *   All rights reserved.
004     *
005     *   Redistribution and use in source and binary forms, with or without
006     *   modification, are permitted provided that the following conditions
007     *   are met:
008     *
009     *     o Redistributions of source code must retain the above copyright
010     *       notice, this list of conditions and the following disclaimer.
011     *
012     *     o Redistributions in binary form must reproduce the above copyright
013     *       notice, this list of conditions and the following disclaimer in
014     *       the documentation and/or other materials provided with the
015     *       distribution.
016     *
017     *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
018     *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
019     *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
020     *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
021     *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
022     *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
023     *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
024     *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025     *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
026     *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027     *
028     *   $JOMC: ResourceType.java 3838 2011-10-08 20:15:41Z schulte2005 $
029     *
030     */
031    package org.jomc.ant.types;
032    
033    import org.apache.commons.lang.builder.ToStringBuilder;
034    
035    /**
036     * Datatype describing a resource.
037     *
038     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a>
039     * @version $JOMC: ResourceType.java 3838 2011-10-08 20:15:41Z schulte2005 $
040     */
041    public class ResourceType implements Cloneable
042    {
043    
044        /** The location of the resource. */
045        private String location;
046    
047        /** Flag indicating the resource is optional. */
048        private boolean optional;
049    
050        /** Timeout value, in milliseconds, to be used when opening communications links to the resource. */
051        private int connectTimeout = 60000;
052    
053        /** Timeout value, in milliseconds, to be used when reading the resource. */
054        private int readTimeout = 60000;
055    
056        /** Creates a new {@code ResourceType} instance. */
057        public ResourceType()
058        {
059            super();
060        }
061    
062        /**
063         * Gets the value of the {@code location} property.
064         *
065         * @return The value of the {@code location} property.
066         *
067         * @see #setLocation(java.lang.String)
068         */
069        public final String getLocation()
070        {
071            return this.location;
072        }
073    
074        /**
075         * Sets the value of the {@code location} property.
076         *
077         * @param value The value of the {@code location} property.
078         *
079         * @see #getLocation()
080         */
081        public final void setLocation( final String value )
082        {
083            this.location = value;
084        }
085    
086        /**
087         * Gets a flag indicating the resource is optional.
088         *
089         * @return {@code true}, if the resource is optional; {@code false}, if the build fails when the resource is not
090         * found.
091         *
092         * @see #setOptional(boolean)
093         */
094        public final boolean isOptional()
095        {
096            return this.optional;
097        }
098    
099        /**
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    }