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.Collections;
031: import java.util.Set;
032: import java.util.Collection;
033: import java.util.Map;
034:
035: /**
036: * The entity-beanType declares an entity bean. The declaration
037: * consists of:
038: * <p/>
039: * - an optional description
040: * - an optional display name
041: * - an optional icon element that contains a small and a large
042: * icon file name
043: * - a unique name assigned to the enterprise bean
044: * in the deployment descriptor
045: * - an optional mapped-name element that can be used to provide
046: * vendor-specific deployment information such as the physical
047: * jndi-name of the entity bean's remote home interface. This
048: * element is not required to be supported by all implementations.
049: * Any use of this element is non-portable.
050: * - the names of the entity bean's remote home
051: * and remote interfaces, if any
052: * - the names of the entity bean's local home and local
053: * interfaces, if any
054: * - the entity bean's implementation class
055: * - the optional entity bean's persistence management type. If
056: * this element is not specified it is defaulted to Container.
057: * - the entity bean's primary key class name
058: * - an indication of the entity bean's reentrancy
059: * - an optional specification of the
060: * entity bean's cmp-version
061: * - an optional specification of the entity bean's
062: * abstract schema name
063: * - an optional list of container-managed fields
064: * - an optional specification of the primary key
065: * field
066: * - an optional declaration of the bean's environment
067: * entries
068: * - an optional declaration of the bean's EJB
069: * references
070: * - an optional declaration of the bean's local
071: * EJB references
072: * - an optional declaration of the bean's web
073: * service references
074: * - an optional declaration of the security role
075: * references
076: * - an optional declaration of the security identity
077: * to be used for the execution of the bean's methods
078: * - an optional declaration of the bean's
079: * resource manager connection factory references
080: * - an optional declaration of the bean's
081: * resource environment references
082: * - an optional declaration of the bean's message
083: * destination references
084: * - an optional set of query declarations
085: * for finder and select methods for an entity
086: * bean with cmp-version 2.x.
087: * <p/>
088: * The optional abstract-schema-name element must be specified
089: * for an entity bean with container-managed persistence and
090: * cmp-version 2.x.
091: * <p/>
092: * The optional primkey-field may be present in the descriptor
093: * if the entity's persistence-type is Container.
094: * <p/>
095: * The optional cmp-version element may be present in the
096: * descriptor if the entity's persistence-type is Container. If
097: * the persistence-type is Container and the cmp-version
098: * element is not specified, its value defaults to 2.x.
099: * <p/>
100: * The optional home and remote elements must be specified if
101: * the entity bean cmp-version is 1.x.
102: * <p/>
103: * The optional home and remote elements must be specified if
104: * the entity bean has a remote home and remote interface.
105: * <p/>
106: * The optional local-home and local elements must be specified
107: * if the entity bean has a local home and local interface.
108: * <p/>
109: * Either both the local-home and the local elements or both
110: * the home and the remote elements must be specified.
111: * <p/>
112: * The optional query elements must be present if the
113: * persistence-type is Container and the cmp-version is 2.x and
114: * query methods other than findByPrimaryKey have been defined
115: * for the entity bean.
116: * <p/>
117: * The other elements that are optional are "optional" in the
118: * sense that they are omitted if the lists represented by them
119: * are empty.
120: * <p/>
121: * At least one cmp-field element must be present in the
122: * descriptor if the entity's persistence-type is Container and
123: * the cmp-version is 1.x, and none must not be present if the
124: * entity's persistence-type is Bean.
125: */
126: @XmlAccessorType(XmlAccessType.FIELD)
127: @XmlType(name="entity-beanType",propOrder={"descriptions","displayNames","icon","ejbName","mappedName","home","remote","localHome","local","ejbClass","persistenceType","primKeyClass","reentrant","cmpVersion","abstractSchemaName","cmpField","primkeyField","envEntry","ejbRef","ejbLocalRef","serviceRef","resourceRef","resourceEnvRef","messageDestinationRef","persistenceContextRef","persistenceUnitRef","postConstruct","preDestroy","securityRoleRef","securityIdentity","query"})
128: public class EntityBean implements EnterpriseBean, RemoteBean {
129:
130: @XmlTransient
131: protected TextMap description = new TextMap();
132: @XmlTransient
133: protected TextMap displayName = new TextMap();
134: @XmlElement(name="icon",required=true)
135: protected LocalCollection<Icon> icon = new LocalCollection<Icon>();
136:
137: @XmlElement(name="ejb-name",required=true)
138: protected String ejbName;
139: @XmlElement(name="mapped-name")
140: protected String mappedName;
141: protected String home;
142: protected String remote;
143: @XmlElement(name="local-home")
144: protected String localHome;
145: protected String local;
146: @XmlElement(name="ejb-class",required=true)
147: protected String ejbClass;
148: @XmlElement(name="persistence-type",required=true)
149: protected PersistenceType persistenceType;
150: @XmlElement(name="prim-key-class",required=true)
151: protected String primKeyClass;
152: @XmlElement(required=true)
153: protected boolean reentrant;
154: @XmlElement(name="cmp-version",defaultValue="2.x")
155: protected CmpVersion cmpVersion;
156: @XmlElement(name="abstract-schema-name")
157: protected String abstractSchemaName;
158: @XmlElement(name="cmp-field",required=true)
159: protected List<CmpField> cmpField;
160: @XmlElement(name="primkey-field")
161: protected String primkeyField;
162: @XmlElement(name="env-entry",required=true)
163: protected KeyedCollection<String, EnvEntry> envEntry;
164: @XmlElement(name="ejb-ref",required=true)
165: protected KeyedCollection<String, EjbRef> ejbRef;
166: @XmlElement(name="ejb-local-ref",required=true)
167: protected KeyedCollection<String, EjbLocalRef> ejbLocalRef;
168: @XmlElement(name="service-ref",required=true)
169: protected KeyedCollection<String, ServiceRef> serviceRef;
170: @XmlElement(name="resource-ref",required=true)
171: protected KeyedCollection<String, ResourceRef> resourceRef;
172: @XmlElement(name="resource-env-ref",required=true)
173: protected KeyedCollection<String, ResourceEnvRef> resourceEnvRef;
174: @XmlElement(name="message-destination-ref",required=true)
175: protected KeyedCollection<String, MessageDestinationRef> messageDestinationRef;
176: @XmlElement(name="persistence-context-ref",required=true)
177: protected KeyedCollection<String, PersistenceContextRef> persistenceContextRef;
178: @XmlElement(name="persistence-unit-ref",required=true)
179: protected KeyedCollection<String, PersistenceUnitRef> persistenceUnitRef;
180: @XmlElement(name="post-construct",required=true)
181: protected List<LifecycleCallback> postConstruct;
182: @XmlElement(name="pre-destroy",required=true)
183: protected List<LifecycleCallback> preDestroy;
184: @XmlElement(name="security-role-ref",required=true)
185: protected List<SecurityRoleRef> securityRoleRef;
186: @XmlElement(name="security-identity")
187: protected SecurityIdentity securityIdentity;
188: @XmlElement(required=true)
189: protected List<Query> query;
190: @XmlAttribute
191: @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
192: @XmlID
193: protected String id;
194:
195: public EntityBean() {
196: Set<String> publicIds = JaxbJavaee.currentPublicId.get();
197: if (publicIds != null
198: && publicIds
199: .contains("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN")) {
200: cmpVersion = CmpVersion.CMP1;
201: } else {
202: cmpVersion = CmpVersion.CMP2;
203: }
204: }
205:
206: public String getJndiConsumerName() {
207: return ejbName;
208: }
209:
210: @XmlElement(name="description",required=true)
211: public Text[] getDescriptions() {
212: return description.toArray();
213: }
214:
215: public void setDescriptions(Text[] text) {
216: description.set(text);
217: }
218:
219: public String getDescription() {
220: return description.get();
221: }
222:
223: @XmlElement(name="display-name",required=true)
224: public Text[] getDisplayNames() {
225: return displayName.toArray();
226: }
227:
228: public void setDisplayNames(Text[] text) {
229: displayName.set(text);
230: }
231:
232: public String getDisplayName() {
233: return displayName.get();
234: }
235:
236: public Collection<Icon> getIcons() {
237: if (icon == null) {
238: icon = new LocalCollection<Icon>();
239: }
240: return icon;
241: }
242:
243: public Map<String, Icon> getIconMap() {
244: if (icon == null) {
245: icon = new LocalCollection<Icon>();
246: }
247: return icon.toMap();
248: }
249:
250: public Icon getIcon() {
251: return icon.getLocal();
252: }
253:
254: public String getEjbName() {
255: return ejbName;
256: }
257:
258: /**
259: * The ejb-nameType specifies an enterprise bean's name. It is
260: * used by ejb-name elements. This name is assigned by the
261: * ejb-jar file producer to name the enterprise bean in the
262: * ejb-jar file's deployment descriptor. The name must be
263: * unique among the names of the enterprise beans in the same
264: * ejb-jar file.
265: * <p/>
266: * There is no architected relationship between the used
267: * ejb-name in the deployment descriptor and the JNDI name that
268: * the Deployer will assign to the enterprise bean's home.
269: * <p/>
270: * The name for an entity bean must conform to the lexical
271: * rules for an NMTOKEN.
272: * <p/>
273: * Example:
274: * <p/>
275: * <ejb-name>EmployeeService</ejb-name>
276: */
277: public void setEjbName(String value) {
278: this .ejbName = value;
279: }
280:
281: public String getMappedName() {
282: return mappedName;
283: }
284:
285: public void setMappedName(String value) {
286: this .mappedName = value;
287: }
288:
289: public String getHome() {
290: return home;
291: }
292:
293: public void setHome(String value) {
294: this .home = value;
295: }
296:
297: public String getRemote() {
298: return remote;
299: }
300:
301: public void setRemote(String value) {
302: this .remote = value;
303: }
304:
305: public String getLocalHome() {
306: return localHome;
307: }
308:
309: public void setLocalHome(String value) {
310: this .localHome = value;
311: }
312:
313: public String getLocal() {
314: return local;
315: }
316:
317: public void setLocal(String value) {
318: this .local = value;
319: }
320:
321: public String getEjbClass() {
322: return ejbClass;
323: }
324:
325: public void setEjbClass(String value) {
326: this .ejbClass = value;
327: }
328:
329: public PersistenceType getPersistenceType() {
330: return persistenceType;
331: }
332:
333: public void setPersistenceType(PersistenceType value) {
334: this .persistenceType = value;
335: }
336:
337: public String getPrimKeyClass() {
338: return primKeyClass;
339: }
340:
341: public void setPrimKeyClass(String value) {
342: this .primKeyClass = value;
343: }
344:
345: public boolean getReentrant() {
346: return reentrant;
347: }
348:
349: public void setReentrant(boolean value) {
350: this .reentrant = value;
351: }
352:
353: public CmpVersion getCmpVersion() {
354: return cmpVersion;
355: }
356:
357: public void setCmpVersion(CmpVersion value) {
358: this .cmpVersion = value;
359: }
360:
361: public String getAbstractSchemaName() {
362: return abstractSchemaName;
363: }
364:
365: public void setAbstractSchemaName(String value) {
366: this .abstractSchemaName = value;
367: }
368:
369: public List<CmpField> getCmpField() {
370: if (cmpField == null) {
371: cmpField = new ArrayList<CmpField>();
372: }
373: return this .cmpField;
374: }
375:
376: public String getPrimkeyField() {
377: return primkeyField;
378: }
379:
380: public void setPrimkeyField(String value) {
381: this .primkeyField = value;
382: }
383:
384: public Collection<EnvEntry> getEnvEntry() {
385: if (envEntry == null) {
386: envEntry = new KeyedCollection<String, EnvEntry>();
387: }
388: return this .envEntry;
389: }
390:
391: public Map<String, EnvEntry> getEnvEntryMap() {
392: if (envEntry == null) {
393: envEntry = new KeyedCollection<String, EnvEntry>();
394: }
395: return this .envEntry.toMap();
396: }
397:
398: public Collection<EjbRef> getEjbRef() {
399: if (ejbRef == null) {
400: ejbRef = new KeyedCollection<String, EjbRef>();
401: }
402: return this .ejbRef;
403: }
404:
405: public Map<String, EjbRef> getEjbRefMap() {
406: if (ejbRef == null) {
407: ejbRef = new KeyedCollection<String, EjbRef>();
408: }
409: return this .ejbRef.toMap();
410: }
411:
412: public Collection<EjbLocalRef> getEjbLocalRef() {
413: if (ejbLocalRef == null) {
414: ejbLocalRef = new KeyedCollection<String, EjbLocalRef>();
415: }
416: return this .ejbLocalRef;
417: }
418:
419: public Map<String, EjbLocalRef> getEjbLocalRefMap() {
420: if (ejbLocalRef == null) {
421: ejbLocalRef = new KeyedCollection<String, EjbLocalRef>();
422: }
423: return this .ejbLocalRef.toMap();
424: }
425:
426: public Collection<ServiceRef> getServiceRef() {
427: if (serviceRef == null) {
428: serviceRef = new KeyedCollection<String, ServiceRef>();
429: }
430: return this .serviceRef;
431: }
432:
433: public Map<String, ServiceRef> getServiceRefMap() {
434: if (serviceRef == null) {
435: serviceRef = new KeyedCollection<String, ServiceRef>();
436: }
437: return this .serviceRef.toMap();
438: }
439:
440: public Collection<ResourceRef> getResourceRef() {
441: if (resourceRef == null) {
442: resourceRef = new KeyedCollection<String, ResourceRef>();
443: }
444: return this .resourceRef;
445: }
446:
447: public Map<String, ResourceRef> getResourceRefMap() {
448: if (resourceRef == null) {
449: resourceRef = new KeyedCollection<String, ResourceRef>();
450: }
451: return this .resourceRef.toMap();
452: }
453:
454: public Collection<ResourceEnvRef> getResourceEnvRef() {
455: if (resourceEnvRef == null) {
456: resourceEnvRef = new KeyedCollection<String, ResourceEnvRef>();
457: }
458: return this .resourceEnvRef;
459: }
460:
461: public Map<String, ResourceEnvRef> getResourceEnvRefMap() {
462: if (resourceEnvRef == null) {
463: resourceEnvRef = new KeyedCollection<String, ResourceEnvRef>();
464: }
465: return this .resourceEnvRef.toMap();
466: }
467:
468: public Collection<MessageDestinationRef> getMessageDestinationRef() {
469: if (messageDestinationRef == null) {
470: messageDestinationRef = new KeyedCollection<String, MessageDestinationRef>();
471: }
472: return this .messageDestinationRef;
473: }
474:
475: public Map<String, MessageDestinationRef> getMessageDestinationRefMap() {
476: if (messageDestinationRef == null) {
477: messageDestinationRef = new KeyedCollection<String, MessageDestinationRef>();
478: }
479: return this .messageDestinationRef.toMap();
480: }
481:
482: public Collection<PersistenceContextRef> getPersistenceContextRef() {
483: if (persistenceContextRef == null) {
484: persistenceContextRef = new KeyedCollection<String, PersistenceContextRef>();
485: }
486: return this .persistenceContextRef;
487: }
488:
489: public Map<String, PersistenceContextRef> getPersistenceContextRefMap() {
490: if (persistenceContextRef == null) {
491: persistenceContextRef = new KeyedCollection<String, PersistenceContextRef>();
492: }
493: return this .persistenceContextRef.toMap();
494: }
495:
496: public Collection<PersistenceUnitRef> getPersistenceUnitRef() {
497: if (persistenceUnitRef == null) {
498: persistenceUnitRef = new KeyedCollection<String, PersistenceUnitRef>();
499: }
500: return this .persistenceUnitRef;
501: }
502:
503: public Map<String, PersistenceUnitRef> getPersistenceUnitRefMap() {
504: if (persistenceUnitRef == null) {
505: persistenceUnitRef = new KeyedCollection<String, PersistenceUnitRef>();
506: }
507: return this .persistenceUnitRef.toMap();
508: }
509:
510: public List<LifecycleCallback> getPostConstruct() {
511: if (postConstruct == null) {
512: postConstruct = new ArrayList<LifecycleCallback>();
513: }
514: return this .postConstruct;
515: }
516:
517: public void addPostConstruct(String method) {
518: assert ejbClass != null : "Set the ejbClass before calling this method";
519: getPostConstruct().add(new LifecycleCallback(ejbClass, method));
520: }
521:
522: public List<LifecycleCallback> getPreDestroy() {
523: if (preDestroy == null) {
524: preDestroy = new ArrayList<LifecycleCallback>();
525: }
526: return this .preDestroy;
527: }
528:
529: public void addPreDestroy(String method) {
530: assert ejbClass != null : "Set the ejbClass before calling this method";
531: getPreDestroy().add(new LifecycleCallback(ejbClass, method));
532: }
533:
534: public List<SecurityRoleRef> getSecurityRoleRef() {
535: if (securityRoleRef == null) {
536: securityRoleRef = new ArrayList<SecurityRoleRef>();
537: }
538: return this .securityRoleRef;
539: }
540:
541: public Collection<String> getBusinessLocal() {
542: return Collections.emptySet();
543: }
544:
545: public Collection<String> getBusinessRemote() {
546: return Collections.emptySet();
547: }
548:
549: public SecurityIdentity getSecurityIdentity() {
550: return securityIdentity;
551: }
552:
553: public void setSecurityIdentity(SecurityIdentity value) {
554: this .securityIdentity = value;
555: }
556:
557: public List<Query> getQuery() {
558: if (query == null) {
559: query = new ArrayList<Query>();
560: }
561: return this .query;
562: }
563:
564: public String getId() {
565: return id;
566: }
567:
568: public void setId(String value) {
569: this .id = value;
570: }
571:
572: public List<AroundInvoke> getAroundInvoke() {
573: return Collections.emptyList();
574: }
575:
576: public void addAroundInvoke(String method) {
577: }
578:
579: public TransactionType getTransactionType() {
580: return TransactionType.CONTAINER;
581: }
582:
583: public void setTransactionType(TransactionType type) {
584: }
585:
586: }
|