Search in sources :

Example 36 with EventListener

use of java.util.EventListener in project cayenne by apache.

the class ProjectController method fireDbAttributeDisplayEvent.

public void fireDbAttributeDisplayEvent(AttributeDisplayEvent e) {
    boolean changed = !Arrays.equals(e.getAttributes(), currentState.dbAttrs);
    if (changed) {
        if (e.getEntity() != currentState.dbEntity) {
            clearState();
            currentState.domain = e.getDomain();
            currentState.map = e.getDataMap();
            currentState.dbEntity = (DbEntity) e.getEntity();
        }
        currentState.dbAttrs = new DbAttribute[e.getAttributes().length];
        System.arraycopy(e.getAttributes(), 0, currentState.dbAttrs, 0, currentState.dbAttrs.length);
    }
    for (EventListener listener : listenerList.getListeners(DbAttributeDisplayListener.class)) {
        DbAttributeDisplayListener temp = (DbAttributeDisplayListener) listener;
        temp.currentDbAttributeChanged(e);
    }
}
Also used : DbAttributeDisplayListener(org.apache.cayenne.modeler.event.DbAttributeDisplayListener) EventListener(java.util.EventListener)

Example 37 with EventListener

use of java.util.EventListener in project nutzboot by nutzam.

the class UndertowStarter method addEventListener.

public void addEventListener(WebEventListenerFace webEventListener) {
    if (webEventListener.getEventListener() == null) {
        return;
    }
    EventListener et = webEventListener.getEventListener();
    log.debugf("add listener %s", et.getClass());
    ImmediateInstanceFactory<EventListener> factory = new ImmediateInstanceFactory<EventListener>(et);
    ListenerInfo listener = new ListenerInfo(et.getClass(), factory);
    deployment.addListener(listener);
}
Also used : ListenerInfo(io.undertow.servlet.api.ListenerInfo) EventListener(java.util.EventListener) ImmediateInstanceFactory(io.undertow.servlet.util.ImmediateInstanceFactory)

Example 38 with EventListener

use of java.util.EventListener in project litiengine by gurkenlabs.

the class ReflectionUtilities method getEvents.

/**
 * Gets the events for the specified type.
 *
 * <p>
 * This will search for all methods that have a parameter of type {@code EventListener} and match the LITIENGINE's
 * naming conventions for event subscription (i.e. the method name starts with one of the prefixes "add" or "on".
 *
 * @param type
 *          The type to inspect the events on.
 * @return All methods on the specified type that are considered to be events.
 * @see EventListener
 */
public static Collection<Method> getEvents(final Class<?> type) {
    final String eventAddPrefix = "add";
    final String eventOnPrefix = "on";
    final List<Method> events = new ArrayList<>();
    Class<?> clazz = type;
    while (clazz != Object.class) {
        // need to iterated thought hierarchy in order to retrieve methods from above
        // the current instance
        // iterate though the list of methods declared in the class represented by class variable, and
        // add those annotated with the specified annotation
        final List<Method> allMethods = new ArrayList<>(Arrays.asList(clazz.getDeclaredMethods()));
        for (final Method method : allMethods) {
            for (Class<?> paramtype : method.getParameterTypes()) {
                if (EventListener.class.isAssignableFrom(paramtype) && (method.getName().startsWith(eventAddPrefix) || method.getName().startsWith(eventOnPrefix))) {
                    events.add(method);
                }
            }
        }
        // move to the upper class in the hierarchy in search for more methods
        clazz = clazz.getSuperclass();
    }
    return events;
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) EventListener(java.util.EventListener)

Example 39 with EventListener

use of java.util.EventListener in project jetty.project by eclipse.

the class StandardDescriptorProcessor method newListenerInstance.

public EventListener newListenerInstance(WebAppContext context, Class<? extends EventListener> clazz, Descriptor descriptor) throws Exception {
    ListenerHolder h = context.getServletHandler().newListenerHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
    EventListener l = context.getServletContext().createInstance(clazz);
    h.setListener(l);
    context.getServletHandler().addListener(h);
    return l;
}
Also used : EventListener(java.util.EventListener) ListenerHolder(org.eclipse.jetty.servlet.ListenerHolder) Source(org.eclipse.jetty.servlet.Source)

Example 40 with EventListener

use of java.util.EventListener in project jetty.project by eclipse.

the class ContextHandler method doStop.

/* ------------------------------------------------------------ */
/*
     * @see org.eclipse.thread.AbstractLifeCycle#doStop()
     */
@Override
protected void doStop() throws Exception {
    _availability = Availability.UNAVAILABLE;
    ClassLoader old_classloader = null;
    ClassLoader old_webapploader = null;
    Thread current_thread = null;
    Context old_context = __context.get();
    enterScope(null, "doStop");
    __context.set(_scontext);
    try {
        // Set the classloader
        if (_classLoader != null) {
            old_webapploader = _classLoader;
            current_thread = Thread.currentThread();
            old_classloader = current_thread.getContextClassLoader();
            current_thread.setContextClassLoader(_classLoader);
        }
        stopContext();
        //retain only durable listeners
        setEventListeners(_durableListeners.toArray(new EventListener[_durableListeners.size()]));
        _durableListeners.clear();
        if (_errorHandler != null)
            _errorHandler.stop();
        for (EventListener l : _programmaticListeners) {
            removeEventListener(l);
            if (l instanceof ContextScopeListener) {
                try {
                    ((ContextScopeListener) l).exitScope(_scontext, null);
                } catch (Throwable e) {
                    LOG.warn(e);
                }
            }
        }
        _programmaticListeners.clear();
    } finally {
        __context.set(old_context);
        exitScope(null);
        LOG.info("Stopped {}", this);
        // reset the classloader
        if ((old_classloader == null || (old_classloader != old_webapploader)) && current_thread != null)
            current_thread.setContextClassLoader(old_classloader);
    }
    _scontext.clearAttributes();
}
Also used : ServletContext(javax.servlet.ServletContext) URLClassLoader(java.net.URLClassLoader) EventListener(java.util.EventListener)

Aggregations

EventListener (java.util.EventListener)71 Test (org.junit.Test)11 ListenerInfo (io.undertow.servlet.api.ListenerInfo)5 ServletRequestListener (javax.servlet.ServletRequestListener)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ServletContextListener (javax.servlet.ServletContextListener)3 HttpSessionListener (javax.servlet.http.HttpSessionListener)3 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)3 EventListenerList (org.eclipse.scout.rt.platform.util.EventListenerList)3 Bundle (org.osgi.framework.Bundle)3 BundleContext (org.osgi.framework.BundleContext)3 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 EventObject (java.util.EventObject)2 List (java.util.List)2 NamingException (javax.naming.NamingException)2 ServletRequestEvent (javax.servlet.ServletRequestEvent)2 HttpSessionIdListener (javax.servlet.http.HttpSessionIdListener)2