java.util.EventListener Java Examples
The following examples show how to use
java.util.EventListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServletContextImpl.java From quarkus-http with Apache License 2.0 | 6 votes |
@Override public void addListener(final Class<? extends EventListener> listenerClass) { ensureNotInitialized(); ensureNotProgramaticListener(); if (ApplicationListeners.listenerState() != NO_LISTENER && ServletContextListener.class.isAssignableFrom(listenerClass)) { throw UndertowServletMessages.MESSAGES.cannotAddServletContextListener(); } InstanceFactory<? extends EventListener> factory = null; try { factory = deploymentInfo.getClassIntrospecter().createInstanceFactory(listenerClass); } catch (Exception e) { throw new IllegalArgumentException(e); } final ListenerInfo listener = new ListenerInfo(listenerClass, factory); deploymentInfo.addListener(listener); deployment.getApplicationListeners().addListener(new ManagedListener(listener, true)); }
Example #2
Source File: MarkerTest.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Checks that an XYPlot deregisters listeners when clearing markers. */ @Test public void testListenersWithXYPlot() { XYPlot plot = new XYPlot(); ValueMarker marker1 = new ValueMarker(1.0); ValueMarker marker2 = new ValueMarker(2.0); plot.addDomainMarker(marker1); plot.addRangeMarker(marker2); EventListener[] listeners1 = marker1.getListeners( MarkerChangeListener.class); assertTrue(Arrays.asList(listeners1).contains(plot)); EventListener[] listeners2 = marker1.getListeners( MarkerChangeListener.class); assertTrue(Arrays.asList(listeners2).contains(plot)); plot.clearDomainMarkers(); plot.clearRangeMarkers(); listeners1 = marker1.getListeners(MarkerChangeListener.class); assertFalse(Arrays.asList(listeners1).contains(plot)); listeners2 = marker1.getListeners(MarkerChangeListener.class); assertFalse(Arrays.asList(listeners2).contains(plot)); }
Example #3
Source File: EventListenerAggregate.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Removes a listener that is equal to the given one from this aggregate. * <code>equals()</code> method is used to compare listeners. * * @param listener the listener to be removed * * @return <code>true</code> if this aggregate contained the specified * <code>listener</code>; <code>false</code> otherwise * * @throws ClassCastException if <code>listener</code> is not * an instatce of <code>listenerClass</code> specified * in the constructor */ public synchronized boolean remove(EventListener listener) { Class<?> listenerClass = getListenerClass(); if (!listenerClass.isInstance(listener)) { // null is not an instance of any class throw new ClassCastException("listener " + listener + " is not " + "an instance of listener class " + listenerClass); } for (int i = 0; i < listenerList.length; i++) { if (listenerList[i].equals(listener)) { EventListener[] tmp = (EventListener[])Array.newInstance(listenerClass, listenerList.length - 1); System.arraycopy(listenerList, 0, tmp, 0, i); System.arraycopy(listenerList, i + 1, tmp, i, listenerList.length - i - 1); listenerList = tmp; return true; } } return false; }
Example #4
Source File: StatelessKnowledgeSessionImpl.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private Collection<? extends EventListener> getListeners(ListnerHolder.Type type) { if ( listeners.isEmpty()) { return Collections.emptySet(); } Collection<EventListener> l = new ArrayList<EventListener>(); for (ListnerHolder listnerHolder : listeners ) { if (listnerHolder.type == type) { l.add( listnerHolder.listener ); } } return l; }
Example #5
Source File: ApplicationContext.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public void addListener(Class<? extends EventListener> listenerClass) { EventListener listener; try { listener = createListener(listenerClass); } catch (ServletException e) { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.init", listenerClass.getName()), e); } addListener(listener); }
Example #6
Source File: ApplicationContext.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public <T extends EventListener> void addListener(T t) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException( sm.getString("applicationContext.addListener.ise", getContextPath())); } boolean match = false; if (t instanceof ServletContextAttributeListener || t instanceof ServletRequestListener || t instanceof ServletRequestAttributeListener || t instanceof HttpSessionIdListener || t instanceof HttpSessionAttributeListener) { context.addApplicationEventListener(t); match = true; } if (t instanceof HttpSessionListener || (t instanceof ServletContextListener && newServletContextListenerAllowed)) { // Add listener directly to the list of instances rather than to // the list of class names. context.addApplicationLifecycleListener(t); match = true; } if (match) return; if (t instanceof ServletContextListener) { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.sclNotAllowed", t.getClass().getName())); } else { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.wrongType", t.getClass().getName())); } }
Example #7
Source File: ApplicationContextFacade.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public void addListener(Class<? extends EventListener> listenerClass) { if (SecurityUtil.isPackageProtectionEnabled()) { doPrivileged("addListener", new Class[]{Class.class}, new Object[]{listenerClass}); } else { context.addListener(listenerClass); } }
Example #8
Source File: AWTEventMulticaster.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static int getListenerCount(EventListener l, Class<?> listenerType) { if (l instanceof AWTEventMulticaster) { AWTEventMulticaster mc = (AWTEventMulticaster)l; return getListenerCount(mc.a, listenerType) + getListenerCount(mc.b, listenerType); } else { // Only count listeners of correct type return listenerType.isInstance(l) ? 1 : 0; } }
Example #9
Source File: AWTEventMulticaster.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static int populateListenerArray(EventListener[] a, EventListener l, int index) { if (l instanceof AWTEventMulticaster) { AWTEventMulticaster mc = (AWTEventMulticaster)l; int lhs = populateListenerArray(a, mc.a, index); return populateListenerArray(a, mc.b, lhs); } else if (a.getClass().getComponentType().isInstance(l)) { a[index] = l; return index + 1; } // Skip nulls, instances of wrong class else { return index; } }
Example #10
Source File: TopLevelWindowMulticaster.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
protected static EventListener removeInternal(EventListener l, EventListener oldl) { if (l == oldl || l == null) { return null; } else if (l instanceof TopLevelWindowMulticaster) { return ((TopLevelWindowMulticaster)l).remove(oldl); } else { return l; // it's not here } }
Example #11
Source File: GUIInitializedMulticaster.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
protected static EventListener removeInternal(EventListener l, EventListener oldl) { if (l == oldl || l == null) { return null; } else if (l instanceof GUIInitializedMulticaster) { return ((GUIInitializedMulticaster)l).remove(oldl); } else { return l; // it's not here } }
Example #12
Source File: AbstractEventSupport.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public void clear() { for (EventListener listener : listeners) { if (listener instanceof Closeable) { ((Closeable) listener).close(); } } this.listeners.clear(); }
Example #13
Source File: AWTEventMulticaster.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
protected static void save(ObjectOutputStream s, String k, EventListener l) throws IOException { if (l == null) { return; } else if (l instanceof AWTEventMulticaster) { ((AWTEventMulticaster)l).saveInternal(s, k); } else if (l instanceof Serializable) { s.writeObject(k); s.writeObject(l); } }
Example #14
Source File: DnDEventMulticaster.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Removes a listener from this multicaster and returns the * resulting multicast listener. * @param oldl the listener to be removed */ protected EventListener remove(EventListener oldl) { if (oldl == a) return b; if (oldl == b) return a; EventListener a2 = removeInternal(a, oldl); EventListener b2 = removeInternal(b, oldl); if (a2 == a && b2 == b) { return this; // it's not here } return addInternal(a2, b2); }
Example #15
Source File: TopLevelWindowMulticaster.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
protected static EventListener removeInternal(EventListener l, EventListener oldl) { if (l == oldl || l == null) { return null; } else if (l instanceof TopLevelWindowMulticaster) { return ((TopLevelWindowMulticaster)l).remove(oldl); } else { return l; // it's not here } }
Example #16
Source File: ServletContextImpl.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public <T extends EventListener> T createListener(final Class<T> clazz) throws ServletException { ensureNotProgramaticListener(); if (!ApplicationListeners.isListenerClass(clazz)) { throw UndertowServletMessages.MESSAGES.listenerMustImplementListenerClass(clazz); } try { return deploymentInfo.getClassIntrospecter().createInstanceFactory(clazz).createInstance().getInstance(); } catch (Exception e) { throw UndertowServletMessages.MESSAGES.couldNotInstantiateComponent(clazz.getName(), e); } }
Example #17
Source File: ServletContextImpl.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public <T extends EventListener> void addListener(final T t) { ensureNotInitialized(); ensureNotProgramaticListener(); if (ApplicationListeners.listenerState() != NO_LISTENER && ServletContextListener.class.isAssignableFrom(t.getClass())) { throw UndertowServletMessages.MESSAGES.cannotAddServletContextListener(); } ListenerInfo listener = new ListenerInfo(t.getClass(), new ImmediateInstanceFactory<EventListener>(t)); deploymentInfo.addListener(listener); deployment.getApplicationListeners().addListener(new ManagedListener(listener, true)); }
Example #18
Source File: EventListenerAggregate.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Adds the listener to this aggregate. * * @param listener the listener to be added * * @throws ClassCastException if <code>listener</code> is not * an instatce of <code>listenerClass</code> specified * in the constructor */ public synchronized void add(EventListener listener) { Class<?> listenerClass = getListenerClass(); if (!listenerClass.isInstance(listener)) { // null is not an instance of any class throw new ClassCastException("listener " + listener + " is not " + "an instance of listener class " + listenerClass); } EventListener[] tmp = (EventListener[])Array.newInstance(listenerClass, listenerList.length + 1); System.arraycopy(listenerList, 0, tmp, 0, listenerList.length); tmp[listenerList.length] = listener; listenerList = tmp; }
Example #19
Source File: ListenerInfo.java From quarkus-http with Apache License 2.0 | 5 votes |
public ListenerInfo(final Class<? extends EventListener> listenerClass, boolean programatic) { this.listenerClass = listenerClass; this.programatic = programatic; try { final Constructor<EventListener> ctor = (Constructor<EventListener>) listenerClass.getDeclaredConstructor(); ctor.setAccessible(true); this.instanceFactory = new ConstructorInstanceFactory<>(ctor); } catch (NoSuchMethodException e) { throw UndertowServletMessages.MESSAGES.componentMustHaveDefaultConstructor("Listener", listenerClass); } }
Example #20
Source File: ListenerInfo.java From quarkus-http with Apache License 2.0 | 5 votes |
public ListenerInfo(final Class<? extends EventListener> listenerClass, final InstanceFactory<? extends EventListener> instanceFactory, boolean programatic) { this.listenerClass = listenerClass; this.instanceFactory = instanceFactory; this.programatic = programatic; if(!ApplicationListeners.isListenerClass(listenerClass)) { throw UndertowServletMessages.MESSAGES.listenerMustImplementListenerClass(listenerClass); } }
Example #21
Source File: EventListenerAggregate.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Adds the listener to this aggregate. * * @param listener the listener to be added * * @throws ClassCastException if <code>listener</code> is not * an instatce of <code>listenerClass</code> specified * in the constructor */ public synchronized void add(EventListener listener) { Class<?> listenerClass = getListenerClass(); if (!listenerClass.isInstance(listener)) { // null is not an instance of any class throw new ClassCastException("listener " + listener + " is not " + "an instance of listener class " + listenerClass); } EventListener[] tmp = (EventListener[])Array.newInstance(listenerClass, listenerList.length + 1); System.arraycopy(listenerList, 0, tmp, 0, listenerList.length); tmp[listenerList.length] = listener; listenerList = tmp; }
Example #22
Source File: ListenerInfo.java From quarkus-http with Apache License 2.0 | 4 votes |
public Class<? extends EventListener> getListenerClass() { return listenerClass; }
Example #23
Source File: MockServletContext.java From spring-analysis-note with MIT License | 4 votes |
@Override public <T extends EventListener> void addListener(T t) { throw new UnsupportedOperationException(); }
Example #24
Source File: DnDEventMulticaster.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
protected static void save(ObjectOutputStream s, String k, EventListener l) throws IOException { AWTEventMulticaster.save(s, k, l); }
Example #25
Source File: GUIInitializedMulticaster.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
protected GUIInitializedMulticaster(EventListener a, EventListener b) { super(a, b); }
Example #26
Source File: Servlets.java From quarkus-http with Apache License 2.0 | 4 votes |
public static ListenerInfo listener(final Class<? extends EventListener> listenerClass) { return new ListenerInfo(listenerClass); }
Example #27
Source File: Test7148143.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public CustomProxy() { super(new EventListener() { }); }
Example #28
Source File: MockServletContext.java From java-technology-stack with MIT License | 4 votes |
@Override public <T extends EventListener> void addListener(T t) { throw new UnsupportedOperationException(); }
Example #29
Source File: ListenerInfo.java From quarkus-http with Apache License 2.0 | 4 votes |
public ListenerInfo(final Class<? extends EventListener> listenerClass) { this(listenerClass, false); }
Example #30
Source File: MockServletContext.java From spring-analysis-note with MIT License | 4 votes |
@Override public <T extends EventListener> T createListener(Class<T> c) throws ServletException { throw new UnsupportedOperationException(); }