View Javadoc
1   /*
2    *   Copyright (C) Christian Schulte <cs@schulte.it>, 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: TransformerResourceType.java 5043 2015-05-27 07:03:39Z schulte $
29   *
30   */
31  package org.jomc.ant.types;
32  
33  import java.util.ArrayList;
34  import java.util.LinkedList;
35  import java.util.List;
36  import org.apache.commons.lang.builder.ToStringBuilder;
37  
38  /**
39   * Datatype describing a XSLT document resource.
40   *
41   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
42   * @version $JOMC: TransformerResourceType.java 5043 2015-05-27 07:03:39Z schulte $
43   */
44  public class TransformerResourceType extends ResourceType
45  {
46  
47      /**
48       * The transformation parameter resources to apply.
49       */
50      private List<PropertiesResourceType> transformationParameterResources;
51  
52      /**
53       * The transformation parameters to apply.
54       */
55      private List<KeyValueType> transformationParameters;
56  
57      /**
58       * The transformation output properties to apply.
59       */
60      private List<KeyValueType> transformationOutputProperties;
61  
62      /**
63       * Creates a new {@code TransformerResourceType}.
64       */
65      public TransformerResourceType()
66      {
67          super();
68      }
69  
70      /**
71       * Gets the transformation parameters to apply.
72       * <p>
73       * This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make
74       * to the returned list will be present inside the object. This is why there is no {@code set} method for the
75       * transformation parameters property.
76       * </p>
77       *
78       * @return The transformation parameters to apply.
79       *
80       * @see #createTransformationParameter()
81       */
82      public final List<KeyValueType> getTransformationParameters()
83      {
84          if ( this.transformationParameters == null )
85          {
86              this.transformationParameters = new LinkedList<KeyValueType>();
87          }
88  
89          return this.transformationParameters;
90      }
91  
92      /**
93       * Creates a new {@code transformationParameter} element instance.
94       *
95       * @return A new {@code transformationParameter} element instance.
96       *
97       * @see #getTransformationParameters()
98       */
99      public KeyValueType createTransformationParameter()
100     {
101         final KeyValueType transformationParameter = new KeyValueType();
102         this.getTransformationParameters().add( transformationParameter );
103         return transformationParameter;
104     }
105 
106     /**
107      * Gets the transformation parameter resources to apply.
108      * <p>
109      * This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make
110      * to the returned list will be present inside the object. This is why there is no {@code set} method for the
111      * transformation parameter resources property.
112      * </p>
113      *
114      * @return The transformation parameter resources to apply.
115      *
116      * @see #createTransformationParameterResource()
117      */
118     public final List<PropertiesResourceType> getTransformationParameterResources()
119     {
120         if ( this.transformationParameterResources == null )
121         {
122             this.transformationParameterResources = new LinkedList<PropertiesResourceType>();
123         }
124 
125         return this.transformationParameterResources;
126     }
127 
128     /**
129      * Creates a new {@code transformationParameterResource} element instance.
130      *
131      * @return A new {@code transformationParameterResource} element instance.
132      *
133      * @see #getTransformationParameterResources()
134      */
135     public PropertiesResourceType createTransformationParameterResource()
136     {
137         final PropertiesResourceType transformationParameterResource = new PropertiesResourceType();
138         this.getTransformationParameterResources().add( transformationParameterResource );
139         return transformationParameterResource;
140     }
141 
142     /**
143      * Gets the transformation output properties to apply.
144      * <p>
145      * This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make
146      * to the returned list will be present inside the object. This is why there is no {@code set} method for the
147      * transformation output properties property.
148      * </p>
149      *
150      * @return The transformation output properties to apply.
151      *
152      * @see #createTransformationOutputProperty()
153      */
154     public final List<KeyValueType> getTransformationOutputProperties()
155     {
156         if ( this.transformationOutputProperties == null )
157         {
158             this.transformationOutputProperties = new LinkedList<KeyValueType>();
159         }
160 
161         return this.transformationOutputProperties;
162     }
163 
164     /**
165      * Creates a new {@code transformationOutputProperty} element instance.
166      *
167      * @return A new {@code transformationOutputProperty} element instance.
168      *
169      * @see #getTransformationOutputProperties()
170      */
171     public KeyValueType createTransformationOutputProperty()
172     {
173         final KeyValueType transformationOutputProperty = new KeyValueType();
174         this.getTransformationOutputProperties().add( transformationOutputProperty );
175         return transformationOutputProperty;
176     }
177 
178     /**
179      * Creates and returns a copy of this object.
180      *
181      * @return A copy of this object.
182      */
183     @Override
184     public TransformerResourceType clone()
185     {
186         final TransformerResourceType clone = (TransformerResourceType) super.clone();
187 
188         if ( this.transformationParameters != null )
189         {
190             clone.transformationParameters =
191                 new ArrayList<KeyValueType>( this.transformationParameters.size() );
192 
193             for ( final KeyValueType e : this.transformationParameters )
194             {
195                 clone.transformationParameters.add( e.clone() );
196             }
197         }
198 
199         if ( this.transformationParameterResources != null )
200         {
201             clone.transformationParameterResources =
202                 new ArrayList<PropertiesResourceType>( this.transformationParameterResources.size() );
203 
204             for ( final PropertiesResourceType e : this.transformationParameterResources )
205             {
206                 clone.transformationParameterResources.add( e.clone() );
207             }
208         }
209 
210         if ( this.transformationOutputProperties != null )
211         {
212             clone.transformationOutputProperties =
213                 new ArrayList<KeyValueType>( this.transformationOutputProperties.size() );
214 
215             for ( final KeyValueType e : this.transformationOutputProperties )
216             {
217                 clone.transformationOutputProperties.add( e.clone() );
218             }
219         }
220 
221         return clone;
222     }
223 
224     /**
225      * Creates and returns a string representation of the object.
226      *
227      * @return A string representation of the object.
228      */
229     @Override
230     public String toString()
231     {
232         return ToStringBuilder.reflectionToString( this );
233     }
234 
235 }