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.adapters.CollapsedStringAdapter;
026: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
027: import java.util.ArrayList;
028: import java.util.List;
029: import java.util.Collection;
030: import java.util.Map;
031:
032: /**
033: * The interceptorType element declares information about a single
034: * interceptor class. It consists of :
035: * <p/>
036: * - An optional description.
037: * - The fully-qualified name of the interceptor class.
038: * - An optional list of around invoke methods declared on the
039: * interceptor class and/or its super-classes.
040: * - An optional list environment dependencies for the interceptor
041: * class and/or its super-classes.
042: * - An optional list of post-activate methods declared on the
043: * interceptor class and/or its super-classes.
044: * - An optional list of pre-passivate methods declared on the
045: * interceptor class and/or its super-classes.
046: */
047: @XmlAccessorType(XmlAccessType.FIELD)
048: @XmlType(name="interceptorType",propOrder={"description","interceptorClass","aroundInvoke","envEntry","ejbRef","ejbLocalRef","serviceRef","resourceRef","resourceEnvRef","messageDestinationRef","persistenceContextRef","persistenceUnitRef","postConstruct","preDestroy","postActivate","prePassivate"})
049: public class Interceptor implements JndiConsumer, Session {
050:
051: @XmlElement(required=true)
052: protected List<Text> description;
053: @XmlElement(name="interceptor-class",required=true)
054: protected String interceptorClass;
055: @XmlElement(name="around-invoke",required=true)
056: protected List<AroundInvoke> aroundInvoke;
057: @XmlElement(name="env-entry",required=true)
058: protected KeyedCollection<String, EnvEntry> envEntry;
059: @XmlElement(name="ejb-ref",required=true)
060: protected KeyedCollection<String, EjbRef> ejbRef;
061: @XmlElement(name="ejb-local-ref",required=true)
062: protected KeyedCollection<String, EjbLocalRef> ejbLocalRef;
063: @XmlElement(name="service-ref",required=true)
064: protected KeyedCollection<String, ServiceRef> serviceRef;
065: @XmlElement(name="resource-ref",required=true)
066: protected KeyedCollection<String, ResourceRef> resourceRef;
067: @XmlElement(name="resource-env-ref",required=true)
068: protected KeyedCollection<String, ResourceEnvRef> resourceEnvRef;
069: @XmlElement(name="message-destination-ref",required=true)
070: protected KeyedCollection<String, MessageDestinationRef> messageDestinationRef;
071: @XmlElement(name="persistence-context-ref",required=true)
072: protected KeyedCollection<String, PersistenceContextRef> persistenceContextRef;
073: @XmlElement(name="persistence-unit-ref",required=true)
074: protected KeyedCollection<String, PersistenceUnitRef> persistenceUnitRef;
075: @XmlElement(name="post-construct",required=true)
076: protected List<LifecycleCallback> postConstruct;
077: @XmlElement(name="pre-destroy",required=true)
078: protected List<LifecycleCallback> preDestroy;
079: @XmlElement(name="post-activate",required=true)
080: protected List<LifecycleCallback> postActivate;
081: @XmlElement(name="pre-passivate",required=true)
082: protected List<LifecycleCallback> prePassivate;
083: @XmlAttribute
084: @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
085: @XmlID
086: protected String id;
087:
088: public Interceptor() {
089: }
090:
091: public Interceptor(Class<?> interceptorClass) {
092: this .interceptorClass = interceptorClass.getName();
093: }
094:
095: public Interceptor(String interceptorClass) {
096: this .interceptorClass = interceptorClass;
097: }
098:
099: public String getJndiConsumerName() {
100: if (interceptorClass == null) {
101: return null;
102: }
103: return interceptorClass.replaceAll(".*\\.", "");
104: }
105:
106: public List<Text> getDescription() {
107: if (description == null) {
108: description = new ArrayList<Text>();
109: }
110: return this .description;
111: }
112:
113: public String getInterceptorClass() {
114: return interceptorClass;
115: }
116:
117: public void setInterceptorClass(String value) {
118: this .interceptorClass = value;
119: }
120:
121: public List<AroundInvoke> getAroundInvoke() {
122: if (aroundInvoke == null) {
123: aroundInvoke = new ArrayList<AroundInvoke>();
124: }
125: return this .aroundInvoke;
126: }
127:
128: public void addAroundInvoke(String method) {
129: assert interceptorClass != null : "Set the interceptorClass before calling this method";
130: getAroundInvoke().add(
131: new AroundInvoke(interceptorClass, method));
132: }
133:
134: public Collection<EnvEntry> getEnvEntry() {
135: if (envEntry == null) {
136: envEntry = new KeyedCollection<String, EnvEntry>();
137: }
138: return this .envEntry;
139: }
140:
141: public Map<String, EnvEntry> getEnvEntryMap() {
142: if (envEntry == null) {
143: envEntry = new KeyedCollection<String, EnvEntry>();
144: }
145: return this .envEntry.toMap();
146: }
147:
148: public Collection<EjbRef> getEjbRef() {
149: if (ejbRef == null) {
150: ejbRef = new KeyedCollection<String, EjbRef>();
151: }
152: return this .ejbRef;
153: }
154:
155: public Map<String, EjbRef> getEjbRefMap() {
156: if (ejbRef == null) {
157: ejbRef = new KeyedCollection<String, EjbRef>();
158: }
159: return this .ejbRef.toMap();
160: }
161:
162: public Collection<EjbLocalRef> getEjbLocalRef() {
163: if (ejbLocalRef == null) {
164: ejbLocalRef = new KeyedCollection<String, EjbLocalRef>();
165: }
166: return this .ejbLocalRef;
167: }
168:
169: public Map<String, EjbLocalRef> getEjbLocalRefMap() {
170: if (ejbLocalRef == null) {
171: ejbLocalRef = new KeyedCollection<String, EjbLocalRef>();
172: }
173: return this .ejbLocalRef.toMap();
174: }
175:
176: public Collection<ServiceRef> getServiceRef() {
177: if (serviceRef == null) {
178: serviceRef = new KeyedCollection<String, ServiceRef>();
179: }
180: return this .serviceRef;
181: }
182:
183: public Map<String, ServiceRef> getServiceRefMap() {
184: if (serviceRef == null) {
185: serviceRef = new KeyedCollection<String, ServiceRef>();
186: }
187: return this .serviceRef.toMap();
188: }
189:
190: public Collection<ResourceRef> getResourceRef() {
191: if (resourceRef == null) {
192: resourceRef = new KeyedCollection<String, ResourceRef>();
193: }
194: return this .resourceRef;
195: }
196:
197: public Map<String, ResourceRef> getResourceRefMap() {
198: if (resourceRef == null) {
199: resourceRef = new KeyedCollection<String, ResourceRef>();
200: }
201: return this .resourceRef.toMap();
202: }
203:
204: public Collection<ResourceEnvRef> getResourceEnvRef() {
205: if (resourceEnvRef == null) {
206: resourceEnvRef = new KeyedCollection<String, ResourceEnvRef>();
207: }
208: return this .resourceEnvRef;
209: }
210:
211: public Map<String, ResourceEnvRef> getResourceEnvRefMap() {
212: if (resourceEnvRef == null) {
213: resourceEnvRef = new KeyedCollection<String, ResourceEnvRef>();
214: }
215: return this .resourceEnvRef.toMap();
216: }
217:
218: public Collection<MessageDestinationRef> getMessageDestinationRef() {
219: if (messageDestinationRef == null) {
220: messageDestinationRef = new KeyedCollection<String, MessageDestinationRef>();
221: }
222: return this .messageDestinationRef;
223: }
224:
225: public Map<String, MessageDestinationRef> getMessageDestinationRefMap() {
226: if (messageDestinationRef == null) {
227: messageDestinationRef = new KeyedCollection<String, MessageDestinationRef>();
228: }
229: return this .messageDestinationRef.toMap();
230: }
231:
232: public Collection<PersistenceContextRef> getPersistenceContextRef() {
233: if (persistenceContextRef == null) {
234: persistenceContextRef = new KeyedCollection<String, PersistenceContextRef>();
235: }
236: return this .persistenceContextRef;
237: }
238:
239: public Map<String, PersistenceContextRef> getPersistenceContextRefMap() {
240: if (persistenceContextRef == null) {
241: persistenceContextRef = new KeyedCollection<String, PersistenceContextRef>();
242: }
243: return this .persistenceContextRef.toMap();
244: }
245:
246: public Collection<PersistenceUnitRef> getPersistenceUnitRef() {
247: if (persistenceUnitRef == null) {
248: persistenceUnitRef = new KeyedCollection<String, PersistenceUnitRef>();
249: }
250: return this .persistenceUnitRef;
251: }
252:
253: public Map<String, PersistenceUnitRef> getPersistenceUnitRefMap() {
254: if (persistenceUnitRef == null) {
255: persistenceUnitRef = new KeyedCollection<String, PersistenceUnitRef>();
256: }
257: return this .persistenceUnitRef.toMap();
258: }
259:
260: public List<LifecycleCallback> getPostConstruct() {
261: if (postConstruct == null) {
262: postConstruct = new ArrayList<LifecycleCallback>();
263: }
264: return this .postConstruct;
265: }
266:
267: public void addPostConstruct(String method) {
268: assert interceptorClass != null : "Set the interceptorClass before calling this method";
269: getPostConstruct().add(
270: new LifecycleCallback(interceptorClass, method));
271: }
272:
273: public List<LifecycleCallback> getPreDestroy() {
274: if (preDestroy == null) {
275: preDestroy = new ArrayList<LifecycleCallback>();
276: }
277: return this .preDestroy;
278: }
279:
280: public void addPreDestroy(String method) {
281: assert interceptorClass != null : "Set the interceptorClass before calling this method";
282: getPreDestroy().add(
283: new LifecycleCallback(interceptorClass, method));
284: }
285:
286: public List<LifecycleCallback> getPostActivate() {
287: if (postActivate == null) {
288: postActivate = new ArrayList<LifecycleCallback>();
289: }
290: return this .postActivate;
291: }
292:
293: public void addPostActivate(String method) {
294: assert interceptorClass != null : "Set the interceptorClass before calling this method";
295: getPostActivate().add(
296: new LifecycleCallback(interceptorClass, method));
297: }
298:
299: public List<LifecycleCallback> getPrePassivate() {
300: if (prePassivate == null) {
301: prePassivate = new ArrayList<LifecycleCallback>();
302: }
303: return this .prePassivate;
304: }
305:
306: public void addPrePassivate(String method) {
307: assert interceptorClass != null : "Set the interceptorClass before calling this method";
308: getPrePassivate().add(
309: new LifecycleCallback(interceptorClass, method));
310: }
311:
312: public List<InitMethod> getInitMethod() {
313: return new ArrayList<InitMethod>();
314: }
315:
316: public List<RemoveMethod> getRemoveMethod() {
317: return new ArrayList<RemoveMethod>();
318: }
319:
320: public String getId() {
321: return id;
322: }
323:
324: public void setId(String value) {
325: this.id = value;
326: }
327:
328: }
|