01: /*
02: * Copyright 2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
26: import java.util.Iterator;
27: import java.util.Map;
28:
29: /**
30: * RenderKitFactory implementation as defined in Spec. JSF.7.3
31: * @author Manfred Geiler (latest modification by $Author: mbr $)
32: * @version $Revision: 511490 $ $Date: 2007-02-25 13:45:23 +0100 (So, 25 Feb 2007) $
33: */
34: public class RenderKitFactoryImpl extends RenderKitFactory {
35: private static final Log log = LogFactory
36: .getLog(RenderKitFactoryImpl.class);
37:
38: private Map<String, RenderKit> _renderkits = new HashMap<String, RenderKit>();
39:
40: public RenderKitFactoryImpl() {
41: }
42:
43: public void addRenderKit(String renderKitId, RenderKit renderKit) {
44: if (renderKitId == null)
45: throw new NullPointerException("renderKitId");
46: if (renderKit == null)
47: throw new NullPointerException("renderKit");
48: if (log.isInfoEnabled()) {
49: if (_renderkits.containsKey(renderKitId)) {
50: log.info("RenderKit with renderKitId '" + renderKitId
51: + "' was replaced.");
52: }
53: }
54: _renderkits.put(renderKitId, renderKit);
55: }
56:
57: public RenderKit getRenderKit(FacesContext context,
58: String renderKitId) throws FacesException {
59: if (renderKitId == null)
60: throw new NullPointerException("renderKitId");
61: RenderKit renderkit = _renderkits.get(renderKitId);
62: if (renderkit == null) {
63: //throw new IllegalArgumentException("Unknown RenderKit '" + renderKitId + "'.");
64: //JSF Spec API Doc says:
65: // "If there is no registered RenderKit for the specified identifier, return null"
66: // vs "IllegalArgumentException - if no RenderKit instance can be returned for the specified identifier"
67: //First sentence is more precise, so we just log a warning
68: log.warn("Unknown RenderKit '" + renderKitId + "'.");
69: }
70: return renderkit;
71: }
72:
73: public Iterator<String> getRenderKitIds() {
74: return _renderkits.keySet().iterator();
75: }
76: }
|