Author: craigmcc Date: Wed Jan 25 12:09:24 2006 New Revision: 372303 URL: http://svn.apache.org/viewcvs?rev=372303&view=rev Log: The Shale Tiger Extensions now support the ability for JSF components, converters, renderers, and validators to register themselves with the JSF runtime, without having to be declared in a faces-config.xml file.
Thanks to Gary vanMatre for the suggestion to do this. Added: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/ struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesComponent.java (with props) struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesConverter.java (with props) struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesRenderer.java (with props) struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesValidator.java (with props) struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/package.html (with props) struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyComponent.java (with props) struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyConverter.java (with props) struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyRenderer.java (with props) struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyValidator.java (with props) Modified: struts/shale/trunk/tiger/build.xml struts/shale/trunk/tiger/nbproject/project.xml struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/faces/LifecycleListener.java struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/LifecycleListenerTestCase.java struts/shale/trunk/xdocs/features-tiger-extensions.xml Modified: struts/shale/trunk/tiger/build.xml URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/build.xml?rev=372303&r1=372302&r2=372303&view=diff ============================================================================== --- struts/shale/trunk/tiger/build.xml (original) +++ struts/shale/trunk/tiger/build.xml Wed Jan 25 12:09:24 2006 @@ -273,6 +273,13 @@ </fileset> </copy> + <!-- Copy runtime objects to webapp structure --> + <mkdir dir="${build.home}/test-webapp/WEB-INF/classes/org/apache/shale/tiger/faces"/> + <copy todir="${build.home}/test-webapp/WEB-INF/classes/org/apache/shale/tiger/faces"> + <fileset dir="${build.home}/test-classes/org/apache/shale/tiger/faces" + includes="My*.class"/> + </copy> + </target> Modified: struts/shale/trunk/tiger/nbproject/project.xml URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/nbproject/project.xml?rev=372303&r1=372302&r2=372303&view=diff ============================================================================== --- struts/shale/trunk/tiger/nbproject/project.xml (original) +++ struts/shale/trunk/tiger/nbproject/project.xml Wed Jan 25 12:09:24 2006 @@ -1,88 +1,88 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://www.netbeans.org/ns/project/1"> - <type>org.netbeans.modules.ant.freeform</type> - <configuration> - <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1"> - <!-- Do not use Project Properties customizer when editing this file manually. --> - <name>Shale Tiger Extensions</name> - <properties/> - <folders> - <source-folder> - <label>Configuration Files</label> - <type>java</type> - <location>src/conf</location> - </source-folder> - <source-folder> - <label>Java Sources</label> - <type>java</type> - <location>src/java</location> - </source-folder> - <source-folder> - <label>Test Sources</label> - <type>java</type> - <location>src/test</location> - </source-folder> - </folders> - <ide-actions> - <action name="build"> - <target>compile</target> - </action> - <action name="clean"> - <target>clean</target> - </action> - <action name="javadoc"> - <target>docs</target> - </action> - <action name="test"> - <target>test</target> - </action> - <action name="rebuild"> - <target>clean</target> - <target>compile</target> - </action> - </ide-actions> - <export> - <type>folder</type> - <location>target/classes</location> - <build-target>compile</build-target> - </export> - <view> - <items> - <source-folder style="packages"> - <label>Configuration Files</label> - <location>src/conf</location> - </source-folder> - <source-folder style="packages"> - <label>Java Sources</label> - <location>src/java</location> - </source-folder> - <source-folder style="packages"> - <label>Test Sources</label> - <location>src/test</location> - </source-folder> - <source-file> - <location>build.xml</location> - </source-file> - </items> - <context-menu> - <ide-action name="build"/> - <ide-action name="clean"/> - <ide-action name="javadoc"/> - <ide-action name="test"/> - <ide-action name="rebuild"/> - </context-menu> - </view> - <subprojects/> - </general-data> - <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/1"> - <compilation-unit> - <package-root>src/conf</package-root> - <package-root>src/java</package-root> - <package-root>src/test</package-root> - <classpath mode="compile">../core-library/target/lib/shale-core.jar;../test-framework/target/lib/shale-test.jar;../../../../../usr/local/jsf-1_1_01/lib/jsf-api.jar;../../../../../usr/local/jsf-1_1_01/lib/commons-digester.jar;../../../../../usr/local/jsf-1_1_01/lib/commons-beanutils.jar;../../../../../usr/local/jsf-1_1_01/lib/commons-collections.jar;../../../../../usr/local/jsf-1_1_01/lib/commons-logging.jar;../../../../../usr/local/junit3.8.1/junit.jar;../../../../../usr/local/jakarta-tomcat-5.0.28/common/lib/jsp-api.jar;../../../../../usr/local/jakarta-tomcat-5.0.28/common/lib/servlet-api.jar</classpath> - <built-to>target/classes</built-to> - <source-level>1.5</source-level> - </compilation-unit> - </java-data> - </configuration> -</project> +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.ant.freeform</type> + <configuration> + <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1"> + <!-- Do not use Project Properties customizer when editing this file manually. --> + <name>Shale Tiger Extensions</name> + <properties/> + <folders> + <source-folder> + <label>Configuration Files</label> + <type>java</type> + <location>src/conf</location> + </source-folder> + <source-folder> + <label>Java Sources</label> + <type>java</type> + <location>src/java</location> + </source-folder> + <source-folder> + <label>Test Sources</label> + <type>java</type> + <location>src/test</location> + </source-folder> + </folders> + <ide-actions> + <action name="build"> + <target>compile</target> + </action> + <action name="clean"> + <target>clean</target> + </action> + <action name="javadoc"> + <target>docs</target> + </action> + <action name="test"> + <target>test</target> + </action> + <action name="rebuild"> + <target>clean</target> + <target>compile</target> + </action> + </ide-actions> + <export> + <type>folder</type> + <location>target/classes</location> + <build-target>compile</build-target> + </export> + <view> + <items> + <source-folder style="packages"> + <label>Configuration Files</label> + <location>src/conf</location> + </source-folder> + <source-folder style="packages"> + <label>Java Sources</label> + <location>src/java</location> + </source-folder> + <source-folder style="packages"> + <label>Test Sources</label> + <location>src/test</location> + </source-folder> + <source-file> + <location>build.xml</location> + </source-file> + </items> + <context-menu> + <ide-action name="build"/> + <ide-action name="clean"/> + <ide-action name="javadoc"/> + <ide-action name="test"/> + <ide-action name="rebuild"/> + </context-menu> + </view> + <subprojects/> + </general-data> + <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/1"> + <compilation-unit> + <package-root>src/conf</package-root> + <package-root>src/java</package-root> + <package-root>src/test</package-root> + <classpath mode="compile">../core-library/target/lib/shale-core.jar:../test-framework/target/lib/shale-test.jar:../../../../../usr/local/jsf-1_1_01/lib/jsf-api.jar:../../../../../usr/local/jsf-1_1_01/lib/commons-digester.jar:../../../../../usr/local/jsf-1_1_01/lib/commons-beanutils.jar:../../../../../usr/local/jsf-1_1_01/lib/commons-collections.jar:../../../../../usr/local/jsf-1_1_01/lib/commons-logging.jar:../../../../../usr/local/junit3.8.1/junit.jar:../lib/jsp-api/jsp-api.jar:../lib/servlet-api/servlet-api.jar</classpath> + <built-to>target/classes</built-to> + <source-level>1.5</source-level> + </compilation-unit> + </java-data> + </configuration> +</project> Modified: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/faces/LifecycleListener.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/faces/LifecycleListener.java?rev=372303&r1=372302&r2=372303&view=diff ============================================================================== --- struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/faces/LifecycleListener.java (original) +++ struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/faces/LifecycleListener.java Wed Jan 25 12:09:24 2006 @@ -28,6 +28,12 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; import javax.faces.FacesException; +import javax.faces.FactoryFinder; +import javax.faces.application.Application; +import javax.faces.application.ApplicationFactory; +import javax.faces.render.RenderKit; +import javax.faces.render.RenderKitFactory; +import javax.faces.render.Renderer; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; @@ -40,6 +46,10 @@ import org.apache.shale.tiger.managed.Value; import org.apache.shale.tiger.managed.config.ManagedBeanConfig; import org.apache.shale.tiger.managed.config.ManagedPropertyConfig; +import org.apache.shale.tiger.register.FacesComponent; +import org.apache.shale.tiger.register.FacesConverter; +import org.apache.shale.tiger.register.FacesRenderer; +import org.apache.shale.tiger.register.FacesValidator; import org.apache.shale.util.Messages; import org.xml.sax.SAXException; @@ -161,6 +171,7 @@ try { classes = webClasses(servletContext); for (Class clazz : classes) { + registerClass(clazz, application()); scanClass(clazz, config); } } catch (Exception e) { @@ -175,6 +186,7 @@ for (JarFile archive : archives) { classes = archiveClasses(servletContext, archive); for (Class clazz : classes) { + registerClass(clazz, application()); scanClass(clazz, config); } } @@ -229,6 +241,23 @@ // --------------------------------------------------------- Private Methods + private Application application = null; + + + /** + * <p>Return the <code>Application</code> for this application.</p> + */ + private Application application() { + + if (application == null) { + application = ((ApplicationFactory) FactoryFinder. + getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication(); + } + return application; + + } + + /** * <p>Return a list of classes from the specified JAR archive. If this * archive has no classes in it, a zero-length list is returned.</p> @@ -417,6 +446,83 @@ } parser.setResource(resource); parser.parse(); + + } + + + private RenderKitFactory rkFactory = null; + + + /** + * <p>Return the <code>RenderKitFactory</code> for this application.</p> + */ + private RenderKitFactory renderKitFactory() { + + if (rkFactory == null) { + rkFactory = (RenderKitFactory) + FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY); + } + return rkFactory; + + } + + + /** + * <p>Register the specified class with the specified JavaServer Faces + * <code>Application</code> instance, based on annotations that the + * class is annotated with.</p> + * + * @param clazz Class to be registered + * @param application <code>Application</code> instance with which to + * register this class + */ + private void registerClass(Class clazz, Application application) { + + if (log().isTraceEnabled()) { + log().trace("registerClass(" + clazz.getName() + ")"); + } + FacesComponent comp = (FacesComponent) clazz.getAnnotation(FacesComponent.class); + if (comp != null) { + if (log().isTraceEnabled()) { + log().trace("addComponent(" + comp.value() + "," + clazz.getName() + ")"); + } + application().addComponent(comp.value(), clazz.getName()); + } + + FacesConverter conv = (FacesConverter) clazz.getAnnotation(FacesConverter.class); + if (conv != null) { + if (log().isTraceEnabled()) { + log().trace("addConverter(" + conv.value() + "," + clazz.getName() + ")"); + } + application().addConverter(conv.value(), clazz.getName()); + } + + FacesRenderer rend = (FacesRenderer) clazz.getAnnotation(FacesRenderer.class); + if (rend != null) { + String renderKitId = rend.renderKitId(); + if (renderKitId == null) { + renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT; + } + if (log().isTraceEnabled()) { + log().trace("addRenderer(" + renderKitId + ", " + rend.componentFamily() + + ", " + rend.rendererType() + ", " + clazz.getName() + ")"); + } + try { + RenderKit rk = renderKitFactory().getRenderKit(null, renderKitId); + rk.addRenderer(rend.componentFamily(), rend.rendererType(), + (Renderer) clazz.newInstance()); + } catch (Exception e) { + throw new FacesException(e); + } + } + + FacesValidator val = (FacesValidator) clazz.getAnnotation(FacesValidator.class); + if (val != null) { + if (log().isTraceEnabled()) { + log().trace("addValidator(" + val.value() + "," + clazz.getName() + ")"); + } + application().addValidator(val.value(), clazz.getName()); + } } Added: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesComponent.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesComponent.java?rev=372303&view=auto ============================================================================== --- struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesComponent.java (added) +++ struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesComponent.java Wed Jan 25 12:09:24 2006 @@ -0,0 +1,46 @@ +/* + * Copyright 2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id$ + */ + +package org.apache.shale.tiger.register; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * <p>Class-level annotation indicating that this class should be registered + * as a JavaServer Faces <code>UIComponent</code> under the component type + * specified by the <code>value</code> attribute.</p> + * + * <p><strong>ASSERTION</strong> - The annotated class implements + * <code>UIComponent</code> or extends <code>UIComponentBase</code>.</p> + * + * @since 1.0.1 + */ [EMAIL PROTECTED](RetentionPolicy.RUNTIME) [EMAIL PROTECTED](ElementType.TYPE) +public @interface FacesComponent { + + /** + * <p>The component type under which this component should be registered.</p> + */ + String value(); + + +} Propchange: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesComponent.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesComponent.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesConverter.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesConverter.java?rev=372303&view=auto ============================================================================== --- struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesConverter.java (added) +++ struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesConverter.java Wed Jan 25 12:09:24 2006 @@ -0,0 +1,46 @@ +/* + * Copyright 2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id$ + */ + +package org.apache.shale.tiger.register; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * <p>Class-level annotation indicating that this class should be registered + * as a JavaServer Faces <code>Converter</code> under the converter id + * specified by the <code>value</code> attribute.</p> + * + * <p><strong>ASSERTION</strong> - The annotated class implements + * <code>Converter</code>.</p> + * + * @since 1.0.1 + */ [EMAIL PROTECTED](RetentionPolicy.RUNTIME) [EMAIL PROTECTED](ElementType.TYPE) +public @interface FacesConverter { + + /** + * <p>The converter id under which this converter should be registered.</p> + */ + String value(); + + +} Propchange: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesConverter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesConverter.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesRenderer.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesRenderer.java?rev=372303&view=auto ============================================================================== --- struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesRenderer.java (added) +++ struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesRenderer.java Wed Jan 25 12:09:24 2006 @@ -0,0 +1,62 @@ +/* + * Copyright 2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id$ + */ + +package org.apache.shale.tiger.register; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import javax.faces.render.RenderKitFactory; + +/** + * <p>Class-level annotation indicating that this class should be registered + * as a JavaServer Faces <code>Renderer</code> under the parameters + * specified by our attributes.</p> + * + * <p><strong>ASSERTION</strong> - The annotated class implements + * <code>Renderer</code>.</p> + * + * @since 1.0.1 + */ [EMAIL PROTECTED](RetentionPolicy.RUNTIME) [EMAIL PROTECTED](ElementType.TYPE) +public @interface FacesRenderer { + + + /** + * <p>The <code>RenderKit</code> identifier of the <code>RenderKit</code> + * with which we should register. If not specified, we will register + * in the default HTML Basic <code>RenderKit</code>.</p> + */ + String renderKitId() default RenderKitFactory.HTML_BASIC_RENDER_KIT; + + + /** + * <p>The renderer type under which we should register.</p> + */ + String rendererType(); + + + /** + * <p>The component family for which we should register.</p> + */ + String componentFamily(); + + +} Propchange: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesRenderer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesRenderer.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesValidator.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesValidator.java?rev=372303&view=auto ============================================================================== --- struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesValidator.java (added) +++ struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesValidator.java Wed Jan 25 12:09:24 2006 @@ -0,0 +1,46 @@ +/* + * Copyright 2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id$ + */ + +package org.apache.shale.tiger.register; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * <p>Class-level annotation indicating that this class should be registered + * as a JavaServer Faces <code>Validator</code> under the validator id + * specified by the <code>value</code> attribute.</p> + * + * <p><strong>ASSERTION</strong> - The annotated class implements + * <code>Validator</code>.</p> + * + * @since 1.0.1 + */ [EMAIL PROTECTED](RetentionPolicy.RUNTIME) [EMAIL PROTECTED](ElementType.TYPE) +public @interface FacesValidator { + + /** + * <p>The validator id under which this validator should be registered.</p> + */ + String value(); + + +} Propchange: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/FacesValidator.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/package.html URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/package.html?rev=372303&view=auto ============================================================================== --- struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/package.html (added) +++ struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/package.html Wed Jan 25 12:09:24 2006 @@ -0,0 +1,84 @@ +<!-- + * Copyright 2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +--> + +<!-- $Id$ --> + +<body> + +<p>This package contains Java SE 5 <em>annotations</em> that allow you to +register several types of JavaServer Faces artifacts (components, converters, +renderers, and validators) without having to define them in a configuration +resource. Because the JavaServer Faces runtime does not support classes with +arbitrary inheritance hierarchies to implement particular features, the +actual classes themselves must also extend the corresponding JavaServer Faces +APIs to be usable.</p> + +<p>To declare a JavaServer Faces <code>UIComponent</code> class:</p> +<pre> + import javax.faces.component.UIComponentBase; + import org.apache.shale.tiger.register.FacesComponent; + + @FacesComponent("com.mycompany.mytypes.MY_COMPONENT_TYPE") + public class MyComponent extends UIComponentBase { + ... + } +</pre> + +<p>To declare a JavaServer Faces by-id <code>Converter</code> class:</p> +<pre> + import javax.faces.convert.Converter; + import org.apache.shale.tiger.register.FacesConverter; + + @FacesConverter("com.mycompany.mytypes.MY_CONVERTER_ID") + public class MyConverter implements Converter { + ... + } +</pre> + +<p>To declare a JavaServer Faces <code>Validator</code> class:</p> +<pre> + import javax.faces.convert.Validator; + import org.apache.shale.tiger.register.Validator; + + @FacesValidator("com.mycompany.mytypes.MY_VALIDATOR_ID") + public class MyValidator implements Validator { + ... + } +</pre> + +<p>To declare a JavaServer Faces <code>Renderer</code> class:</p> +<pre> + import javax.faces.render.Renderer; + import org.apache.shale.tiger.register.FacesRenderer; + + @FacesRenderer(renderKitId="myRenderKitId" rendererType="myRendererType" + componentFamily="javax.faces.Input") + public class MyRenderer implements Renderer { + ... + } +</pre> + +<p>If the <code>renderKitId</code> attribute is not specified, the +<code>Renderer</code> will be registered in the default HTML Basic +<code>RenderKit</code>.</p> + +<p>API STATUS: Experimental.</p> + +<p>IMPLEMENTATION STATUS: Not yet implemented.</p> + [EMAIL PROTECTED] 1.0.1 + +</body> Propchange: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/package.html ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/register/package.html ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Modified: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/LifecycleListenerTestCase.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/LifecycleListenerTestCase.java?rev=372303&r1=372302&r2=372303&view=diff ============================================================================== --- struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/LifecycleListenerTestCase.java (original) +++ struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/LifecycleListenerTestCase.java Wed Jan 25 12:09:24 2006 @@ -19,6 +19,10 @@ import java.io.File; import java.util.Map; import java.util.Set; +import javax.faces.component.UIComponent; +import javax.faces.convert.Converter; +import javax.faces.render.Renderer; +import javax.faces.validator.Validator; import javax.servlet.ServletContextEvent; import junit.framework.Test; import junit.framework.TestCase; @@ -271,6 +275,31 @@ public void testPristine() { assertNotNull(listener); + + } + + + // Test registration of JavaServer Faces objects + public void testRegister() { + + // Create a ServletContextEvent we will pass to the event methods + ServletContextEvent event = new ServletContextEvent(servletContext); + + // Initialize the servlet context listener + listener.contextInitialized(event); + + // Check for the widgets that should have been registered + UIComponent comp = application.createComponent("foo.MyComponent"); + assertNotNull(comp); + Converter conv = application.createConverter("foo.MyConverter"); + assertNotNull(conv); + Renderer rend = renderKit.getRenderer("foo.MyFamily", "foo.MyRenderer"); + assertNotNull(rend); + Validator val = application.createValidator("foo.MyValidator"); + assertNotNull(val); + + // Finalize the servlet context listener + listener.contextDestroyed(event); } Added: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyComponent.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyComponent.java?rev=372303&view=auto ============================================================================== --- struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyComponent.java (added) +++ struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyComponent.java Wed Jan 25 12:09:24 2006 @@ -0,0 +1,36 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id$ + */ + +package org.apache.shale.tiger.faces; + +import javax.faces.component.UIComponentBase; +import org.apache.shale.tiger.register.FacesComponent; + +/** + * <p>Test component for Shale Tiger unit tests.</p> + */ [EMAIL PROTECTED]("foo.MyComponent") +public class MyComponent extends UIComponentBase { + + + public String getFamily() { + return "MyFamily"; + } + + +} Propchange: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyComponent.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyComponent.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyConverter.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyConverter.java?rev=372303&view=auto ============================================================================== --- struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyConverter.java (added) +++ struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyConverter.java Wed Jan 25 12:09:24 2006 @@ -0,0 +1,40 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id$ + */ + +package org.apache.shale.tiger.faces; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import org.apache.shale.tiger.register.FacesConverter; + +/** + * <p>Test converter for Shale Tiger unit tests.</p> + */ [EMAIL PROTECTED]("foo.MyConverter") +public class MyConverter implements Converter { + + public String getAsString(FacesContext facesContext, UIComponent uIComponent, Object object) { + throw new UnsupportedOperationException(); + } + + public Object getAsObject(FacesContext facesContext, UIComponent uIComponent, String string) { + throw new UnsupportedOperationException(); + } + +} Propchange: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyConverter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyConverter.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyRenderer.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyRenderer.java?rev=372303&view=auto ============================================================================== --- struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyRenderer.java (added) +++ struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyRenderer.java Wed Jan 25 12:09:24 2006 @@ -0,0 +1,32 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id$ + */ + +package org.apache.shale.tiger.faces; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.render.Renderer; +import org.apache.shale.tiger.register.FacesRenderer; + +/** + * <p>Test renderer for Shale Tiger unit tests.</p> + */ [EMAIL PROTECTED](rendererType="foo.MyRenderer", componentFamily="foo.MyFamily") +public class MyRenderer extends Renderer { + +} Propchange: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyRenderer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyRenderer.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyValidator.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyValidator.java?rev=372303&view=auto ============================================================================== --- struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyValidator.java (added) +++ struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyValidator.java Wed Jan 25 12:09:24 2006 @@ -0,0 +1,37 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id$ + */ + +package org.apache.shale.tiger.faces; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.validator.Validator; +import javax.faces.validator.ValidatorException; +import org.apache.shale.tiger.register.FacesValidator; + +/** + * <p>Test validator for Shale Tiger unit tests.</p> + */ [EMAIL PROTECTED]("foo.MyValidator") +public class MyValidator implements Validator { + + public void validate(FacesContext facesContext, UIComponent uIComponent, Object object) throws ValidatorException { + throw new UnsupportedOperationException(); + } + +} Propchange: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/MyValidator.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Modified: struts/shale/trunk/xdocs/features-tiger-extensions.xml URL: http://svn.apache.org/viewcvs/struts/shale/trunk/xdocs/features-tiger-extensions.xml?rev=372303&r1=372302&r2=372303&view=diff ============================================================================== --- struts/shale/trunk/xdocs/features-tiger-extensions.xml (original) +++ struts/shale/trunk/xdocs/features-tiger-extensions.xml Wed Jan 25 12:09:24 2006 @@ -26,6 +26,10 @@ rather than requiring the backing bean to implement the <code>ViewController</code> interface and provide methods with the names defined by this interface.</li> + <li>The ability for JavaServer Faces components, converters, + renderers,and validators to register themselves with the + runtime system, without having to be declared in a + <code>faces-config.xml</code> resource.</li> </ul> <p>These features are enabled automatically if you include @@ -108,6 +112,22 @@ view controller callbacks, you are <code>NOT</code> required to provide a method that is marked with the corresponding annotaiton.</p> + <h4>Annotated Component Registration</h4> + + <p>A standard JavaServer Faces runtime environment allows an + application, or a component library, to register custom classes + as JavaServer Faces components, converters, renderers,and validators, + using the <code><component></code>, <code><converter></code>, + <code><renderer></code>, and <code><validator></code> + elements, respectively, in a <code>faces-config.xml</code> resource. + The Shale Tiger extensions allow the implementation classes for these + objects to register themselves by virtue of the existence of an + annotation on the class, without requiring a configuration resource + to be present. In each case, the class being registered must still + implement the corresponding JavaServer Faces API (for example, a + converter registered in this manner must still implement the + <code>javax.faces.convert.Converter</code> interface).</p> + </subsection> <a name="tiger-using"/> @@ -188,6 +208,81 @@ // This class is not interested in preprocess or destroy // methods, so they are not defined + } +</source> + + <h4>Using Annotated Component Registration</h4> + + <p>To use the <em>Annotated Component Registration</em> feature, + you mus use annotations from the <code>org.apache.shale.tiger.register</code> + package, as illustrated below:</p> + + <p>An annotated component registration should look like this:</p> + +<source> + package com.mycompany.mypackage; + + import javax.faces.component.UIComponentBase; + import org.apache.shale.tiger.register.FacesComponent; + + @FacesComponent("my.component.type") + public class MyComponent extends UIComponentBase { + + ... + + } +</source> + + <p>An annotated converter registration should look like this:</p> + +<source> + package com.mycompany.mypackage; + + import javax.faces.convert.Converter; + import org.apache.shale.tiger.register.FacesConverter; + + @FacesConverter("my.converter.id") + public class MyConverter implements Converter { + + ... + + } +</source> + + <p>An annotated renderer registration should look like this + (if the <code>renderKitId</code> attribute is not specified, + the renderer will be registered with the standard HTML Basic + renderkit):</p> + +<source> + package com.mycompany.mypackage; + + import javax.faces.render.Renderer; + import org.apache.shale.tiger.register.FacesRenderer; + + @FacesRenderer(renderKitId="my.render.kit.id", + componentFamily="my.component.family", + rendererType="my.renderer.type") + public class MyRenderer extends Renderer { + + ... + + } +</source> + + <p>An annotated validator registration should look like this:</p> + +<source> + package com.mycompany.mypackage; + + import javax.faces.validator.Validator; + import org.apache.shale.tiger.register.FacesValidator; + + @FacesConverter("my.validator.id") + public class MyValidator implements Validator { + + ... + } </source> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]