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);
}
}
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);
}
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;
}
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;
}
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();
}
Aggregations