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.XmlElementWrapper;
026: import javax.xml.bind.annotation.XmlElements;
027: import javax.xml.bind.annotation.XmlTransient;
028: import javax.xml.bind.annotation.XmlRootElement;
029: import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
030: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
031: import java.util.Map;
032: import java.util.LinkedHashMap;
033: import java.util.Collection;
034:
035: /**
036: * The ejb-jarType defines the root element of the EJB
037: * deployment descriptor. It contains
038: * <p/>
039: * - an optional description of the ejb-jar file
040: * - an optional display name
041: * - an optional icon that contains a small and a large
042: * icon file name
043: * - structural information about all included
044: * enterprise beans that is not specified through
045: * annotations
046: * - structural information about interceptor classes
047: * - a descriptor for container managed relationships,
048: * if any.
049: * - an optional application-assembly descriptor
050: * - an optional name of an ejb-client-jar file for the
051: * ejb-jar.
052: */
053: @XmlRootElement(name="ejb-jar")
054: @XmlAccessorType(XmlAccessType.FIELD)
055: @XmlType(name="ejb-jarType",propOrder={"descriptions","displayNames","icon","enterpriseBeans","interceptors","relationships","assemblyDescriptor","ejbClientJar"})
056: public class EjbJar {
057:
058: @XmlTransient
059: protected TextMap description = new TextMap();
060: @XmlTransient
061: protected TextMap displayName = new TextMap();
062: @XmlElement(name="icon",required=true)
063: protected LocalCollection<Icon> icon = new LocalCollection<Icon>();
064: @XmlTransient
065: protected Map<String, EnterpriseBean> enterpriseBeans = new LinkedHashMap<String, EnterpriseBean>();
066:
067: private Interceptors interceptors;
068: protected Relationships relationships;
069: @XmlElement(name="assembly-descriptor")
070: protected AssemblyDescriptor assemblyDescriptor;
071: @XmlElement(name="ejb-client-jar")
072: protected String ejbClientJar;
073: @XmlAttribute
074: @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
075: @XmlID
076: protected String id;
077: @XmlAttribute(name="metadata-complete")
078: protected Boolean metadataComplete;
079: @XmlAttribute(required=true)
080: @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
081: protected String version;
082:
083: public EjbJar() {
084: }
085:
086: public EjbJar(String id) {
087: this .id = id;
088: }
089:
090: @XmlElement(name="description",required=true)
091: public Text[] getDescriptions() {
092: return description.toArray();
093: }
094:
095: public void setDescriptions(Text[] text) {
096: description.set(text);
097: }
098:
099: public String getDescription() {
100: return description.get();
101: }
102:
103: @XmlElement(name="display-name",required=true)
104: public Text[] getDisplayNames() {
105: return displayName.toArray();
106: }
107:
108: public void setDisplayNames(Text[] text) {
109: displayName.set(text);
110: }
111:
112: public String getDisplayName() {
113: return displayName.get();
114: }
115:
116: public Collection<Icon> getIcons() {
117: if (icon == null) {
118: icon = new LocalCollection<Icon>();
119: }
120: return icon;
121: }
122:
123: public Map<String, Icon> getIconMap() {
124: if (icon == null) {
125: icon = new LocalCollection<Icon>();
126: }
127: return icon.toMap();
128: }
129:
130: public Icon getIcon() {
131: return icon.getLocal();
132: }
133:
134: @XmlElementWrapper(name="enterprise-beans")
135: @XmlElements({@XmlElement(name="message-driven",required=true,type=MessageDrivenBean.class),@XmlElement(name="session",required=true,type=SessionBean.class),@XmlElement(name="entity",required=true,type=EntityBean.class)})
136: public EnterpriseBean[] getEnterpriseBeans() {
137: return enterpriseBeans.values()
138: .toArray(new EnterpriseBean[] {});
139: }
140:
141: public void setEnterpriseBeans(EnterpriseBean[] v) {
142: enterpriseBeans.clear();
143: for (EnterpriseBean e : v)
144: enterpriseBeans.put(e.getEjbName(), e);
145: }
146:
147: public <T extends EnterpriseBean> T addEnterpriseBean(T bean) {
148: enterpriseBeans.put(bean.getEjbName(), bean);
149: return bean;
150: }
151:
152: public EnterpriseBean removeEnterpriseBean(String name) {
153: EnterpriseBean bean = enterpriseBeans.remove(name);
154: return bean;
155: }
156:
157: public EnterpriseBean getEnterpriseBean(String ejbName) {
158: return enterpriseBeans.get(ejbName);
159: }
160:
161: public Map<String, EnterpriseBean> getEnterpriseBeansByEjbName() {
162: return enterpriseBeans;
163: }
164:
165: public Interceptor[] getInterceptors() {
166: if (interceptors == null)
167: return new Interceptor[] {};
168: return interceptors.getInterceptor();
169: }
170:
171: public Interceptor addInterceptor(Interceptor interceptor) {
172: if (interceptors == null)
173: interceptors = new Interceptors();
174: return interceptors.addInterceptor(interceptor);
175: }
176:
177: public Interceptor getInterceptor(String className) {
178: if (interceptors == null)
179: return null;
180: return interceptors.getInterceptor(className);
181: }
182:
183: public Relationships getRelationships() {
184: return relationships;
185: }
186:
187: public void setRelationships(Relationships value) {
188: this .relationships = value;
189: }
190:
191: public AssemblyDescriptor getAssemblyDescriptor() {
192: if (assemblyDescriptor == null) {
193: assemblyDescriptor = new AssemblyDescriptor();
194: }
195: return assemblyDescriptor;
196: }
197:
198: public void setAssemblyDescriptor(AssemblyDescriptor value) {
199: this .assemblyDescriptor = value;
200: }
201:
202: public String getEjbClientJar() {
203: return ejbClientJar;
204: }
205:
206: public void setEjbClientJar(String value) {
207: this .ejbClientJar = value;
208: }
209:
210: public String getId() {
211: return id;
212: }
213:
214: public void setId(String value) {
215: this .id = value;
216: }
217:
218: public Boolean isMetadataComplete() {
219: return metadataComplete != null && metadataComplete;
220: }
221:
222: public void setMetadataComplete(Boolean value) {
223: this .metadataComplete = value;
224: }
225:
226: public String getVersion() {
227: if (version == null) {
228: return "3.0";
229: } else {
230: return version;
231: }
232: }
233:
234: public void setVersion(String value) {
235: this.version = value;
236: }
237:
238: }
|