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: TransformerResourceType.java 3878 2011-10-24 00:58:09Z schulte2005 $
029     *
030     */
031    package org.jomc.ant.types;
032    
033    import java.util.ArrayList;
034    import java.util.LinkedList;
035    import java.util.List;
036    import org.apache.commons.lang.builder.ToStringBuilder;
037    
038    /**
039     * Datatype describing a XSLT document resource.
040     *
041     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a>
042     * @version $JOMC: TransformerResourceType.java 3878 2011-10-24 00:58:09Z schulte2005 $
043     */
044    public class TransformerResourceType extends ResourceType
045    {
046    
047        /** The transformation parameter resources to apply. */
048        private List<PropertiesResourceType> transformationParameterResources;
049    
050        /** The transformation parameters to apply. */
051        private List<KeyValueType> transformationParameters;
052    
053        /** The transformation output properties to apply. */
054        private List<KeyValueType> transformationOutputProperties;
055    
056        /** Creates a new {@code TransformerResourceType}. */
057        public TransformerResourceType()
058        {
059            super();
060        }
061    
062        /**
063         * Gets the transformation parameters to apply.
064         * <p>This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make
065         * to the returned list will be present inside the object. This is why there is no {@code set} method for the
066         * transformation parameters property.</p>
067         *
068         * @return The transformation parameters to apply.
069         *
070         * @see #createTransformationParameter()
071         */
072        public final List<KeyValueType> getTransformationParameters()
073        {
074            if ( this.transformationParameters == null )
075            {
076                this.transformationParameters = new LinkedList<KeyValueType>();
077            }
078    
079            return this.transformationParameters;
080        }
081    
082        /**
083         * Creates a new {@code transformationParameter} element instance.
084         *
085         * @return A new {@code transformationParameter} element instance.
086         *
087         * @see #getTransformationParameters()
088         */
089        public KeyValueType createTransformationParameter()
090        {
091            final KeyValueType transformationParameter = new KeyValueType();
092            this.getTransformationParameters().add( transformationParameter );
093            return transformationParameter;
094        }
095    
096        /**
097         * Gets the transformation parameter resources to apply.
098         * <p>This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make
099         * to the returned list will be present inside the object. This is why there is no {@code set} method for the
100         * transformation parameter resources property.</p>
101         *
102         * @return The transformation parameter resources to apply.
103         *
104         * @see #createTransformationParameterResource()
105         */
106        public final List<PropertiesResourceType> getTransformationParameterResources()
107        {
108            if ( this.transformationParameterResources == null )
109            {
110                this.transformationParameterResources = new LinkedList<PropertiesResourceType>();
111            }
112    
113            return this.transformationParameterResources;
114        }
115    
116        /**
117         * Creates a new {@code transformationParameterResource} element instance.
118         *
119         * @return A new {@code transformationParameterResource} element instance.
120         *
121         * @see #getTransformationParameterResources()
122         */
123        public PropertiesResourceType createTransformationParameterResource()
124        {
125            final PropertiesResourceType transformationParameterResource = new PropertiesResourceType();
126            this.getTransformationParameterResources().add( transformationParameterResource );
127            return transformationParameterResource;
128        }
129    
130        /**
131         * Gets the transformation output properties to apply.
132         * <p>This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make
133         * to the returned list will be present inside the object. This is why there is no {@code set} method for the
134         * transformation output properties property.</p>
135         *
136         * @return The transformation output properties to apply.
137         *
138         * @see #createTransformationOutputProperty()
139         */
140        public final List<KeyValueType> getTransformationOutputProperties()
141        {
142            if ( this.transformationOutputProperties == null )
143            {
144                this.transformationOutputProperties = new LinkedList<KeyValueType>();
145            }
146    
147            return this.transformationOutputProperties;
148        }
149    
150        /**
151         * Creates a new {@code transformationOutputProperty} element instance.
152         *
153         * @return A new {@code transformationOutputProperty} element instance.
154         *
155         * @see #getTransformationOutputProperties()
156         */
157        public KeyValueType createTransformationOutputProperty()
158        {
159            final KeyValueType transformationOutputProperty = new KeyValueType();
160            this.getTransformationOutputProperties().add( transformationOutputProperty );
161            return transformationOutputProperty;
162        }
163    
164        /**
165         * Creates and returns a copy of this object.
166         *
167         * @return A copy of this object.
168         */
169        @Override
170        public TransformerResourceType clone()
171        {
172            final TransformerResourceType clone = (TransformerResourceType) super.clone();
173    
174            if ( this.transformationParameters != null )
175            {
176                clone.transformationParameters =
177                    new ArrayList<KeyValueType>( this.transformationParameters.size() );
178    
179                for ( KeyValueType e : this.transformationParameters )
180                {
181                    clone.transformationParameters.add( e.clone() );
182                }
183            }
184    
185            if ( this.transformationParameterResources != null )
186            {
187                clone.transformationParameterResources =
188                    new ArrayList<PropertiesResourceType>( this.transformationParameterResources.size() );
189    
190                for ( PropertiesResourceType e : this.transformationParameterResources )
191                {
192                    clone.transformationParameterResources.add( e.clone() );
193                }
194            }
195    
196            if ( this.transformationOutputProperties != null )
197            {
198                clone.transformationOutputProperties =
199                    new ArrayList<KeyValueType>( this.transformationOutputProperties.size() );
200    
201                for ( KeyValueType e : this.transformationOutputProperties )
202                {
203                    clone.transformationOutputProperties.add( e.clone() );
204                }
205            }
206    
207            return clone;
208        }
209    
210        /**
211         * Creates and returns a string representation of the object.
212         *
213         * @return A string representation of the object.
214         */
215        @Override
216        public String toString()
217        {
218            return ToStringBuilder.reflectionToString( this );
219        }
220    
221    }