All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.jagg.model.ChainedMethodCall Maven / Gradle / Ivy

Go to download

jAgg is a Java 5.0 API that supports “group by” operations on Lists of Java objects: aggregate operations such as count, sum, max, min, avg, and many more. It also allows custom aggregate operations.

The newest version!
package net.sf.jagg.model;

import java.lang.reflect.InvocationTargetException;

import net.sf.jagg.exception.PropertyAccessException;

/**
 * A ChainedMethodCall represents a chain of method calls given by
 * a single property string.
 *
 * @author Randy Gettman
 * @since 0.8.0
 */
public abstract class ChainedMethodCall
{
   private ChainedMethodCall myNext;

   /**
    * Sets the next ChainedMethodCall in the chain, if any.
    * @param next The next ChainedMethodCall in the chain, if any.
    */
   public void setNext(ChainedMethodCall next)
   {
      myNext = next;
   }

   /**
    * Invokes this ChainedMethodCall.  If there is a next
    * ChainedMethodCall, then invoke it also.
    * @param object The object on which to invoke this method.
    * @return The return of all calls in the chain.
    * @throws PropertyAccessException If there was a problem invoking the
    *    method.
    */
   public Object invoke(Object object) throws PropertyAccessException
   {
      try
      {
         Object result = invokeMethod(object);
         if (myNext != null)
         {
            result = myNext.invoke(result);
         }
         return result;
      }
      catch (IllegalAccessException e)
      {
         throw new PropertyAccessException("IllegalAccessException caught!", e);
      }
      catch (InvocationTargetException e)
      {
         throw new PropertyAccessException("InvocationTargetException caught!", e);
      }
   }

   /**
    * Invokes only this ChainedMethodCall.  Invoking other methods
    * in the chain is handled by the invoke method.
    * @param object The object on which to invoke this method.
    * @return The result of invoking this method.
    * @see #invoke
    * @throws IllegalAccessException If the Method is inaccessible
    *    (private, etc.)
    * @throws InvocationTargetException If the Method throws an
    *    Exception during execution.
    */
   protected abstract Object invokeMethod(Object object) throws IllegalAccessException, InvocationTargetException;

   /**
    * Returns the return type of the ChainedMethodCall.
    * @return A Class object representing the return type of the
    *    whole chained call.
    */
   public Class getChainedReturnType()
   {
      if (myNext != null)
         return myNext.getChainedReturnType();
      return getReturnType();
   }

   /**
    * Returns the return type of this particularChainedMethodCall.
    * The return type of the entire chained call is handled by the
    * getChainedReturnType method.
    * @return A Class object representing the return type of this
    *    particular method, not the entire chained call.
    */
   public abstract Class getReturnType();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy