Package org.apache.velocity.exception

Examples of org.apache.velocity.exception.MethodInvocationException


                    /**
                     * At this point we know that an attempt is about to be made
                     * to call a method or property on a null value.
                     */
                    String name = jjtGetChild(i).getFirstToken().image;
                    throw new MethodInvocationException("Attempted to access '" 
                        + name + "' on a null value", null, name, uberInfo.getTemplateName(),
                        jjtGetChild(i).getLine(), jjtGetChild(i).getColumn());
                 
                }
                previousResult = result;
View Full Code Here


            if (result == null)
            {
                if (strictRef)
                {
                    String name = jjtGetChild(i+1).getFirstToken().image;
                    throw new MethodInvocationException("Attempted to access '" 
                        + name + "' on a null value", null, name, uberInfo.getTemplateName(),
                        jjtGetChild(i+1).getLine(), jjtGetChild(i+1).getColumn());
                }           
             
                String msg = "reference set is not a valid reference at "
                    + Log.formatFileString(uberInfo);
                log.error(msg);

                return false;
            }
        }

        /*
         *  We support two ways of setting the value in a #set($ref.foo = $value ) :
         *  1) ref.setFoo( value )
         *  2) ref,put("foo", value ) to parallel the get() map introspection
         */

        try
        {
            VelPropertySet vs =
                    rsvc.getUberspect().getPropertySet(result, identifier,
                            value, uberInfo);

            if (vs == null)
            {
                if (strictRef)
                {
                    throw new MethodInvocationException("Object '" + result.getClass().getName() +
                       "' does not contain property '" + identifier + "'", null, identifier,
                       uberInfo.getTemplateName(), uberInfo.getLine(), uberInfo.getColumn());
                }
                else
                {
                  return false;
                }
            }

            vs.invoke(result, value);
        }
        catch(InvocationTargetException ite)
        {
            /*
             *  this is possible
             */

            throw  new MethodInvocationException(
                "ASTReference : Invocation of method '"
                + identifier + "' in  " + result.getClass()
                + " threw exception "
                + ite.getTargetException().toString(),
               ite.getTargetException(), identifier, context.getCurrentTemplateName(), this.getLine(), this.getColumn());
View Full Code Here

        {
          if (!context.containsKey(variable))
          {
              log.error("Variable $" + variable + " has not been set at "
                        + Log.formatFileString(uberInfo));
              throw new MethodInvocationException("Variable $" + variable +
                  " has not been set", null, identifier,
                  uberInfo.getTemplateName(), uberInfo.getLine(), uberInfo.getColumn());           
          }
        }
        return obj;       
View Full Code Here

        if (vg == null)
        {
            if (strictRef)
            {
                throw new MethodInvocationException("Object '" + o.getClass().getName() +             
                    "' does not contain property '" + identifier + "'", null, identifier,
                    uberInfo.getTemplateName(), uberInfo.getLine(), uberInfo.getColumn());
            }
            else
            {
                return null;
            }
        }

        /*
         *  now try and execute.  If we get a MIE, throw that
         *  as the app wants to get these.  If not, log and punt.
         */
        try
        {
            return vg.invoke(o);
        }
        catch(InvocationTargetException ite)
        {
            /*
             *  if we have an event cartridge, see if it wants to veto
             *  also, let non-Exception Throwables go...
             */

            Throwable t = ite.getTargetException();
            if (t instanceof Exception)
            {
                try
                {
                    return EventHandlerUtil.methodException(rsvc, context, o.getClass(), vg.getMethodName(),
                            (Exception) t);
                }

                /**
                 * If the event handler throws an exception, then wrap it
                 * in a MethodInvocationException.  Don't pass through RuntimeExceptions like other
                 * similar catchall code blocks.
                 */
                catch( Exception e )
                {
                    throw new MethodInvocationException(
                      "Invocation of method '" + vg.getMethodName() + "'"
                      + " in  " + o.getClass()
                      + " threw exception "
                      + ite.getTargetException().toString(),
                      ite.getTargetException(), vg.getMethodName(), context.getCurrentTemplateName(), this.getLine(), this.getColumn());
                }
            }
            else
            {
                /*
                 * no event cartridge to override. Just throw
                 */

                throw  new MethodInvocationException(
                "Invocation of method '" + vg.getMethodName() + "'"
                + " in  " + o.getClass()
                + " threw exception "
                + ite.getTargetException().toString(),
                ite.getTargetException(), vg.getMethodName(), context.getCurrentTemplateName(), this.getLine(), this.getColumn());
View Full Code Here

            Class param = paramClasses[i];
            plist.append(param == null ? "null" : param.getName());
            if (i < params.length - 1)
              plist.append(", ");
          }
          throw new MethodInvocationException("Object '"
              + o.getClass().getName() + "' does not contain method "
              + methodName + "(" + plist + ")", null, methodName, node
               .getTemplateName(), node.getLine(), node.getColumn());
        }
        else
View Full Code Here

                    Object obj = innerContext.get(ref.getRootString());
                    if (obj == null && ref.strictRef)
                    {
                        if (!innerContext.containsKey(ref.getRootString()))
                        {
                            throw new MethodInvocationException("Parameter '" + ref.getRootString()
                                + "' not defined", null, key, ref.getTemplateName(),
                                ref.getLine(), ref.getColumn());
                        }
                    }
                    return obj;
View Full Code Here

             * in a MethodInvocationException.  Don't pass through RuntimeExceptions like other
             * similar catchall code blocks.
             */
            catch( Exception e )
            {
                throw new MethodInvocationException(
                    "Invocation of method '"
                    + methodName + "' in  " + o.getClass()
                    + " threw exception "
                    + e.toString(),
                    e, methodName, getTemplateName(), this.getLine(), this.getColumn());
            }
        }

        /*
         *  let non-Exception Throwables go...
         */
        else
        {
            /*
             * no event cartridge to override. Just throw
             */

            throw new MethodInvocationException(
            "Invocation of method '"
            + methodName + "' in  " + o.getClass()
            + " threw exception "
            + t.toString(),
            t, methodName, getTemplateName(), this.getLine(), this.getColumn());
View Full Code Here

            if (result == null)
            {
                if (strictRef)
                {
                    String name = jjtGetChild(i+1).getTokens().get(0).image;
                    throw new MethodInvocationException("Attempted to access '" 
                        + name + "' on a null value", null, name, uberInfo.getTemplateName(),
                        jjtGetChild(i+1).getLine(), jjtGetChild(i+1).getColumn());
                }           
             
                String msg = "reference set is not a valid reference at "
                    + VelocityException.formatFileString(uberInfo);
                Logger.error(this,msg);

                return false;
            }
        }

        if (astIndex != null)
        {
            // If astIndex is not null then we are actually setting an index reference,
            // something of the form $foo[1] =, or in general any reference that ends with
            // the brackets.  This means that we need to call a more general method
            // of the form set(Integer, <something>), or put(Object, <something), where
            // the first parameter is the index value and the second is the LHS of the set.
         
            Object argument = astIndex.jjtGetChild(0).value(context);
            // If negative, turn -1 into (size - 1)
            argument = ASTIndex.adjMinusIndexArg(argument, result, context, astIndex);           
            Object [] params = {argument, value};
            Class[] paramClasses = {params[0] == null ? null : params[0].getClass(),
                                    params[1] == null ? null : params[1].getClass()};

            String methodName = "set";
            VelMethod method = ClassUtils.getMethod(methodName, params, paramClasses,
                result, context, astIndex, false);
           
            if (method == null)
            {
                // If we can't find a 'set' method, lets try 'put',  This warrents a little
                // investigation performance wise... if the user is using the hash
                // form $foo["blaa"], then it may be expensive to first try and fail on 'set'
                // then go to 'put'?  The problem is that getMethod will try the cache, then
                // perform introspection on 'result' for 'set'
                methodName = "put";
                method = ClassUtils.getMethod(methodName, params, paramClasses,
                      result, context, astIndex, false);
            }  
           
            if (method == null)
            {
                // couldn't find set or put method, so bail
                if (strictRef)
                {
                    throw new VelocityException(
                        "Found neither a 'set' or 'put' method with param types '("
                        + printClass(paramClasses[0]) + "," + printClass(paramClasses[1])
                        + ")' on class '" + result.getClass().getName()
                        + "' at " + VelocityException.formatFileString(astIndex));
                }
                return false;
            }
         
            try
            {
                method.invoke(result, params);
            }
            catch(RuntimeException e)
            {
                // Kludge since invoke throws Exception, pass up Runtimes
                throw e;
            }
            catch(Exception e)
            {
                throw new MethodInvocationException(
                  "Exception calling method '"
                  + methodName + "("
                  + printClass(paramClasses[0]) + "," + printClass(paramClasses[1])
                  + ")' in  " + result.getClass(),
                  e.getCause(), identifier, astIndex.getTemplateName(), astIndex.getLine(),
                    astIndex.getColumn());
            }
           
            return true;
        }
       
       
        /*
         *  We support two ways of setting the value in a #set($ref.foo = $value ) :
         *  1) ref.setFoo( value )
         *  2) ref,put("foo", value ) to parallel the get() map introspection
         */

        try
        {
            RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
            VelPropertySet vs =
                    rsvc.getUberspect().getPropertySet(result, identifier,
                            value, uberInfo);

            if (vs == null)
            {
                if (strictRef)
                {
                    throw new MethodInvocationException("Object '" + result.getClass().getName() +
                       "' does not contain property '" + identifier + "'", null, identifier,
                       uberInfo.getTemplateName(), uberInfo.getLine(), uberInfo.getColumn());
                }
                else
                {
                  return false;
                }
            }

            vs.invoke(result, value);
        }
        catch(InvocationTargetException ite)
        {
            /*
             *  this is possible
             */

            throw  new MethodInvocationException(
                "ASTReference : Invocation of method '"
                + identifier + "' in  " + result.getClass()
                + " threw exception "
                + ite.getTargetException().toString(),
               ite.getTargetException(), identifier, getTemplateName(), this.getLine(), this.getColumn());
View Full Code Here

        {
          if (!context.containsKey(variable))
          {
              Logger.error(this,"Variable $" + variable + " has not been set at "
                        + VelocityException.formatFileString(uberInfo));
              throw new MethodInvocationException("Variable $" + variable +
                  " has not been set", null, identifier,
                  uberInfo.getTemplateName(), uberInfo.getLine(), uberInfo.getColumn());           
          }
        }
        return obj;       
View Full Code Here

        if (vg == null)
        {
            if (strictRef)
            {
                throw new MethodInvocationException("Object '" + o.getClass().getName() +             
                    "' does not contain property '" + identifier + "'", null, identifier,
                    uberInfo.getTemplateName(), uberInfo.getLine(), uberInfo.getColumn());
            }
            else
            {
                return null;
            }
        }

        /*
         *  now try and execute.  If we get a MIE, throw that
         *  as the app wants to get these.  If not, log and punt.
         */
        try
        {
            return vg.invoke(o);
        }
        catch(InvocationTargetException ite)
        {
            /*
             *  if we have an event cartridge, see if it wants to veto
             *  also, let non-Exception Throwables go...
             */

            Throwable t = ite.getTargetException();
            if (t instanceof Exception)
            {
                try
                {
                    RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
                    return EventHandlerUtil.methodException(rsvc, context, o.getClass(), vg.getMethodName(),
                            (Exception) t);
                }

                /**
                 * If the event handler throws an exception, then wrap it
                 * in a MethodInvocationException.  Don't pass through RuntimeExceptions like other
                 * similar catchall code blocks.
                 */
                catch( Exception e )
                {
                    throw new MethodInvocationException(
                      "Invocation of method '" + vg.getMethodName() + "'"
                      + " in  " + o.getClass()
                      + " threw exception "
                      + ite.getTargetException().toString(),
                      ite.getTargetException(), vg.getMethodName(), getTemplateName(), this.getLine(), this.getColumn());
                }
            }
            else
            {
                /*
                 * no event cartridge to override. Just throw
                 */

                throw  new MethodInvocationException(
                "Invocation of method '" + vg.getMethodName() + "'"
                + " in  " + o.getClass()
                + " threw exception "
                + ite.getTargetException().toString(),
                ite.getTargetException(), vg.getMethodName(), getTemplateName(), this.getLine(), this.getColumn());
View Full Code Here

TOP

Related Classes of org.apache.velocity.exception.MethodInvocationException

Copyright © 2018 www.massapicom. 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.