| 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: TransformerResourceType.java 4613 2012-09-22 10:07:08Z 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 4613 2012-09-22 10:07:08Z schulte $ |
| 43 | */ |
| 44 | public class TransformerResourceType extends ResourceType |
| 45 | { |
| 46 | |
| 47 | /** The transformation parameter resources to apply. */ |
| 48 | private List<PropertiesResourceType> transformationParameterResources; |
| 49 | |
| 50 | /** The transformation parameters to apply. */ |
| 51 | private List<KeyValueType> transformationParameters; |
| 52 | |
| 53 | /** The transformation output properties to apply. */ |
| 54 | private List<KeyValueType> transformationOutputProperties; |
| 55 | |
| 56 | /** Creates a new {@code TransformerResourceType}. */ |
| 57 | public TransformerResourceType() |
| 58 | { |
| 59 | super(); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Gets the transformation parameters to apply. |
| 64 | * <p>This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make |
| 65 | * to the returned list will be present inside the object. This is why there is no {@code set} method for the |
| 66 | * transformation parameters property.</p> |
| 67 | * |
| 68 | * @return The transformation parameters to apply. |
| 69 | * |
| 70 | * @see #createTransformationParameter() |
| 71 | */ |
| 72 | public final List<KeyValueType> getTransformationParameters() |
| 73 | { |
| 74 | if ( this.transformationParameters == null ) |
| 75 | { |
| 76 | this.transformationParameters = new LinkedList<KeyValueType>(); |
| 77 | } |
| 78 | |
| 79 | return this.transformationParameters; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Creates a new {@code transformationParameter} element instance. |
| 84 | * |
| 85 | * @return A new {@code transformationParameter} element instance. |
| 86 | * |
| 87 | * @see #getTransformationParameters() |
| 88 | */ |
| 89 | public KeyValueType createTransformationParameter() |
| 90 | { |
| 91 | final KeyValueType transformationParameter = new KeyValueType(); |
| 92 | this.getTransformationParameters().add( transformationParameter ); |
| 93 | return transformationParameter; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Gets the transformation parameter resources to apply. |
| 98 | * <p>This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make |
| 99 | * 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 | } |