KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > hibernate > FactoryClassSubTask


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.modules.hibernate;
6
7 import java.util.Collection JavaDoc;
8
9 import xjavadoc.XClass;
10
11 import xdoclet.TemplateSubTask;
12 import xdoclet.XDocletException;
13 import xdoclet.tagshandler.PackageTagsHandler;
14 import xdoclet.util.Translator;
15 /**
16  * Generate a SessionFactory facade that is capable of configuring Hibernate inline, as well as provide a convenient
17  * method of switching later to other SessionFactory implementations.
18  *
19  * @author Brian Topping (topping@bill2.com)
20  * @created August 8, 2003
21  * @version $Revision: 1.8 $
22  * @ant.element name="factoryclass" display-name="Factory class generator"
23  * parent="xdoclet.modules.hibernate.HibernateDocletTask" @ xdoclet.merge-file file="hibernate-factory-custom.xdt"
24  * relates-to="HibernateFactory.java" description="A Java unparsed entity or XDoclet template file, for custom
25  * elements to be included in the generated HibernateFactory.java"
26  */

27 public class FactoryClassSubTask extends TemplateSubTask implements HibernateProperties
28 {
29
30     /**
31      * Default template to use for hibernate files
32      */

33     private static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/hibernate-factory.xdt";
34     private static String JavaDoc GENERATED_FILE_NAME = "HibernateFactory.java";
35
36     private String JavaDoc dataSource;
37     private String JavaDoc dialect;
38     private String JavaDoc driver;
39     private String JavaDoc username;
40     private String JavaDoc password;
41     private String JavaDoc factoryClass;
42     private boolean useJndiFactory = false;
43     private String JavaDoc jndiName;
44     private String JavaDoc jdbcUrl;
45     private String JavaDoc poolSize;
46
47     /**
48      * Constructor for the HibernateSubTask object
49      */

50     public FactoryClassSubTask()
51     {
52         setSubTaskName("factoryclass");
53         setHavingClassTag("hibernate.class");
54         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
55         setDestinationFile(GENERATED_FILE_NAME);
56     }
57
58     public String JavaDoc getDataSource()
59     {
60         return dataSource;
61     }
62
63     public String JavaDoc getDialect()
64     {
65         return dialect;
66     }
67
68     public String JavaDoc getDriver()
69     {
70         return driver;
71     }
72
73     public String JavaDoc getPassword()
74     {
75         return password;
76     }
77
78     public String JavaDoc getUsername()
79     {
80         return username;
81     }
82
83     public String JavaDoc getFactoryClass()
84     {
85         return factoryClass;
86     }
87
88     public boolean isUseJndiFactory()
89     {
90         return useJndiFactory;
91     }
92
93     public Collection JavaDoc getJndiProperties()
94     {
95         throw new UnsupportedOperationException JavaDoc("FactoryClassSubTask does not have a jndiProperties attribute.");
96     }
97
98     /**
99      * We don't provide/have/use other mappings here for now.
100      * @see xdoclet.modules.hibernate.HibernateProperties#getOtherMappings()
101      */

102     public Collection JavaDoc getOtherMappings() {
103         throw new UnsupportedOperationException JavaDoc("FactoryClassSubTask doesn't have other mappings");
104     }
105
106     public Collection JavaDoc getOtherProperties()
107     {
108         throw new UnsupportedOperationException JavaDoc("FactoryClassSubTask does not have an otherProperties attribute.");
109     }
110
111     public String JavaDoc getTransactionManagerStrategy()
112     {
113         throw new UnsupportedOperationException JavaDoc("FactoryClassSubTask does not have a transactionManagerStrategy attribute.");
114     }
115
116     public String JavaDoc getUserTransactionName()
117     {
118         throw new UnsupportedOperationException JavaDoc("FactoryClassSubTask does not have a userTransactionName attribute.");
119     }
120
121     public String JavaDoc getUserName()
122     {
123         return username;
124     }
125
126     public boolean getUseOuterJoin()
127     {
128         throw new UnsupportedOperationException JavaDoc("FactoryClassSubTask does not have a useOuterJoin attribute.");
129     }
130
131     public boolean getShowSql()
132     {
133         throw new UnsupportedOperationException JavaDoc("FactoryClassSubTask does not have a showSql attribute.");
134     }
135
136     public String JavaDoc getJndiName()
137     {
138         return jndiName;
139     }
140
141     public String JavaDoc getJdbcUrl()
142     {
143         return jdbcUrl;
144     }
145
146     public String JavaDoc getPoolSize()
147     {
148         return poolSize;
149     }
150
151     /**
152      * @param jndiName
153      * @ant.not-required
154      */

155     public void setJndiName(String JavaDoc jndiName)
156     {
157         this.jndiName = jndiName;
158     }
159
160     /**
161      * @param jdbcUrl
162      */

163     public void setJdbcUrl(String JavaDoc jdbcUrl)
164     {
165         this.jdbcUrl = jdbcUrl;
166     }
167
168     /**
169      * @param poolSize
170      */

171     public void setPoolSize(String JavaDoc poolSize)
172     {
173         this.poolSize = poolSize;
174     }
175
176     /**
177      * The data source name to be generated into the factory
178      *
179      * @param dataSource
180      */

181     public void setDataSource(String JavaDoc dataSource)
182     {
183         this.dataSource = dataSource;
184     }
185
186     /**
187      * The Hibernate DB dialect to be generated into the factory
188      *
189      * @param dialect
190      */

191     public void setDialect(String JavaDoc dialect)
192     {
193         this.dialect = dialect;
194     }
195
196     /**
197      * The driver class name to be generated into the factory
198      *
199      * @param driver
200      */

201     public void setDriver(String JavaDoc driver)
202     {
203         this.driver = driver;
204     }
205
206     /**
207      * The password to be generated into the factory
208      *
209      * @param password
210      */

211     public void setPassword(String JavaDoc password)
212     {
213         this.password = password;
214     }
215
216     /**
217      * The username to be generated into the factory
218      *
219      * @param username
220      */

221     public void setUsername(String JavaDoc username)
222     {
223         this.username = username;
224     }
225
226     /**
227      * The fully qualified class name of the generated factory
228      *
229      * @param factoryClass
230      */

231     public void setFactoryClass(String JavaDoc factoryClass)
232     {
233         this.factoryClass = factoryClass;
234     }
235
236     /**
237      * @param useJndiFactory
238      * @ant.not-required No. Default is false.
239      */

240     public void setUseJndiFactory(boolean useJndiFactory)
241     {
242         this.useJndiFactory = useJndiFactory;
243     }
244
245
246     public void validateOptions() throws XDocletException
247     {
248         super.validateOptions();
249
250         if (getFactoryClass() == null) {
251             throw new XDocletException(Translator.getString(XDocletModulesHibernateMessages.class,
252                 XDocletModulesHibernateMessages.FACTORY_NAME_REQUIRED));
253         }
254     }
255
256     /**
257      * Describe what the method does
258      *
259      * @exception XDocletException Describe the exception
260      */

261     public void execute() throws XDocletException
262     {
263         setDestinationFile(PackageTagsHandler.packageNameAsPathFor(factoryClass) + ".java");
264         startProcess();
265     }
266
267     /**
268      * Gets the GeneratedFileName attribute of the EntityCmpSubTask object
269      *
270      * @param clazz Describe what the parameter does
271      * @return The GeneratedFileName value
272      * @exception XDocletException
273      */

274     protected String JavaDoc getGeneratedFileName(XClass clazz) throws XDocletException
275     {
276         return PackageTagsHandler.packageNameAsPathFor(factoryClass) + ".java";
277     }
278
279     /**
280      * Called when the engine is started
281      *
282      * @exception XDocletException Thrown in case of problem
283      */

284     protected void engineStarted() throws XDocletException
285     {
286         System.out.println(Translator.getString(XDocletModulesHibernateMessages.class,
287             XDocletModulesHibernateMessages.GENERATING_HIBERNATE_FACTORY_CLASS));
288     }
289 }
290
291
Popular Tags