KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metadata > ConfigurationMetaData


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.metadata;
23
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.LinkedList JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.jboss.deployment.DeploymentException;
30 import org.jboss.mx.util.ObjectNameFactory;
31 import org.w3c.dom.Element JavaDoc;
32
33 /** The configuration information for an EJB container.
34  * @author <a HREF="mailto:sebastien.alborini@m4x.org">Sebastien Alborini</a>
35  * @author <a HREF="mailto:scott.stark@jboss.org">Scott Stark</a>
36  * @author <a HREF="mailto:christoph.jung@infor.de">Christoph G. Jung</a>
37  * @version $Revision: 58183 $
38  */

39 public class ConfigurationMetaData extends MetaData
40 {
41    // Constants -----------------------------------------------------
42
public static final String JavaDoc CMP_2x_13 = "Standard CMP 2.x EntityBean";
43    public static final String JavaDoc CMP_1x_13 = "Standard CMP EntityBean";
44    public static final String JavaDoc BMP_13 = "Standard BMP EntityBean";
45    public static final String JavaDoc STATELESS_13 = "Standard Stateless SessionBean";
46    public static final String JavaDoc STATEFUL_13 = "Standard Stateful SessionBean";
47    public static final String JavaDoc MESSAGE_DRIVEN_13 = "Standard Message Driven Bean";
48    public static final String JavaDoc MESSAGE_INFLOW_DRIVEN = "Standard Message Inflow Driven Bean";
49
50    public static final String JavaDoc CLUSTERED_CMP_2x_13 = "Clustered CMP 2.x EntityBean";
51    public static final String JavaDoc CLUSTERED_CMP_1x_13 = "Clustered CMP EntityBean";
52    public static final String JavaDoc CLUSTERED_BMP_13 = "Clustered BMP EntityBean";
53    public static final String JavaDoc CLUSTERED_STATEFUL_13 = "Clustered Stateful SessionBean";
54    public static final String JavaDoc CLUSTERED_STATELESS_13 = "Clustered Stateless SessionBean";
55
56    public static final byte A_COMMIT_OPTION = 0;
57    public static final byte B_COMMIT_OPTION = 1;
58    public static final byte C_COMMIT_OPTION = 2;
59    /** D_COMMIT_OPTION is a lazy load option. By default it synchronizes every 30 seconds */
60    public static final byte D_COMMIT_OPTION = 3;
61    public static final String JavaDoc[] commitOptionStrings = {"A", "B", "C", "D"};
62
63    // Attributes ----------------------------------------------------
64
private String JavaDoc name;
65    private String JavaDoc instancePool;
66    private String JavaDoc instanceCache;
67    private String JavaDoc persistenceManager;
68    private String JavaDoc webClassLoader = "org.jboss.web.WebClassLoader";
69    private String JavaDoc lockClass = "org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock";
70    private byte commitOption;
71    private long optionDRefreshRate = 30000;
72    private boolean callLogging;
73    private boolean syncOnCommitOnly = false;
74    /** if true, INSERT will be issued after ejbPostCreate */
75    private boolean insertAfterEjbPostCreate = false;
76    /** The container level security domain */
77    private String JavaDoc securityDomain;
78    /** The container invoker binding names */
79    private String JavaDoc[] invokerNames;
80    /** The InstancePool configuration */
81    private Element JavaDoc containerPoolConf;
82    /** The InstanceCache configuration */
83    private Element JavaDoc containerCacheConf;
84    /** The ejb container interceptor stack configuration */
85    private Element JavaDoc containerInterceptorsConf;
86    /** The JMX object names for container level dependencies */
87    private Collection JavaDoc depends = new LinkedList JavaDoc();
88    /** The cluster-config element info */
89    private ClusterConfigMetaData clusterConfig = null;
90    /** By the spec ejbStore must be called even for clean instances. But not everyone agrees. */
91    private boolean ejbStoreForClean;
92    /** Whether dirty instances that couldn't be evicted from the cache after cache.flush()
93        should or should not (to prevent potential data inconsistency) be stored*/

94    private boolean storeNotFlushed = true;
95
96    // Static --------------------------------------------------------
97

98    // Constructors --------------------------------------------------
99
public ConfigurationMetaData()
100    {
101    }
102
103    public ConfigurationMetaData(String JavaDoc name)
104    {
105       this.name = name;
106    }
107
108    // Public --------------------------------------------------------
109

110    public String JavaDoc getName()
111    {
112       return name;
113    }
114
115    public String JavaDoc getInstancePool()
116    {
117       return instancePool;
118    }
119
120    public String JavaDoc getInstanceCache()
121    {
122       return instanceCache;
123    }
124
125    public String JavaDoc getPersistenceManager()
126    {
127       return persistenceManager;
128    }
129
130    public String JavaDoc getSecurityDomain()
131    {
132       return securityDomain;
133    }
134
135    public String JavaDoc[] getInvokers()
136    {
137       return invokerNames;
138    }
139
140    public String JavaDoc getWebClassLoader()
141    {
142       return webClassLoader;
143    }
144
145    public String JavaDoc getLockClass()
146    {
147       return lockClass;
148    }
149
150    public Element JavaDoc getContainerPoolConf()
151    {
152       return containerPoolConf;
153    }
154
155    public Element JavaDoc getContainerCacheConf()
156    {
157       return containerCacheConf;
158    }
159
160    public String JavaDoc getDefaultInvokerName()
161    {
162       if (invokerNames.length == 0)
163          throw new IllegalStateException JavaDoc("No invokers defined");
164       return invokerNames[0];
165    }
166    
167    public Element JavaDoc getContainerInterceptorsConf()
168    {
169       return containerInterceptorsConf;
170    }
171
172    public boolean getCallLogging()
173    {
174       return callLogging;
175    }
176
177    public boolean getSyncOnCommitOnly()
178    {
179       return syncOnCommitOnly;
180    }
181
182    public boolean isInsertAfterEjbPostCreate()
183    {
184       return insertAfterEjbPostCreate;
185    }
186
187    public boolean isEjbStoreForClean()
188    {
189       return this.ejbStoreForClean;
190    }
191
192    public boolean isStoreNotFlushed()
193    {
194       return storeNotFlushed;
195    }
196
197    public byte getCommitOption()
198    {
199       return commitOption;
200    }
201
202    public long getOptionDRefreshRate()
203    {
204       return optionDRefreshRate;
205    }
206
207    public ClusterConfigMetaData getClusterConfigMetaData()
208    {
209       return this.clusterConfig;
210    }
211
212    public Collection JavaDoc getDepends()
213    {
214       return depends;
215    }
216
217    public void setName(String JavaDoc name)
218    {
219       this.name = name;
220    }
221
222    public void setInstancePool(String JavaDoc instancePool)
223    {
224       this.instancePool = instancePool;
225    }
226
227    public void setInstanceCache(String JavaDoc instanceCache)
228    {
229       this.instanceCache = instanceCache;
230    }
231
232    public void setPersistenceManager(String JavaDoc persistenceManager)
233    {
234       this.persistenceManager = persistenceManager;
235    }
236
237    public void setWebClassLoader(String JavaDoc webClassLoader)
238    {
239       this.webClassLoader = webClassLoader;
240    }
241
242    public void setCommitOption(String JavaDoc commitOption)
243    {
244       try
245       {
246          this.commitOption = stringToCommitOption(commitOption);
247       }
248       catch(DeploymentException e)
249       {
250          throw new IllegalStateException JavaDoc(e.getMessage());
251       }
252    }
253
254    public void setOptionDRefreshRate(long optionDRefreshRate)
255    {
256       this.optionDRefreshRate = optionDRefreshRate;
257    }
258
259    public void setCallLogging(boolean callLogging)
260    {
261       this.callLogging = callLogging;
262    }
263
264    public void setSyncOnCommitOnly(boolean syncOnCommitOnly)
265    {
266       this.syncOnCommitOnly = syncOnCommitOnly;
267    }
268
269    public void setInsertAfterEjbPostCreate(boolean insertAfterEjbPostCreate)
270    {
271       this.insertAfterEjbPostCreate = insertAfterEjbPostCreate;
272    }
273
274    public void setSecurityDomain(String JavaDoc securityDomain)
275    {
276       this.securityDomain = securityDomain;
277    }
278
279    public void setInvokerNames(String JavaDoc[] invokerNames)
280    {
281       this.invokerNames = invokerNames;
282    }
283
284    public void setContainerPoolConf(Element JavaDoc containerPoolConf)
285    {
286       this.containerPoolConf = containerPoolConf;
287    }
288
289    public void setContainerCacheConf(Element JavaDoc containerCacheConf)
290    {
291       this.containerCacheConf = containerCacheConf;
292    }
293
294    public void setContainerInterceptorsConf(Element JavaDoc containerInterceptorsConf)
295    {
296       this.containerInterceptorsConf = containerInterceptorsConf;
297    }
298
299    public void setClusterConfig(ClusterConfigMetaData clusterConfig)
300    {
301       this.clusterConfig = clusterConfig;
302    }
303
304    public void setEjbStoreForClean(boolean ejbStoreForClean)
305    {
306       this.ejbStoreForClean = ejbStoreForClean;
307    }
308
309    public void setStoreNotFlushed(boolean storeNotFlushed)
310    {
311       this.storeNotFlushed = storeNotFlushed;
312    }
313
314    public void setLockClass(String JavaDoc lockClass)
315    {
316       this.lockClass = lockClass;
317    }
318
319    public void importJbossXml(Element JavaDoc element) throws DeploymentException
320    {
321
322       // everything is optional to allow jboss.xml to modify part of a configuration
323
// defined in standardjboss.xml
324

325       // set call logging
326
callLogging = Boolean.valueOf(getElementContent(getOptionalChild(element, "call-logging"), String.valueOf(callLogging))).booleanValue();
327
328       // set synchronize on commit only
329
syncOnCommitOnly = Boolean.valueOf(getElementContent(getOptionalChild(element, "sync-on-commit-only"), String.valueOf(syncOnCommitOnly))).booleanValue();
330
331       // set insert-after-ejb-post-create
332
insertAfterEjbPostCreate = Boolean.valueOf(getElementContent(getOptionalChild(element, "insert-after-ejb-post-create"), String.valueOf(insertAfterEjbPostCreate))).booleanValue();
333
334       // ejbStoreForClean
335
ejbStoreForClean = Boolean.valueOf(getElementContent(getOptionalChild(element, "call-ejb-store-on-clean"), String.valueOf(ejbStoreForClean))).booleanValue();
336
337       // store-not-flushed
338
storeNotFlushed = Boolean.valueOf(getElementContent(getOptionalChild(element, "store-not-flushed"), String.valueOf(storeNotFlushed))).booleanValue();
339
340       // set the instance pool
341
instancePool = getElementContent(getOptionalChild(element, "instance-pool"), instancePool);
342
343       // set the instance cache
344
instanceCache = getElementContent(getOptionalChild(element, "instance-cache"), instanceCache);
345
346       // set the persistence manager
347
persistenceManager = getElementContent(getOptionalChild(element, "persistence-manager"), persistenceManager);
348
349       // set the web classloader
350
webClassLoader = getElementContent(getOptionalChild(element, "web-class-loader"), webClassLoader);
351
352       // set the lock class
353
lockClass = getElementContent(getOptionalChild(element, "locking-policy"), lockClass);
354
355       // set the security domain
356
securityDomain = getElementContent(getOptionalChild(element, "security-domain"), securityDomain);
357    
358       //Get configured invokers
359
List JavaDoc invokers=new java.util.ArrayList JavaDoc();
360       
361       for (Iterator JavaDoc invokerElements = getChildrenByTagName(element, "invoker-proxy-binding-name"); invokerElements.hasNext();)
362       {
363          Element JavaDoc invokerElement = (Element JavaDoc) invokerElements.next();
364          String JavaDoc invokerName = getElementContent(invokerElement);
365          invokers.add(invokerName);
366       } // end of for ()
367
invokerNames=(String JavaDoc[]) invokers.toArray(new String JavaDoc[invokers.size()]);
368             
369       // set the commit option
370
String JavaDoc commit = getElementContent(getOptionalChild(element, "commit-option"), commitOptionToString(commitOption));
371
372       commitOption = stringToCommitOption(commit);
373
374       //get the refresh rate for option D
375
String JavaDoc refresh = getElementContent(getOptionalChild(element, "optiond-refresh-rate"),
376             Long.toString(optionDRefreshRate / 1000));
377       optionDRefreshRate = stringToRefreshRate(refresh);
378
379       // the classes which can understand the following are dynamically loaded during deployment :
380
// We save the Elements for them to use later
381

382       // The configuration for the container interceptors
383
containerInterceptorsConf = getOptionalChild(element, "container-interceptors", containerInterceptorsConf);
384
385       // configuration for instance pool
386
containerPoolConf = getOptionalChild(element, "container-pool-conf", containerPoolConf);
387
388       // configuration for instance cache
389
containerCacheConf = getOptionalChild(element, "container-cache-conf", containerCacheConf);
390
391       //Get depends object names
392
for (Iterator JavaDoc dependsElements = getChildrenByTagName(element, "depends"); dependsElements.hasNext();)
393       {
394          Element JavaDoc dependsElement = (Element JavaDoc) dependsElements.next();
395          String JavaDoc dependsName = getElementContent(dependsElement);
396          depends.add(ObjectNameFactory.create(dependsName));
397       } // end of for ()
398

399       // Check for clustering configuration
400
Element JavaDoc clusterConfigElement = getOptionalChild(element, "cluster-config");
401       if (clusterConfigElement != null)
402       {
403          clusterConfig = new ClusterConfigMetaData();
404          clusterConfig.importJbossXml(clusterConfigElement);
405       }
406    }
407
408    // Package protected ---------------------------------------------
409

410    // Protected -----------------------------------------------------
411

412    // Private -------------------------------------------------------
413
private static String JavaDoc commitOptionToString(byte commitOption)
414          throws DeploymentException
415    {
416       try
417       {
418          return commitOptionStrings[commitOption];
419       }
420       catch (ArrayIndexOutOfBoundsException JavaDoc e)
421       {
422          throw new DeploymentException("Invalid commit option: " + commitOption);
423       }
424    }
425
426    private static byte stringToCommitOption(String JavaDoc commitOption)
427          throws DeploymentException
428    {
429       for (byte i = 0; i < commitOptionStrings.length; ++i)
430          if (commitOptionStrings[i].equals(commitOption))
431             return i;
432
433       throw new DeploymentException("Invalid commit option: '" + commitOption + "'");
434    }
435
436    /** Parse the refresh rate string into a long
437     * @param refreshRate in seconds
438     * @return refresh rate in milliseconds suitable for use in Thread.sleep
439     * @throws DeploymentException on failure to parse refreshRate as a long
440     */

441    private static long stringToRefreshRate(String JavaDoc refreshRate)
442          throws DeploymentException
443    {
444       try
445       {
446          long rate = Long.parseLong(refreshRate);
447          // Convert from seconds to milliseconds
448
rate *= 1000;
449          return rate;
450       }
451       catch (Exception JavaDoc e)
452       {
453          throw new DeploymentException("Invalid optiond-refresh-rate '"
454                + refreshRate + "'. Should be a number");
455       }
456
457    }
458
459    // Inner classes -------------------------------------------------
460
}
461
Popular Tags