Examples of VelMethod


Examples of org.apache.commons.jexl.util.introspection.VelMethod

            // check if there is a size method on the object that returns an
            // integer
            // and if so, just use it
            Object[] params = new Object[0];
            Info velInfo = new Info("", 1, 1);
            VelMethod vm = Introspector.getUberspect().getMethod(val, "size", params, velInfo);
            if (vm != null && vm.getReturnType() == Integer.TYPE) {
                Integer result = (Integer) vm.invoke(val, params);
                return result.intValue();
            }
            throw new Exception("size() : unknown type : " + val.getClass());
        }
    }
View Full Code Here

Examples of org.apache.commons.jexl.util.introspection.VelMethod

        try {
            for (int i = 0; i < paramCount; i++) {
                params[i] = ((SimpleNode) jjtGetChild(i + 1)).value(jc);
            }

            VelMethod vm = Introspector.getUberspect().getMethod(obj, methodName, params, DUMMY);
            /*
             * DG: If we can't find an exact match, narrow the parameters and
             * try again!
             */
            if (vm == null) {

                // replace all numbers with the smallest type that will fit
                for (int i = 0; i < params.length; i++) {
                    Object param = params[i];
                    if (param instanceof Number) {
                        params[i] = narrow((Number) param);
                    }
                }
                vm = Introspector.getUberspect().getMethod(obj, methodName, params, DUMMY);
                if (vm == null) {
                    return null;
                }
            }

            return vm.invoke(obj, params);
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();

            if (t instanceof Exception) {
                throw (Exception) t;
View Full Code Here

Examples of org.apache.commons.jexl.util.introspection.VelMethod

        else {
          // check if there is a size method on the object that returns an integer
          // and if so, just use it
          Object[] params = new Object[0];
          Info velInfo = new Info("",1,1);
            VelMethod vm = Introspector.getUberspect().getMethod(val, "size", params, velInfo);
            if (vm != null && vm.getReturnType() == Integer.TYPE)
            {
              Integer result = (Integer)vm.invoke(val, params);
              return result.intValue();
            }
            else
            {
                throw new Exception("size() : unknown type : " + val.getClass());
View Full Code Here

Examples of org.apache.commons.jexl.util.introspection.VelMethod

            for (int i=0; i<paramCount; i++)
            {
                params[i] = ( (SimpleNode) jjtGetChild(i+1)).value(jc);
            }

            VelMethod vm = Introspector.getUberspect().getMethod(obj, methodName, params, DUMMY);

            if (vm == null)
                return null;

            return vm.invoke(obj, params);
        }
        catch(InvocationTargetException e)
        {
            Throwable t = e.getTargetException();
View Full Code Here

Examples of org.apache.flex.forks.velocity.util.introspection.VelMethod

         *  to be thread- as well as context-safe, we *must* do it now,
         *  at execution time.  There can be no in-node caching,
         *  but if we are careful, we can do it in the context.
         */

        VelMethod method = null;

        Object [] params = new Object[paramCount];

        try
        {
            /*
             *   check the cache
             */

            IntrospectionCacheData icd =  context.icacheGet( this );
            Class c = o.getClass();

            /*
             *  like ASTIdentifier, if we have cache information, and the
             *  Class of Object o is the same as that in the cache, we are
             *  safe.
             */

            if ( icd != null && icd.contextData == c )
            {
                /*
                 * sadly, we do need recalc the values of the args, as this can
                 * change from visit to visit
                 */

                for (int j = 0; j < paramCount; j++)
                    params[j] = jjtGetChild(j + 1).value(context);

                /*
                 * and get the method from the cache
                 */

                method = (VelMethod) icd.thingy;
            }
            else
            {
                /*
                 *  otherwise, do the introspection, and then
                 *  cache it
                 */

                for (int j = 0; j < paramCount; j++)
                    params[j] = jjtGetChild(j + 1).value(context);

                method = rsvc.getUberspect().getMethod(o, methodName, params, new Info("",1,1));

                if (method != null)
                {   
                    icd = new IntrospectionCacheData();
                    icd.contextData = c;
                    icd.thingy = method;
                    context.icachePut( this, icd );
                }
            }
            /*
             *  if we still haven't gotten the method, either we are calling
             *  a method that doesn't exist (which is fine...)  or I screwed
             *  it up.
             */

            if (method == null)
                return null;
        }
        catch( MethodInvocationException mie )
        {
            /*
             *  this can come from the doIntrospection(), as the arg values
             *  are evaluated to find the right method signature.  We just
             *  want to propogate it here, not do anything fancy
             */

            throw mie;
        }
        catch( Exception e )
        {
            /*
             *  can come from the doIntropection() also, from Introspector
             */

            rsvc.error("ASTMethod.execute() : exception from introspection : " + e);
            return null;
        }

        try
        {
            /*
             *  get the returned object.  It may be null, and that is
             *  valid for something declared with a void return type.
             *  Since the caller is expecting something to be returned,
             *  as long as things are peachy, we can return an empty
             *  String so ASTReference() correctly figures out that
             *  all is well.
             */

            Object obj = method.invoke(o, params);
           
            if (obj == null)
            {
                if( method.getReturnType() == Void.TYPE)
                     return new String("");
            }
           
            return obj;
        }
View Full Code Here

Examples of org.apache.velocity.util.introspection.VelMethod

         *  to be thread- as well as context-safe, we *must* do it now,
         *  at execution time.  There can be no in-node caching,
         *  but if we are careful, we can do it in the context.
         */

        VelMethod method = null;

        Object [] params = new Object[paramCount];

        try
        {
            /*
             * sadly, we do need recalc the values of the args, as this can
             * change from visit to visit
             */

            Class[] paramClasses = new Class[paramCount];
           
            for (int j = 0; j < paramCount; j++)
            {
                params[j] = jjtGetChild(j + 1).value(context);
               
                if (params[j] != null)
                {
                    paramClasses[j] = params[j].getClass();
                }
            }
               
            /*
             *   check the cache
             */
           
            MethodCacheKey mck = new MethodCacheKey(paramClasses);
            IntrospectionCacheData icd =  context.icacheGet( mck );
           
            /*
             *  like ASTIdentifier, if we have cache information, and the
             *  Class of Object o is the same as that in the cache, we are
             *  safe.
             */

            if ( icd != null && (o != null && icd.contextData == o.getClass()) )
            {

                /*
                 * get the method from the cache
                 */

                method = (VelMethod) icd.thingy;
            }
            else
            {
                /*
                 *  otherwise, do the introspection, and then
                 *  cache it
                 */

                for (int j = 0; j < paramCount; j++)
                    params[j] = jjtGetChild(j + 1).value(context);

                method = rsvc.getUberspect().getMethod(o, methodName, params, new Info(context.getCurrentTemplateName(), getLine(), getColumn()));

                if ((method != null) && (o != null))
                {   
                    icd = new IntrospectionCacheData();
                    icd.contextData = o.getClass();
                    icd.thingy = method;
                   
                    context.icachePut( mck, icd );
                }
            }
            /*
             *  if we still haven't gotten the method, either we are calling
             *  a method that doesn't exist (which is fine...)  or I screwed
             *  it up.
             */

            if (method == null)
                return null;
        }
        catch( MethodInvocationException mie )
        {
            /*
             *  this can come from the doIntrospection(), as the arg values
             *  are evaluated to find the right method signature.  We just
             *  want to propogate it here, not do anything fancy
             */

            throw mie;
        }
        /**
         * pass through application level runtime exceptions
         */
        catch( RuntimeException e )
        {
            throw e;
        }
        catch( Exception e )
        {
            /*
             *  can come from the doIntropection() also, from Introspector
             */

            log.error("ASTMethod.execute() : exception from introspection", e);
            return null;
        }

        try
        {
            /*
             *  get the returned object.  It may be null, and that is
             *  valid for something declared with a void return type.
             *  Since the caller is expecting something to be returned,
             *  as long as things are peachy, we can return an empty
             *  String so ASTReference() correctly figures out that
             *  all is well.
             */

            Object obj = method.invoke(o, params);
           
            if (obj == null)
            {
                if( method.getReturnType() == Void.TYPE)
                {
                    return "";
                }
            }
           
View Full Code Here

Examples of org.apache.velocity.util.introspection.VelMethod

         *  to be thread- as well as context-safe, we *must* do it now,
         *  at execution time.  There can be no in-node caching,
         *  but if we are careful, we can do it in the context.
         */

        VelMethod method = null;

        Object [] params = new Object[paramCount];

        try
        {
            /*
             * sadly, we do need recalc the values of the args, as this can
             * change from visit to visit
             */

            final Class[] paramClasses = paramCount > 0 ? new Class[paramCount] : ArrayUtils.EMPTY_CLASS_ARRAY;

            for (int j = 0; j < paramCount; j++)
            {
                params[j] = jjtGetChild(j + 1).value(context);

                if (params[j] != null)
                {
                    paramClasses[j] = params[j].getClass();
                }
            }

            /*
             *   check the cache
             */

            MethodCacheKey mck = new MethodCacheKey(methodName, paramClasses);
            IntrospectionCacheData icd =  context.icacheGet( mck );

            /*
             *  like ASTIdentifier, if we have cache information, and the
             *  Class of Object o is the same as that in the cache, we are
             *  safe.
             */

            if ( icd != null && (o != null && icd.contextData == o.getClass()) )
            {

                /*
                 * get the method from the cache
                 */

                method = (VelMethod) icd.thingy;
            }
            else
            {
                /*
                 *  otherwise, do the introspection, and then
                 *  cache it
                 */

                method = rsvc.getUberspect().getMethod(o, methodName, params, new Info(context.getCurrentTemplateName(), getLine(), getColumn()));

                if ((method != null) && (o != null))
                {
                    icd = new IntrospectionCacheData();
                    icd.contextData = o.getClass();
                    icd.thingy = method;

                    context.icachePut( mck, icd );
                }
            }

            /*
             *  if we still haven't gotten the method, either we are calling
             *  a method that doesn't exist (which is fine...)  or I screwed
             *  it up.
             */

            if (method == null)
            {
                return null;
            }
        }
        catch( MethodInvocationException mie )
        {
            /*
             *  this can come from the doIntrospection(), as the arg values
             *  are evaluated to find the right method signature.  We just
             *  want to propogate it here, not do anything fancy
             */

            throw mie;
        }
        /**
         * pass through application level runtime exceptions
         */
        catch( RuntimeException e )
        {
            throw e;
        }
        catch( Exception e )
        {
            /*
             *  can come from the doIntropection() also, from Introspector
             */

            log.error("ASTMethod.execute() : exception from introspection", e);
            return null;
        }

        try
        {
            /*
             *  get the returned object.  It may be null, and that is
             *  valid for something declared with a void return type.
             *  Since the caller is expecting something to be returned,
             *  as long as things are peachy, we can return an empty
             *  String so ASTReference() correctly figures out that
             *  all is well.
             */

            Object obj = method.invoke(o, params);

            if (obj == null)
            {
                if( method.getReturnType() == Void.TYPE)
                {
                    return "";
                }
            }

View Full Code Here

Examples of org.apache.velocity.util.introspection.VelMethod

public class UberspectTestImpl extends UberspectImpl
{

    public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i) throws Exception
    {
        VelMethod method = super.getMethod(obj, methodName, args, i);

        if (method == null)
        {
            if (obj == null)
                throw new UberspectTestException("Can't call method '" + methodName + "' on null object",i);
View Full Code Here

Examples of org.apache.velocity.util.introspection.VelMethod

         *  to be thread- as well as context-safe, we *must* do it now,
         *  at execution time.  There can be no in-node caching,
         *  but if we are careful, we can do it in the context.
         */

        VelMethod method = null;

        Object [] params = new Object[paramCount];

        try
        {
            /*
             * sadly, we do need recalc the values of the args, as this can
             * change from visit to visit
             */

            final Class[] paramClasses = paramCount > 0 ? new Class[paramCount] : ArrayUtils.EMPTY_CLASS_ARRAY;

            for (int j = 0; j < paramCount; j++)
            {
                params[j] = jjtGetChild(j + 1).value(context);

                if (params[j] != null)
                {
                    paramClasses[j] = params[j].getClass();
                }
            }

            /*
             *   check the cache
             */

            MethodCacheKey mck = new MethodCacheKey(methodName, paramClasses);
            IntrospectionCacheData icd =  context.icacheGet( mck );

            /*
             *  like ASTIdentifier, if we have cache information, and the
             *  Class of Object o is the same as that in the cache, we are
             *  safe.
             */

            if ( icd != null && (o != null && icd.contextData == o.getClass()) )
            {

                /*
                 * get the method from the cache
                 */

                method = (VelMethod) icd.thingy;
            }
            else
            {
                /*
                 *  otherwise, do the introspection, and then
                 *  cache it
                 */

                for (int j = 0; j < paramCount; j++)
                    params[j] = jjtGetChild(j + 1).value(context);

                method = rsvc.getUberspect().getMethod(o, methodName, params, new Info(context.getCurrentTemplateName(), getLine(), getColumn()));

                if ((method != null) && (o != null))
                {
                    icd = new IntrospectionCacheData();
                    icd.contextData = o.getClass();
                    icd.thingy = method;

                    context.icachePut( mck, icd );
                }
            }

            /*
             *  if we still haven't gotten the method, either we are calling
             *  a method that doesn't exist (which is fine...)  or I screwed
             *  it up.
             */

            if (method == null)
            {
                return null;
            }
        }
        catch( MethodInvocationException mie )
        {
            /*
             *  this can come from the doIntrospection(), as the arg values
             *  are evaluated to find the right method signature.  We just
             *  want to propogate it here, not do anything fancy
             */

            throw mie;
        }
        /**
         * pass through application level runtime exceptions
         */
        catch( RuntimeException e )
        {
            throw e;
        }
        catch( Exception e )
        {
            /*
             *  can come from the doIntropection() also, from Introspector
             */

            log.error("ASTMethod.execute() : exception from introspection", e);
            return null;
        }

        try
        {
            /*
             *  get the returned object.  It may be null, and that is
             *  valid for something declared with a void return type.
             *  Since the caller is expecting something to be returned,
             *  as long as things are peachy, we can return an empty
             *  String so ASTReference() correctly figures out that
             *  all is well.
             */

            Object obj = method.invoke(o, params);

            if (obj == null)
            {
                if( method.getReturnType() == Void.TYPE)
                {
                    return "";
                }
            }

View Full Code Here

Examples of org.apache.velocity.util.introspection.VelMethod

   */   
  public static VelMethod getMethod(String methodName, Object[] params,
                                    Class[] paramClasses, Object o, InternalContextAdapter context,
                                    SimpleNode node, boolean strictRef)
  {
    VelMethod method = null;
    try
    {
      /*
       * check the cache
       */
 
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.