geirm       01/05/20 12:48:56

  Added:       src/java/org/apache/velocity/app/event EventCartridge.java
                        EventHandler.java MethodExceptionEventHandler.java
                        NullSetEventHandler.java
                        ReferenceInsertionEventHandler.java
  Log:
  Migration from the o.a.v.context package (where it didn't belong, but was
  there bacause I didn't have to think about context and protection issues)
  to o.a.v.app.event
  
  Revision  Changes    Path
  1.1                  
jakarta-velocity/src/java/org/apache/velocity/app/event/EventCartridge.java
  
  Index: EventCartridge.java
  ===================================================================
  package org.apache.velocity.app.event;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.velocity.context.InternalEventContext;
  import org.apache.velocity.context.Context;
  
  import java.util.ArrayList;
  
  /**
   *  'Package' of event handlers...
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Geir Magnusson Jr.</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Jose Alberto Fernandez</a>
   * @version $Id: EventCartridge.java,v 1.1 2001/05/20 19:48:55 geirm Exp $
   */
  public class EventCartridge implements ReferenceInsertionEventHandler,
                                         NullSetEventHandler,
                                         MethodExceptionEventHandler
  {
      private ReferenceInsertionEventHandler rieh = null;
      private NullSetEventHandler nseh = null;
      private MethodExceptionEventHandler meeh = null;
  
      /**
       *  Adds an event handler(s) to the Cartridge.  This method
       *  will find all possible event handler interfaces supported
       *  by the passed in object.
       *
       *  @param ev object impementing a valid EventHandler-derived interface
       *  @return true if a supported interface, false otherwise or if null
       */
      public boolean addEventHandler( EventHandler ev )
      {
          if (ev == null)
          {
              return false;
          }
          
          boolean found = false;
  
          if ( ev instanceof ReferenceInsertionEventHandler)
          {
              rieh = (ReferenceInsertionEventHandler) ev;
              found = true;
          }
         
          if ( ev instanceof NullSetEventHandler )
          {
              nseh = (NullSetEventHandler) ev;
              found = true;
          }
  
          if ( ev instanceof MethodExceptionEventHandler )
          {
              meeh = (MethodExceptionEventHandler) ev;
              found = true;
          }
   
          return found;
      }
      
      /**
       *  Removes an event handler(s) from the Cartridge.  This method
       *  will find all possible event handler interfaces supported
       *  by the passed in object and remove them.
       *
       *  @param ev object impementing a valid EventHandler-derived interface
       *  @return true if a supported interface, false otherwise or if null
       */
      public boolean removeEventHandler(EventHandler ev)
      {
          if ( ev == null )
          {
              return false;
          }
  
          boolean found = false;
          
          if (ev == rieh) 
          {
              rieh = null;
              found = true;
          }
        
          if (ev == nseh) 
          {
              nseh = null;
              found = true;
          }
  
          if (ev == meeh) 
          {
              meeh = null;
              found = true;
          }
  
          return found;
      }
  
      /**
       *  Implementation of ReferenceInsertionEventHandler method
       *  <code>referenceInsert()</code>.
       *
       *  Called during Velocity merge before a reference value will
       *  be inserted into the output stream.
       *
       *  @param reference reference from template about to be inserted
       *  @param value  value about to be inserted (after toString() )
       *  @return Object on which toString() should be called for output.
       */
      public Object referenceInsert( String reference, Object value  )
      {
          if (rieh == null)
          {
              return value;
          }
  
          return rieh.referenceInsert( reference, value );
      }
  
      /**
       *  Implementation of NullSetEventHandler method
       *  <code>nullSetLogMessage()</code>.
       *
       *  Called during Velocity merge to determine if when
       *  a #set() results in a null assignment, a warning
       *  is logged.
       *
       *  @param reference reference from template about to be inserted
       *  @return true if to be logged, false otherwise
       */
      public boolean nullSetLogMessage( String reference )
      {
          if ( nseh == null)
          {
              return true;
          }
  
          return nseh.nullSetLogMessage( reference );
      }
      
      /**
       *  Implementation of MethodExceptionEventHandler  method
       *  <code>methodException()</code>.
       *
       *  Called during Velocity merge if a reference is null
       *
       *  @param claz  Class that is causing the exception
       *  @param method method called that causes the exception
       *  @param e Exception thrown by the method
       *  @return Object to return as method result
       *  @throws exception to be wrapped and propogated to app  
       */
      public Object methodException( Class claz, String method, Exception e )
          throws Exception
      {
          /*
           *  if we don't have a handler, just throw what we were handed
           */
          if (meeh == null)
          {
              throw e;
          }
  
          /*
           *  otherwise, call it..
           */
          return meeh.methodException( claz, method, e );
      }
      
      /**
       *  Attached the EventCartridge to the context
       *
       *  Final because not something one should mess with lightly :)
       *
       *  @param context context to attach to
       *  @return true if successful, false otherwise
       */
      public final boolean attachToContext( Context context )
      {
          if (  context instanceof InternalEventContext )
          {         
              InternalEventContext iec = (InternalEventContext) context;
  
              iec.attachEventCartridge( this );
  
              return true;
          }
          else
          {
              return false;
          }
      }
  }
  
  
  
  1.1                  
jakarta-velocity/src/java/org/apache/velocity/app/event/EventHandler.java
  
  Index: EventHandler.java
  ===================================================================
  package org.apache.velocity.app.event;
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /**
   *  Base interface for all event handlers
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Geir Magnusson Jr.</a>
   * @version $Id: EventHandler.java,v 1.1 2001/05/20 19:48:55 geirm Exp $
   */
  public interface  EventHandler
  {
  
  }
  
  
  
  1.1                  
jakarta-velocity/src/java/org/apache/velocity/app/event/MethodExceptionEventHandler.java
  
  Index: MethodExceptionEventHandler.java
  ===================================================================
  package org.apache.velocity.app.event;
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /**
   *  Called when a method throws an exception.  This gives the
   *  application a chance to deal with it and either
   *  return something nice, or throw.
   *
   *  Please return what you want rendered into the output stream.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Geir Magnusson Jr.</a>
   * @version $Id: MethodExceptionEventHandler.java,v 1.1 2001/05/20 19:48:56 geirm 
Exp $
   */
  public interface MethodExceptionEventHandler extends EventHandler
  {
      public Object methodException( Class claz, String method, Exception e )
           throws Exception;
  }
  
  
  
  1.1                  
jakarta-velocity/src/java/org/apache/velocity/app/event/NullSetEventHandler.java
  
  Index: NullSetEventHandler.java
  ===================================================================
  package org.apache.velocity.app.event;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /**
   *  Called when the RHS of a #set() is null
   *
   *  Please return what you want rendered into the output stream.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Geir Magnusson Jr.</a>
   * @version $Id: NullSetEventHandler.java,v 1.1 2001/05/20 19:48:56 geirm Exp $
   */
  public interface NullSetEventHandler extends EventHandler
  {
      public boolean nullSetLogMessage( String reference );
  }
  
  
  
  1.1                  
jakarta-velocity/src/java/org/apache/velocity/app/event/ReferenceInsertionEventHandler.java
  
  Index: ReferenceInsertionEventHandler.java
  ===================================================================
  package org.apache.velocity.app.event;
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /**
   *  Reference 'Stream insertion' event handler.  Called with object
   *  that will be inserted into stream via value.toString().
   *
   *  Please return an Object that will toString() nicely :)
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Geir Magnusson Jr.</a>
   * @version $Id: ReferenceInsertionEventHandler.java,v 1.1 2001/05/20 19:48:56 geirm 
Exp $
   */
  public interface  ReferenceInsertionEventHandler extends EventHandler
  {
      public Object referenceInsert( String reference, Object value  );
  }
  
  
  

Reply via email to