Author: craigmcc Date: Fri Jun 30 15:31:25 2006 New Revision: 418399 URL: http://svn.apache.org/viewvc?rev=418399&view=rev Log: Forgot to add the new annotations and classes for SHALE-197 resolution.
Added: struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/AfterPhase.java struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/BeforePhase.java struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/FacesPhaseListener.java struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/faces/ struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/faces/PhaseListenerAdapter.java struts/shale/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/faces/MyPhaseListener.java Added: struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/AfterPhase.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/AfterPhase.java?rev=418399&view=auto ============================================================================== --- struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/AfterPhase.java (added) +++ struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/AfterPhase.java Fri Jun 30 15:31:25 2006 @@ -0,0 +1,43 @@ +/* + * 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: FacesComponent.java 372303 2006-01-25 20:09:24Z craigmcc $ + */ + +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>Method-level annotation indicating that this method should be called + * to process the "after phase" handling for the containing phase listener.</p> + * + * <p><strong>ASSERTION</strong> - The containing class is annotated with + * the [EMAIL PROTECTED] FacesPhaseListener} annotation.</p> + * + * <p><strong> ASSERTION</strong> - The annotated method has a return type + * of <code>void</code> and accepts a single parameter of type + * <code>javax.faces.event.PhaseEvent</code>.</p> + * + * @since 1.0.3 + */ [EMAIL PROTECTED](RetentionPolicy.RUNTIME) [EMAIL PROTECTED](ElementType.METHOD) +public @interface AfterPhase { + +} Added: struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/BeforePhase.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/BeforePhase.java?rev=418399&view=auto ============================================================================== --- struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/BeforePhase.java (added) +++ struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/BeforePhase.java Fri Jun 30 15:31:25 2006 @@ -0,0 +1,43 @@ +/* + * 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: FacesComponent.java 372303 2006-01-25 20:09:24Z craigmcc $ + */ + +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>Method-level annotation indicating that this method should be called + * to process the "before phase" handling for the containing phase listener.</p> + * + * <p><strong>ASSERTION</strong> - The containing class is annotated with + * the [EMAIL PROTECTED] FacesPhaseListener} annotation.</p> + * + * <p><strong> ASSERTION</strong> - The annotated method has a return type + * of <code>void</code> and accepts a single parameter of type + * <code>javax.faces.event.PhaseEvent</code>.</p> + * + * @since 1.0.3 + */ [EMAIL PROTECTED](RetentionPolicy.RUNTIME) [EMAIL PROTECTED](ElementType.METHOD) +public @interface BeforePhase { + +} Added: struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/FacesPhaseListener.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/FacesPhaseListener.java?rev=418399&view=auto ============================================================================== --- struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/FacesPhaseListener.java (added) +++ struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/FacesPhaseListener.java Fri Jun 30 15:31:25 2006 @@ -0,0 +1,64 @@ +/* + * 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: FacesComponent.java 372303 2006-01-25 20:09:24Z craigmcc $ + */ + +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 + * with the current <code>Lifecycle</code> instance as a JavaServer Faces + * <code>PhaseListener</code>. If the implementation class actually + * implements the <code>PhaseListener</code> interface, it will be + * registered directly. Otherwise, an adapter will be registered that + * calls through to the methods specified by the [EMAIL PROTECTED] BeforePhase} + * and/or [EMAIL PROTECTED] AfterPhase} annotations.</p> + * + * @since 1.0.3 + */ [EMAIL PROTECTED](RetentionPolicy.RUNTIME) [EMAIL PROTECTED](ElementType.TYPE) +public @interface FacesPhaseListener { + + + /** + * <p>Identifier for the phase that this listener is interested + * in participating in.</p> + */ + public enum PhaseId { + ANY_PHASE, + RESTORE_VIEW, + APPLY_REQUEST_VALUES, + PROCESS_VALIDATIONS, + UPDATE_MODEL_VALUES, + INVOKE_APPLICATION, + RENDER_RESPONSE + } + + + /** + * <p>Identifies the phase(s) that this listener is interested in being + * notified about. If not specified, PhaseId.ANY_PHASE is assumed.</p> + */ + public PhaseId phaseId() default PhaseId.ANY_PHASE; + + +} Added: struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/faces/PhaseListenerAdapter.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/faces/PhaseListenerAdapter.java?rev=418399&view=auto ============================================================================== --- struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/faces/PhaseListenerAdapter.java (added) +++ struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/register/faces/PhaseListenerAdapter.java Fri Jun 30 15:31:25 2006 @@ -0,0 +1,211 @@ +/* + * 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: FacesComponent.java 372303 2006-01-25 20:09:24Z craigmcc $ + */ + +package org.apache.shale.tiger.register.faces; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import javax.faces.FacesException; +import javax.faces.event.PhaseEvent; +import javax.faces.event.PhaseId; +import javax.faces.event.PhaseListener; +import org.apache.shale.tiger.register.AfterPhase; +import org.apache.shale.tiger.register.BeforePhase; +import org.apache.shale.tiger.register.FacesPhaseListener; + +/** + * <p>Adapter class for a phase listener that specifies the + * [EMAIL PROTECTED] FacesPhaseListener} annotation, but does not actually + * implement the <code>PhaseListener</code> interface.</p> + */ +public final class PhaseListenerAdapter implements PhaseListener { + + + /** + * <p>Construct a new adapter instance around the specified object + * instance, whose defining class MUST specify the + * [EMAIL PROTECTED] FacesPhaseListener} annotation, and whose implementation + * MUST NOT be an implementation of <code>javax.faces.event.PhaseListener</code>.</p> + * + * @param instance The object instance for which we should + * construct a call-through adapter + * + * @exception IllegalArgumentException if the class for the specified + * instance does not have a @FacesPhaseListener annotation + * @exception IllegalArgumentException if the method specified by the + * @BeforePhase or @AfterPhase annotaion does not take exactly one + * parameter of type <code>javax.faces.event.PhaseEvent</code> + */ + public PhaseListenerAdapter(Object instance) { + + // Save the instance that we are adapting for + this.instance = instance; + + // Look up the @FacesFacesListener annotation for this class + FacesPhaseListener fpl = instance.getClass().getAnnotation(FacesPhaseListener.class); + if (fpl == null) { + throw new IllegalArgumentException("Implementing class " + + instance.getClass().getName() + " does not have the @FacesPhaseListener annotation"); + } + + // Extract the relevant before and after event methods from the + // underlying class + Method methods[] = instance.getClass().getMethods(); + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + Class signature[] = method.getParameterTypes(); + if (method.getAnnotation(BeforePhase.class) != null) { + if (signature.length != 1) { + throw new IllegalArgumentException("Method " + method.getName() + + " of class " + instance.getClass().getName() + + " does not take a exactly one parameter"); + } else if (!(signature[0] == PhaseEvent.class)) { + throw new IllegalArgumentException("Method " + method.getName() + + " of class " + instance.getClass().getName() + + " does not take a javax.faces.event.PhaaseEvent parameter"); + } else { + this.beforePhase = method; + } + } else if (method.getAnnotation(AfterPhase.class) != null) { + if (signature.length != 1) { + throw new IllegalArgumentException("Method " + method.getName() + + " of class " + instance.getClass().getName() + + " does not take a exactly one parameter"); + } else if (!(signature[0] == PhaseEvent.class)) { + throw new IllegalArgumentException("Method " + method.getName() + + " of class " + instance.getClass().getName() + + " does not take a javax.faces.event.PhaaseEvent parameter"); + } else { + this.afterPhase = method; + } + } + } + + // Extract the relevant phase identifer from the underlying class + FacesPhaseListener.PhaseId pi = fpl.phaseId(); + if (pi == FacesPhaseListener.PhaseId.ANY_PHASE) { + this.phaseId = PhaseId.ANY_PHASE; + } else if (pi == FacesPhaseListener.PhaseId.RESTORE_VIEW) { + this.phaseId = PhaseId.RESTORE_VIEW; + } else if (pi == FacesPhaseListener.PhaseId.APPLY_REQUEST_VALUES) { + this.phaseId = PhaseId.APPLY_REQUEST_VALUES; + } else if (pi == FacesPhaseListener.PhaseId.PROCESS_VALIDATIONS) { + this.phaseId = PhaseId.PROCESS_VALIDATIONS; + } else if (pi == FacesPhaseListener.PhaseId.UPDATE_MODEL_VALUES) { + this.phaseId = PhaseId.UPDATE_MODEL_VALUES; + } else if (pi == FacesPhaseListener.PhaseId.INVOKE_APPLICATION) { + this.phaseId = PhaseId.INVOKE_APPLICATION; + } else if (pi == FacesPhaseListener.PhaseId.RENDER_RESPONSE) { + this.phaseId = PhaseId.RENDER_RESPONSE; + } + + } + + + // ------------------------------------------------------ Instance Variables + + + /** + * <p>Method definition for the [EMAIL PROTECTED] AfterPhase} method for this + * phase listener class.</p> + */ + private Method afterPhase; + + + /** + * <p>Method definition for the [EMAIL PROTECTED] BeforePhase} method for this + * phase listener class.</p> + */ + private Method beforePhase; + + + /** + * <p>The listener instance for which we are an adapter.</p> + */ + private Object instance; + + + /** + * <p>The <code>PhaseId</code> to be returned by our + * <code>getPhaseId()</code> method.</p> + */ + private PhaseId phaseId; + + + // --------------------------------------------------- PhaseListener Methods + + + /** + * <p>Process an "after phase" event.</p> + * + * @param event The <code>PhaseEvent</code> to be processed + * + * @exception FacesException if an exception occurs invoking the + * appropriate event handling method + */ + public void afterPhase(PhaseEvent event) { + + if (afterPhase == null) { + return; + } + try { + afterPhase.invoke(instance, event); + } catch (InvocationTargetException e) { + throw new FacesException(e.getTargetException()); + } catch (Exception e) { + throw new FacesException(e); + } + + } + + + /** + * <p>Process a "before phase" event.</p> + * + * @param event The <code>PhaseEvent</code> to be processed + * + * @exception FacesException if an exception occurs invoking the + * appropriate event handling method + */ + public void beforePhase(PhaseEvent event) { + + if (beforePhase == null) { + return; + } + try { + beforePhase.invoke(instance, event); + } catch (InvocationTargetException e) { + throw new FacesException(e.getTargetException()); + } catch (Exception e) { + throw new FacesException(e); + } + + } + + + /** + * <p>Return the identifier of the phase(s) we are interested in.</p> + */ + public PhaseId getPhaseId() { + + return this.phaseId; + + } + + +} Added: struts/shale/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/faces/MyPhaseListener.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/faces/MyPhaseListener.java?rev=418399&view=auto ============================================================================== --- struts/shale/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/faces/MyPhaseListener.java (added) +++ struts/shale/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/faces/MyPhaseListener.java Fri Jun 30 15:31:25 2006 @@ -0,0 +1,46 @@ +/* + * 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: MyComponent.java 372303 2006-01-25 20:09:24Z craigmcc $ + */ + +package org.apache.shale.tiger.faces; + +import javax.faces.event.PhaseEvent; +import org.apache.shale.tiger.register.AfterPhase; +import org.apache.shale.tiger.register.BeforePhase; +import org.apache.shale.tiger.register.FacesPhaseListener; +import org.apache.shale.tiger.register.FacesPhaseListener.PhaseId; + +/** + * <p>Test phase listener for Shale Tiger unit tests.</p> + */ [EMAIL PROTECTED](phaseId=PhaseId.ANY_PHASE) +public class MyPhaseListener { + + + @BeforePhase + public void myBeforePhase(PhaseEvent event) { + ; + } + + + @AfterPhase + public void myAfterPhase(PhaseEvent event) { + ; + } + + +}