1 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 ; 24 import java.util.Enumeration ; 25 import java.util.Collections ; 26 import java.util.Map ; 27 import java.util.Iterator ; 28 import java.io.Serializable ; 29 30 31 public class AttributeContainer 32 { 33 private static final Logger logger = Logger.getLogger( AttributeContainer.class ); 34 35 private Map _attrs; 36 37 public Object getAttribute( String attrName ) 38 { 39 return ( _attrs != null ? _attrs.get( attrName ) : null ); 40 } 41 42 public void setAttribute( String attrName, Object o ) 43 { 44 if ( _attrs == null ) 45 { 46 _attrs = new HashMap (); 47 } 48 49 _attrs.put( attrName, o ); 50 } 51 52 public Enumeration getAttributeNames() 53 { 54 if ( _attrs == null ) 55 { 56 _attrs = new HashMap (); 57 } 58 59 return Collections.enumeration( _attrs.keySet() ); 60 } 61 62 public String [] getAttributeNamesArray() 63 { 64 if ( _attrs == null ) 65 { 66 return new String [0]; 67 } 68 69 return ( String [] ) _attrs.keySet().toArray( new String [0] ); 70 } 71 72 public void removeAttribute( String 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 getSerializableAttrs() 86 { 87 Map ret = new HashMap (); 88 89 for ( Iterator i = _attrs.entrySet().iterator(); i.hasNext(); ) 90 { 91 Map.Entry entry = ( Map.Entry ) i.next(); 92 93 if ( entry.getValue() instanceof Serializable ) 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 getAttrMap() 111 { 112 return _attrs; 113 } 114 115 protected final void setAttrMap( Map attrs ) 116 { 117 _attrs = attrs; 118 } 119 } 120 | Popular Tags |