KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > renderkit > RenderKitFactoryImpl


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.myfaces.renderkit;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20
21 import javax.faces.FacesException;
22 import javax.faces.context.FacesContext;
23 import javax.faces.render.RenderKit;
24 import javax.faces.render.RenderKitFactory;
25 import java.util.HashMap JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28
29 /**
30  * RenderKitFactory implementation as defined in Spec. JSF.7.3
31  * @author Manfred Geiler (latest modification by $Author: matze $)
32  * @version $Revision: 1.15 $ $Date: 2004/10/13 11:51:00 $
33  * $Log: RenderKitFactoryImpl.java,v $
34  * Revision 1.15 2004/10/13 11:51:00 matze
35  * renamed packages to org.apache
36  *
37  * Revision 1.14 2004/07/05 12:52:41 manolito
38  * Apache License
39  *
40  * Revision 1.13 2004/06/23 15:48:01 manolito
41  * Map members now non-static
42  *
43  * Revision 1.12 2004/05/18 07:13:32 manolito
44  * X-checked against specs: no more synchronization needed, allow replacement of renderKit, no excepetion on unknown id
45  *
46  */

47 public class RenderKitFactoryImpl
48     extends RenderKitFactory
49 {
50     private static final Log log = LogFactory.getLog(RenderKitFactoryImpl.class);
51
52     private Map JavaDoc _renderkits = new HashMap JavaDoc();
53
54     public RenderKitFactoryImpl()
55     {
56     }
57
58
59     public void addRenderKit(String JavaDoc renderKitId, RenderKit renderKit)
60     {
61         if (renderKitId == null) throw new NullPointerException JavaDoc("renderKitId");
62         if (renderKit == null) throw new NullPointerException JavaDoc("renderKit");
63         if (log.isInfoEnabled())
64         {
65             if (_renderkits.containsKey(renderKitId))
66             {
67                 log.info("RenderKit with renderKitId '" + renderKitId + "' was replaced.");
68             }
69         }
70         _renderkits.put(renderKitId, renderKit);
71     }
72
73
74     public RenderKit getRenderKit(FacesContext context, String JavaDoc renderKitId)
75             throws FacesException
76     {
77         if (renderKitId == null) throw new NullPointerException JavaDoc("renderKitId");
78         RenderKit renderkit = (RenderKit)_renderkits.get(renderKitId);
79         if (renderkit == null)
80         {
81             //throw new IllegalArgumentException("Unknown RenderKit '" + renderKitId + "'.");
82
//JSF Spec API Doc says:
83
// "If there is no registered RenderKit for the specified identifier, return null"
84
// vs "IllegalArgumentException - if no RenderKit instance can be returned for the specified identifier"
85
//First sentence is more precise, so we just log a warning
86
log.warn("Unknown RenderKit '" + renderKitId + "'.");
87         }
88         return renderkit;
89     }
90
91
92     public Iterator JavaDoc getRenderKitIds()
93     {
94         return _renderkits.keySet().iterator();
95     }
96 }
97
Popular Tags