KickJava   Java API By Example, From Geeks To Geeks.

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


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 xdoclet.XDocletException;
10
11 import xdoclet.XmlSubTask;
12
13 import xdoclet.util.Translator;
14 /**
15  * Generate jboss mbean descriptor for hibernated classes
16  *
17  * @author Konstantin Pribluda (kpribluda@j-tec-team.de)
18  * @author Heiko W. Rupp (pilhuhn at users dot sf dot net)
19  * @created December 11, 2002
20  * @version $Revision: 1.18 $
21  * @ant.element name="jbossservice" display-name="JBoss service configuration"
22  * parent="xdoclet.modules.hibernate.HibernateDocletTask"
23  * @xdoclet.merge-file file="jboss-service-custom.xdt" relates-to="jboss-service.xml" description="An XML unparsed
24  * entity or XDoclet template file, for custom elements to be included in the generated jboss-service.xml"
25  * @xdoclet.merge-file file="jboss-service-custom-attributes.ent" relates-to="jboss-service.xml" description="An XML
26  * unparsed entity for custom attributes to be included within the <mbean/> block of the generated
27  * jboss-service.xml"
28  */

29 public class JBossServiceSubTask
30      extends XmlSubTask implements HibernateProperties
31 {
32
33     /**
34      * Default template to use for hibernate files
35      */

36     private static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/jboss-service.xdt";
37
38     /**
39      * Pattern for generation of hibernate files
40      */

41     private static String JavaDoc GENERATED_SERVICE_FILE_NAME = "jboss-service.xml";
42
43     private String JavaDoc _jndiName = null;
44     private String JavaDoc _dataSource = null;
45     private String JavaDoc _dialect = null;
46     private String JavaDoc _serviceName = null;
47     private boolean _useOuterJoin = false;
48     private boolean _showSql = false;
49     private String JavaDoc _userName = null;
50     private String JavaDoc _password = null;
51     private String JavaDoc _userTransactionName = null;
52     private String JavaDoc _transactionStrategy = null;
53     private String JavaDoc _cacheProvider = null;
54     private String JavaDoc _depends = null;
55
56     private String JavaDoc _transactionManagerStrategy = null;
57     private String JavaDoc _maxFetchDepth = null;
58     private String JavaDoc _jdbcFetchSize = null;
59     private String JavaDoc _useQueryCache = null;
60     private String JavaDoc _querySubstitutions = null;
61     private String JavaDoc _defaultSchema = null;
62     private String JavaDoc _autoCreate = null;
63     private String JavaDoc _version = "2.1";
64
65     /**
66      * Constructor for the HibernateSubTask object
67      */

68     public JBossServiceSubTask()
69     {
70         setSubTaskName("jbossservice");
71         setHavingClassTag("hibernate.class");
72         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
73         setDestinationFile(GENERATED_SERVICE_FILE_NAME);
74     }
75
76     public String JavaDoc getTransactionManagerStrategy()
77     {
78         return _transactionManagerStrategy;
79     }
80
81     public String JavaDoc getUserTransactionName()
82     {
83         return _userTransactionName;
84     }
85
86     public String JavaDoc getTransactionStrategy()
87     {
88         return _transactionStrategy;
89     }
90
91     public String JavaDoc getCacheProvider()
92     {
93         return _cacheProvider;
94     }
95
96     public String JavaDoc getDepends()
97     {
98         return _depends;
99     }
100
101     public String JavaDoc getUserName()
102     {
103         return _userName;
104     }
105
106     public String JavaDoc getPassword()
107     {
108         return _password;
109     }
110
111     public boolean getUseOuterJoin()
112     {
113         return _useOuterJoin;
114     }
115
116     public boolean getShowSql()
117     {
118         return _showSql;
119     }
120
121     /**
122      * return configured service name
123      *
124      * @return
125      */

126     public String JavaDoc getServiceName()
127     {
128         return _serviceName;
129     }
130
131     public String JavaDoc getJndiName()
132     {
133         return _jndiName;
134     }
135
136     public String JavaDoc getDataSource()
137     {
138         return _dataSource;
139     }
140
141     public String JavaDoc getDialect()
142     {
143         return _dialect;
144     }
145
146     public String JavaDoc getAutoCreate()
147     {
148         return _autoCreate;
149     }
150
151     public String JavaDoc getDriver()
152     {
153         throw new UnsupportedOperationException JavaDoc("JBossServiceSubTask does not have a Driver attribute.");
154     }
155
156     public String JavaDoc getJdbcUrl()
157     {
158         throw new UnsupportedOperationException JavaDoc("JBossServiceSubTask does not have a jdbcUrl attribute.");
159     }
160
161     public String JavaDoc getPoolSize()
162     {
163         throw new UnsupportedOperationException JavaDoc("JBossServiceSubTask does not have a poolSize attribute.");
164     }
165
166     public Collection JavaDoc getJndiProperties()
167     {
168         throw new UnsupportedOperationException JavaDoc("JBossServiceSubTask does not have a jndiProperties attribute.");
169     }
170
171     public Collection JavaDoc getOtherProperties()
172     {
173         throw new UnsupportedOperationException JavaDoc("JBossServiceSubTask does not have an otherProperties attribute.");
174     }
175
176     public Collection JavaDoc getOtherMappings()
177     {
178         throw new UnsupportedOperationException JavaDoc("JBossServiceSubTask does not have an otherMappings attribute.");
179     }
180
181     /**
182      * @return
183      */

184     public String JavaDoc getDefaultSchema()
185     {
186         return _defaultSchema;
187     }
188
189     /**
190      * @return
191      */

192     public String JavaDoc getJdbcFetchSize()
193     {
194         return _jdbcFetchSize;
195     }
196
197     /**
198      * @return
199      */

200     public String JavaDoc getMaxFetchDepth()
201     {
202         return _maxFetchDepth;
203     }
204
205     /**
206      * @return
207      */

208     public String JavaDoc getQuerySubstitutions()
209     {
210         return _querySubstitutions;
211     }
212
213     /**
214      * @return
215      */

216     public String JavaDoc getUseQueryCache()
217     {
218         return _useQueryCache;
219     }
220
221     public String JavaDoc getVersion()
222     {
223         return _version;
224     }
225
226     /**
227      * Parameter for <tt>hibernate.hbm2ddl.auto</tt> property. Available since hibernate 2.1.6. Allowed values are
228      * 'create', 'create-drop' and 'update'.
229      *
230      * @param autoCreate
231      * @ant.not-required
232      */

233     public void setAutoCreate(String JavaDoc autoCreate)
234     {
235         _autoCreate = autoCreate;
236     }
237
238     /**
239      * Strategy for obtaining the JTA <tt>TransactionManager</tt>
240      *
241      * @param transactionManagerStrategy
242      * @ant.required
243      */

244     public void setTransactionManagerStrategy(String JavaDoc transactionManagerStrategy)
245     {
246         _transactionManagerStrategy = transactionManagerStrategy;
247     }
248
249     /**
250      * The JNDI name of the JTA UserTransaction object
251      *
252      * @param userTransactionName
253      * @ant.not-required
254      */

255     public void setUserTransactionName(String JavaDoc userTransactionName)
256     {
257         _userTransactionName = userTransactionName;
258     }
259
260     /**
261      * The fully qualified class name of the Hibernate <tt>TransactionFactory</tt> implementation.
262      *
263      * @param transactionStrategy
264      * @ant.not-required
265      */

266     public void setTransactionStrategy(String JavaDoc transactionStrategy)
267     {
268         _transactionStrategy = transactionStrategy;
269     }
270
271     /**
272      * The fully qualified class name of the Hibernate <tt>CacheProvider</tt> implementation. For Hibernate 2.1+ only.
273      *
274      * @param cacheProvider
275      * @ant.not-required
276      */

277     public void setCacheProvider(String JavaDoc cacheProvider)
278     {
279         _cacheProvider = cacheProvider;
280     }
281
282     /**
283      * The complete name of the data source service name that this service depends on.
284      *
285      * @param depends
286      * @ant.not-required
287      */

288     public void setDepends(String JavaDoc depends)
289     {
290         _depends = depends;
291     }
292
293     /**
294      * Use this user name to login to the database
295      *
296      * @param userName
297      * @ant.not-required
298      */

299     public void setUserName(String JavaDoc userName)
300     {
301         _userName = userName;
302     }
303
304     /**
305      * Use this password to login to the database
306      *
307      * @param password
308      * @ant.not-required
309      */

310     public void setPassword(String JavaDoc password)
311     {
312         _password = password;
313     }
314
315     /**
316      * Whether to use outer join
317      *
318      * @param useOuterJoin
319      * @ant.not-required No. Defaults to false.
320      */

321     public void setUseOuterJoin(boolean useOuterJoin)
322     {
323         _useOuterJoin = useOuterJoin;
324     }
325
326     /**
327      * Log sql statements.
328      *
329      * @param showSql
330      * @ant.not-required No. Defaults to false.
331      */

332     public void setShowSql(boolean showSql)
333     {
334         _showSql = showSql;
335     }
336
337     /**
338      * @param serviceName
339      * @ant.required
340      */

341     public void setServiceName(String JavaDoc serviceName)
342     {
343         _serviceName = serviceName;
344     }
345
346     /**
347      * JNDI name to bind to the <tt>SessionFactory</tt>
348      *
349      * @param jndiName
350      * @ant.required
351      */

352     public void setJndiName(String JavaDoc jndiName)
353     {
354         _jndiName = jndiName;
355     }
356
357     /**
358      * JNDI name of data source to use in the session factory. Note, that if you don't supply it here, you have to have
359      * it in a hibernate.properties file in your classpath.
360      *
361      * @param dataSource
362      * @ant.not-required
363      */

364     public void setDataSource(String JavaDoc dataSource)
365     {
366         _dataSource = dataSource;
367     }
368
369     /**
370      * SQL <a HREF="http://www.hibernate.org/hib_docs/api/net/sf/hibernate/dialect/Dialect.html">dialect</a> of the
371      * database. Note, that if you don't supply it here, you have to have it in a hibernate.properties file in your
372      * classpath. Use the fully-qualified class name of the dialect here.
373      *
374      * @param dialect
375      * @ant.not-required
376      */

377     public void setDialect(String JavaDoc dialect)
378     {
379         _dialect = dialect;
380     }
381
382     /**
383      * Only for Hibernate 2.1+
384      *
385      * @param string
386      * @ant.not-required
387      */

388     public void setDefaultSchema(String JavaDoc string)
389     {
390         _defaultSchema = string;
391     }
392
393     /**
394      * Only for Hibernate 2.1+
395      *
396      * @param string
397      * @ant.not-required
398      */

399     public void setJdbcFetchSize(String JavaDoc string)
400     {
401         _jdbcFetchSize = string;
402     }
403
404     /**
405      * Only for Hibernate 2.1+
406      *
407      * @param string
408      * @ant.not-required
409      */

410     public void setMaxFetchDepth(String JavaDoc string)
411     {
412         _maxFetchDepth = string;
413     }
414
415     /**
416      * Only for Hibernate 2.1+
417      *
418      * @param string
419      * @ant.not-required
420      */

421     public void setQuerySubstitutions(String JavaDoc string)
422     {
423         _querySubstitutions = string;
424     }
425
426     /**
427      * Only for Hibernate 2.1+
428      *
429      * @param string
430      * @ant.not-required
431      */

432     public void setUseQueryCache(String JavaDoc string)
433     {
434         _useQueryCache = string;
435     }
436
437     /**
438      * Set the Hibernate version that the jboss service should be generated for. Values are "1.1", "2.0" and "2.1". This
439      * value normally corresponds to the setting of the <tt>hibernate</tt> subtask.
440      * Default is "2.1" !
441      * @param version
442      * @ant.not-required
443      */

444     public void setVersion(String JavaDoc version)
445     {
446         _version = version;
447     }
448
449
450     public void validateOptions() throws XDocletException
451     {
452         super.validateOptions();
453
454         if (getJndiName() == null) {
455             throw new XDocletException(Translator.getString(XDocletModulesHibernateMessages.class,
456                 XDocletModulesHibernateMessages.JNDI_NAME_REQUIRED));
457         }
458
459         if (getServiceName() == null) {
460             throw new XDocletException(Translator.getString(XDocletModulesHibernateMessages.class,
461                 XDocletModulesHibernateMessages.SERVICE_NAME_REQUIRED));
462         }
463     }
464
465     /**
466      * Called when the engine is started
467      *
468      * @exception XDocletException Thrown in case of problem
469      */

470     protected void engineStarted() throws XDocletException
471     {
472         System.out.println(Translator.getString(XDocletModulesHibernateMessages.class,
473             XDocletModulesHibernateMessages.GENERATING_JBOSS_SERVICE_DESCRIPTOR));
474     }
475 }
476
Popular Tags