001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.jee;
018:
019: import javax.xml.bind.annotation.XmlAccessType;
020: import javax.xml.bind.annotation.XmlAccessorType;
021: import javax.xml.bind.annotation.XmlAttribute;
022: import javax.xml.bind.annotation.XmlElement;
023: import javax.xml.bind.annotation.XmlID;
024: import javax.xml.bind.annotation.XmlTransient;
025: import javax.xml.bind.annotation.XmlType;
026: import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
027: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
028: import java.util.ArrayList;
029: import java.util.List;
030: import java.util.Collection;
031: import java.util.LinkedHashSet;
032: import java.util.Map;
033:
034: /**
035: * The session-beanType declares an session bean. The
036: * declaration consists of:
037: * <p/>
038: * - an optional description
039: * - an optional display name
040: * - an optional icon element that contains a small and a large
041: * icon file name
042: * - a name assigned to the enterprise bean
043: * in the deployment description
044: * - an optional mapped-name element that can be used to provide
045: * vendor-specific deployment information such as the physical
046: * jndi-name of the session bean's remote home/business interface.
047: * This element is not required to be supported by all
048: * implementations. Any use of this element is non-portable.
049: * - the names of all the remote or local business interfaces,
050: * if any
051: * - the names of the session bean's remote home and
052: * remote interfaces, if any
053: * - the names of the session bean's local home and
054: * local interfaces, if any
055: * - the name of the session bean's web service endpoint
056: * interface, if any
057: * - the session bean's implementation class
058: * - the session bean's state management type
059: * - an optional declaration of the session bean's timeout method.
060: * - the optional session bean's transaction management type.
061: * If it is not present, it is defaulted to Container.
062: * - an optional list of the session bean class and/or
063: * superclass around-invoke methods.
064: * - an optional declaration of the bean's
065: * environment entries
066: * - an optional declaration of the bean's EJB references
067: * - an optional declaration of the bean's local
068: * EJB references
069: * - an optional declaration of the bean's web
070: * service references
071: * - an optional declaration of the security role
072: * references
073: * - an optional declaration of the security identity
074: * to be used for the execution of the bean's methods
075: * - an optional declaration of the bean's resource
076: * manager connection factory references
077: * - an optional declaration of the bean's resource
078: * environment references.
079: * - an optional declaration of the bean's message
080: * destination references
081: * <p/>
082: * The elements that are optional are "optional" in the sense
083: * that they are omitted when if lists represented by them are
084: * empty.
085: * <p/>
086: * Either both the local-home and the local elements or both
087: * the home and the remote elements must be specified for the
088: * session bean.
089: * <p/>
090: * The service-endpoint element may only be specified if the
091: * bean is a stateless session bean.
092: */
093: @XmlAccessorType(XmlAccessType.FIELD)
094: @XmlType(name="session-beanType",propOrder={"descriptions","displayNames","icon","ejbName","mappedName","home","remote","localHome","local","businessLocal","businessRemote","serviceEndpoint","ejbClass","sessionType","timeoutMethod","initMethod","removeMethod","transactionType","aroundInvoke","envEntry","ejbRef","ejbLocalRef","serviceRef","resourceRef","resourceEnvRef","messageDestinationRef","persistenceContextRef","persistenceUnitRef","postConstruct","preDestroy","postActivate","prePassivate","securityRoleRef","securityIdentity"})
095: public class SessionBean implements EnterpriseBean, RemoteBean,
096: Session, TimerConsumer {
097: @XmlTransient
098: protected TextMap description = new TextMap();
099: @XmlTransient
100: protected TextMap displayName = new TextMap();
101: @XmlElement(name="icon",required=true)
102: protected LocalCollection<Icon> icon = new LocalCollection<Icon>();
103:
104: @XmlElement(name="ejb-name",required=true)
105: protected String ejbName;
106: @XmlElement(name="mapped-name")
107: protected String mappedName;
108: protected String home;
109: protected String remote;
110: @XmlElement(name="local-home")
111: protected String localHome;
112: protected String local;
113: @XmlElement(name="business-local")
114: protected LinkedHashSet<String> businessLocal;
115: @XmlElement(name="business-remote")
116: protected LinkedHashSet<String> businessRemote;
117: @XmlElement(name="service-endpoint")
118: protected String serviceEndpoint;
119: @XmlElement(name="ejb-class")
120: protected String ejbClass;
121: @XmlElement(name="session-type")
122: protected SessionType sessionType = SessionType.STATELESS;
123: @XmlElement(name="timeout-method")
124: protected NamedMethod timeoutMethod;
125: @XmlElement(name="init-method",required=true)
126: protected List<InitMethod> initMethod;
127: @XmlElement(name="remove-method",required=true)
128: protected List<RemoveMethod> removeMethod;
129: @XmlElement(name="transaction-type")
130: protected TransactionType transactionType;
131: @XmlElement(name="around-invoke",required=true)
132: protected List<AroundInvoke> aroundInvoke;
133: @XmlElement(name="env-entry",required=true)
134: protected KeyedCollection<String, EnvEntry> envEntry;
135: @XmlElement(name="ejb-ref",required=true)
136: protected KeyedCollection<String, EjbRef> ejbRef;
137: @XmlElement(name="ejb-local-ref",required=true)
138: protected KeyedCollection<String, EjbLocalRef> ejbLocalRef;
139: @XmlElement(name="service-ref",required=true)
140: protected KeyedCollection<String, ServiceRef> serviceRef;
141: @XmlElement(name="resource-ref",required=true)
142: protected KeyedCollection<String, ResourceRef> resourceRef;
143: @XmlElement(name="resource-env-ref",required=true)
144: protected KeyedCollection<String, ResourceEnvRef> resourceEnvRef;
145: @XmlElement(name="message-destination-ref",required=true)
146: protected KeyedCollection<String, MessageDestinationRef> messageDestinationRef;
147: @XmlElement(name="persistence-context-ref",required=true)
148: protected KeyedCollection<String, PersistenceContextRef> persistenceContextRef;
149: @XmlElement(name="persistence-unit-ref",required=true)
150: protected KeyedCollection<String, PersistenceUnitRef> persistenceUnitRef;
151: @XmlElement(name="post-construct",required=true)
152: protected List<LifecycleCallback> postConstruct;
153: @XmlElement(name="pre-destroy",required=true)
154: protected List<LifecycleCallback> preDestroy;
155: @XmlElement(name="post-activate",required=true)
156: protected List<LifecycleCallback> postActivate;
157: @XmlElement(name="pre-passivate",required=true)
158: protected List<LifecycleCallback> prePassivate;
159: @XmlElement(name="security-role-ref",required=true)
160: protected List<SecurityRoleRef> securityRoleRef;
161: @XmlElement(name="security-identity")
162: protected SecurityIdentity securityIdentity;
163: @XmlAttribute
164: @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
165: @XmlID
166: protected String id;
167:
168: public SessionBean() {
169: }
170:
171: public SessionBean(String ejbName, String ejbClass,
172: SessionType sessionType) {
173: this .ejbName = ejbName;
174: this .ejbClass = ejbClass;
175: this .sessionType = sessionType;
176: }
177:
178: public String getJndiConsumerName() {
179: return ejbName;
180: }
181:
182: @XmlElement(name="description",required=true)
183: public Text[] getDescriptions() {
184: return description.toArray();
185: }
186:
187: public void setDescriptions(Text[] text) {
188: description.set(text);
189: }
190:
191: public String getDescription() {
192: return description.get();
193: }
194:
195: @XmlElement(name="display-name",required=true)
196: public Text[] getDisplayNames() {
197: return displayName.toArray();
198: }
199:
200: public void setDisplayNames(Text[] text) {
201: displayName.set(text);
202: }
203:
204: public String getDisplayName() {
205: return displayName.get();
206: }
207:
208: public Collection<Icon> getIcons() {
209: if (icon == null) {
210: icon = new LocalCollection<Icon>();
211: }
212: return icon;
213: }
214:
215: public Map<String, Icon> getIconMap() {
216: if (icon == null) {
217: icon = new LocalCollection<Icon>();
218: }
219: return icon.toMap();
220: }
221:
222: public Icon getIcon() {
223: return icon.getLocal();
224: }
225:
226: public String getEjbName() {
227: return ejbName;
228: }
229:
230: /**
231: * The ejb-nameType specifies an enterprise bean's name. It is
232: * used by ejb-name elements. This name is assigned by the
233: * ejb-jar file producer to name the enterprise bean in the
234: * ejb-jar file's deployment descriptor. The name must be
235: * unique among the names of the enterprise beans in the same
236: * ejb-jar file.
237: * <p/>
238: * There is no architected relationship between the used
239: * ejb-name in the deployment descriptor and the JNDI name that
240: * the Deployer will assign to the enterprise bean's home.
241: * <p/>
242: * The name for an entity bean must conform to the lexical
243: * rules for an NMTOKEN.
244: * <p/>
245: * Example:
246: * <p/>
247: * <ejb-name>EmployeeService</ejb-name>
248: */
249: public void setEjbName(String value) {
250: this .ejbName = value;
251: }
252:
253: public String getMappedName() {
254: return mappedName;
255: }
256:
257: public void setMappedName(String value) {
258: this .mappedName = value;
259: }
260:
261: public String getHome() {
262: return home;
263: }
264:
265: public void setHome(String value) {
266: this .home = value;
267: }
268:
269: public String getRemote() {
270: return remote;
271: }
272:
273: public void setRemote(String value) {
274: this .remote = value;
275: }
276:
277: public void setHomeAndRemote(String home, String remote) {
278: this .remote = remote;
279: this .home = home;
280: }
281:
282: public void setHomeAndRemote(Class<?> home, Class<?> remote) {
283: this .remote = remote.getName();
284: this .home = home.getName();
285: }
286:
287: public void setHomeAndLocal(String localHome, String local) {
288: this .local = local;
289: this .localHome = localHome;
290: }
291:
292: public void setHomeAndLocal(Class<?> localHome, Class<?> local) {
293: this .local = local.getName();
294: this .localHome = localHome.getName();
295: }
296:
297: public String getLocalHome() {
298: return localHome;
299: }
300:
301: public void setLocalHome(String value) {
302: this .localHome = value;
303: }
304:
305: public String getLocal() {
306: return local;
307: }
308:
309: public void setLocal(String value) {
310: this .local = value;
311: }
312:
313: public Collection<String> getBusinessLocal() {
314: if (businessLocal == null) {
315: businessLocal = new LinkedHashSet<String>();
316: }
317: return businessLocal;
318: }
319:
320: public void addBusinessLocal(String businessLocal) {
321: if (businessLocal == null)
322: return;
323: getBusinessLocal().add(businessLocal);
324: }
325:
326: public Collection<String> getBusinessRemote() {
327: if (businessRemote == null) {
328: businessRemote = new LinkedHashSet<String>();
329: }
330: return businessRemote;
331: }
332:
333: public void addBusinessRemote(String businessRemote) {
334: if (businessRemote == null)
335: return;
336: getBusinessRemote().add(businessRemote);
337: }
338:
339: public String getServiceEndpoint() {
340: return serviceEndpoint;
341: }
342:
343: public void setServiceEndpoint(String value) {
344: this .serviceEndpoint = value;
345: }
346:
347: public String getEjbClass() {
348: return ejbClass;
349: }
350:
351: public void setEjbClass(String value) {
352: this .ejbClass = value;
353: }
354:
355: public SessionType getSessionType() {
356: return sessionType;
357: }
358:
359: public void setSessionType(SessionType value) {
360: this .sessionType = value;
361: }
362:
363: public NamedMethod getTimeoutMethod() {
364: return timeoutMethod;
365: }
366:
367: public void setTimeoutMethod(NamedMethod value) {
368: this .timeoutMethod = value;
369: }
370:
371: public List<InitMethod> getInitMethod() {
372: if (initMethod == null) {
373: initMethod = new ArrayList<InitMethod>();
374: }
375: return this .initMethod;
376: }
377:
378: public List<RemoveMethod> getRemoveMethod() {
379: if (removeMethod == null) {
380: removeMethod = new ArrayList<RemoveMethod>();
381: }
382: return this .removeMethod;
383: }
384:
385: public TransactionType getTransactionType() {
386: return transactionType;
387: }
388:
389: public void setTransactionType(TransactionType value) {
390: this .transactionType = value;
391: }
392:
393: public List<AroundInvoke> getAroundInvoke() {
394: if (aroundInvoke == null) {
395: aroundInvoke = new ArrayList<AroundInvoke>();
396: }
397: return this .aroundInvoke;
398: }
399:
400: public void addAroundInvoke(String method) {
401: assert ejbClass != null : "Set the ejbClass before calling this method";
402: getAroundInvoke().add(new AroundInvoke(ejbClass, method));
403: }
404:
405: public Collection<EnvEntry> getEnvEntry() {
406: if (envEntry == null) {
407: envEntry = new KeyedCollection<String, EnvEntry>();
408: }
409: return this .envEntry;
410: }
411:
412: public Map<String, EnvEntry> getEnvEntryMap() {
413: if (envEntry == null) {
414: envEntry = new KeyedCollection<String, EnvEntry>();
415: }
416: return this .envEntry.toMap();
417: }
418:
419: public Collection<EjbRef> getEjbRef() {
420: if (ejbRef == null) {
421: ejbRef = new KeyedCollection<String, EjbRef>();
422: }
423: return this .ejbRef;
424: }
425:
426: public Map<String, EjbRef> getEjbRefMap() {
427: if (ejbRef == null) {
428: ejbRef = new KeyedCollection<String, EjbRef>();
429: }
430: return this .ejbRef.toMap();
431: }
432:
433: public Collection<EjbLocalRef> getEjbLocalRef() {
434: if (ejbLocalRef == null) {
435: ejbLocalRef = new KeyedCollection<String, EjbLocalRef>();
436: }
437: return this .ejbLocalRef;
438: }
439:
440: public Map<String, EjbLocalRef> getEjbLocalRefMap() {
441: if (ejbLocalRef == null) {
442: ejbLocalRef = new KeyedCollection<String, EjbLocalRef>();
443: }
444: return this .ejbLocalRef.toMap();
445: }
446:
447: public Collection<ServiceRef> getServiceRef() {
448: if (serviceRef == null) {
449: serviceRef = new KeyedCollection<String, ServiceRef>();
450: }
451: return this .serviceRef;
452: }
453:
454: public Map<String, ServiceRef> getServiceRefMap() {
455: if (serviceRef == null) {
456: serviceRef = new KeyedCollection<String, ServiceRef>();
457: }
458: return this .serviceRef.toMap();
459: }
460:
461: public Collection<ResourceRef> getResourceRef() {
462: if (resourceRef == null) {
463: resourceRef = new KeyedCollection<String, ResourceRef>();
464: }
465: return this .resourceRef;
466: }
467:
468: public Map<String, ResourceRef> getResourceRefMap() {
469: if (resourceRef == null) {
470: resourceRef = new KeyedCollection<String, ResourceRef>();
471: }
472: return this .resourceRef.toMap();
473: }
474:
475: public Collection<ResourceEnvRef> getResourceEnvRef() {
476: if (resourceEnvRef == null) {
477: resourceEnvRef = new KeyedCollection<String, ResourceEnvRef>();
478: }
479: return this .resourceEnvRef;
480: }
481:
482: public Map<String, ResourceEnvRef> getResourceEnvRefMap() {
483: if (resourceEnvRef == null) {
484: resourceEnvRef = new KeyedCollection<String, ResourceEnvRef>();
485: }
486: return this .resourceEnvRef.toMap();
487: }
488:
489: public Collection<MessageDestinationRef> getMessageDestinationRef() {
490: if (messageDestinationRef == null) {
491: messageDestinationRef = new KeyedCollection<String, MessageDestinationRef>();
492: }
493: return this .messageDestinationRef;
494: }
495:
496: public Map<String, MessageDestinationRef> getMessageDestinationRefMap() {
497: if (messageDestinationRef == null) {
498: messageDestinationRef = new KeyedCollection<String, MessageDestinationRef>();
499: }
500: return this .messageDestinationRef.toMap();
501: }
502:
503: public Collection<PersistenceContextRef> getPersistenceContextRef() {
504: if (persistenceContextRef == null) {
505: persistenceContextRef = new KeyedCollection<String, PersistenceContextRef>();
506: }
507: return this .persistenceContextRef;
508: }
509:
510: public Map<String, PersistenceContextRef> getPersistenceContextRefMap() {
511: if (persistenceContextRef == null) {
512: persistenceContextRef = new KeyedCollection<String, PersistenceContextRef>();
513: }
514: return this .persistenceContextRef.toMap();
515: }
516:
517: public Collection<PersistenceUnitRef> getPersistenceUnitRef() {
518: if (persistenceUnitRef == null) {
519: persistenceUnitRef = new KeyedCollection<String, PersistenceUnitRef>();
520: }
521: return this .persistenceUnitRef;
522: }
523:
524: public Map<String, PersistenceUnitRef> getPersistenceUnitRefMap() {
525: if (persistenceUnitRef == null) {
526: persistenceUnitRef = new KeyedCollection<String, PersistenceUnitRef>();
527: }
528: return this .persistenceUnitRef.toMap();
529: }
530:
531: public List<LifecycleCallback> getPostConstruct() {
532: if (postConstruct == null) {
533: postConstruct = new ArrayList<LifecycleCallback>();
534: }
535: return this .postConstruct;
536: }
537:
538: public void addPostConstruct(String method) {
539: assert ejbClass != null : "Set the ejbClass before calling this method";
540: getPostConstruct().add(new LifecycleCallback(ejbClass, method));
541: }
542:
543: public List<LifecycleCallback> getPreDestroy() {
544: if (preDestroy == null) {
545: preDestroy = new ArrayList<LifecycleCallback>();
546: }
547: return this .preDestroy;
548: }
549:
550: public void addPreDestroy(String method) {
551: assert ejbClass != null : "Set the ejbClass before calling this method";
552: getPreDestroy().add(new LifecycleCallback(ejbClass, method));
553: }
554:
555: public List<LifecycleCallback> getPostActivate() {
556: if (postActivate == null) {
557: postActivate = new ArrayList<LifecycleCallback>();
558: }
559: return this .postActivate;
560: }
561:
562: public void addPostActivate(String method) {
563: assert ejbClass != null : "Set the ejbClass before calling this method";
564: getPostActivate().add(new LifecycleCallback(ejbClass, method));
565: }
566:
567: public List<LifecycleCallback> getPrePassivate() {
568: if (prePassivate == null) {
569: prePassivate = new ArrayList<LifecycleCallback>();
570: }
571: return this .prePassivate;
572: }
573:
574: public void addPrePassivate(String method) {
575: assert ejbClass != null : "Set the ejbClass before calling this method";
576: getPrePassivate().add(new LifecycleCallback(ejbClass, method));
577: }
578:
579: public List<SecurityRoleRef> getSecurityRoleRef() {
580: if (securityRoleRef == null) {
581: securityRoleRef = new ArrayList<SecurityRoleRef>();
582: }
583: return this .securityRoleRef;
584: }
585:
586: public SecurityIdentity getSecurityIdentity() {
587: return securityIdentity;
588: }
589:
590: public void setSecurityIdentity(SecurityIdentity value) {
591: this .securityIdentity = value;
592: }
593:
594: public String getId() {
595: return id;
596: }
597:
598: public void setId(String value) {
599: this.id = value;
600: }
601:
602: }
|