001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb.plugins;
023:
024: import org.jboss.ejb.Container;
025: import org.jboss.ejb.Interceptor;
026: import org.jboss.invocation.Invocation;
027: import org.jboss.logging.Logger;
028:
029: import java.lang.reflect.Method;
030:
031: /**
032: * An abstract base class for container interceptors.
033: *
034: * @author <a href="mailto:rickard.oberg@telkel.com">Rickard �berg</a>
035: * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
036: * @version $Revision: 57209 $
037: */
038: public abstract class AbstractInterceptor implements Interceptor {
039: // Constants -----------------------------------------------------
040:
041: // Attributes ----------------------------------------------------
042:
043: /** The next interceptor in the chain. */
044: protected Interceptor nextInterceptor;
045: /** Logging instance */
046: protected Logger log = Logger.getLogger(this .getClass());
047: /** The container the interceptor is associated with */
048: protected Container container;
049:
050: // Static --------------------------------------------------------
051:
052: // Constructors --------------------------------------------------
053:
054: // Public --------------------------------------------------------
055:
056: // Interceptor implementation ------------------------------------
057:
058: public void setContainer(Container container) {
059: this .container = container;
060: }
061:
062: public Container getContainer() {
063: return container;
064: }
065:
066: public void setNext(final Interceptor interceptor) {
067: // assert interceptor != null
068: nextInterceptor = interceptor;
069: }
070:
071: public Interceptor getNext() {
072: return nextInterceptor;
073: }
074:
075: public void create() throws Exception {
076: // empty
077: }
078:
079: public void start() throws Exception {
080: // empty
081: }
082:
083: public void stop() {
084: // empty
085: }
086:
087: public void destroy() {
088: // empty
089: }
090:
091: public Object invokeHome(final Invocation mi) throws Exception {
092: // assert mi != null;
093: return getNext().invokeHome(mi);
094: }
095:
096: public Object invoke(final Invocation mi) throws Exception {
097: // assert mi != null;
098: return getNext().invoke(mi);
099: }
100:
101: /**
102: See if the given exception e is compatible with an exception declared
103: as thrown by the invocation method.
104:
105: @param invocation - the current invocation
106: @param e - the exception thrown by the invocation
107: @return true if e is a declared exception, false otherwise
108: */
109: public boolean isAppException(Invocation invocation, Throwable e) {
110: Method m = invocation.getMethod();
111: Class[] exceptions = m.getExceptionTypes();
112: boolean isAppException = false;
113: for (int n = 0; isAppException == false
114: && n < exceptions.length; n++) {
115: Class exType = exceptions[n];
116: isAppException = exType.isInstance(e);
117: }
118: return isAppException;
119: }
120:
121: // Protected -----------------------------------------------------
122: }
|