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.XmlType;
025: import javax.xml.bind.annotation.XmlTransient;
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.Map;
032:
033: /**
034: * The message-driven element declares a message-driven
035: * bean. The declaration consists of:
036: * <p/>
037: * - an optional description
038: * - an optional display name
039: * - an optional icon element that contains a small and a large
040: * icon file name.
041: * - a name assigned to the enterprise bean in
042: * the deployment descriptor
043: * - an optional mapped-name element that can be used to provide
044: * vendor-specific deployment information such as the physical
045: * jndi-name of destination from which this message-driven bean
046: * should consume. This element is not required to be supported
047: * by all implementations. Any use of this element is non-portable.
048: * - the message-driven bean's implementation class
049: * - an optional declaration of the bean's messaging
050: * type
051: * - an optional declaration of the bean's timeout method.
052: * - the optional message-driven bean's transaction management
053: * type. If it is not defined, it is defaulted to Container.
054: * - an optional declaration of the bean's
055: * message-destination-type
056: * - an optional declaration of the bean's
057: * message-destination-link
058: * - an optional declaration of the message-driven bean's
059: * activation configuration properties
060: * - an optional list of the message-driven bean class and/or
061: * superclass around-invoke methods.
062: * - an optional declaration of the bean's environment
063: * entries
064: * - an optional declaration of the bean's EJB references
065: * - an optional declaration of the bean's local EJB
066: * references
067: * - an optional declaration of the bean's web service
068: * references
069: * - an optional declaration of the security
070: * identity to be used for the execution of the bean's
071: * methods
072: * - an optional declaration of the bean's
073: * resource manager connection factory
074: * references
075: * - an optional declaration of the bean's resource
076: * environment references.
077: * - an optional declaration of the bean's message
078: * destination references
079: */
080: @XmlAccessorType(XmlAccessType.FIELD)
081: @XmlType(name="message-driven-beanType",propOrder={"descriptions","displayNames","icon","ejbName","mappedName","ejbClass","messagingType","timeoutMethod","transactionType","messageDrivenDestination","messageDestinationType","messageDestinationLink","activationConfig","aroundInvoke","envEntry","ejbRef","ejbLocalRef","serviceRef","resourceRef","resourceEnvRef","messageDestinationRef","persistenceContextRef","persistenceUnitRef","postConstruct","preDestroy","securityIdentity"})
082: public class MessageDrivenBean implements EnterpriseBean, TimerConsumer {
083:
084: @XmlTransient
085: protected TextMap description = new TextMap();
086: @XmlTransient
087: protected TextMap displayName = new TextMap();
088: @XmlElement(name="icon",required=true)
089: protected LocalCollection<Icon> icon = new LocalCollection<Icon>();
090:
091: @XmlElement(name="ejb-name",required=true)
092: protected String ejbName;
093: @XmlElement(name="mapped-name")
094: protected String mappedName;
095: @XmlElement(name="ejb-class")
096: protected String ejbClass;
097: @XmlElement(name="messaging-type")
098: protected String messagingType;
099: @XmlElement(name="timeout-method")
100: protected NamedMethod timeoutMethod;
101: @XmlElement(name="transaction-type")
102: protected TransactionType transactionType;
103: @XmlElement(name="message-driven-destination")
104: protected MessageDrivenDestination messageDrivenDestination;
105: @XmlElement(name="message-destination-type")
106: protected String messageDestinationType;
107: @XmlElement(name="message-destination-link")
108: protected String messageDestinationLink;
109: @XmlElement(name="activation-config")
110: protected ActivationConfig activationConfig;
111: @XmlElement(name="around-invoke",required=true)
112: protected List<AroundInvoke> aroundInvoke;
113: @XmlElement(name="env-entry",required=true)
114: protected KeyedCollection<String, EnvEntry> envEntry;
115: @XmlElement(name="ejb-ref",required=true)
116: protected KeyedCollection<String, EjbRef> ejbRef;
117: @XmlElement(name="ejb-local-ref",required=true)
118: protected KeyedCollection<String, EjbLocalRef> ejbLocalRef;
119: @XmlElement(name="service-ref",required=true)
120: protected KeyedCollection<String, ServiceRef> serviceRef;
121: @XmlElement(name="resource-ref",required=true)
122: protected KeyedCollection<String, ResourceRef> resourceRef;
123: @XmlElement(name="resource-env-ref",required=true)
124: protected KeyedCollection<String, ResourceEnvRef> resourceEnvRef;
125: @XmlElement(name="message-destination-ref",required=true)
126: protected KeyedCollection<String, MessageDestinationRef> messageDestinationRef;
127: @XmlElement(name="persistence-context-ref",required=true)
128: protected KeyedCollection<String, PersistenceContextRef> persistenceContextRef;
129: @XmlElement(name="persistence-unit-ref",required=true)
130: protected KeyedCollection<String, PersistenceUnitRef> persistenceUnitRef;
131: @XmlElement(name="post-construct",required=true)
132: protected List<LifecycleCallback> postConstruct;
133: @XmlElement(name="pre-destroy",required=true)
134: protected List<LifecycleCallback> preDestroy;
135: @XmlElement(name="security-identity")
136: protected SecurityIdentity securityIdentity;
137: @XmlAttribute
138: @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
139: @XmlID
140: protected String id;
141:
142: public MessageDrivenBean() {
143: }
144:
145: public MessageDrivenBean(String ejbName) {
146: this .ejbName = ejbName;
147: }
148:
149: public String getJndiConsumerName() {
150: return ejbName;
151: }
152:
153: @XmlElement(name="description",required=true)
154: public Text[] getDescriptions() {
155: return description.toArray();
156: }
157:
158: public void setDescriptions(Text[] text) {
159: description.set(text);
160: }
161:
162: public String getDescription() {
163: return description.get();
164: }
165:
166: @XmlElement(name="display-name",required=true)
167: public Text[] getDisplayNames() {
168: return displayName.toArray();
169: }
170:
171: public void setDisplayNames(Text[] text) {
172: displayName.set(text);
173: }
174:
175: public String getDisplayName() {
176: return displayName.get();
177: }
178:
179: public Collection<Icon> getIcons() {
180: if (icon == null) {
181: icon = new LocalCollection<Icon>();
182: }
183: return icon;
184: }
185:
186: public Map<String, Icon> getIconMap() {
187: if (icon == null) {
188: icon = new LocalCollection<Icon>();
189: }
190: return icon.toMap();
191: }
192:
193: public Icon getIcon() {
194: return icon.getLocal();
195: }
196:
197: public String getEjbName() {
198: return ejbName;
199: }
200:
201: /**
202: * The ejb-nameType specifies an enterprise bean's name. It is
203: * used by ejb-name elements. This name is assigned by the
204: * ejb-jar file producer to name the enterprise bean in the
205: * ejb-jar file's deployment descriptor. The name must be
206: * unique among the names of the enterprise beans in the same
207: * ejb-jar file.
208: * <p/>
209: * There is no architected relationship between the used
210: * ejb-name in the deployment descriptor and the JNDI name that
211: * the Deployer will assign to the enterprise bean's home.
212: * <p/>
213: * The name for an entity bean must conform to the lexical
214: * rules for an NMTOKEN.
215: * <p/>
216: * Example:
217: * <p/>
218: * <ejb-name>EmployeeService</ejb-name>
219: */
220: public void setEjbName(String value) {
221: this .ejbName = value;
222: }
223:
224: public String getMappedName() {
225: return mappedName;
226: }
227:
228: public void setMappedName(String value) {
229: this .mappedName = value;
230: }
231:
232: public String getEjbClass() {
233: return ejbClass;
234: }
235:
236: public void setEjbClass(String value) {
237: this .ejbClass = value;
238: }
239:
240: public String getMessagingType() {
241: return messagingType;
242: }
243:
244: public void setMessagingType(String value) {
245: this .messagingType = value;
246: }
247:
248: public NamedMethod getTimeoutMethod() {
249: return timeoutMethod;
250: }
251:
252: public void setTimeoutMethod(NamedMethod value) {
253: this .timeoutMethod = value;
254: }
255:
256: public MessageDrivenDestination getMessageDrivenDestination() {
257: return messageDrivenDestination;
258: }
259:
260: public void setMessageDrivenDestination(
261: MessageDrivenDestination value) {
262: this .messageDrivenDestination = value;
263: }
264:
265: public TransactionType getTransactionType() {
266: return transactionType;
267: }
268:
269: public void setTransactionType(TransactionType value) {
270: this .transactionType = value;
271: }
272:
273: public String getMessageDestinationType() {
274: return messageDestinationType;
275: }
276:
277: public void setMessageDestinationType(String value) {
278: this .messageDestinationType = value;
279: }
280:
281: /**
282: * The Assembler sets the value to reflect the flow of messages
283: * between producers and consumers in the application.
284: * <p/>
285: * The value must be the message-destination-name of a message
286: * destination in the same Deployment File or in another
287: * Deployment File in the same Java EE application unit.
288: * <p/>
289: * Alternatively, the value may be composed of a path name
290: * specifying a Deployment File containing the referenced
291: * message destination with the message-destination-name of the
292: * destination appended and separated from the path name by
293: * "#". The path name is relative to the Deployment File
294: * containing Deployment Component that is referencing the
295: * message destination. This allows multiple message
296: * destinations with the same name to be uniquely identified.
297: */
298: public String getMessageDestinationLink() {
299: return messageDestinationLink;
300: }
301:
302: public void setMessageDestinationLink(String value) {
303: this .messageDestinationLink = value;
304: }
305:
306: public ActivationConfig getActivationConfig() {
307: // convert the message-driven-destination to activation-config-property
308: // OPENEJB-701 EJB 2.0 depricated message-driven-destination tag not supported
309: // https://issues.apache.org/jira/browse/OPENEJB-701
310: if (messageDrivenDestination != null) {
311: if (activationConfig == null) {
312: activationConfig = new ActivationConfig();
313: }
314: DestinationType destinationType = messageDrivenDestination
315: .getDestinationType();
316: if (destinationType != null) {
317: activationConfig.addProperty("destinationType",
318: destinationType.getvalue());
319: }
320: SubscriptionDurability subscriptionDurability = messageDrivenDestination
321: .getSubscriptionDurability();
322: if (subscriptionDurability != null) {
323: activationConfig.addProperty("subscriptionDurability",
324: subscriptionDurability.getvalue());
325: }
326: messageDrivenDestination = null;
327: }
328: return activationConfig;
329: }
330:
331: public void setActivationConfig(ActivationConfig value) {
332: this .activationConfig = value;
333: }
334:
335: public List<AroundInvoke> getAroundInvoke() {
336: if (aroundInvoke == null) {
337: aroundInvoke = new ArrayList<AroundInvoke>();
338: }
339: return this .aroundInvoke;
340: }
341:
342: public void addAroundInvoke(String method) {
343: assert ejbClass != null : "Set the ejbClass before calling this method";
344: getAroundInvoke().add(new AroundInvoke(ejbClass, method));
345: }
346:
347: public Collection<EnvEntry> getEnvEntry() {
348: if (envEntry == null) {
349: envEntry = new KeyedCollection<String, EnvEntry>();
350: }
351: return this .envEntry;
352: }
353:
354: public Map<String, EnvEntry> getEnvEntryMap() {
355: if (envEntry == null) {
356: envEntry = new KeyedCollection<String, EnvEntry>();
357: }
358: return this .envEntry.toMap();
359: }
360:
361: public Collection<EjbRef> getEjbRef() {
362: if (ejbRef == null) {
363: ejbRef = new KeyedCollection<String, EjbRef>();
364: }
365: return this .ejbRef;
366: }
367:
368: public Map<String, EjbRef> getEjbRefMap() {
369: if (ejbRef == null) {
370: ejbRef = new KeyedCollection<String, EjbRef>();
371: }
372: return this .ejbRef.toMap();
373: }
374:
375: public Collection<EjbLocalRef> getEjbLocalRef() {
376: if (ejbLocalRef == null) {
377: ejbLocalRef = new KeyedCollection<String, EjbLocalRef>();
378: }
379: return this .ejbLocalRef;
380: }
381:
382: public Map<String, EjbLocalRef> getEjbLocalRefMap() {
383: if (ejbLocalRef == null) {
384: ejbLocalRef = new KeyedCollection<String, EjbLocalRef>();
385: }
386: return this .ejbLocalRef.toMap();
387: }
388:
389: public Collection<ServiceRef> getServiceRef() {
390: if (serviceRef == null) {
391: serviceRef = new KeyedCollection<String, ServiceRef>();
392: }
393: return this .serviceRef;
394: }
395:
396: public Map<String, ServiceRef> getServiceRefMap() {
397: if (serviceRef == null) {
398: serviceRef = new KeyedCollection<String, ServiceRef>();
399: }
400: return this .serviceRef.toMap();
401: }
402:
403: public Collection<ResourceRef> getResourceRef() {
404: if (resourceRef == null) {
405: resourceRef = new KeyedCollection<String, ResourceRef>();
406: }
407: return this .resourceRef;
408: }
409:
410: public Map<String, ResourceRef> getResourceRefMap() {
411: if (resourceRef == null) {
412: resourceRef = new KeyedCollection<String, ResourceRef>();
413: }
414: return this .resourceRef.toMap();
415: }
416:
417: public Collection<ResourceEnvRef> getResourceEnvRef() {
418: if (resourceEnvRef == null) {
419: resourceEnvRef = new KeyedCollection<String, ResourceEnvRef>();
420: }
421: return this .resourceEnvRef;
422: }
423:
424: public Map<String, ResourceEnvRef> getResourceEnvRefMap() {
425: if (resourceEnvRef == null) {
426: resourceEnvRef = new KeyedCollection<String, ResourceEnvRef>();
427: }
428: return this .resourceEnvRef.toMap();
429: }
430:
431: public Collection<MessageDestinationRef> getMessageDestinationRef() {
432: if (messageDestinationRef == null) {
433: messageDestinationRef = new KeyedCollection<String, MessageDestinationRef>();
434: }
435: return this .messageDestinationRef;
436: }
437:
438: public Map<String, MessageDestinationRef> getMessageDestinationRefMap() {
439: if (messageDestinationRef == null) {
440: messageDestinationRef = new KeyedCollection<String, MessageDestinationRef>();
441: }
442: return this .messageDestinationRef.toMap();
443: }
444:
445: public Collection<PersistenceContextRef> getPersistenceContextRef() {
446: if (persistenceContextRef == null) {
447: persistenceContextRef = new KeyedCollection<String, PersistenceContextRef>();
448: }
449: return this .persistenceContextRef;
450: }
451:
452: public Map<String, PersistenceContextRef> getPersistenceContextRefMap() {
453: if (persistenceContextRef == null) {
454: persistenceContextRef = new KeyedCollection<String, PersistenceContextRef>();
455: }
456: return this .persistenceContextRef.toMap();
457: }
458:
459: public Collection<PersistenceUnitRef> getPersistenceUnitRef() {
460: if (persistenceUnitRef == null) {
461: persistenceUnitRef = new KeyedCollection<String, PersistenceUnitRef>();
462: }
463: return this .persistenceUnitRef;
464: }
465:
466: public Map<String, PersistenceUnitRef> getPersistenceUnitRefMap() {
467: if (persistenceUnitRef == null) {
468: persistenceUnitRef = new KeyedCollection<String, PersistenceUnitRef>();
469: }
470: return this .persistenceUnitRef.toMap();
471: }
472:
473: public List<LifecycleCallback> getPostConstruct() {
474: if (postConstruct == null) {
475: postConstruct = new ArrayList<LifecycleCallback>();
476: }
477: return this .postConstruct;
478: }
479:
480: public void addPostConstruct(String method) {
481: assert ejbClass != null : "Set the ejbClass before calling this method";
482: getPostConstruct().add(new LifecycleCallback(ejbClass, method));
483: }
484:
485: public List<LifecycleCallback> getPreDestroy() {
486: if (preDestroy == null) {
487: preDestroy = new ArrayList<LifecycleCallback>();
488: }
489: return this .preDestroy;
490: }
491:
492: public void addPreDestroy(String method) {
493: assert ejbClass != null : "Set the ejbClass before calling this method";
494: getPreDestroy().add(new LifecycleCallback(ejbClass, method));
495: }
496:
497: public SecurityIdentity getSecurityIdentity() {
498: return securityIdentity;
499: }
500:
501: public void setSecurityIdentity(SecurityIdentity value) {
502: this .securityIdentity = value;
503: }
504:
505: public String getId() {
506: return id;
507: }
508:
509: public void setId(String value) {
510: this.id = value;
511: }
512:
513: }
|