Examples of ListenerInvoker


Examples of com.comphenix.protocol.injector.ListenerInvoker

   * @param source - packet to invert.
   * @return The inverted packet.
   */
  @SuppressWarnings("deprecation")
  Object createNegativePacket(Object source) {
    ListenerInvoker invoker = injector.getInvoker();
   
    PacketType type = invoker.getPacketType(source);

    // We want to subtract the byte amount that were added to the running
    // total of outstanding packets. Otherwise, cancelling too many packets
    // might cause a "disconnect.overflow" error.
    //
    // We do that by constructing a special packet of the same type that returns
    // a negative integer for all zero-parameter integer methods. This includes the
    // size() method, which is used by the queue method to count the number of
    // bytes to add.
    //
    // Essentially, we have:
    //
    //   public class NegativePacket extends [a packet] {
    //      @Override
    //      public int size() {
    //         return -super.size();
    //      }
    //   ect.
    //   }
    Enhancer ex = EnhancerFactory.getInstance().createEnhancer();
    ex.setSuperclass(MinecraftReflection.getPacketClass());
    ex.setInterfaces(new Class[] { FakePacket.class } );
    ex.setUseCache(true);
    ex.setCallbackType(InvertedIntegerCallback.class);

    Class<?> proxyClass = ex.createClass();
    Enhancer.registerCallbacks(proxyClass, new Callback[] { callback });
   
    try {
      // Temporarily associate the fake packet class
      invoker.registerPacketClass(proxyClass, type.getLegacyId());
      Object proxy = proxyClass.newInstance();
     
      InjectedArrayList.registerDelegate(proxy, source);
      return proxy;
     
    } catch (Exception e) {
      // Don't pollute the throws tree
      throw new RuntimeException("Cannot create fake class.", e);
    } finally {
      // Remove this association
      invoker.unregisterPacketClass(proxyClass);
    }
  }
View Full Code Here

Examples of org.apache.tapestry.listener.ListenerInvoker

        final IActionListener action = getAction();

        if (listener == null && action == null)
            return;

        final ListenerInvoker listenerInvoker = getListenerInvoker();

        Object parameters = getParameters();
        if (parameters != null)
        {
            if (parameters instanceof Collection)
            {
                cycle.setListenerParameters(((Collection) parameters).toArray());
            }
            else
            {
                cycle.setListenerParameters(new Object[]
                { parameters });
            }
        }
       
        // Invoke 'listener' now, but defer 'action' for later
        if (listener != null)
            listenerInvoker.invokeListener(listener, AbstractSubmit.this, cycle);
       
        if (action != null) {
            Runnable notify = new Runnable()
            {
                public void run()
                {
                    listenerInvoker.invokeListener(action, AbstractSubmit.this, cycle);
                }
            };

            form.addDeferredRunnable(notify);
        }
View Full Code Here

Examples of org.apache.tapestry.listener.ListenerInvoker

        final IActionListener listener = getListener();

        if (listener == null)
            return;

        final ListenerInvoker listenerInvoker = getListenerInvoker();

        Object parameters = getParameters();
        if (parameters != null)
        {
            if (parameters instanceof Collection)
            {
                cycle.setListenerParameters(((Collection) parameters).toArray());
            }
            else
            {
                cycle.setListenerParameters(new Object[]
                { parameters });
            }
        }

        // Have a listener; notify it now, or defer for later?

        Runnable notify = new Runnable()
        {
            public void run()
            {
                listenerInvoker.invokeListener(listener, AbstractSubmit.this, cycle);
            }
        };

        if (getDefer())
            form.addDeferredRunnable(notify);
View Full Code Here

Examples of org.apache.tapestry.listener.ListenerInvoker

        final IActionListener action = getAction();

        if (listener == null && action == null)
            return;

        final ListenerInvoker listenerInvoker = getListenerInvoker();

        Object parameters = getParameters();
        if (parameters != null)
        {
            if (parameters instanceof Collection)
            {
                cycle.setListenerParameters(((Collection) parameters).toArray());
            }
            else
            {
                cycle.setListenerParameters(new Object[] { parameters });
            }
        }
       
        // Invoke 'listener' now, but defer 'action' for later
        if (listener != null)
            listenerInvoker.invokeListener(listener, AbstractSubmit.this, cycle);
       
        if (action != null)
        {
            Runnable notify = new Runnable()
            {
                public void run()
                {
                    listenerInvoker.invokeListener(action, AbstractSubmit.this, cycle);
                }
            };

            form.addDeferredRunnable(notify);
        }
View Full Code Here

