001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jsf.context;
030:
031: import java.io.*;
032: import java.net.URL;
033: import java.net.MalformedURLException;
034: import java.util.*;
035: import java.security.*;
036:
037: import javax.faces.*;
038: import javax.faces.context.*;
039:
040: import javax.servlet.*;
041: import javax.servlet.http.*;
042:
043: import com.caucho.server.connection.*;
044:
045: abstract class AttributeMap extends AbstractMap<String, Object> {
046: public abstract Enumeration getNames();
047:
048: abstract public Object get(String key);
049:
050: abstract public Object put(String key, Object value);
051:
052: abstract public Object remove(String key);
053:
054: public Set<Map.Entry<String, Object>> entrySet() {
055: return new EntrySet();
056: }
057:
058: class EntrySet extends AbstractSet<Map.Entry<String, Object>> {
059: public int size() {
060: int count = 0;
061:
062: Enumeration e = getNames();
063: while (e.hasMoreElements()) {
064: count++;
065:
066: e.nextElement();
067: }
068:
069: return count;
070: }
071:
072: public Iterator<Map.Entry<String, Object>> iterator() {
073: return new EntryIterator();
074: }
075: }
076:
077: class EntryIterator implements Iterator<Map.Entry<String, Object>> {
078: private Enumeration _e;
079: private String _lastName;
080:
081: EntryIterator() {
082: _e = getNames();
083: }
084:
085: public boolean hasNext() {
086: return _e.hasMoreElements();
087: }
088:
089: public Map.Entry<String, Object> next() {
090: _lastName = (String) _e.nextElement();
091: return new AttrEntry(_lastName);
092: }
093:
094: public void remove() {
095: AttributeMap.this .remove(_lastName);
096: }
097: }
098:
099: class AttrEntry implements Map.Entry<String, Object> {
100: String _key;
101:
102: AttrEntry(String key) {
103: _key = key;
104: }
105:
106: public String getKey() {
107: return _key;
108: }
109:
110: public Object getValue() {
111: return get(_key);
112: }
113:
114: public Object setValue(Object value) {
115: return put(_key, value);
116: }
117:
118: public int hashCode() {
119: return _key.hashCode();
120: }
121:
122: public boolean equals(Object o) {
123: if (this == o)
124: return true;
125: else if (!(o instanceof AttrEntry))
126: return false;
127:
128: AttrEntry entry = (AttrEntry) o;
129:
130: return _key.equals(entry._key);
131: }
132: }
133: }
|