001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jsf.cfg;
030:
031: import com.caucho.config.types.DescriptionGroupConfig;
032: import java.util.*;
033:
034: import javax.annotation.*;
035:
036: import javax.el.*;
037:
038: import javax.faces.*;
039: import javax.faces.application.*;
040: import javax.faces.component.*;
041: import javax.faces.component.html.*;
042: import javax.faces.context.*;
043: import javax.faces.convert.*;
044: import javax.faces.el.*;
045: import javax.faces.event.*;
046: import javax.faces.render.*;
047: import javax.faces.validator.*;
048:
049: import java.lang.reflect.*;
050: import javax.xml.bind.annotation.*;
051:
052: import com.caucho.config.*;
053: import com.caucho.config.j2ee.*;
054: import com.caucho.jsf.el.*;
055: import com.caucho.util.*;
056:
057: public class RenderKitConfig extends DescriptionGroupConfig {
058: private static final L10N L = new L10N(RenderKitConfig.class);
059:
060: private String _name = RenderKitFactory.HTML_BASIC_RENDER_KIT;
061: private Class _class;
062:
063: private RenderKit _renderKit;
064:
065: private ArrayList<RendererConfig> _rendererList = new ArrayList<RendererConfig>();
066:
067: public void setName(String name) {
068: _name = name;
069: }
070:
071: public void setRenderKitId(String name) {
072: setName(name);
073: }
074:
075: public void setClass(Class cl) {
076: Config.validate(cl, RenderKit.class);
077:
078: _class = cl;
079: }
080:
081: public void setRenderKitClass(Class cl) {
082: setClass(cl);
083: }
084:
085: public void addRenderer(RendererConfig renderer) {
086: _rendererList.add(renderer);
087: }
088:
089: @PostConstruct
090: public void init() throws InstantiationException,
091: IllegalAccessException {
092: if (_class != null)
093: _renderKit = (RenderKit) _class.newInstance();
094: }
095:
096: public void configure() {
097: RenderKitFactory factory = (RenderKitFactory) FactoryFinder
098: .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
099:
100: FacesContext context = new DummyFacesContext();
101:
102: RenderKit oldRenderKit = factory.getRenderKit(context, _name);
103: RenderKit renderKit = oldRenderKit;
104:
105: if (_class != null) {
106: if (oldRenderKit != null) {
107: try {
108: Constructor ctor = _class
109: .getConstructor(new Class[] { RenderKit.class });
110:
111: renderKit = (RenderKit) ctor
112: .newInstance(oldRenderKit);
113: } catch (NoSuchMethodException e) {
114: } catch (RuntimeException e) {
115: throw e;
116: } catch (Exception e) {
117: throw ConfigException.create(e);
118: }
119: }
120:
121: try {
122: renderKit = (RenderKit) _class.newInstance();
123: } catch (RuntimeException e) {
124: throw e;
125: } catch (Exception e) {
126: throw ConfigException.create(e);
127: }
128:
129: if (_name == null)
130: throw new ConfigException(L.l(
131: "'{0}' is an unknown render-kit-id.", _name));
132:
133: factory.addRenderKit(_name, renderKit);
134: }
135:
136: if (renderKit == null)
137: throw new ConfigException(L.l(
138: "'{0}' is an unknown render-kit-id.", _name));
139:
140: for (RendererConfig renderer : _rendererList)
141: renderer.configure(renderKit);
142: }
143: }
|