KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > runtime > IASEjbExtraDescriptors


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * This generated bean class Ejb matches the DTD element ejb
26  *
27  * Generated on Mon Dec 10 09:16:05 PST 2001
28  */

29
30 package com.sun.enterprise.deployment.runtime;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.StringTokenizer JavaDoc;
34 import java.util.logging.Level JavaDoc;
35
36
37 import com.sun.enterprise.deployment.Application;
38 import com.sun.enterprise.deployment.EjbDescriptor;
39 import com.sun.enterprise.deployment.MethodDescriptor;
40 import com.sun.enterprise.deployment.DescriptorConstants;
41 import com.sun.enterprise.deployment.runtime.RuntimeDescriptor;
42 import com.sun.enterprise.deployment.util.DOLUtils;
43
44 /**
45  * Class that contains all the extra iAS elements for an EJB that are not
46  * in the RI DTD like:
47  *
48  * MdbConnectionFactoryDescriptor
49  * jmsMaxMessagesLoad
50  * isReadOnlyBean
51  * refreshPeriodInSeconds
52  * commitOption
53  * checkpointedMethods
54  * passByReference
55  * BeanPoolDescriptor
56  * BeanCacheDescriptor
57  * FlushAtEndOfMethodDescriptor
58  * CheckpointAtEndOfMethodDescriptor
59  *
60  * @author Ludo
61  * @since JDK 1.4
62  */

