dev@glassfish.java.net

Re: svn commit: r6437 - trunk/jsf-ri: src/com/sun/faces/application src/com/sun/faces/facelets/tag/jsf/core systest/src/com/sun/faces/annotation systes...

From: Jason Lee <jasondlee_at_sun.com>
Date: Fri, 06 Feb 2009 20:30:24 -0600

Looks like an event was deleted between my update and my commit, so
I'm betting Hudson will break. I am removing my use of that Event in
the tests right now.
On Feb 6, 2009, at 8:26 PM, jdlee_at_dev.java.net wrote:

> Author: jdlee
> Date: 2009-02-07 02:26:04+0000
> New Revision: 6437
>
> Modified:
> trunk/jsf-ri/src/com/sun/faces/application/NamedEventManager.java
> trunk/jsf-ri/src/com/sun/faces/facelets/tag/jsf/core/
> EventHandler.java
> trunk/jsf-ri/systest/src/com/sun/faces/annotation/
> AnnotationTestBean.java
> trunk/jsf-ri/systest/src/com/sun/faces/systest/model/
> EventTagBean.java
> trunk/jsf-ri/systest/src/com/sun/faces/systest/tags/
> EventTestCase.java
> trunk/jsf-ri/systest/web/eventTag.xhtml
>
> Log:
> * Moved Util.loadClass and related code to
> NamedEventManager.getNamedEvent() for more consistent error checking
> * Add Class.isAssignable check
> * Add no-arg method option to the "listener" method, making it the
> first method call attempted, as it's likely going to be the common
> case
> * Added test to exercise the no-arg code paths
> * Add code to the systest to exercise the FQCN code path
> * Code clean up
>
> r=rlubke
>
>
>
> Modified: trunk/jsf-ri/src/com/sun/faces/application/
> NamedEventManager.java
> Url: https://mojarra.dev.java.net/source/browse/mojarra/trunk/jsf-ri/src/com/sun/faces/application/NamedEventManager.java?view=diff&rev=6437&p1=trunk/jsf-ri/src/com/sun/faces/application/NamedEventManager.java&p2=trunk/jsf-ri/src/com/sun/faces/application/NamedEventManager.java&r1=6436&r2=6437
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- trunk/jsf-ri/src/com/sun/faces/application/
> NamedEventManager.java (original)
> +++ trunk/jsf-ri/src/com/sun/faces/application/
> NamedEventManager.java 2009-02-07 02:26:04+0000
> @@ -4,14 +4,17 @@
> */
> package com.sun.faces.application;
>
> +import com.sun.faces.util.Util;
> import java.util.HashSet;
> import java.util.Map;
> import java.util.Set;
> import java.util.concurrent.ConcurrentHashMap;
> +import javax.faces.FacesException;
> import javax.faces.event.AfterAddToViewEvent;
> import javax.faces.event.AfterValidateEvent;
> import javax.faces.event.BeforeRenderEvent;
> import javax.faces.event.BeforeValidateEvent;
> +import javax.faces.event.ComponentSystemEvent;
> import javax.faces.event.SystemEvent;
>
> /**
> @@ -42,6 +45,17 @@
> public Class<? extends SystemEvent> getNamedEvent(String name) {
> String foo = namedEvents.toString();
> Class<? extends SystemEvent> namedEvent =
> namedEvents.get(name);
> + if (namedEvent == null) {
> + try {
> + namedEvent = Util.loadClass(name, this);
> + } catch (ClassNotFoundException ex) {
> + throw new FacesException ("An unknown event type
> was specified: " + name, ex);
> + }
> + }
> + if (!
> ComponentSystemEvent.class.isAssignableFrom(namedEvent)) {
> + throw new ClassCastException();
> + }
> +
> return namedEvent;
> }
>
>
> Modified: trunk/jsf-ri/src/com/sun/faces/facelets/tag/jsf/core/
> EventHandler.java
> Url: https://mojarra.dev.java.net/source/browse/mojarra/trunk/jsf-ri/src/com/sun/faces/facelets/tag/jsf/core/EventHandler.java?view=diff&rev=6437&p1=trunk/jsf-ri/src/com/sun/faces/facelets/tag/jsf/core/EventHandler.java&p2=trunk/jsf-ri/src/com/sun/faces/facelets/tag/jsf/core/EventHandler.java&r1=6436&r2=6437
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- trunk/jsf-ri/src/com/sun/faces/facelets/tag/jsf/core/
> EventHandler.java (original)
> +++ trunk/jsf-ri/src/com/sun/faces/facelets/tag/jsf/core/
> EventHandler.java 2009-02-07 02:26:04+0000
> @@ -13,6 +13,7 @@
> import javax.el.ELContext;
> import javax.el.ELException;
> import javax.el.MethodExpression;
> +import javax.el.MethodNotFoundException;
> import javax.faces.FacesException;
> import javax.faces.context.FacesContext;
> import javax.faces.component.UIComponent;
> @@ -43,30 +44,20 @@
> Class<? extends SystemEvent> eventClass = getEventClass(ctx);
> if (eventClass != null) {
> parent.subscribeToEvent(eventClass,
> - new
> DeclarativeSystemEventListener(listener.getMethodExpression(ctx,
> Object.class, new Class[] { ComponentSystemEvent.class })));
> + new DeclarativeSystemEventListener(
> + listener.getMethodExpression(ctx,
> Object.class, new Class[] { ComponentSystemEvent.class }),
> + listener.getMethodExpression(ctx,
> Object.class, new Class[] { })));
> }
> }
>
> protected Class<? extends SystemEvent>
> getEventClass(FaceletContext ctx) {
> - Class<? extends SystemEvent> clazz = null;
> String eventType = (String)
> this.type.getValueExpression(ctx, String.class).getValue(ctx);
> if (eventType == null) {
> throw new FacesException("Attribute 'type' can not be
> null");
> }
> - ApplicationAssociate associate =
> -
> ApplicationAssociate
> .getInstance(ctx.getFacesContext().getExternalContext());
> - NamedEventManager nem = associate.getNamedEventManager();
> -
> - clazz = nem.getNamedEvent(eventType);
> - if (clazz == null) {
> - try {
> - clazz = Util.loadClass(eventType, this);
> - } catch (ClassNotFoundException ex) {
> - throw new FacesException ("An unknown event type
> was specified: " + eventType);
> - }
> - }
>
> - return clazz;
> + return
> ApplicationAssociate
> .getInstance(ctx.getFacesContext().getExternalContext())
> + .getNamedEventManager().getNamedEvent(eventType);
> }
>
> }
> @@ -76,16 +67,24 @@
>
> private static final long serialVersionUID = 8945415935164238908L;
>
> - private MethodExpression action;
> + private MethodExpression oneArgListener;
> + private MethodExpression noArgListener;
>
> // Necessary for state saving
> public DeclarativeSystemEventListener() {}
>
> - public DeclarativeSystemEventListener(MethodExpression action) {
> - this.action = action;
> + public DeclarativeSystemEventListener(MethodExpression oneArg,
> MethodExpression noArg) {
> + this.oneArgListener = oneArg;
> + this.noArgListener = noArg;
> }
>
> public void processEvent(ComponentSystemEvent event) throws
> AbortProcessingException {
> -
> action.invoke(FacesContext.getCurrentInstance().getELContext(), new
> Object[]{event});
> + final ELContext elContext =
> FacesContext.getCurrentInstance().getELContext();
> + try{
> + noArgListener.invoke(elContext, new Object[]{});
> + } catch (MethodNotFoundException mnfe) {
> + // Attempt to call public void
> method(ComponentSystemEvent event)
> + oneArgListener.invoke(elContext, new Object[]{event});
> + }
> }
> }
> \ No newline at end of file
>
> Modified: trunk/jsf-ri/systest/src/com/sun/faces/annotation/
> AnnotationTestBean.java
> Url: https://mojarra.dev.java.net/source/browse/mojarra/trunk/jsf-ri/systest/src/com/sun/faces/annotation/AnnotationTestBean.java?view=diff&rev=6437&p1=trunk/jsf-ri/systest/src/com/sun/faces/annotation/AnnotationTestBean.java&p2=trunk/jsf-ri/systest/src/com/sun/faces/annotation/AnnotationTestBean.java&r1=6436&r2=6437
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- trunk/jsf-ri/systest/src/com/sun/faces/annotation/
> AnnotationTestBean.java (original)
> +++ trunk/jsf-ri/systest/src/com/sun/faces/annotation/
> AnnotationTestBean.java 2009-02-07 02:26:04+0000
> @@ -172,8 +172,12 @@
> // Test short name
>
> assertNotNull
> (ApplicationAssociate.getInstance(ctx.getExternalContext())
> .getNamedEventManager
> ().getNamedEvent
> ("com.sun.faces.annotation.anotherAnnotatedComponentSystem"));
> + // Test FQCN
> +
> assertNotNull
> (ApplicationAssociate.getInstance(ctx.getExternalContext())
> +
> .getNamedEventManager
> ().getNamedEvent(AnnotatedComponentSystemEvent.class.getName()));
>
> assertNotNull
> (ApplicationAssociate.getInstance(ctx.getExternalContext())
> .getNamedEventManager
> ().getNamedEvent("explicitEventName"));
> +
> }
>
> private void assertNotNull(Object v) {
>
> Modified: trunk/jsf-ri/systest/src/com/sun/faces/systest/model/
> EventTagBean.java
> Url: https://mojarra.dev.java.net/source/browse/mojarra/trunk/jsf-ri/systest/src/com/sun/faces/systest/model/EventTagBean.java?view=diff&rev=6437&p1=trunk/jsf-ri/systest/src/com/sun/faces/systest/model/EventTagBean.java&p2=trunk/jsf-ri/systest/src/com/sun/faces/systest/model/EventTagBean.java&r1=6436&r2=6437
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- trunk/jsf-ri/systest/src/com/sun/faces/systest/model/
> EventTagBean.java (original)
> +++ trunk/jsf-ri/systest/src/com/sun/faces/systest/model/
> EventTagBean.java 2009-02-07 02:26:04+0000
> @@ -35,6 +35,13 @@
> output.setValue("The '" + event.getClass().getName() + "'
> event fired!");
> }
>
> + public void beforeEncodeNoArg() {
> + FacesContext context = FacesContext.getCurrentInstance();
> + UIOutput output = (UIOutput)
> context.getViewRoot().findComponent("form:noArgTest");
> +// UIOutput output = (UIOutput)event.getComponent();
> + output.setValue("The no-arg event fired!");
> + }
> +
> public void afterValidate(ComponentSystemEvent event) {
> FacesContext context = FacesContext.getCurrentInstance();
> final UIForm form = (UIForm) event.getComponent();
>
> Modified: trunk/jsf-ri/systest/src/com/sun/faces/systest/tags/
> EventTestCase.java
> Url: https://mojarra.dev.java.net/source/browse/mojarra/trunk/jsf-ri/systest/src/com/sun/faces/systest/tags/EventTestCase.java?view=diff&rev=6437&p1=trunk/jsf-ri/systest/src/com/sun/faces/systest/tags/EventTestCase.java&p2=trunk/jsf-ri/systest/src/com/sun/faces/systest/tags/EventTestCase.java&r1=6436&r2=6437
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- trunk/jsf-ri/systest/src/com/sun/faces/systest/tags/
> EventTestCase.java (original)
> +++ trunk/jsf-ri/systest/src/com/sun/faces/systest/tags/
> EventTestCase.java 2009-02-07 02:26:04+0000
> @@ -90,7 +90,7 @@
> HtmlPage page = getPage("/faces/eventTag.xhtml");
> List<HtmlSpan> outputs = new ArrayList<HtmlSpan>(4);
> getAllElementsOfGivenClass(page, outputs, HtmlSpan.class);
> - assertTrue(outputs.size() == 4);
> + assertTrue(outputs.size() == 6);
> validateOutput(outputs);
>
> HtmlSubmitInput submit = (HtmlSubmitInput)
> getInputContainingGivenId(page, "click");
> @@ -98,7 +98,7 @@
> page = submit.click();
> outputs.clear();
> getAllElementsOfGivenClass(page, outputs, HtmlSpan.class);
> - assertTrue(outputs.size() == 4);
> + assertTrue(outputs.size() == 6);
> validateOutput(outputs);
> }
>
> @@ -152,5 +152,13 @@
> s = outputs.get(3);
> assertTrue(("The 'javax.faces.event.AfterAddToViewEvent'
> event fired!").equals(s.asText()));
>
> + // Fully-qualified class name
> + s = outputs.get(4);
> + assertTrue(("The 'javax.faces.event.AfterAddToParentEvent'
> event fired!").equals(s.asText()));
> +
> + // No-arg
> + s = outputs.get(5);
> + assertTrue(("The no-arg event fired!").equals(s.asText()));
> +
> }
> }
>
> Modified: trunk/jsf-ri/systest/web/eventTag.xhtml
> Url: https://mojarra.dev.java.net/source/browse/mojarra/trunk/jsf-ri/systest/web/eventTag.xhtml?view=diff&rev=6437&p1=trunk/jsf-ri/systest/web/eventTag.xhtml&p2=trunk/jsf-ri/systest/web/eventTag.xhtml&r1=6436&r2=6437
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- trunk/jsf-ri/systest/web/eventTag.xhtml (original)
> +++ trunk/jsf-ri/systest/web/eventTag.xhtml 2009-02-07 02:26:04+0000
> @@ -61,6 +61,14 @@
> <h:outputText id="afterAddToViewTest2" >
> <f:event type="javax.faces.event.afterAddToView"
> listener="#{eventTagBean.beforeEncode}" />
> </h:outputText>
> + <br />
> + <h:outputText id="fqcnTest" >
> + <f:event type="javax.faces.event.AfterAddToParentEvent"
> listener="#{eventTagBean.beforeEncode}" />
> + </h:outputText>
> + <br />
> + <h:outputText id="noArgTest" >
> + <f:event type="beforeRender"
> listener="#{eventTagBean.beforeEncodeNoArg}" />
> + </h:outputText>
> <h:commandButton id="click" value="Click" />
> </h:form>
> </h:body>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commits-unsubscribe_at_mojarra.dev.java.net
> For additional commands, e-mail: commits-help_at_mojarra.dev.java.net
>

         Jason Lee
Senior Java Developer
GlassFish Administration Console

Sun Microsystems, Inc.
Phone x31197/+1 405-343-1964
Email jasondlee_at_sun.com
Blog http://blogs.sun.com/jasondlee
Blog http://blogs.steeplesoft.com