📄 applicationmap.java
字号:
/* * WebWork, Web Application Framework * * Distributable under Apache license. * See terms of license at opensource.org */package webwork.action.factory;import javax.servlet.ServletContext;import java.util.*;/** * @author Rickard 謆erg (rickard@middleware-company.com) * @version $Revision: 1.8 $ */public class ApplicationMap extends AbstractMap{ ServletContext context; Set entries; public ApplicationMap(ServletContext ctx) { this.context = ctx; } public Set entrySet() { if (entries == null) { entries = new HashSet(); // Add servlet context attributes Enumeration enum = context.getAttributeNames(); while (enum.hasMoreElements()) { final String key = enum.nextElement().toString(); final Object value = context.getAttribute(key); entries.add(new Map.Entry() { public boolean equals(Object obj) { Map.Entry entry = (Map.Entry)obj; return (key==null ? entry.getKey()==null : key.equals(entry.getKey())) && (value==null ? entry.getValue()==null : value.equals(entry.getValue())); } public int hashCode() { return (key==null ? 0 : key.hashCode()) ^ (value==null ? 0 : value.hashCode()); } public Object getKey() { return key; } public Object getValue() { return value; } public Object setValue(Object obj) { context.setAttribute(key.toString(), obj); return value; } }); } // Add servlet context init parameters enum = context.getInitParameterNames(); while (enum.hasMoreElements()) { final String key = enum.nextElement().toString(); final Object value = context.getInitParameter(key); entries.add(new Map.Entry() { public boolean equals(Object obj) { Map.Entry entry = (Map.Entry)obj; return (key==null ? entry.getKey()==null : key.equals(entry.getKey())) && (value==null ? entry.getValue()==null : value.equals(entry.getValue())); } public int hashCode() { return (key==null ? 0 : key.hashCode()) ^ (value==null ? 0 : value.hashCode()); } public Object getKey() { return key; } public Object getValue() { return value; } public Object setValue(Object obj) { context.setAttribute(key.toString(), obj); return value; } }); } } return entries; } public Object put(Object key, Object value) { entries = null; context.setAttribute(key.toString(), value); return get(key); } public Object get(Object key) { // Try context attributes first, then init parameters // This gives the proper shadowing effects String keyString = key.toString(); Object value = context.getAttribute(keyString); return value == null ? context.getInitParameter(keyString) : value; } public Object remove(Object key) { entries = null; Object value = get(key); context.removeAttribute(key.toString()); return value; } public void clear() { entries = null; Enumeration enum = context.getAttributeNames(); while (enum.hasMoreElements()) { context.removeAttribute(enum.nextElement().toString()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -