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.test.interceptor;
017:
018: import javax.annotation.PostConstruct;
019: import javax.annotation.PreDestroy;
020: import javax.annotation.Resource;
021: import javax.ejb.PostActivate;
022: import javax.ejb.PrePassivate;
023: import javax.ejb.SessionContext;
024: import javax.interceptor.AroundInvoke;
025: import javax.interceptor.InvocationContext;
026:
027: /**
028: * @author <a href="mailto:goyathlay.geronimo@gmail.com">Prasad Kashyap</a>
029: *
030: * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 $
031: */
032: public class SuperClassInterceptor {
033:
034: @Resource
035: SessionContext sessionContext;
036:
037: /**
038: *
039: */
040: public SuperClassInterceptor() {
041: super ();
042: }
043:
044: /**
045: * The interceptor method.
046: * This should intercept all business methods in this bean class
047: * except those annotated with <code>@ExcludeClassInterceptors</code>
048: *
049: * @param ctx - InvocationContext
050: *
051: * @return - the result of the next method invoked. If a method returns void, proceed returns null.
052: * For lifecycle callback interceptor methods, if there is no callback method defined on the bean class,
053: * the invocation of proceed in the last interceptor method in the chain is a no-op, and null is returned.
054: * If there is more than one such interceptor method, the invocation of proceed causes the container to execute those methods in order.
055: *
056: * @throws runtime exceptions or application exceptions that are allowed in the throws clause of the business method.
057: */
058: @SuppressWarnings("unchecked")
059: @AroundInvoke
060: public Object super ClassInterceptor(InvocationContext ctx)
061: throws Exception {
062: Interceptor.profile(ctx, "superClassInterceptor");
063: return ctx.proceed();
064: }
065:
066: /**
067: * The interceptor method.
068: * This should intercept postConstruct of the bean
069: *
070: * @param ctx - InvocationContext
071: *
072: * @throws runtime exceptions.
073: */
074: @PostConstruct
075: public void super ClassInterceptorPostConstruct(InvocationContext ctx)
076: throws Exception {
077: /*if (sessionContext != null) {
078: System.out.println(sessionContext.lookup("java:comp/env"));
079: }
080: else {
081: System.out.println("SessionContext is null");
082: }
083: */
084: Interceptor.profile(ctx, "superClassInterceptorPostConstruct");
085: ctx.proceed();
086: return;
087: }
088:
089: /**
090: * The interceptor method.
091: * This should intercept postActivate of the bean
092: *
093: * @param ctx - InvocationContext
094: *
095: * @throws runtime exceptions.
096: */
097: @PostActivate
098: public void super ClassInterceptorPostActivate(InvocationContext ctx)
099: throws Exception {
100: Interceptor.profile(ctx, "superClassInterceptorPostActivate");
101: ctx.proceed();
102: return;
103: }
104:
105: /**
106: * The interceptor method.
107: * This should intercept prePassivate of the bean.
108: *
109: * @param ctx - InvocationContext
110: *
111: * @throws runtime exceptions.
112: */
113: @PrePassivate
114: public void super ClassInterceptorPrePassivate(InvocationContext ctx)
115: throws Exception {
116: Interceptor.profile(ctx, "superClassInterceptorPrePassivate");
117: ctx.proceed();
118: return;
119: }
120:
121: /**
122: * The interceptor method.
123: * This should intercept preDestroy of the bean.
124: *
125: * @param ctx - InvocationContext
126: *
127: * @throws runtime exceptions.
128: */
129: @PreDestroy
130: public void super ClassInterceptorPreDestroy(InvocationContext ctx)
131: throws Exception {
132: Interceptor.profile(ctx, "superClassInterceptorPreDestroy");
133: ctx.proceed();
134: return;
135: }
136:
137: }
|