001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.pageflow.scoping.internal;
020:
021: import org.apache.beehive.netui.util.logging.Logger;
022:
023: import java.util.HashMap;
024: import java.util.Enumeration;
025: import java.util.Collections;
026: import java.util.Map;
027: import java.util.Iterator;
028: import java.io.Serializable;
029:
030: public class AttributeContainer {
031: private static final Logger logger = Logger
032: .getInstance(AttributeContainer.class);
033:
034: private Map _attrs;
035:
036: public Object getAttribute(String attrName) {
037: return (_attrs != null ? _attrs.get(attrName) : null);
038: }
039:
040: public void setAttribute(String attrName, Object o) {
041: if (_attrs == null) {
042: _attrs = new HashMap();
043: }
044:
045: _attrs.put(attrName, o);
046: }
047:
048: public Enumeration getAttributeNames() {
049: if (_attrs == null) {
050: _attrs = new HashMap();
051: }
052:
053: return Collections.enumeration(_attrs.keySet());
054: }
055:
056: public String[] getAttributeNamesArray() {
057: if (_attrs == null) {
058: return new String[0];
059: }
060:
061: return (String[]) _attrs.keySet().toArray(new String[0]);
062: }
063:
064: public void removeAttribute(String attrName) {
065: if (_attrs != null) {
066: _attrs.remove(attrName);
067: }
068: }
069:
070: public void removeAllAttributes() {
071: _attrs = null;
072: }
073:
074: protected final Map getSerializableAttrs() {
075: Map ret = new HashMap();
076:
077: for (Iterator i = _attrs.entrySet().iterator(); i.hasNext();) {
078: Map.Entry entry = (Map.Entry) i.next();
079:
080: if (entry.getValue() instanceof Serializable) {
081: ret.put(entry.getKey(), entry.getValue());
082: } else {
083: if (logger.isInfoEnabled()) {
084: logger
085: .info("Dropping non-serializable request attribute "
086: + entry.getKey()
087: + " ("
088: + entry.getValue() + ").");
089: }
090: }
091: }
092:
093: return ret;
094: }
095:
096: protected final Map getAttrMap() {
097: return _attrs;
098: }
099:
100: protected final void setAttrMap(Map attrs) {
101: _attrs = attrs;
102: }
103: }
|