View Javadoc

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  package org.apache.portals.bridges.jsf;
17  
18  import java.util.Enumeration;
19  
20  import javax.portlet.PortletContext;
21  
22  import org.apache.portals.bridges.jsf.AbstractAttributeMap;
23  
24  /***
25   * <p>
26   * {@link PortletContext}attributes as a Map.
27   * </p>
28   * <p>
29   * See MyFaces project for servlet implementation.
30   * </p>
31   * 
32   * @author <a href="dlestrat@apache.org">David Le Strat </a>
33   */
34  public class ApplicationMap extends AbstractAttributeMap
35  {
36      /*** Illegal argument exception message. */
37      final private static String ILLEGAL_ARGUMENT = "Only PortletContext supported";
38  
39      /*** The {@link PortletContext}. */
40      final private PortletContext portletContext;
41  
42      /***
43       * @param context The context.
44       */
45      public ApplicationMap(Object context)
46      {
47          if (context instanceof PortletContext)
48          {
49              this.portletContext = (PortletContext) context;
50          }
51          else
52          {
53              throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
54          }
55      }
56  
57      /***
58       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttribute(java.lang.String)
59       */
60      public Object getAttribute(String key)
61      {
62          if (null != this.portletContext)
63          {
64              return this.portletContext.getAttribute(key);
65          }
66          else
67          {
68              throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
69          }
70      }
71  
72      /***
73       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#setAttribute(java.lang.String,
74       *      java.lang.Object)
75       */
76      public void setAttribute(String key, Object value)
77      {
78          if (null != this.portletContext)
79          {
80              this.portletContext.setAttribute(key, value);
81          }
82      }
83  
84      /***
85       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#removeAttribute(java.lang.String)
86       */
87      public void removeAttribute(String key)
88      {
89          if (null != this.portletContext)
90          {
91              this.portletContext.removeAttribute(key);
92          }
93      }
94  
95      /***
96       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttributeNames()
97       */
98      public Enumeration getAttributeNames()
99      {
100         if (null != this.portletContext)
101         {
102             return this.portletContext.getAttributeNames();
103         }
104         else
105         {
106             throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
107         }
108     }
109 }