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.Arrays;
030:
031: /**
032: * The interceptor-bindingType element describes the binding of
033: * interceptor classes to beans within the ejb-jar.
034: * It consists of :
035: * <p/>
036: * - An optional description.
037: * - The name of an ejb within the ejb-jar or the wildcard value "*",
038: * which is used to define interceptors that are bound to all
039: * beans in the ejb-jar.
040: * - A list of interceptor classes that are bound to the contents of
041: * the ejb-name element or a specification of the total ordering
042: * over the interceptors defined for the given level and above.
043: * - An optional exclude-default-interceptors element. If set to true,
044: * specifies that default interceptors are not to be applied to
045: * a bean-class and/or business method.
046: * - An optional exclude-class-interceptors element. If set to true,
047: * specifies that class interceptors are not to be applied to
048: * a business method.
049: * - An optional set of method elements for describing the name/params
050: * of a method-level interceptor.
051: * <p/>
052: * Interceptors bound to all classes using the wildcard syntax
053: * "*" are default interceptors for the components in the ejb-jar.
054: * In addition, interceptors may be bound at the level of the bean
055: * class (class-level interceptors) or business methods (method-level
056: * interceptors ).
057: * <p/>
058: * The binding of interceptors to classes is additive. If interceptors
059: * are bound at the class-level and/or default-level as well as the
060: * method-level, both class-level and/or default-level as well as
061: * method-level will apply.
062: * <p/>
063: * There are four possible styles of the interceptor element syntax :
064: * <p/>
065: * 1.
066: <interceptor-binding>
067: <ejb-name>*</ejb-name>
068: <interceptor-class>INTERCEPTOR</interceptor-class>
069: </interceptor-binding>
070: * <p/>
071: * Specifying the ejb-name as the wildcard value "*" designates
072: * default interceptors (interceptors that apply to all session and
073: * message-driven beans contained in the ejb-jar).
074: * <p/>
075: * 2.
076: <interceptor-binding>
077: <ejb-name>EJBNAME</ejb-name>
078: <interceptor-class>INTERCEPTOR</interceptor-class>
079: </interceptor-binding>
080:
081: * <p/>
082: * This style is used to refer to interceptors associated with the
083: * specified enterprise bean(class-level interceptors).
084: * <p/>
085: * 3.
086: <interceptor-binding>
087: <ejb-name>EJBNAME</ejb-name>
088: <interceptor-class>INTERCEPTOR</interceptor-class>
089: <method>
090: <method-name>METHOD</method-name>
091: </method>
092: </interceptor-binding>
093:
094: * <p/>
095: * This style is used to associate a method-level interceptor with
096: * the specified enterprise bean. If there are multiple methods
097: * with the same overloaded name, the element of this style refers
098: * to all the methods with the overloaded name. Method-level
099: * interceptors can only be associated with business methods of the
100: * bean class. Note that the wildcard value "*" cannot be used
101: * to specify method-level interceptors.
102: * <p/>
103: * 4.
104: <interceptor-binding>
105: <ejb-name>EJBNAME</ejb-name>
106: <interceptor-class>INTERCEPTOR</interceptor-class>
107: <method>
108: <method-name>METHOD</method-name>
109: <method-params>
110: <method-param>PARAM-1</method-param>
111: <method-param>PARAM-2</method-param>
112: ...
113: <method-param>PARAM-N</method-param>
114: </method-params>
115: </method>
116: </interceptor-binding>
117: * <p/>
118: * ...
119: * This style is used to associate a method-level interceptor with
120: * the specified method of the specified enterprise bean. This
121: * style is used to refer to a single method within a set of methods
122: * with an overloaded name. The values PARAM-1 through PARAM-N
123: * are the fully-qualified Java types of the method's input parameters
124: * (if the method has no input arguments, the method-params element
125: * contains no method-param elements). Arrays are specified by the
126: * array element's type, followed by one or more pair of square
127: * brackets (e.g. int[][]).
128: */
129: @XmlAccessorType(XmlAccessType.FIELD)
130: @XmlType(name="interceptor-bindingType",propOrder={"description","ejbName","interceptorClass","interceptorOrder","excludeDefaultInterceptors","excludeClassInterceptors","method"})
131: public class InterceptorBinding {
132:
133: @XmlElement(required=true)
134: protected List<Text> description;
135: @XmlElement(name="ejb-name",required=true)
136: protected String ejbName;
137: @XmlElement(name="interceptor-class",required=true)
138: protected List<String> interceptorClass;
139: @XmlElement(name="interceptor-order")
140: protected InterceptorOrder interceptorOrder;
141: @XmlElement(name="exclude-default-interceptors")
142: protected boolean excludeDefaultInterceptors;
143: @XmlElement(name="exclude-class-interceptors")
144: protected boolean excludeClassInterceptors;
145: protected NamedMethod method;
146: @XmlAttribute
147: @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
148: @XmlID
149: protected String id;
150:
151: public InterceptorBinding() {
152: }
153:
154: public InterceptorBinding(EnterpriseBean bean,
155: Interceptor... interceptors) {
156: this (bean.getEjbName(), interceptors);
157: }
158:
159: public InterceptorBinding(String ejbName,
160: Interceptor... interceptors) {
161: this .ejbName = ejbName;
162: List<String> interceptorClasses = this .getInterceptorClass();
163: for (Interceptor interceptor : interceptors) {
164: interceptorClasses.add(interceptor.getInterceptorClass());
165: }
166: }
167:
168: public InterceptorBinding(String ejbName,
169: String... interceptorClasses) {
170: this .ejbName = ejbName;
171: this .getInterceptorClass().addAll(
172: Arrays.asList(interceptorClasses));
173: }
174:
175: public InterceptorBinding(String ejbName) {
176: this .ejbName = ejbName;
177: }
178:
179: public List<Text> getDescription() {
180: if (description == null) {
181: description = new ArrayList<Text>();
182: }
183: return this .description;
184: }
185:
186: public String getEjbName() {
187: return ejbName;
188: }
189:
190: public void setEjbName(String value) {
191: this .ejbName = value;
192: }
193:
194: public List<String> getInterceptorClass() {
195: if (interceptorClass == null) {
196: interceptorClass = new ArrayList<String>();
197: }
198: return this .interceptorClass;
199: }
200:
201: public InterceptorOrder getInterceptorOrder() {
202: return interceptorOrder;
203: }
204:
205: public InterceptorOrder setInterceptorOrder(InterceptorOrder value) {
206: this .interceptorOrder = value;
207: return value;
208: }
209:
210: public boolean getExcludeDefaultInterceptors() {
211: return excludeDefaultInterceptors;
212: }
213:
214: public void setExcludeDefaultInterceptors(boolean value) {
215: this .excludeDefaultInterceptors = value;
216: }
217:
218: public boolean getExcludeClassInterceptors() {
219: return excludeClassInterceptors;
220: }
221:
222: public void setExcludeClassInterceptors(boolean value) {
223: this .excludeClassInterceptors = value;
224: }
225:
226: public NamedMethod getMethod() {
227: return method;
228: }
229:
230: public void setMethod(NamedMethod value) {
231: this .method = value;
232: }
233:
234: public String getId() {
235: return id;
236: }
237:
238: public void setId(String value) {
239: this.id = value;
240: }
241:
242: }
|