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 org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  
24  import javax.faces.FacesException;
25  import javax.faces.context.FacesContext;
26  import javax.faces.render.RenderKit;
27  import javax.faces.render.RenderKitFactory;
28  import java.util.HashMap;
29  import java.util.Iterator;
30  import java.util.Map;
31  
32  /**
33   * RenderKitFactory implementation as defined in Spec. JSF.7.3
34   * @author Manfred Geiler (latest modification by $Author: skitching $)
35   * @version $Revision: 684465 $ $Date: 2008-08-10 06:38:21 -0500 (Sun, 10 Aug 2008) $
36   */
37  public class RenderKitFactoryImpl
38      extends RenderKitFactory
39  {
40      private static final Log log = LogFactory.getLog(RenderKitFactoryImpl.class);
41  
42      private Map<String, RenderKit> _renderkits = new HashMap<String, RenderKit>();
43  
44      public RenderKitFactoryImpl()
45      {
46      }
47  
48      public void purgeRenderKit()
49      {
50          _renderkits.clear();
51      }
52      
53      public void addRenderKit(String renderKitId, RenderKit renderKit)
54      {
55          if (renderKitId == null) throw new NullPointerException("renderKitId");
56          if (renderKit == null) throw new NullPointerException("renderKit");
57          if (log.isInfoEnabled())
58          {
59              if (_renderkits.containsKey(renderKitId))
60              {
61                  log.info("RenderKit with renderKitId '" + renderKitId + "' was replaced.");
62              }
63          }
64          _renderkits.put(renderKitId, renderKit);
65      }
66  
67  
68      public RenderKit getRenderKit(FacesContext context, String renderKitId)
69              throws FacesException
70      {
71          if (renderKitId == null) throw new NullPointerException("renderKitId");
72          RenderKit renderkit = _renderkits.get(renderKitId);
73          if (renderkit == null)
74          {
75              //throw new IllegalArgumentException("Unknown RenderKit '" + renderKitId + "'.");
76              //JSF Spec API Doc says:
77              // "If there is no registered RenderKit for the specified identifier, return null"
78              // vs "IllegalArgumentException - if no RenderKit instance can be returned for the specified identifier"
79              //First sentence is more precise, so we just log a warning
80              log.warn("Unknown RenderKit '" + renderKitId + "'.");
81          }
82          return renderkit;
83      }
84  
85  
86      public Iterator<String> getRenderKitIds()
87      {
88          return _renderkits.keySet().iterator();
89      }
90  }