Examples of org.apache.tapestry.listener.ListenerInvoker

    {
        IMarkupWriter writer = newWriter();
        IRequestCycle cycle = newCycle();
        IValidationDelegate delegate = newDelegate();
        MockForm form = new MockForm(delegate);
        ListenerInvoker listenerInvoker = newMock(ListenerInvoker.class);
       
        ComponentEventInvoker invoker = new ComponentEventInvoker();
        invoker.setInvoker(listenerInvoker);
       
        trainIsRewound(cycle, form, true);
View Full Code Here

Examples of org.apache.tapestry.listener.ListenerInvoker

        IRequestCycle cycle = newCycle();
        IComponent comp = newComponent();
        checkOrder(comp, false);
       
        IPage page = newMock(IPage.class);
        ListenerInvoker listenerInvoker = newMock(ListenerInvoker.class);
        ListenerMap listenerMap = newMock(ListenerMap.class);
        IActionListener listener1 = newMock(IActionListener.class);

        IComponentSpecification spec = new ComponentSpecification();
       
        Map comps = new HashMap();
        comps.put("testId", comp);
       
        Map tprops = new HashMap();
        tprops.put("id", "testId");
        BrowserEvent event = new BrowserEvent("onSelect", new EventTarget(tprops));
       
        ComponentEventInvoker invoker = new ComponentEventInvoker();
        invoker.setInvoker(listenerInvoker);
       
        spec.addEventListener("testId", new String[] { "onSelect" },
                "fooListener", null, false, false, false, false);
        invoker.addEventListener("testId", spec);

        expect(comp.getExtendedId()).andReturn("testId").anyTimes();
        expect(comp.getSpecification()).andReturn(spec).anyTimes();
        expect(comp.getPage()).andReturn(page);

        expect(page.getComponents()).andReturn(comps);
        expect(comp.getListeners()).andReturn(listenerMap);
       
        expect(listenerMap.getListener("fooListener")).andReturn(listener1);
       
        listenerInvoker.invokeListener(listener1, comp, cycle);
       
        replay();
       
        invoker.invokeListeners(comp, cycle, event);
       
View Full Code Here

Examples of org.apache.tapestry.listener.ListenerInvoker

        checkOrder(comp, false);
       
        IPage page = newMock(IPage.class);
        IComponentSpecification spec = new ComponentSpecification();
       
        ListenerInvoker listenerInvoker = newMock(ListenerInvoker.class);
        ListenerMap listenerMap = newMock(ListenerMap.class);
        IActionListener listener = newMock(IActionListener.class);
       
        Map comps = new HashMap();
        comps.put("testId", comp);
       
        Map tprops = new HashMap();
        tprops.put("id", "testId");
        BrowserEvent event = new BrowserEvent("onSelect", new EventTarget(tprops));
       
        ComponentEventInvoker invoker = new ComponentEventInvoker();
        invoker.setInvoker(listenerInvoker);
       
        spec.addElementEventListener("testId", new String[] { "onSelect" },
                "fooListener", null, false, true, true);
        invoker.addEventListener("testId", spec);
       
        expect(comp.getExtendedId()).andReturn("testId").anyTimes();
        expect(comp.getSpecification()).andReturn(spec).anyTimes();
        expect(comp.getPage()).andReturn(page);
        expect(page.getComponents()).andReturn(comps);
        expect(comp.getListeners()).andReturn(listenerMap);
       
        expect(listenerMap.getListener("fooListener")).andReturn(listener);
       
        listenerInvoker.invokeListener(listener, comp, cycle);
       
        replay();
       
        invoker.invokeListeners(comp, cycle, event);
       
View Full Code Here

Examples of org.apache.tapestry.listener.ListenerInvoker

        IForm form = newForm();
        checkOrder(form, false);
        FormSupport formSupport = newMock(FormSupport.class);
        IComponentSpecification spec = new ComponentSpecification();
        IValidationDelegate delegate = newMock(IValidationDelegate.class);
        ListenerInvoker listenerInvoker = newMock(ListenerInvoker.class);
        ListenerMap listenerMap = newMock(ListenerMap.class);
        IActionListener listener = newMock(IActionListener.class);
        IPage page = newMock(IPage.class);
        checkOrder(page, false);
       
View Full Code Here

Examples of org.apache.tapestry.listener.ListenerInvoker

        checkOrder(form, false);
        FormSupport formSupport = newMock(FormSupport.class);
        IComponentSpecification spec = new ComponentSpecification();
        IValidationDelegate delegate = newMock(IValidationDelegate.class);
       
        ListenerInvoker listenerInvoker = newMock(ListenerInvoker.class);
        ListenerMap listenerMap = newMock(ListenerMap.class);
        IActionListener listener = newMock(IActionListener.class);
        IPage page = newMock(IPage.class);
        checkOrder(page, false);
       
View Full Code Here

Examples of org.apache.tapestry.listener.ListenerInvoker

        IRequestCycle cycle = newCycle();
        IComponent comp = newComponent();
        checkOrder(comp, false);
       
        IPage page = newMock(IPage.class);
        ListenerInvoker listenerInvoker = newMock(ListenerInvoker.class);
        ListenerMap listenerMap = newMock(ListenerMap.class);
        IActionListener listener1 = newMock(IActionListener.class);

        IComponentSpecification spec = new ComponentSpecification();
       
        Map comps = new HashMap();
        comps.put("testId", comp);
       
        Map tprops = new HashMap();
        tprops.put("id", "testId");
        BrowserEvent event = new BrowserEvent("onSelect", new EventTarget(tprops));
       
        ComponentEventInvoker invoker = new ComponentEventInvoker();
        invoker.setInvoker(listenerInvoker);
       
        spec.addEventListener("testId", new String[] { "onSelect" },
                "fooListener", null, false, false, false, false);
        invoker.addEventListener("testId", spec);

        expect(comp.getExtendedId()).andReturn("testId").anyTimes();
        expect(comp.getSpecification()).andReturn(spec).anyTimes();
        expect(comp.getPage()).andReturn(page);

        expect(page.getComponents()).andReturn(comps);
        expect(comp.getListeners()).andReturn(listenerMap);
       
        expect(listenerMap.getListener("fooListener")).andReturn(listener1);
       
        listenerInvoker.invokeListener(listener1, comp, cycle);
       
        replay();
       
        invoker.invokeListeners(comp, cycle, event);
       
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.