001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.jee;
017:
018: import javax.xml.bind.annotation.XmlAccessorType;
019: import javax.xml.bind.annotation.XmlAccessType;
020: import javax.xml.bind.annotation.XmlType;
021: import javax.xml.bind.annotation.XmlTransient;
022: import javax.xml.bind.annotation.XmlElement;
023: import javax.xml.bind.annotation.XmlAttribute;
024: import javax.xml.bind.annotation.XmlID;
025: import javax.xml.bind.annotation.XmlRootElement;
026: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
027: import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
028: import java.util.List;
029: import java.util.ArrayList;
030: import java.util.Collections;
031: import java.util.Collection;
032: import java.util.Map;
033:
034: @XmlRootElement(name="application-client")
035: @XmlAccessorType(XmlAccessType.FIELD)
036: @XmlType(name="application-clientType",propOrder={"descriptions","displayNames","icon","envEntry","ejbRef","serviceRef","resourceRef","resourceEnvRef","messageDestinationRef","persistenceUnitRef","postConstruct","preDestroy","callbackHandler","messageDestination"})
037: public class ApplicationClient implements JndiConsumer {
038:
039: @XmlTransient
040: protected TextMap description = new TextMap();
041: @XmlTransient
042: protected TextMap displayName = new TextMap();
043: @XmlElement(name="icon",required=true)
044: protected LocalCollection<Icon> icon = new LocalCollection<Icon>();
045:
046: @XmlElement(name="env-entry",required=true)
047: protected KeyedCollection<String, EnvEntry> envEntry;
048: @XmlElement(name="ejb-ref",required=true)
049: protected KeyedCollection<String, EjbRef> ejbRef;
050: @XmlElement(name="service-ref",required=true)
051: protected KeyedCollection<String, ServiceRef> serviceRef;
052: @XmlElement(name="resource-ref",required=true)
053: protected KeyedCollection<String, ResourceRef> resourceRef;
054: @XmlElement(name="resource-env-ref",required=true)
055: protected KeyedCollection<String, ResourceEnvRef> resourceEnvRef;
056: @XmlElement(name="message-destination-ref",required=true)
057: protected KeyedCollection<String, MessageDestinationRef> messageDestinationRef;
058: @XmlElement(name="persistence-unit-ref",required=true)
059: protected KeyedCollection<String, PersistenceUnitRef> persistenceUnitRef;
060: @XmlElement(name="post-construct",required=true)
061: protected List<LifecycleCallback> postConstruct;
062: @XmlElement(name="pre-destroy",required=true)
063: protected List<LifecycleCallback> preDestroy;
064: @XmlElement(name="callback-handler")
065: protected String callbackHandler;
066: @XmlElement(name="message-destination",required=true)
067: protected KeyedCollection<String, MessageDestination> messageDestination;
068:
069: @XmlAttribute
070: @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
071: @XmlID
072: protected String id;
073: @XmlAttribute(name="metadata-complete")
074: protected Boolean metadataComplete;
075: @XmlAttribute(required=true)
076: @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
077: protected String version;
078:
079: @XmlTransient
080: protected String mainClass;
081:
082: public ApplicationClient() {
083: }
084:
085: public String getJndiConsumerName() {
086: if (mainClass == null) {
087: return null;
088: }
089: return mainClass.replaceAll(".*\\.", "");
090: }
091:
092: @XmlElement(name="description",required=true)
093: public Text[] getDescriptions() {
094: return description.toArray();
095: }
096:
097: public void setDescriptions(Text[] text) {
098: description.set(text);
099: }
100:
101: public String getDescription() {
102: return description.get();
103: }
104:
105: @XmlElement(name="display-name",required=true)
106: public Text[] getDisplayNames() {
107: return displayName.toArray();
108: }
109:
110: public void setDisplayNames(Text[] text) {
111: displayName.set(text);
112: }
113:
114: public String getDisplayName() {
115: return displayName.get();
116: }
117:
118: public Collection<Icon> getIcons() {
119: if (icon == null) {
120: icon = new LocalCollection<Icon>();
121: }
122: return icon;
123: }
124:
125: public Map<String, Icon> getIconMap() {
126: if (icon == null) {
127: icon = new LocalCollection<Icon>();
128: }
129: return icon.toMap();
130: }
131:
132: public Icon getIcon() {
133: return icon.getLocal();
134: }
135:
136: public Collection<EnvEntry> getEnvEntry() {
137: if (envEntry == null) {
138: envEntry = new KeyedCollection<String, EnvEntry>();
139: }
140: return this .envEntry;
141: }
142:
143: public Map<String, EnvEntry> getEnvEntryMap() {
144: if (envEntry == null) {
145: envEntry = new KeyedCollection<String, EnvEntry>();
146: }
147: return this .envEntry.toMap();
148: }
149:
150: public Collection<EjbRef> getEjbRef() {
151: if (ejbRef == null) {
152: ejbRef = new KeyedCollection<String, EjbRef>();
153: }
154: return this .ejbRef;
155: }
156:
157: public Map<String, EjbRef> getEjbRefMap() {
158: if (ejbRef == null) {
159: ejbRef = new KeyedCollection<String, EjbRef>();
160: }
161: return this .ejbRef.toMap();
162: }
163:
164: public Collection<EjbLocalRef> getEjbLocalRef() {
165: return Collections.emptyList();
166: }
167:
168: public Map<String, EjbLocalRef> getEjbLocalRefMap() {
169: return Collections.emptyMap();
170: }
171:
172: public Collection<ServiceRef> getServiceRef() {
173: if (serviceRef == null) {
174: serviceRef = new KeyedCollection<String, ServiceRef>();
175: }
176: return this .serviceRef;
177: }
178:
179: public Map<String, ServiceRef> getServiceRefMap() {
180: if (serviceRef == null) {
181: serviceRef = new KeyedCollection<String, ServiceRef>();
182: }
183: return this .serviceRef.toMap();
184: }
185:
186: public Collection<ResourceRef> getResourceRef() {
187: if (resourceRef == null) {
188: resourceRef = new KeyedCollection<String, ResourceRef>();
189: }
190: return this .resourceRef;
191: }
192:
193: public Map<String, ResourceRef> getResourceRefMap() {
194: if (resourceRef == null) {
195: resourceRef = new KeyedCollection<String, ResourceRef>();
196: }
197: return this .resourceRef.toMap();
198: }
199:
200: public Collection<ResourceEnvRef> getResourceEnvRef() {
201: if (resourceEnvRef == null) {
202: resourceEnvRef = new KeyedCollection<String, ResourceEnvRef>();
203: }
204: return this .resourceEnvRef;
205: }
206:
207: public Map<String, ResourceEnvRef> getResourceEnvRefMap() {
208: if (resourceEnvRef == null) {
209: resourceEnvRef = new KeyedCollection<String, ResourceEnvRef>();
210: }
211: return this .resourceEnvRef.toMap();
212: }
213:
214: public Collection<MessageDestinationRef> getMessageDestinationRef() {
215: if (messageDestinationRef == null) {
216: messageDestinationRef = new KeyedCollection<String, MessageDestinationRef>();
217: }
218: return this .messageDestinationRef;
219: }
220:
221: public Map<String, MessageDestinationRef> getMessageDestinationRefMap() {
222: if (messageDestinationRef == null) {
223: messageDestinationRef = new KeyedCollection<String, MessageDestinationRef>();
224: }
225: return this .messageDestinationRef.toMap();
226: }
227:
228: public Collection<PersistenceContextRef> getPersistenceContextRef() {
229: return Collections.emptyList();
230: }
231:
232: public Map<String, PersistenceContextRef> getPersistenceContextRefMap() {
233: return Collections.emptyMap();
234: }
235:
236: public Collection<PersistenceUnitRef> getPersistenceUnitRef() {
237: if (persistenceUnitRef == null) {
238: persistenceUnitRef = new KeyedCollection<String, PersistenceUnitRef>();
239: }
240: return this .persistenceUnitRef;
241: }
242:
243: public Map<String, PersistenceUnitRef> getPersistenceUnitRefMap() {
244: if (persistenceUnitRef == null) {
245: persistenceUnitRef = new KeyedCollection<String, PersistenceUnitRef>();
246: }
247: return this .persistenceUnitRef.toMap();
248: }
249:
250: public List<LifecycleCallback> getPostConstruct() {
251: if (postConstruct == null) {
252: postConstruct = new ArrayList<LifecycleCallback>();
253: }
254: return this .postConstruct;
255: }
256:
257: public List<LifecycleCallback> getPreDestroy() {
258: if (preDestroy == null) {
259: preDestroy = new ArrayList<LifecycleCallback>();
260: }
261: return this .preDestroy;
262: }
263:
264: public void addPostConstruct(String method) {
265: assert mainClass != null : "Set the mainClass before calling this method";
266: getPostConstruct()
267: .add(new LifecycleCallback(mainClass, method));
268: }
269:
270: public void addPreDestroy(String method) {
271: assert mainClass != null : "Set the mainClass before calling this method";
272: getPreDestroy().add(new LifecycleCallback(mainClass, method));
273: }
274:
275: public String getCallbackHandler() {
276: return callbackHandler;
277: }
278:
279: public void setCallbackHandler(String callbackHandler) {
280: this .callbackHandler = callbackHandler;
281: }
282:
283: public Collection<MessageDestination> getMessageDestination() {
284: if (messageDestination == null) {
285: messageDestination = new KeyedCollection<String, MessageDestination>();
286: }
287: return this .messageDestination;
288: }
289:
290: public String getId() {
291: return id;
292: }
293:
294: public void setId(String value) {
295: this .id = value;
296: }
297:
298: public Boolean isMetadataComplete() {
299: return metadataComplete != null && metadataComplete;
300: }
301:
302: public void setMetadataComplete(Boolean value) {
303: this .metadataComplete = value;
304: }
305:
306: public String getVersion() {
307: if (version == null) {
308: return "5";
309: } else {
310: return version;
311: }
312: }
313:
314: public void setVersion(String value) {
315: this .version = value;
316: }
317:
318: public String getMainClass() {
319: return mainClass;
320: }
321:
322: public void setMainClass(String mainClass) {
323: this.mainClass = mainClass;
324: }
325:
326: }
|