下面列出了怎么用javax.servlet.ServletContextAttributeEvent的API类实例代码及写法,或者点击链接到github查看源代码。
@SuppressWarnings("unchecked")
@Override
public void attributeAdded(ServletContextAttributeEvent arg0) {
if(userMap == null){
userMap = (Map<Integer, WsOutbound>) arg0.getServletContext().getAttribute("OnLineList");
}
//System.out.println("listener==>attributeAdded");
Enumeration<String> att = arg0.getServletContext().getAttributeNames();
while(att.hasMoreElements()){
String next = att.nextElement();
if(next.startsWith("action")){
ServerMsg message = (ServerMsg) arg0.getServletContext().getAttribute(next);
if(message != null){
arg0.getServletContext().removeAttribute(next);
doAction(message);
}
}
}
}
/**
* Record the fact that a servlet context attribute was added.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeAdded(ServletContextAttributeEvent event) {
log("attributeAdded('" + event.getName() + "', '" +
event.getValue() + "')");
}
/**
* Record the fact that a servlet context attribute was removed.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeRemoved(ServletContextAttributeEvent event) {
log("attributeRemoved('" + event.getName() + "', '" +
event.getValue() + "')");
}
/**
* Record the fact that a servlet context attribute was replaced.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeReplaced(ServletContextAttributeEvent event) {
log("attributeReplaced('" + event.getName() + "', '" +
event.getValue() + "')");
}
@Override
public void removeAttribute(String name) {
Object value = null;
// Remove the specified attribute
// 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 (Object obj : listeners) {
if (!(obj instanceof ServletContextAttributeListener)) {
continue;
}
ServletContextAttributeListener listener = (ServletContextAttributeListener) obj;
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);
}
}
}
/**
* Record the fact that a servlet context attribute was added.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeAdded(ServletContextAttributeEvent event) {
log("attributeAdded('" + event.getName() + "', '" +
event.getValue() + "')");
}
/**
* Record the fact that a servlet context attribute was removed.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeRemoved(ServletContextAttributeEvent event) {
log("attributeRemoved('" + event.getName() + "', '" +
event.getValue() + "')");
}
/**
* Record the fact that a servlet context attribute was replaced.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeReplaced(ServletContextAttributeEvent event) {
log("attributeReplaced('" + event.getName() + "', '" +
event.getValue() + "')");
}
public void servletContextAttributeAdded(final String name, final Object value) {
if(!started) {
return;
}
final ServletContextAttributeEvent sre = new ServletContextAttributeEvent(servletContext, name, value);
for (int i = 0; i < servletContextAttributeListeners.length; ++i) {
this.<ServletContextAttributeListener>get(servletContextAttributeListeners[i]).attributeAdded(sre);
}
}
public void servletContextAttributeRemoved(final String name, final Object value) {
if(!started) {
return;
}
final ServletContextAttributeEvent sre = new ServletContextAttributeEvent(servletContext, name, value);
for (int i = 0; i < servletContextAttributeListeners.length; ++i) {
this.<ServletContextAttributeListener>get(servletContextAttributeListeners[i]).attributeRemoved(sre);
}
}
public void servletContextAttributeReplaced(final String name, final Object value) {
if(!started) {
return;
}
final ServletContextAttributeEvent sre = new ServletContextAttributeEvent(servletContext, name, value);
for (int i = 0; i < servletContextAttributeListeners.length; ++i) {
this.<ServletContextAttributeListener>get(servletContextAttributeListeners[i]).attributeReplaced(sre);
}
}
/**
* Handle attribute added event.
*
* @param event the event.
*/
@Override
public void attributeAdded(ServletContextAttributeEvent event) {
if (event.getName().equals("attributeAdded")) {
event.getServletContext().setAttribute("attributeAdded2", true);
}
}
/**
* Handle attribute removed event.
*
* @param event the event.
*/
@Override
public void attributeRemoved(ServletContextAttributeEvent event) {
if (event.getName().equals("attributeRemoved")) {
event.getServletContext().setAttribute("attributeRemoved2", true);
}
}
/**
* Handle attribute replaced event.
*
* @param event the event.
*/
@Override
public void attributeReplaced(ServletContextAttributeEvent event) {
if (event.getName().equals("attributeReplaced")) {
event.getServletContext().setAttribute("attributeReplaced2", true);
}
}
public void servletContextAttributeAdded(final String name, final Object value) {
if(!started) {
return;
}
final ServletContextAttributeEvent sre = new ServletContextAttributeEvent(servletContext, name, value);
for (int i = 0; i < servletContextAttributeListeners.length; ++i) {
this.<ServletContextAttributeListener>get(servletContextAttributeListeners[i]).attributeAdded(sre);
}
}
public void servletContextAttributeRemoved(final String name, final Object value) {
if(!started) {
return;
}
final ServletContextAttributeEvent sre = new ServletContextAttributeEvent(servletContext, name, value);
for (int i = 0; i < servletContextAttributeListeners.length; ++i) {
this.<ServletContextAttributeListener>get(servletContextAttributeListeners[i]).attributeRemoved(sre);
}
}
public void servletContextAttributeReplaced(final String name, final Object value) {
if(!started) {
return;
}
final ServletContextAttributeEvent sre = new ServletContextAttributeEvent(servletContext, name, value);
for (int i = 0; i < servletContextAttributeListeners.length; ++i) {
this.<ServletContextAttributeListener>get(servletContextAttributeListeners[i]).attributeReplaced(sre);
}
}
/**
* Record the fact that a servlet context attribute was added.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeAdded(ServletContextAttributeEvent event) {
log("attributeAdded('" + event.getName() + "', '" +
event.getValue() + "')");
}
/**
* Record the fact that a servlet context attribute was removed.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeRemoved(ServletContextAttributeEvent event) {
log("attributeRemoved('" + event.getName() + "', '" +
event.getValue() + "')");
}
/**
* Record the fact that a servlet context attribute was replaced.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeReplaced(ServletContextAttributeEvent event) {
log("attributeReplaced('" + event.getName() + "', '" +
event.getValue() + "')");
}
/**
* Record the fact that a servlet context attribute was added.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeAdded(ServletContextAttributeEvent event) {
log("attributeAdded('" + event.getName() + "', '" +
event.getValue() + "')");
}
/**
* Record the fact that a servlet context attribute was removed.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeRemoved(ServletContextAttributeEvent event) {
log("attributeRemoved('" + event.getName() + "', '" +
event.getValue() + "')");
}
/**
* Record the fact that a servlet context attribute was replaced.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeReplaced(ServletContextAttributeEvent event) {
log("attributeReplaced('" + event.getName() + "', '" +
event.getValue() + "')");
}
/**
* Record the fact that a servlet context attribute was added.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeAdded(ServletContextAttributeEvent event) {
log("attributeAdded('" + event.getName() + "', '" +
event.getValue() + "')");
}
/**
* Record the fact that a servlet context attribute was removed.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeRemoved(ServletContextAttributeEvent event) {
log("attributeRemoved('" + event.getName() + "', '" +
event.getValue() + "')");
}
/**
* Record the fact that a servlet context attribute was replaced.
*
* @param event The servlet context attribute event
*/
@Override
public void attributeReplaced(ServletContextAttributeEvent event) {
log("attributeReplaced('" + event.getName() + "', '" +
event.getValue() + "')");
}
@Override
public void attributeAdded(final ServletContextAttributeEvent event) {
servletContextAttributeEvent = event;
}
@Override
public void attributeRemoved(final ServletContextAttributeEvent event) {
servletContextAttributeEvent = event;
}
@Override
public void attributeReplaced(final ServletContextAttributeEvent event) {
servletContextAttributeEvent = event;
}
@Override
public void attributeAdded(ServletContextAttributeEvent event) {
DEQUE.add("dl add " + event.getName());
}