63 public class IASEjbExtraDescriptors extends RuntimeDescriptor {
64     
65     public static final String JavaDoc AVAILABILITY_ENABLED =
66         "AvailabilityEnabled";
67
68     private boolean isReadOnlyBean;
69     
70     /**
71      * A string field whose value denoted the rate at which the read-only-bean
72      * must be refreshed from the data source.
73      * Valid values are: negative (never refreshed), 0 (always refreshed)
74      * and positive (refreshed at specified intervals).
75      * Note that the value is just a hint to the container.
76      */

77     private int refreshPeriodInSeconds;
78     
79     /**
80      * A string value specifies the maximum number of messages to
81      * load into a JMS session at one time for a message-driven
82      * bean to serve. If not specified, the default is 1.
83      */

84     private int jmsMaxMessagesLoad;
85
86     private MdbConnectionFactoryDescriptor mdbConnectionFactory;
87     
88     /**
89      * A string field whose valid values are either A, B, or C.
90      * Default value is set in the server configuration (server.xml).
91      */

92     private String JavaDoc commitOption = null;
93     
94     /**
95      * This contains the bean pool properties. Used only for stateless
96      * session bean and mdb pools.
97      */

98     private BeanPoolDescriptor beanPool;
99
100     /**
101      * This contains the bean cache properties. Used only for entity beans.
102      */

103     private BeanCacheDescriptor beanCache;
104
105     private FlushAtEndOfMethodDescriptor flushMethodDescriptor = null;
106
107     private CheckpointAtEndOfMethodDescriptor checkpointMethodDescriptor = null;
108
109     private String JavaDoc checkpointedMethods = null;
110
111     /**
112      * This contains the pass-by-reference property.
113      */

114     private Boolean JavaDoc passByReference = null;
115     
116     
117     /*
118      * This contains the EjbDescriptor - J2EE specific descriptor
119      * @see com.sun.enterprise.deployment.EjbDescriptor EjbDescriptor
120      */

121     private EjbDescriptor ejbDescriptor = null;
122     
123     /**
124      * This contains the timeout used for container started transactions
125      * This value is used by the container only if the value is greater than 0
126      */

127     private int cmtTimeoutInSeconds = 0;
128
129     /**
130      * Specifes the thread pool to be used for this ejb's invocation
131      */

132     private String JavaDoc useThreadPoolId;
133
134     // contants used to parse the checkpointedMethods
135
private final static String JavaDoc METHODS_DELIM = ";";
136     private final static String JavaDoc PARAMS_DELIM = ",";
137     private final static String JavaDoc LEFT_PAREN = "(";
138     private final static String JavaDoc RIGHT_PAREN = ")";
139     private final static String JavaDoc PARAM_DELIM = " ";
140
141     /**
142      * Default constructor.
143      */

144     public IASEjbExtraDescriptors() {
145         jmsMaxMessagesLoad = 1;
146         isReadOnlyBean = false;
147         refreshPeriodInSeconds = DescriptorConstants.REFRESH_PERIOD_IN_SECONDS_DEFAULT;//RO Bean never refreshed???
148
}
149     
150     /**
151      * Getter for property beanCache.
152      * @return Value of property beanCache.
153      */

154     public BeanCacheDescriptor getBeanCache() {
155         return beanCache;
156     }
157     
158     /**
159      * Setter for property beanCache.
160      * @param beanCache New value of property beanCache.
161      */

162     public void setBeanCache(BeanCacheDescriptor beanCache) {
163         this.beanCache = beanCache;
164     }
165
166      /**
167       * Getter for property beanPool.
168       * @return Value of property beanPool.
169       */

170     public BeanPoolDescriptor getBeanPool() {
171         return beanPool;
172     }
173     
174     /**
175      * Setter for property beanPool.
176      * @param beanPool New value of property beanPool.
177      */

178     public void setBeanPool(BeanPoolDescriptor beanPool) {
179         this.beanPool = beanPool;
180     }
181     
182      /**
183       * Getter for flush-at-end-of-method
184       * @return Value of flushMethodDescriptor
185       */

186     public FlushAtEndOfMethodDescriptor getFlushAtEndOfMethodDescriptor() {
187         return flushMethodDescriptor;
188     }
189
190     /**
191      * Setter for flush-at-end-of-method
192      * @param flushMethodDescriptor New value of flushMethodDescriptor.
193      */

194     public void setFlushAtEndOfMethodDescriptor(
195         FlushAtEndOfMethodDescriptor flushMethodDescriptor) {
196         this.flushMethodDescriptor = flushMethodDescriptor;
197     }
198
199      /**
200       * Getter for checkpoint-at-end-of-method
201       * @return Value of checkpointMethodDescriptor
202       */

203     public CheckpointAtEndOfMethodDescriptor
204         getCheckpointAtEndOfMethodDescriptor() {
205         return checkpointMethodDescriptor;
206     }
207
208     /**
209      * Setter for checkpoint-at-end-of-method
210      * @param checkpointMethodDescriptor New value of
211      * checkpointMethodDescriptor.
212      */

213     public void setCheckpointAtEndOfMethodDescriptor(
214         CheckpointAtEndOfMethodDescriptor checkpointMethodDescriptor) {
215         this.checkpointMethodDescriptor = checkpointMethodDescriptor;
216     }
217
218      /**
219       * Getter for property checkpointedMethods
220       * @return Value of property checkpointedMethods
221       */

222     public String JavaDoc getCheckpointedMethods() {
223         return checkpointedMethods;
224     }
225
226     /**
227      * Setter for property checkpointedMethods
228      * @param checkpointedMethods New value of checkpointed methods.
229      */

230     public void setCheckpointedMethods(String JavaDoc checkpointedMethods) {
231         this.checkpointedMethods = checkpointedMethods;
232     }
233
234     /**
235      * Getter for property commitOption.
236      * @return Value of property commitOption.
237      */

238     public java.lang.String JavaDoc getCommitOption() {
239         return commitOption;
240     }
241     
242     /**
243      * Setter for property commitOption.
244      * @param commitOption New value of property commitOption.
245      */

246     public void setCommitOption(java.lang.String JavaDoc commitOption) {
247         this.commitOption = commitOption;
248     }
249
250     /**
251      * Getter for property cmt-timeout-in-seconds.
252      * @return Value of property cmt-timeout-in-seconds.
253      */

254     public int getCmtTimeoutInSeconds() {
255         return this.cmtTimeoutInSeconds;
256     }
257
258     /**
259      * Setter for property cmt-timeout-in-seconds.
260      * @param commitOption New value of property cmt-timeout-in-seconds.
261      */

262     public void setCmtTimeoutInSeconds(int val) {
263         this.cmtTimeoutInSeconds = val;
264     }
265
266     /**
267      * Getter for the property use-thread-pool-id
268      * @return The value of use-thread-pool-id
269      */

270     public String JavaDoc getUseThreadPoolId() {
271         return this.useThreadPoolId;
272     }
273
274     /**
275      * Setter for the property use-thread-pool-id
276      * @param The value for use-thread-pool-id
277      */

278     public void setUseThreadPoolId(String JavaDoc val) {
279         this.useThreadPoolId = val;
280     }
281
282     /**
283      * Getter for property isReadOnlyBean.
284      * @return Value of property isReadOnlyBean.
285      */

286     public boolean isIsReadOnlyBean() {
287         return isReadOnlyBean;
288     }
289     
290     /**
291      * Setter for property isReadOnlyBean.
292      * @param isReadOnlyBean New value of property isReadOnlyBean.
293      */

294     public void setIsReadOnlyBean(boolean isReadOnlyBean) {
295         this.isReadOnlyBean = isReadOnlyBean;
296     }
297     
298     /**
299      * Getter for property jmsMaxMessagesLoad.
300      * @return Value of property jmsMaxMessagesLoad.
301      */

302     public int getJmsMaxMessagesLoad() {
303         return jmsMaxMessagesLoad;
304     }
305     
306     /**
307      * Setter for property jmsMaxMessagesLoad.
308      * @param jmsMaxMessagesLoad New value of property jmsMaxMessagesLoad.
309      */

310     public void setJmsMaxMessagesLoad(int jmsMaxMessagesLoad) {
311         this.jmsMaxMessagesLoad = jmsMaxMessagesLoad;
312     }
313     
314     /**
315      * Getter for property mdbConnectionFactory.
316      * @return Value of property mdbConnectionFactory.
317      */

318     public MdbConnectionFactoryDescriptor getMdbConnectionFactory() {
319         return mdbConnectionFactory;
320     }
321     
322     /**
323      * Setter for property mdbConnectionFactory.
324      * @param mdbConnectionFactory New value of property mdbConnectionFactory.
325      */

326     public void setMdbConnectionFactory(
327             MdbConnectionFactoryDescriptor mdbConnectionFactory) {
328
329         this.mdbConnectionFactory = mdbConnectionFactory;
330     }
331     
332     /**
333      * Getter for property refreshPeriodInSeconds.
334      * @return Value of property refreshPeriodInSeconds.
335      */

336     public int getRefreshPeriodInSeconds() {
337         return refreshPeriodInSeconds;
338     }
339     
340     /**
341      * Setter for property refreshPeriodInSeconds.
342      * @param refreshPeriodInSeconds New value of property
343      * refreshPeriodInSeconds.
344      */

345     public void setRefreshPeriodInSeconds(int refreshPeriodInSeconds) {
346         this.refreshPeriodInSeconds = refreshPeriodInSeconds;
347     }
348
349     /**
350      * Gets ejb pass-by-reference value.
351      * @return Value of property passByReference if it is not null. Otherwise
352      * returns value of passByReference property of Application if
353      * it is not null. Default value is false.
354      */

355     public boolean getPassByReference() {
356         boolean passByReference = false; // default
357

358         // if pass-by-reference defined for ejb
359
if (this.isPassByReferenceDefined()) {
360             passByReference = this.passByReference.booleanValue();
361         // if pass-by-reference undefined for ejb set to
362
// application's pass-by-reference value if defined
363
} else {
364             ejbDescriptor = this.getEjbDescriptor();
365             if (ejbDescriptor != null) {
366                 Application application = ejbDescriptor.getApplication();
367                 if (application != null) {
368                     if (application.isPassByReferenceDefined()) {
369                         passByReference = application.getPassByReference();
370                     }
371                 }
372             }
373         }
374        
375         return passByReference;
376     }
377
378     /**
379      * Sets ejb pass-by-reference value.
380      * @param pass-by-reference New value of property pass-by-reference.
381      */

382     public void setPassByReference(boolean passByReference) {
383         this.passByReference = Boolean.valueOf(passByReference);
384     }
385     
386     /**
387      * Sets ejb pass-by-reference value.
388      * @param pass-by-reference New value of property pass-by-reference.
389      */

390     public void setPassByReference(Boolean JavaDoc passByReference) {
391         this.passByReference = passByReference;
392     }
393     
394     /**
395      * Evaluates property passByReference for null value
396      * @return boolean true if property passByReference is not null
397      * boolean false if property passByReference is null
398      */

399     public boolean isPassByReferenceDefined() {
400         boolean passByReferenceDefined = false;
401         if (this.passByReference != null) {
402             passByReferenceDefined = true;
403         }
404         return passByReferenceDefined;
405     }
406     
407     /**
408      * Getter for property ejbDescriptor.
409      * @returns EjbDescriptor object property - J2EE specific
410      * ejb descriptor
411      */

412     public EjbDescriptor getEjbDescriptor() {
413         return this.ejbDescriptor;
414     }
415     
416     /**
417      * Setter for property ejbDescriptor
418      * @param ejbDescriptor - EjbDescriptor object - J2EE specific ejb descriptor
419      */

420     public void setEjbDescriptor(EjbDescriptor ejbDescriptor) {
421         this.ejbDescriptor = ejbDescriptor;
422     }
423
424     /**
425       * Convenience method to check if a method is flush enabled or not
426       * @param methodDesc - Method Descriptor object to check
427       * @return boolean true if methodDesc is flushed enabled
428       * boolean false if methodDesc is not flushed enabled
429       */

430     public boolean isFlushEnabledFor(MethodDescriptor methodDesc) {
431         if (flushMethodDescriptor != null) {
432             return flushMethodDescriptor.isFlushEnabledFor(methodDesc);
433         }
434         return false;
435     }
436
437      /**
438       * Parse checkpointed-methods element and save its values in
439       * CheckpointAtEndOfMethodDescriptor
440       *
441       * The methods should be separated by semicolons.
442       * The param list should separated by commas.
443       * All method param types should be full qualified.
444       * Variable name is allowed for the param type.
445       * No return type or exception type.
446       *
447       * Example:
448       * foo(java.lang.String, a.b.c d); bar(java.lang.String s)
449       *
450       */

451     public void parseCheckpointedMethods(EjbDescriptor ejbDesc) {
452         if (checkpointedMethods == null ||
453             checkpointedMethods.trim().length() == 0) {
454             return;
455         }
456         if (checkpointMethodDescriptor == null) {
457             checkpointMethodDescriptor =
458                 new CheckpointAtEndOfMethodDescriptor();
459             setCheckpointAtEndOfMethodDescriptor(checkpointMethodDescriptor);
460             checkpointMethodDescriptor.setEjbDescriptor(ejbDesc);
461         }
462         StringTokenizer JavaDoc methodsTokenizer =
463             new StringTokenizer JavaDoc(checkpointedMethods, METHODS_DELIM);
464         while (methodsTokenizer.hasMoreTokens()) {
465             // process each method
466
String JavaDoc method = methodsTokenizer.nextToken().trim();
467             if (method.length() == 0) {
468                 continue;
469             }
470             MethodDescriptor methodDescriptor =
471                 parseCheckpointedMethod(method);
472             if (methodDescriptor != null) {
473                 checkpointMethodDescriptor.getMethodDescriptors().add(
474                     methodDescriptor);
475             }
476         }
477     }
478
479
480     // parse the given method string into a MethodDescriptor
481
private MethodDescriptor parseCheckpointedMethod (String JavaDoc method) {
482         String JavaDoc methodName, methodParams;
483         ArrayList JavaDoc paramTypeList = new ArrayList JavaDoc();
484         try {
485             if ( method.indexOf(LEFT_PAREN) != -1 &&
486                 method.indexOf(RIGHT_PAREN) != -1 ) {
487                 int pos = method.indexOf(LEFT_PAREN);
488                 int pos2 = method.indexOf(RIGHT_PAREN);
489                 // retrieve the method name
490
methodName = method.substring(0, pos).trim();
491                 // retrieve the parameter list
492
if (pos < pos2-1) {
493                     methodParams = method.substring(pos+1, pos2).trim();
494                     StringTokenizer JavaDoc paramsTokenizer =
495                         new StringTokenizer JavaDoc(methodParams, PARAMS_DELIM);
496                     while (paramsTokenizer.hasMoreTokens()) {
497                         // process each param
498
String JavaDoc param = paramsTokenizer.nextToken().trim();
499                         if (param.length() == 0) {
500                             continue;
501                         }
502                         StringTokenizer JavaDoc paramTokenizer =
503                             new StringTokenizer JavaDoc(param, PARAM_DELIM);
504                         while (paramTokenizer.hasMoreTokens()) {
505                             String JavaDoc paramType =
506                                 paramTokenizer.nextToken().trim();
507                             if (paramType.length() != 0) {
508                                 paramTypeList.add(paramType);
509                                 // only interested in the first token
510
break;
511                             }
512                         }
513                     }
514                 }
515                 if (paramTypeList.size() > 0) {
516                     String JavaDoc[] paramTypeArray = (String JavaDoc[])paramTypeList.toArray(
517                         new String JavaDoc[paramTypeList.size()]);
518                     return new MethodDescriptor(methodName, null,
519                         paramTypeArray, null);
520                 } else {
521                     return new MethodDescriptor(methodName, null, null, null);
522                 }
523             } else {
524                 DOLUtils.getDefaultLogger().log(Level.WARNING, "enterprise.deployment_badformat_checkpointedmethods", new Object JavaDoc[] {method});
525                 return null;
526             }
527         } catch (Exception JavaDoc e) {
528             e.printStackTrace();
529             // any parsing exception indicates it is not a well-formed
530
// string, we will just print warning and return null
531
DOLUtils.getDefaultLogger().log(Level.WARNING, "enterprise.deployment_badformat_checkpointedmethods", new Object JavaDoc[] {method});
532             return null;
533         }
534     }
535 }
536
Popular Tags