View Javadoc

1   package org.apache.torque.generator.configuration;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.torque.generator.configuration.controller.Loglevel;
23  import org.apache.torque.generator.configuration.option.OptionsConfiguration;
24  import org.apache.torque.generator.configuration.paths.ProjectPaths;
25  import org.apache.torque.generator.configuration.paths.TorqueGeneratorPaths;
26  import org.apache.torque.generator.source.SourceProvider;
27  
28  /**
29   * Contains all necessary information about a generation unit.
30   */
31  public class UnitDescriptor
32  {
33      /**
34       * Possible packaging forms of a unit of generation.
35       */
36      public enum Packaging
37      {
38          /** the generation unit is provided as a jar file .*/
39          JAR,
40          /** the generation unit is provided in a local directory. */
41          DIRECTORY,
42          /** the generation unit is provided in the classpath. */
43          CLASSPATH
44      }
45  
46      /**
47       * The packaging of the generation unit.
48       */
49      private Packaging packaging;
50  
51     /**
52      * The paths the Torque generator must know about the surrounding project.
53      */
54      private ProjectPaths projectPaths;
55  
56      /**
57       * How the Torque generator's configuration is organized internally.
58       */
59      private TorqueGeneratorPaths configurationPaths;
60  
61      /**
62       * The parent of this generation unit, or null if it has no parent.
63       */
64      private UnitDescriptor inheritsFrom;
65  
66      /**  Overrides the source defined in the control file. */
67      private SourceProvider overrideSourceProvider;
68  
69      /** Options to override the settings in the project Directory. */
70      private OptionsConfiguration overrideOptions;
71  
72      /**
73       * The Loglevel to override the loglevel in the Torque
74       * generator configuration.
75       */
76      private Loglevel loglevel;
77  
78      /**
79       * The output encoding if no specific encoding has been set in the output;
80       * null for the default platform encoding.
81       */
82      private String defaultOutputEncoding = null;
83  
84      /**
85       * Constructor without inheritance, override options, overrideSourceFileset
86       * and loglevel.
87       *
88       * @param packaging The packaging of the generation unit, not null.
89       * @param projectPaths The paths the Torque generator must know about
90       *        the surrounding project, not null.
91       * @param configurationPaths The paths within the configuration
92       *        of the configuration unit, not null.
93       */
94      public UnitDescriptor(
95              Packaging packaging,
96              ProjectPaths projectPaths,
97              TorqueGeneratorPaths configurationPaths)
98      {
99          if (packaging == null)
100         {
101             throw new NullPointerException("packaging must not be null");
102         }
103         if (projectPaths == null)
104         {
105             throw new NullPointerException(
106                     "projectPaths must not be null");
107         }
108         if (configurationPaths == null)
109         {
110             throw new NullPointerException(
111                     "configurationPaths must not be null");
112         }
113 
114         this.packaging = packaging;
115         this.projectPaths = projectPaths;
116         this.configurationPaths = configurationPaths;
117     }
118 
119     /**
120      * Returns the packaging of the unit of generation.
121      *
122      * @return the packaging of the unit of generation, not null.
123      */
124     public Packaging getPackaging()
125     {
126         return packaging;
127     }
128 
129     /**
130      * Returns the paths which the Torque generator must know about the
131      * surrounding project.
132      *
133      * @return the paths of the surrounding project, not null.
134      */
135     public ProjectPaths getProjectPaths()
136     {
137         return projectPaths;
138     }
139 
140     /**
141      * Returns the paths in the configuration of this generation unit.
142      * @return the paths in the configuration of this generation unit,
143      *          not null.
144      */
145     public TorqueGeneratorPaths getConfigurationPaths()
146     {
147         return configurationPaths;
148     }
149 
150     /**
151      * Returns the descriptor of the generation unit from which this generation
152      * unit inherits, or null if this generation unit does not inherit from
153      * another generation unit.
154      *
155      * @return the parents unit descriptor, or null if no parent exists.
156      */
157     public UnitDescriptor getInheritsFrom()
158     {
159         return inheritsFrom;
160     }
161 
162     /**
163      * Sets the descriptor of the generation unit from which this generation
164      * unit inherits.
165      *
166      * @param inheritsFrom the parents unit descriptor,
167      *        or null if no parent exists.
168      */
169     public void setInheritsFrom(UnitDescriptor inheritsFrom)
170     {
171         this.inheritsFrom = inheritsFrom;
172     }
173 
174     /**
175      * Returns the source provider overriding the source defined in the
176      * control file, or null if the control file definition
177      * is not overridden.
178      *
179      * @return the overriding source provider, or null.
180      */
181     public SourceProvider getOverrideSourceProvider()
182     {
183         return overrideSourceProvider;
184     }
185 
186     /**
187      * Sets the source provider overriding the source defined in the
188      * control file.
189      *
190      * @param overrideSourceProvider the overriding source provider,
191      *        or null if the control file definition is not overridden.
192      */
193     public void setOverrideSourceProvider(SourceProvider overrideSourceProvider)
194     {
195         this.overrideSourceProvider = overrideSourceProvider;
196     }
197 
198     /**
199      * Returns the configuration of the overriding options, if any.
200      *
201      * @return the configuration of the overriding options, or null.
202      */
203     public OptionsConfiguration getOverrideOptions()
204     {
205         return overrideOptions;
206     }
207 
208     /**
209      * Sets the configuration of the overriding options, if any.
210      *
211      * @param overrideOptions the configuration of the overriding options,
212      *        or null.
213      */
214     public void setOverrideOptions(OptionsConfiguration overrideOptions)
215     {
216         this.overrideOptions = overrideOptions;
217     }
218 
219     /**
220      * Returns the log level overriding the loglevel defined in the
221      * configuration unit.
222      *
223      * @return the log level, or null.
224      */
225     public Loglevel getLoglevel()
226     {
227         return loglevel;
228     }
229 
230     /**
231      * Sets the log level overriding the loglevel defined in the
232      * configuration unit.
233      *
234      * @param loglevel the log level, or null.
235      */
236     public void setLoglevel(Loglevel loglevel)
237     {
238         this.loglevel = loglevel;
239     }
240 
241     /**
242      * Returns the output encoding if no specific encoding has been set
243      * in the output.
244      *
245      * @return the default output encoding, null for the default
246      *         platform encoding.
247      */
248     public String getDefaultOutputEncoding()
249     {
250         return defaultOutputEncoding;
251     }
252 
253     /**
254      * Sets the output encoding which is used if no specific encoding
255      * has been set in the output.
256      *
257      * @param defaultOutputEncoding the default output encoding,
258      *        null for the default platform encoding.
259      */
260     public void setDefaultOutputEncoding(String defaultOutputEncoding)
261     {
262         this.defaultOutputEncoding = defaultOutputEncoding;
263     }
264 }