KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > scoping > internal > AttributeContainer


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.pageflow.scoping.internal;
19
20 import org.apache.log4j.Logger;
21 import org.apache.log4j.Priority;
22
23 import java.util.HashMap JavaDoc;
24 import java.util.Enumeration JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.io.Serializable JavaDoc;
29
30
31 public class AttributeContainer
32 {
33     private static final Logger logger = Logger.getLogger( AttributeContainer.class );
34     
35     private Map JavaDoc _attrs;
36
37     public Object JavaDoc getAttribute( String JavaDoc attrName )
38     {
39         return ( _attrs != null ? _attrs.get( attrName ) : null );
40     }
41
42     public void setAttribute( String JavaDoc attrName, Object JavaDoc o )
43     {
44         if ( _attrs == null )
45         {
46             _attrs = new HashMap JavaDoc();
47         }
48
49         _attrs.put( attrName, o );
50     }
51
52     public Enumeration JavaDoc getAttributeNames()
53     {
54         if ( _attrs == null )
55         {
56             _attrs = new HashMap JavaDoc();
57         }
58
59         return Collections.enumeration( _attrs.keySet() );
60     }
61
62     public String JavaDoc[] getAttributeNamesArray()
63     {
64         if ( _attrs == null )
65         {
66             return new String JavaDoc[0];
67         }
68
69         return ( String JavaDoc[] ) _attrs.keySet().toArray( new String JavaDoc[0] );
70     }
71
72     public void removeAttribute( String JavaDoc attrName )
73     {
74         if ( _attrs != null )
75         {
76             _attrs.remove( attrName );
77         }
78     }
79
80     public void removeAllAttributes()
81     {
82         _attrs = null;
83     }
84
85     protected final Map JavaDoc getSerializableAttrs()
86     {
87         Map JavaDoc ret = new HashMap JavaDoc();
88
89         for ( Iterator JavaDoc i = _attrs.entrySet().iterator(); i.hasNext(); )
90         {
91             Map.Entry JavaDoc entry = ( Map.Entry JavaDoc ) i.next();
92
93             if ( entry.getValue() instanceof Serializable JavaDoc )
94             {
95                 ret.put( entry.getKey(), entry.getValue() );
96             }
97             else
98             {
99                 if ( logger.isEnabledFor( Priority.INFO ) )
100                 {
101                     logger.info( "Dropping non-serializable request attribute " + entry.getKey()
102                                   + " (" + entry.getValue() + ")." );
103                 }
104             }
105         }
106
107         return ret;
108     }
109     
110     protected final Map JavaDoc getAttrMap()
111     {
112         return _attrs;
113     }
114
115     protected final void setAttrMap( Map JavaDoc attrs )
116     {
117         _attrs = attrs;
118     }
119 }
120
Popular Tags