View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.renderkit;
20  
21  import java.util.HashMap;
22  import java.util.Iterator;
23  import java.util.Map;
24  import java.util.logging.Level;
25  import java.util.logging.Logger;
26  
27  import javax.faces.FacesException;
28  import javax.faces.context.FacesContext;
29  import javax.faces.render.RenderKit;
30  import javax.faces.render.RenderKitFactory;
31  
32  /**
33   * RenderKitFactory implementation as defined in Spec. JSF.7.3
34   * 
35   * @author Manfred Geiler (latest modification by $Author: bommel $)
36   * @version $Revision: 1187700 $ $Date: 2011-10-22 07:19:37 -0500 (Sat, 22 Oct 2011) $
37   */
38  public class RenderKitFactoryImpl extends RenderKitFactory
39  {
40      //private static final Log log = LogFactory.getLog(RenderKitFactoryImpl.class);
41      private static final Logger log = Logger.getLogger(RenderKitFactoryImpl.class.getName());
42  
43      private Map<String, RenderKit> _renderkits = new HashMap<String, RenderKit>();
44  
45      public RenderKitFactoryImpl()
46      {
47      }
48  
49      public void purgeRenderKit()
50      {
51          _renderkits.clear();
52      }
53  
54      @Override
55      public void addRenderKit(String renderKitId, RenderKit renderKit)
56      {
57          if (renderKitId == null)
58              throw new NullPointerException("renderKitId");
59          if (renderKit == null)
60              throw new NullPointerException("renderKit");
61          if (log.isLoggable(Level.INFO))
62          {
63              if (_renderkits.containsKey(renderKitId))
64              {
65                  log.info("RenderKit with renderKitId '" + renderKitId + "' was replaced.");
66              }
67          }
68          _renderkits.put(renderKitId, renderKit);
69      }
70  
71      @Override
72      public RenderKit getRenderKit(FacesContext context, String renderKitId) throws FacesException
73      {
74          if (renderKitId == null)
75              throw new NullPointerException("renderKitId");
76          RenderKit renderkit = _renderkits.get(renderKitId);
77          if (renderkit == null)
78          {
79              // throw new IllegalArgumentException("Unknown RenderKit '" + renderKitId + "'.");
80              // JSF Spec API Doc says:
81              // "If there is no registered RenderKit for the specified identifier, return null"
82              // vs "IllegalArgumentException - if no RenderKit instance can be returned for the specified identifier"
83              // First sentence is more precise, so we just log a warning
84              log.warning("Unknown RenderKit '" + renderKitId + "'.");
85          }
86          return renderkit;
87      }
88  
89      @Override
90      public Iterator<String> getRenderKitIds()
91      {
92          return _renderkits.keySet().iterator();
93      }
94  }