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 4613 2012-09-22 10:07:08Z schulte $
029 *
030 */
031package org.jomc.mojo;
032
033import org.apache.commons.lang.builder.ToStringBuilder;
034
035/**
036 * Datatype describing a resource.
037 *
038 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
039 * @version $JOMC: ResourceType.java 4613 2012-09-22 10:07:08Z schulte $
040 * @since 1.2
041 */
042public class ResourceType implements Cloneable
043{
044
045    /** The location of the resource. */
046    private String location;
047
048    /** Flag indicating the resource is optional. */
049    private boolean optional;
050
051    /** Timeout value, in milliseconds, to be used when opening communications links to the resource. */
052    private int connectTimeout = 60000;
053
054    /** Timeout value, in milliseconds, to be used when reading the resource. */
055    private int readTimeout = 60000;
056
057    /** Creates a new {@code ResourceType} instance. */
058    public ResourceType()
059    {
060        super();
061    }
062
063    /**
064     * Gets the value of the {@code location} property.
065     *
066     * @return The value of the {@code location} property.
067     */
068    public final String getLocation()
069    {
070        return this.location;
071    }
072
073    /**
074     * Sets the value of the {@code location} property.
075     *
076     * @param value The value of the {@code location} property.
077     */
078    public final void setLocation( final String value )
079    {
080        this.location = value;
081    }
082
083    /**
084     * Gets a flag indicating the resource is optional.
085     *
086     * @return {@code true}, if the resource is optional; {@code false}, if the build fails when the resource is not
087     * found.
088     */
089    public final boolean isOptional()
090    {
091        return this.optional;
092    }
093
094    /**
095     * Sets the flag indicating the resource is optional.
096     *
097     * @param value {@code true}, to flag the resource optional; {@code false}, to fail the build when the resource is
098     * not found.
099     */
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}