Save This Page
Home » jboss-5.0.0.CR1-src » org » jboss » deployment » [javadoc | source]
    1   /*
    2    * JBoss, Home of Professional Open Source
    3    * Copyright 2005, JBoss Inc., and individual contributors as indicated
    4    * by the @authors tag. See the copyright.txt in the distribution for a
    5    * full listing of individual contributors.
    6    *
    7    * This is free software; you can redistribute it and/or modify it
    8    * under the terms of the GNU Lesser General Public License as
    9    * published by the Free Software Foundation; either version 2.1 of
   10    * the License, or (at your option) any later version.
   11    *
   12    * This software is distributed in the hope that it will be useful,
   13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   15    * Lesser General Public License for more details.
   16    *
   17    * You should have received a copy of the GNU Lesser General Public
   18    * License along with this software; if not, write to the Free
   19    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   20    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   21    */
   22   package org.jboss.deployment;
   23   
   24   import org.jboss.mx.interceptor.AbstractInterceptor;
   25   import org.jboss.mx.interceptor.Interceptor;
   26   import org.jboss.mx.server.Invocation;
   27   
   28   /**
   29    * Base class for SubDeployer interceptors.
   30    * 
   31    * Override one or more of the init(), create(), start(), stop(), destroy()
   32    * methods to add behaviour. Don't forget to call invokeNext() inside
   33    * your implementation, if you want the call to be continued.
   34    *
   35    * @author  <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
   36    * @version $Revision: 57108 $   
   37    */
   38   public abstract class SubDeployerInterceptor extends AbstractInterceptor
   39   {
   40      // Constructors --------------------------------------------------
   41      
   42      /**
   43       * Default CTOR
   44       */
   45      public SubDeployerInterceptor()
   46      {
   47         super();
   48      }
   49      
   50      /**
   51       * CTOR
   52       * 
   53       * @param name - the name to use for this interceptor
   54       */
   55      public SubDeployerInterceptor(String name)
   56      {
   57         // invoker is unknown
   58         super(name);
   59      }
   60      
   61      // Interceptor implementation ------------------------------------   
   62      
   63      /**
   64       * This invoke method checks for invocations of interest, .i.e.
   65       * init(), create(), start(), stop(), destroy() operation calls
   66       * with a single DeploymentInfo argument and wraps the invocation
   67       * with calls to corresponding init(), create(), etc. methods.
   68       */
   69      public Object invoke(Invocation invocation) throws Throwable
   70      {
   71         String type = invocation.getType();
   72         
   73         // make sure this is an operation invocation
   74         if (type.equals(Invocation.OP_INVOKE))
   75         {
   76            Object args[] = invocation.getArgs();
   77            Object retn = invocation.getReturnTypeClass();
   78            
   79            // make sure the signature matches -> void <methodName>(DeploymentInfo di)
   80            if ((args.length == 1) && (args[0] instanceof DeploymentInfo) && (retn == null))
   81            {         
   82               String method = invocation.getName();
   83               DeploymentInfo di = (DeploymentInfo)args[0];
   84               
   85               if (method.equals("init"))
   86               {
   87                  return init(invocation, di);
   88               }
   89               else if (method.equals("create"))
   90               {
   91                  return create(invocation, di);
   92               }
   93               else if (method.equals("start"))
   94               {
   95                  return start(invocation, di);
   96               }
   97               else if (method.equals("stop"))
   98               {
   99                  return stop(invocation, di);
  100               }
  101               else if (method.equals("destroy"))
  102               {
  103                  return destroy(invocation, di);
  104               }
  105            }
  106         }
  107         // if we reached this point invocation is of no interest
  108         // to SubDeployerInterceptor so simply forward it
  109         return invokeNext(invocation);
  110      }
  111      
  112      // Protected -----------------------------------------------------
  113   
  114      /**
  115       * Use this to forward the call
  116       */
  117      protected Object invokeNext(Invocation invocation) throws Throwable
  118      {
  119         // call the next in the interceptor chain,
  120         // if nobody follows dispatch the call
  121         Interceptor next = invocation.nextInterceptor();
  122         if (next != null)
  123         {
  124            return next.invoke(invocation);
  125         }
  126         else
  127         {
  128            return invocation.dispatch();
  129         }
  130      }
  131      
  132      // Protected overrides -------------------------------------------
  133      
  134      // Override the following methods to add behaviour. Remember
  135      // to call invokeNext() if you want the call to proceed.
  136      
  137      protected Object init(Invocation invocation, DeploymentInfo di) throws Throwable
  138      {
  139         return invokeNext(invocation);
  140      }
  141      
  142      protected Object create(Invocation invocation, DeploymentInfo di) throws Throwable
  143      {
  144         return invokeNext(invocation);
  145      }
  146      
  147      protected Object start(Invocation invocation, DeploymentInfo di) throws Throwable
  148      {
  149         return invokeNext(invocation);
  150      }
  151      
  152      protected Object stop(Invocation invocation, DeploymentInfo di) throws Throwable
  153      {
  154         return invokeNext(invocation);
  155      }
  156      
  157      protected Object destroy(Invocation invocation, DeploymentInfo di) throws Throwable
  158      {
  159         return invokeNext(invocation);
  160      }
  161   
  162   }

Save This Page
Home » jboss-5.0.0.CR1-src » org » jboss » deployment » [javadoc | source]