Package org.apache.velocity.app.event

Examples of org.apache.velocity.app.event.EventCartridge


        {
            return vg.invoke(o);
        }
        catch(InvocationTargetException ite)
        {
            EventCartridge ec = context.getEventCartridge();

            /*
             *  if we have an event cartridge, see if it wants to veto
             *  also, let non-Exception Throwables go...
             */

            if (ec != null
                    && ite.getTargetException() instanceof java.lang.Exception)
            {
                try
                {
                    return ec.methodException(o.getClass(), vg.getMethodName(),
                            (Exception)ite.getTargetException());
                }
                catch(Exception e)
                {
                    throw new MethodInvocationException(
View Full Code Here


        MyFastLocalHandler localHandler2 = new MyFastLocalHandler();
        eventCartridge.addEventHandler(localHandler);
        eventCartridge.addEventHandler(localHandler2);

        // cloned instance
        EventCartridge ecruntime = eventCartridge.getRuntimeInstance();
        assertNotSame(eventCartridge, ecruntime);

        Iterator<?> i = ecruntime.getReferenceInsertionEventHandlers();

        // 1. same as handler
        assertSame(handler, i.next());

        // 2. cloned localHandler
        MyLocalHandler newLocalHandler = (MyLocalHandler) i.next();
        assertNotNull(newLocalHandler);
        assertNotSame(localHandler, newLocalHandler);

        // 3. fast cloned localHandler
        MyFastLocalHandler newLocalHandler2 = (MyFastLocalHandler) i.next();
        assertNotNull(newLocalHandler2);
        assertNotSame(localHandler2, newLocalHandler2);

        assertFalse(i.hasNext());

        // other handlers
        i = ecruntime.getMethodExceptionEventHandlers();

        // same as newLocalHandler
        assertSame(newLocalHandler, i.next());

        // same as newLocalHandler
View Full Code Here

      util = new Util();
    }

    if (util instanceof EventHandler)
    {
      EventCartridge ec = new EventCartridge();
      ec.addEventHandler(util);
      ec.attachToContext(cx);
    }
    cx.put(UTIL_KEY, util);
    return cx;
  }
View Full Code Here

        {
            return vg.invoke(o);
        }
        catch(InvocationTargetException ite)
        {
            EventCartridge ec = context.getEventCartridge();

            /*
             *  if we have an event cartridge, see if it wants to veto
             *  also, let non-Exception Throwables go...
             */

            if (ec != null
                    && ite.getTargetException() instanceof java.lang.Exception)
            {
                try
                {
                    return ec.methodException(o.getClass(), vg.getMethodName(),
                            (Exception)ite.getTargetException());
                }
                catch(Exception e)
                {
                    throw new MethodInvocationException(
View Full Code Here

            /*
             *  first, are we supposed to say anything anyway?
             */
            if(blather)
            {
                EventCartridge ec = context.getEventCartridge();

                boolean doit = true;
              
                /*
                 *  if we have an EventCartridge...
                 */
                if (ec != null)
                {
                    doit = ec.shouldLogOnNullSet( left.literal(), right.literal() );
                }

                if (doit)
                {
                    rsvc.error("RHS of #set statement is null. Context will not be modified. "
View Full Code Here

             *  wrap it, and throw.  We don't log here as we want to figure
             *  out which reference threw the exception, so do that
             *  above
             */

            EventCartridge ec = context.getEventCartridge();

            /*
             *  if we have an event cartridge, see if it wants to veto
             *  also, let non-Exception Throwables go...
             */

            if ( ec != null && ite.getTargetException() instanceof java.lang.Exception)
            {
                try
                {
                    return ec.methodException( o.getClass(), methodName, (Exception)ite.getTargetException() );
                }
                catch( Exception e )
                {
                    throw new MethodInvocationException(
                        "Invocation of method '"
View Full Code Here

         *  the normal processing
         *
         *  if we have an event cartridge, get a new value object
         */

        EventCartridge ec = context.getEventCartridge();

        if (ec != null)
        {
            value =  ec.referenceInsert(literal, value);
        }

        /*
         *  if value is null...
         */
 
View Full Code Here

    private void initializeEventHandlers()
        throws Exception
    {

        eventCartridge = new EventCartridge();

        /**
         * For each type of event handler, get the class name, instantiate it, and store it.
         */

 
View Full Code Here

        return supported;
    }

    public EventCartridge getRuntimeInstance() {
        EventCartridge runtimeInstance = this;

        if (needsClone) {
            runtimeInstance = new EventCartridge();

            for (EventHandler ev : allHandlers) {
                if (ev instanceof ContextAware) {
                    if (ev instanceof FastCloneable) {
                        ev = (EventHandler) ((FastCloneable) ev).createCopy();
                    } else {
                        try {
                            ev = (EventHandler) cloneMethod.invoke(ev);
                        } catch (Exception e) {
                            throw new TemplateException("Could not clone a ContextAware event handler: "
                                                        + ev.getClass().getName(), e);
                        }
                    }
                }

                runtimeInstance.addEventHandler(ev);
            }
        }

        return runtimeInstance;
    }
View Full Code Here

            // 模板中的修改将保留在context中。
            eventContext = new EventContext(context);
        }

        // 将event cartridge复制以后(如有必要)附到context中。
        EventCartridge ec = configuration.getEventCartridge().getRuntimeInstance();

        if (ec != null) {
            assertTrue(ec.attachToContext(eventContext), "Could not attach EventCartridge to velocity context");
        }

        return eventContext;
    }
View Full Code Here

TOP

Related Classes of org.apache.velocity.app.event.EventCartridge

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.