use of javax.servlet.ServletContextAttributeEvent in project felix by apache.
the class ProxyServletContextListener method contextInitialized.
// ---------- ServletContextListener
@Override
public void contextInitialized(final ServletContextEvent sce) {
this.servletContext = sce.getServletContext();
// add all required listeners
this.servletContext.addListener(new HttpSessionListener() {
private HttpSessionListener getHttpSessionListener() {
final EventDispatcherTracker tracker = eventDispatcherTracker;
if (tracker != null) {
return tracker.getHttpSessionListener();
}
return null;
}
@Override
public void sessionCreated(final HttpSessionEvent se) {
final HttpSessionListener sessionDispatcher = getHttpSessionListener();
if (sessionDispatcher != null) {
sessionDispatcher.sessionCreated(se);
}
}
@Override
public void sessionDestroyed(final HttpSessionEvent se) {
final HttpSessionListener sessionDispatcher = getHttpSessionListener();
if (sessionDispatcher != null) {
sessionDispatcher.sessionDestroyed(se);
}
}
});
this.servletContext.addListener(new HttpSessionIdListener() {
private HttpSessionIdListener getHttpSessionIdListener() {
final EventDispatcherTracker tracker = eventDispatcherTracker;
if (tracker != null) {
return tracker.getHttpSessionIdListener();
}
return null;
}
@Override
public void sessionIdChanged(final HttpSessionEvent event, final String oldSessionId) {
final HttpSessionIdListener sessionIdDispatcher = getHttpSessionIdListener();
if (sessionIdDispatcher != null) {
sessionIdDispatcher.sessionIdChanged(event, oldSessionId);
}
}
});
this.servletContext.addListener(new HttpSessionAttributeListener() {
private HttpSessionAttributeListener getHttpSessionAttributeListener() {
final EventDispatcherTracker tracker = eventDispatcherTracker;
if (tracker != null) {
return tracker.getHttpSessionAttributeListener();
}
return null;
}
@Override
public void attributeAdded(final HttpSessionBindingEvent se) {
final HttpSessionAttributeListener attributeDispatcher = getHttpSessionAttributeListener();
if (attributeDispatcher != null) {
attributeDispatcher.attributeAdded(se);
}
}
@Override
public void attributeRemoved(final HttpSessionBindingEvent se) {
final HttpSessionAttributeListener attributeDispatcher = getHttpSessionAttributeListener();
if (attributeDispatcher != null) {
attributeDispatcher.attributeRemoved(se);
}
}
@Override
public void attributeReplaced(final HttpSessionBindingEvent se) {
final HttpSessionAttributeListener attributeDispatcher = getHttpSessionAttributeListener();
if (attributeDispatcher != null) {
attributeDispatcher.attributeReplaced(se);
}
}
});
this.servletContext.addListener(new ServletContextAttributeListener() {
@Override
public void attributeAdded(final ServletContextAttributeEvent event) {
if (event.getName().equals(BundleContext.class.getName())) {
startTracker(event.getValue());
}
}
@Override
public void attributeRemoved(final ServletContextAttributeEvent event) {
if (event.getName().equals(BundleContext.class.getName())) {
stopTracker();
}
}
@Override
public void attributeReplaced(final ServletContextAttributeEvent event) {
if (event.getName().equals(BundleContext.class.getName())) {
stopTracker();
startTracker(event.getServletContext().getAttribute(event.getName()));
}
}
});
}
use of javax.servlet.ServletContextAttributeEvent in project tomcat70 by apache.
the class ApplicationContext method setAttribute.
/**
* Bind the specified value with the specified context attribute name,
* replacing any existing value for that name.
*
* @param name Attribute name to be bound
* @param value New attribute value to be bound
*/
@Override
public void setAttribute(String name, Object value) {
// Name cannot be null
if (name == null)
throw new IllegalArgumentException(sm.getString("applicationContext.setAttribute.namenull"));
// Null value is the same as removeAttribute()
if (value == null) {
removeAttribute(name);
return;
}
// Check for read only attribute
if (readOnlyAttributes.containsKey(name))
return;
Object oldValue = attributes.put(name, value);
boolean replaced = oldValue != null;
// Notify interested application event listeners
Object[] listeners = context.getApplicationEventListeners();
if ((listeners == null) || (listeners.length == 0))
return;
ServletContextAttributeEvent event = null;
if (replaced)
event = new ServletContextAttributeEvent(context.getServletContext(), name, oldValue);
else
event = new ServletContextAttributeEvent(context.getServletContext(), name, value);
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof ServletContextAttributeListener))
continue;
ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners[i];
try {
if (replaced) {
context.fireContainerEvent("beforeContextAttributeReplaced", listener);
listener.attributeReplaced(event);
context.fireContainerEvent("afterContextAttributeReplaced", listener);
} else {
context.fireContainerEvent("beforeContextAttributeAdded", listener);
listener.attributeAdded(event);
context.fireContainerEvent("afterContextAttributeAdded", listener);
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
if (replaced)
context.fireContainerEvent("afterContextAttributeReplaced", listener);
else
context.fireContainerEvent("afterContextAttributeAdded", listener);
// FIXME - should we do anything besides log these?
log(sm.getString("applicationContext.attributeEvent"), t);
}
}
}
use of javax.servlet.ServletContextAttributeEvent in project opennms by OpenNMS.
the class ServletContextImpl method removeAttribute.
@Override
public void removeAttribute(String name) {
Object oldValue;
if (this.attributes != null) {
oldValue = this.attributes.remove(name);
} else {
oldValue = this.context.getAttribute(name);
this.context.removeAttribute(name);
}
if (oldValue != null) {
attributeListener.attributeRemoved(new ServletContextAttributeEvent(this, name, oldValue));
}
}
use of javax.servlet.ServletContextAttributeEvent in project felix by apache.
the class ServletContextImpl method removeAttribute.
@Override
public void removeAttribute(String name) {
Object oldValue;
if (this.attributes != null) {
oldValue = this.attributes.remove(name);
} else {
oldValue = this.context.getAttribute(name);
this.context.removeAttribute(name);
}
if (oldValue != null) {
this.handlerRegistry.getEventListenerRegistry().attributeRemoved(new ServletContextAttributeEvent(this, name, oldValue));
}
}
use of javax.servlet.ServletContextAttributeEvent in project tomcat70 by apache.
the class ApplicationContext method removeAttribute.
/**
* Remove the context attribute with the specified name, if any.
*
* @param name Name of the context attribute to be removed
*/
@Override
public void removeAttribute(String name) {
Object value = null;
// Check for read only attribute
if (readOnlyAttributes.containsKey(name)) {
return;
}
value = attributes.remove(name);
if (value == null) {
return;
}
// Notify interested application event listeners
Object[] listeners = context.getApplicationEventListeners();
if ((listeners == null) || (listeners.length == 0))
return;
ServletContextAttributeEvent event = new ServletContextAttributeEvent(context.getServletContext(), name, value);
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof ServletContextAttributeListener))
continue;
ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners[i];
try {
context.fireContainerEvent("beforeContextAttributeRemoved", listener);
listener.attributeRemoved(event);
context.fireContainerEvent("afterContextAttributeRemoved", listener);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
context.fireContainerEvent("afterContextAttributeRemoved", listener);
// FIXME - should we do anything besides log these?
log(sm.getString("applicationContext.attributeEvent"), t);
}
}
}
Aggregations