FileDocCategorySizeDatePackage
PortletApplicationMap.javaAPI DocExample6925Mon Jul 23 13:26:40 BST 2007org.apache.struts2.portlet

PortletApplicationMap

public class PortletApplicationMap extends AbstractMap implements Serializable
Portlet specific {@link java.util.Map} implementation representing the {@link javax.portlet.PortletContext} of a Portlet.

Fields Summary
private static final long
serialVersionUID
private javax.portlet.PortletContext
context
private Set
entries
Constructors Summary
public PortletApplicationMap(javax.portlet.PortletContext ctx)
Creates a new map object given the {@link PortletContext}.

param
ctx The portlet context.


                       
       
        this.context = ctx;
    
Methods Summary
public voidclear()
Removes all entries from the Map and removes all attributes from the portlet context.

        entries = null;

        Enumeration e = context.getAttributeNames();

        while (e.hasMoreElements()) {
            context.removeAttribute(e.nextElement().toString());
        }
    
public java.util.SetentrySet()
Creates a Set of all portlet context attributes as well as context init parameters.

return
a Set of all portlet context attributes as well as context init parameters.

        if (entries == null) {
            entries = new HashSet<Object>();

            // Add portlet context attributes
            Enumeration enumeration = context.getAttributeNames();

            while (enumeration.hasMoreElements()) {
                final String key = enumeration.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 portlet context init params
            enumeration = context.getInitParameterNames();

            while (enumeration.hasMoreElements()) {
                final String key = enumeration.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 java.lang.Objectget(java.lang.Object key)
Returns the portlet context attribute or init parameter based on the given key. If the entry is not found, null is returned.

param
key the entry key.
return
the portlet context attribute or init parameter or null if the entry is not found.

        // Try context attributes first, then init params
        // This gives the proper shadowing effects
        String keyString = key.toString();
        Object value = context.getAttribute(keyString);

        return (value == null) ? context.getInitParameter(keyString) : value;
    
public java.lang.Objectput(java.lang.Object key, java.lang.Object value)
Sets a portlet context attribute given a attribute name and value.

param
key the name of the attribute.
param
value the value to set.
return
the attribute that was just set.

        entries = null;
        context.setAttribute(key.toString(), value);

        return get(key);
    
public java.lang.Objectremove(java.lang.Object key)
Removes the specified portlet context attribute.

param
key the attribute to remove.
return
the entry that was just removed.

        entries = null;

        Object value = get(key);
        context.removeAttribute(key.toString());

        return value;