myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dennis Byrne" <den...@dbyrne.net>
Subject Re: svn commit: r511230 - in /myfaces/core/branches/jsf12/impl/src: main/java/org/apache/myfaces/config/ main/java/org/apache/myfaces/config/annotation/ main/java/org/apache/myfaces/el/ main/java/org/apache/myfaces/el/unified/resolver/ test/java/org/
Date Sat, 24 Feb 2007 16:44:18 GMT
No problem.

Dennis Byrne

On 2/24/07, Mathias Brökelmann <mbroekelmann@googlemail.com> wrote:
>
> sorry there is no problem with your implementation of
> ManagedBeanResolver. I was just a little bit confused by your changes
> to VariableResolverImpl. Because the implementation of this class must
> be stripped down for 1.2 and does not handle managed beans any more.
>
> 2007/2/24, Dennis Byrne <dennis@dbyrne.net>:
> > Hi Mathias,
> >
> > Can you tell me which section(s)?
> >
> > ManagedBeanResolver calls
> > ManagedBeanBuilder.buildManagedBean().  In
> > ManagedBeanBuilder.buildManagedBean uses
> > AnnotatedManagedBeanHandler, insuring that @PostContruct is
> respected.  You
> > are saying the problem is that this behavior is in *both*
> > ManagedBeanResolver and VariableResolverImpl?
> > >
> > > Dennis Byrne
> > >
> > >
> > >
> > > On 2/24/07, Mathias Brökelmann <mbroekelmann@googlemail.com> wrote:
> > > > Hi Dennis,
> > > >
> > > > I have a problem with the handling of ManagedBeans in
> > > > VariableResolverImpl. According to the spec the VariableResolverImpl
> > > > should only delegate to the application elresolver now. The managed
> > > > beans where resolved in a new ManagedBeanResolver. We already have
> an
> > > > implementation for this so I ask you to implement this into the
> > > > ManagedBeanResolver.
> > > >
> > > > I currently change VariableResolverImpl and ElResolver setup
> according
> > > > to the spec.
> > > >
> > > > Cheers,
> > > > Mathias
> > > >
> > > > 2007/2/24, dennisbyrne@apache.org <dennisbyrne@apache.org>:
> > > > > Author: dennisbyrne
> > > > > Date: Fri Feb 23 22:59:15 2007
> > > > > New Revision: 511230
> > > > >
> > > > > URL: http://svn.apache.org/viewvc?view=rev&rev=511230
> > > > > Log:
> > > > > implemented sectoin 5.4.1 as far as @PostConstruct is concerned,
> > @PreDestroy is still left
> > > > > refactored ManagedBeanBuilder and both Resolvers
> > > > >
> > > > > Added:
> > > > >
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/
> > > > >
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandler.java
> > > > >
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/
> > > > >
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedExceptionManagedBeanHandlerTestCase.java
> > > > >
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBean.java
> > > > >
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandlerTestCase.java
> > > > >
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedRuntimeExceptionManagedBeanHandlerTestCase.java
> > > > > Modified:
> > > > >
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java
> > > > >
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/VariableResolverImpl.java
> > > > >
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ManagedBeanResolver.java
> > > > >
> > > > > Modified:
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java
> > > > > URL:
> >
> http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java?view=diff&rev=511230&r1=511229&r2=511230
> > > > >
> >
> ==============================================================================
> > > > > ---
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java
> > (original)
> > > > > +++
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java
> > Fri Feb 23 22:59:15 2007
> > > > > @@ -15,23 +15,34 @@
> > > > >   */
> > > > >  package org.apache.myfaces.config;
> > > > >
> > > > > +import java.lang.reflect.Array;
> > > > > +import java.util.ArrayList;
> > > > > +import java.util.HashMap;
> > > > > +import java.util.Iterator;
> > > > > +import java.util.List;
> > > > > +import java.util.Map;
> > > > > +
> > > > >  import javax.el.ELContext;
> > > > > +import javax.el.ELException;
> > > > >  import javax.el.ELResolver;
> > > > >  import javax.el.ExpressionFactory ;
> > > > >  import javax.el.ValueExpression;
> > > > > -import org.apache.myfaces.config.element.*;
> > > > > -import org.apache.commons.beanutils.PropertyUtils;
> > > > > -import org.apache.commons.logging.Log;
> > > > > -import org.apache.commons.logging.LogFactory;
> > > > > -
> > > > >  import javax.faces.FacesException;
> > > > >  import javax.faces.application.Application;
> > > > > -import javax.faces.context.FacesContext;
> > > > >  import javax.faces.context.ExternalContext ;
> > > > > +import javax.faces.context.FacesContext;
> > > > >  import javax.faces.webapp.UIComponentTag;
> > > > > -import java.util.*;
> > > > > -import java.lang.reflect.Array;
> > > > > -import javax.el.ELException;
> > > > > +
> > > > > +import org.apache.commons.beanutils.PropertyUtils;
> > > > > +import org.apache.commons.logging.Log;
> > > > > +import org.apache.commons.logging.LogFactory;
> > > > > +import
> > org.apache.myfaces.config.annotation.AnnotatedManagedBeanHandler
> > ;
> > > > > +import
> > org.apache.myfaces.config.element.ListEntries;
> > > > > +import org.apache.myfaces.config.element.ListEntry;
> > > > > +import
> > org.apache.myfaces.config.element.ManagedBean;
> > > > > +import
> > org.apache.myfaces.config.element.ManagedProperty ;
> > > > > +import org.apache.myfaces.config.element.MapEntries;
> > > > > +import org.apache.myfaces.config.element.MapEntry;
> > > > >  import
> > org.apache.myfaces.shared_impl.util.ClassUtils;
> > > > >
> > > > >
> > > > > @@ -45,12 +56,22 @@
> > > > >  {
> > > > >      private static Log log =
> > LogFactory.getLog(ManagedBeanBuilder.class);
> > > > >      private RuntimeConfig _runtimeConfig;
> > > > > -
> > > > > +    public final static String REQUEST = "request";
> > > > > +    public final static String APPLICATION = "application";
> > > > > +    public final static String SESSION = "session";
> > > > > +    public final static String NONE = "none";
> > > > >
> > > > >      public Object buildManagedBean(FacesContext facesContext,
> > ManagedBean beanConfiguration) throws FacesException
> > > > >      {
> > > > > -        Object bean =
> > ClassUtils.newInstance(beanConfiguration.getManagedBeanClassName
> > ());
> > > > > +        final Object bean =
> > ClassUtils.newInstance(beanConfiguration.getManagedBeanClassName());
> > > > >
> > > > > +        final AnnotatedManagedBeanHandler handler = new
> > AnnotatedManagedBeanHandler(bean, beanConfiguration);
> > > > > +
> > > > > +        final boolean threwUnchecked = handler.run();
> > > > > +
> > > > > +        if(threwUnchecked)
> > > > > +               return null;
> > > > > +
> > > > >          switch (beanConfiguration.getInitMode ())
> > > > >          {
> > > > >              case ManagedBean.INIT_MODE_PROPERTIES:
> > > > > @@ -240,18 +261,18 @@
> > > > >              String valueScope = getScope(facesContext,
> expression);
> > > > >
> > > > >              // if the target scope is 'none' value scope has to
> be
> > 'none', too
> > > > > -            if (targetScope == null ||
> > targetScope.equalsIgnoreCase("none")) {
> > > > > -                if (valueScope != null &&
> > !(valueScope.equalsIgnoreCase("none"))) {
> > > > > +            if (targetScope == null ||
> > targetScope.equalsIgnoreCase(NONE)) {
> > > > > +                if (valueScope != null &&
> > !(valueScope.equalsIgnoreCase(NONE))) {
> > > > >                      return false;
> > > > >                  }
> > > > >                  return true;
> > > > >              }
> > > > >
> > > > >              // 'application' scope can reference 'application'
> and
> > 'none'
> > > > > -            if (targetScope.equalsIgnoreCase("application")) {
> > > > > +            if (targetScope.equalsIgnoreCase(APPLICATION)) {
> > > > >                  if (valueScope != null) {
> > > > > -                    if (valueScope.equalsIgnoreCase("request") ||
> > > > > -                         valueScope.equalsIgnoreCase("session"))
> {
> > > > > +                    if (valueScope.equalsIgnoreCase(REQUEST) ||
> > > > > +                        valueScope.equalsIgnoreCase(SESSION)) {
> > > > >                          return false;
> > > > >                      }
> > > > >                  }
> > > > > @@ -259,9 +280,9 @@
> > > > >              }
> > > > >
> > > > >              // 'session' scope can reference 'session',
> > 'application', and 'none' but not 'request'
> > > > > -            if (targetScope.equalsIgnoreCase("session")) {
> > > > > +            if (targetScope.equalsIgnoreCase(SESSION)) {
> > > > >                  if (valueScope != null) {
> > > > > -                    if ( valueScope.equalsIgnoreCase("request"))
> {
> > > > > +                    if (valueScope.equalsIgnoreCase(REQUEST)) {
> > > > >                          return false;
> > > > >                      }
> > > > >                  }
> > > > > @@ -269,7 +290,7 @@
> > > > >              }
> > > > >
> > > > >              // 'request' scope can reference any value scope
> > > > > -            if (targetScope.equalsIgnoreCase("request")) {
> > > > > +            if ( targetScope.equalsIgnoreCase(REQUEST)) {
> > > > >                  return true;
> > > > >              }
> > > > >          }
> > > > > @@ -282,60 +303,59 @@
> > > > >          String beanName = getFirstSegment(expression);
> > > > >          ExternalContext externalContext =
> > facesContext.getExternalContext();
> > > > >
> > > > > -        // check scope objects
> > > > > +
> > > > > +               // check scope objects
> > > > >          if (beanName.equalsIgnoreCase("requestScope")) {
> > > > > -            return "request";
> > > > > +            return REQUEST;
> > > > >          }
> > > > > -        if (beanName.equalsIgnoreCase("sessionScope")) {
> > > > > -            return "session";
> > > > > +               if (beanName.equalsIgnoreCase ("sessionScope")) {
> > > > > +            return SESSION;
> > > > >          }
> > > > > -        if (beanName.equalsIgnoreCase("applicationScope")) {
> > > > > -            return "application";
> > > > > +               if (beanName.equalsIgnoreCase("applicationScope"))
> {
> > > > > +            return APPLICATION;
> > > > >          }
> > > > >
> > > > >             // check implicit objects
> > > > >          if (beanName.equalsIgnoreCase ("cookie")) {
> > > > > -           return "request";
> > > > > +               return REQUEST;
> > > > >          }
> > > > >          if (beanName.equalsIgnoreCase("facesContext")) {
> > > > > -            return "request";
> > > > > +            return REQUEST;
> > > > >          }
> > > > >
> > > > >          if (beanName.equalsIgnoreCase("header")) {
> > > > > -            return "request";
> > > > > +            return REQUEST;
> > > > >          }
> > > > >          if (beanName.equalsIgnoreCase("headerValues")) {
> > > > > -            return "request";
> > > > > +            return REQUEST;
> > > > >          }
> > > > >
> > > > >          if ( beanName.equalsIgnoreCase("initParam")) {
> > > > > -           return "application";
> > > > > +               return APPLICATION;
> > > > >          }
> > > > >          if (beanName.equalsIgnoreCase("param")) {
> > > > > -            return "request";
> > > > > +            return REQUEST;
> > > > >          }
> > > > >          if (beanName.equalsIgnoreCase("paramValues")) {
> > > > > -            return "request";
> > > > > +            return REQUEST;
> > > > >          }
> > > > >          if (beanName.equalsIgnoreCase("view")) {
> > > > > -            return "request";
> > > > > +            return REQUEST;
> > > > >          }
> > > > >
> > > > > -
> > > > >          // not found so far - check all scopes
> > > > >          if (externalContext.getRequestMap().get(beanName) !=
> null) {
> > > > > -            return "request";
> > > > > +            return REQUEST;
> > > > >          }
> > > > >          if (externalContext.getSessionMap().get(beanName) !=
> null) {
> > > > > -            return "session";
> > > > > +            return SESSION;
> > > > >          }
> > > > >          if (
> > externalContext.getApplicationMap().get(beanName) != null)
> > {
> > > > > -            return "application";
> > > > > +            return APPLICATION;
> > > > >          }
> > > > >
> > > > >          //not found - check mangaged bean config
> > > > >
> > > > > -
> > > > >          ManagedBean mbc =
> > getRuntimeConfig(facesContext).getManagedBean(beanName);
> > > > >
> > > > >          if (mbc != null) {
> > > > > @@ -344,9 +364,6 @@
> > > > >
> > > > >          return null;
> > > > >      }
> > > > > -
> > > > > -
> > > > > -
> > > > >
> > > > >      /**
> > > > >       * Extract the first expression segment, that is the
> substring up
> > to the first '.' or '['
> > > > >
> > > > > Added:
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandler.java
> > > > > URL:
> >
> http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandler.java?view=auto&rev=511230
> > > > >
> >
> ==============================================================================
> > > > > ---
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandler.java
> > (added)
> > > > > +++
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandler.java
> > Fri Feb 23 22:59:15 2007
> > > > > @@ -0,0 +1,136 @@
> > > > > +package org.apache.myfaces.config.annotation ;
> > > > > +
> > > > > +import java.lang.annotation.Annotation;
> > > > > +import java.lang.reflect.InvocationTargetException;
> > > > > +import java.lang.reflect.Method;
> > > > > +
> > > > > +import javax.faces.FacesException;
> > > > > +
> > > > > +import org.apache.commons.logging.Log;
> > > > > +import org.apache.commons.logging.LogFactory;
> > > > > +import org.apache.myfaces.config.ManagedBeanBuilder;
> > > > > +import org.apache.myfaces.config.element.ManagedBean
> > ;
> > > > > +
> > > > > +/**
> > > > > + * @see JSF spec 1.2, section 5.4
> > > > > + * @warn Do not import javax.annotation.* in this class
> > > > > + * @author Dennis Byrne
> > > > > + */
> > > > > +
> > > > > +public class AnnotatedManagedBeanHandler {
> > > > > +
> > > > > +       private static Log log =
> > LogFactory.getLog(AnnotatedManagedBeanHandler.class);
> > > > > +
> > > > > +       private Object managedBean;
> > > > > +
> > > > > +       private ManagedBean beanConfiguration;
> > > > > +
> > > > > +       public AnnotatedManagedBeanHandler(Object
> > managedBean, ManagedBean beanConfiguration) {
> > > > > +
> > > > > +               if (managedBean == null) {
> > > > > +                       throw new NullPointerException("Object
> > managedBean");
> > > > > +               }
> > > > > +
> > > > > +               if (beanConfiguration == null) {
> > > > > +                       throw new
> > NullPointerException("ManagedBean beanConfiguration");
> > > > > +               }
> > > > > +
> > > > > +               this.managedBean = managedBean;
> > > > > +               this.beanConfiguration = beanConfiguration;
> > > > > +
> > > > > +       }
> > > > > +
> > > > > +       public boolean run() {
> > > > > +
> > > > > +               boolean threwUnchecked = false;
> > > > > +
> > > > > +               if
> > (ManagedBeanBuilder.NONE.equals(beanConfiguration.getManagedBeanScope
> ()))
> > {
> > > > > +                       ; // this only applies to a, s, and r
> scope
> > beans
> > > > > +               } else {
> > > > > +                       threwUnchecked =
> > run(managedBean.getClass().getMethods());
> > > > > +               }
> > > > > +
> > > > > +               return threwUnchecked;
> > > > > +       }
> > > > > +
> > > > > +       private boolean run(Method[] methods) {
> > > > > +
> > > > > +               boolean threwUnchecked = false;
> > > > > +
> > > > > +               for (Method method : methods)
> > > > > +                       if (run(method)) {
> > > > > +                               threwUnchecked = true;
> > > > > +                               break;
> > > > > +                       }// break if we invoke method ? or invoke
> all
> > w/ annoation?
> > > > > +
> > > > > +               return threwUnchecked;
> > > > > +       }
> > > > > +
> > > > > +       private boolean run(Method method) {
> > > > > +
> > > > > +               Annotation[] annotations = method.getAnnotations
> ();
> > > > > +               boolean threwUnchecked = false;
> > > > > +
> > > > > +               for (Annotation annotation : annotations) {
> > > > > +                       if (isPostConstruct(annotation)) {
> > > > > +                               if (run(annotation, method)) {
> > > > > +
> > threwUnchecked = true;
> > > > > +                                       break; //
> > spec says not to call anymore methods on this
> > > > > +                               }
> > > > > +                       }
> > > > > +               }
> > > > > +
> > > > > +               return threwUnchecked;
> > > > > +       }
> > > > > +
> > > > > +       private boolean run(Annotation annotation, Method method)
> {
> > > > > +
> > > > > +               boolean threwUnchecked = true; // start w/
> pessimism
> > > > > +
> > > > > +               try {
> > > > > +
> > > > > +                       method.invoke(managedBean, null);
> > > > > +
> > > > > +                       threwUnchecked = false;
> > > > > +
> > > > > +               } catch (InvocationTargetException ite) { // catch
> > most specific first
> > > > > +
> > > > > +                       final Throwable cause = ite.getCause();
> > > > > +
> > > > > +                       handleException(method, cause == null ?
> ite :
> > cause);
> > > > > +
> > > > > +               } catch (Exception e) {
> > > > > +
> > > > > +                       handleException(method, e);
> > > > > +               }
> > > > > +
> > > > > +               return threwUnchecked;
> > > > > +       }
> > > > > +
> > > > > +       private void handleException(Method method, Throwable e) {
> > > > > +               final String genericLoggingMessage =
> > getGenericLoggingMessage(method, e);
> > > > > +
> > > > > +               if (e instanceof RuntimeException) // why did they
> > make RE extend E ?
> > > > > +               {
> > > > > +                       log.error(genericLoggingMessage + "
> MyFaces
> > cannot " + " put the bean in "
> > > > > +                                       +
> > beanConfiguration.getManagedBeanScope() + " scope " + " ...
> > execution continues. ");
> > > > > +               } else {
> > > > > +                       throw new
> > FacesException(genericLoggingMessage + " The spec is
> > ambivalent on checked exceptions.");
> > > > > +               }
> > > > > +       }
> > > > > +
> > > > > +       private String getGenericLoggingMessage(Method method,
> > Throwable e) {
> > > > > +               return "When invoking " + method.getName() + " on
> a
> > managed bean '" + beanConfiguration.getManagedBeanName ()
> > > > > +                               + "'," + " an exception " +
> > e.getClass() + "{" + e.getMessage() + "} was thrown. "
> > > > > +                               + " See section 5.4.1 of the JSF
> > specification.";
> > > > > +       }
> > > > > +
> > > > > +       private boolean isPostConstruct(Annotation annotation) {
> > > > > +
> > > > > +               final Class<? extends Annotation> annotationType =
> > annotation.annotationType();
> > > > > +               final String name = annotationType.getName();
> > > > > +               // use the literal String because we want to avoid
> > ClassDefNotFoundError
> > > > > +               return " javax.annotation.PostConstruct
> ".equals(name);
> > > > > +
> > > > > +       }
> > > > > +}
> > > > >
> > > > > Modified:
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/VariableResolverImpl.java
> > > > > URL:
> >
> http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/VariableResolverImpl.java?view=diff&rev=511230&r1=511229&r2=511230
> > > > >
> >
> ==============================================================================
> > > > > ---
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/VariableResolverImpl.java
> > (original)
> > > > > +++
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/VariableResolverImpl.java
> > Fri Feb 23 22:59:15 2007
> > > > > @@ -29,6 +29,7 @@
> > > > >  import org.apache.myfaces.config.ManagedBeanBuilder;
> > > > >  import org.apache.myfaces.config.RuntimeConfig;
> > > > >  import
> > org.apache.myfaces.config.element.ManagedBean;
> > > > > +import
> > org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.Scope;
> > > > >
> > > > >  import org.apache.commons.logging.Log;
> > > > >  import org.apache.commons.logging.LogFactory;
> > > > > @@ -313,25 +314,7 @@
> > > > >                   beansUnderConstruction.remove(managedBeanName);
> > > > >              }
> > > > >
> > > > > -            // put in scope
> > > > > -            String scopeKey = mbc.getManagedBeanScope();
> > > > > -
> > > > > -            // find the scope handler object
> > > > > -            Scope scope = (Scope) _scopes.get(scopeKey);
> > > > > -            if (scope == null)
> > > > > -            {
> > > > > -                log.error("Managed bean '" + name + "' has
> illegal
> > scope: "
> > > > > -                    + scopeKey);
> > > > > -            }
> > > > > -            else
> > > > > -            {
> > > > > -                scope.put(externalContext, name, obj);
> > > > > -            }
> > > > > -
> > > > > -            if(obj==null && log.isDebugEnabled())
> > > > > -            {
> > > > > -                log.debug("Variable '" + name + "' could not be
> > resolved.");
> > > > > -            }
> > > > > +            putInScope(mbc, externalContext, obj);
> > > > >
> > > > >              return obj;
> > > > >          }
> > > > > @@ -344,6 +327,28 @@
> > > > >          return null;
> > > > >      }
> > > > >
> > > > > +       private void putInScope(ManagedBean managedBean,
> > ExternalContext extContext, Object obj) {
> > > > > +
> > > > > +               final String managedBeanName =
> > managedBean.getManagedBeanName();
> > > > > +
> > > > > +               if (obj == null) {
> > > > > +                       if (log.isDebugEnabled())
> > > > > +                               log.debug("Variable '" +
> > managedBeanName + "' could not be resolved.");
> > > > > +               } else {
> > > > > +
> > > > > +                       String scopeKey =
> > managedBean.getManagedBeanScope ();
> > > > > +
> > > > > +                       // find the scope handler object
> > > > > +                       Scope scope = (Scope)
> _scopes.get(scopeKey);
> > > > > +                       if (scope == null) {
> > > > > +                               log.error("Managed bean '" +
> > managedBeanName + "' has illegal scope: " + scopeKey);
> > > > > +                       } else {
> > > > > +                               scope.put(extContext,
> managedBeanName,
> > obj);
> > > > > +                       }
> > > > > +               }
> > > > > +
> > > > > +       }
> > > > > +
> > > > >      protected RuntimeConfig getRuntimeConfig(FacesContext
> > facesContext)
> > > > >      {
> > > > >          if (_runtimeConfig == null)
> > > > >
> > > > > Modified:
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ManagedBeanResolver.java
> > > > > URL:
> >
> http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ManagedBeanResolver.java?view=diff&rev=511230&r1=511229&r2=511230
> > > > >
> >
> ==============================================================================
> > > > > ---
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ManagedBeanResolver.java
> > (original)
> > > > > +++
> >
> myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ManagedBeanResolver.java
> > Fri Feb 23 22:59:15 2007
> > > > > @@ -192,22 +192,30 @@
> > > > >              beansUnderConstruction.remove(managedBeanName);
> > > > >          }
> > > > >
> > > > > -        // put in scope
> > > > > -        String scopeKey = managedBean.getManagedBeanScope ();
> > > > > +       putInScope(managedBean, extContext, obj);
> > > > > +    }
> > > > > +
> > > > > +       private void putInScope(ManagedBean managedBean,
> > ExternalContext extContext, Object obj) {
> > > > >
> > > > > -        // find the scope handler object
> > > > > -        Scope scope = (Scope) _scopes.get(scopeKey);
> > > > > -        if (scope == null) {
> > > > > -            log.error("Managed bean '" + managedBeanName + "' has
> > illegal scope: "
> > > > > -                + scopeKey);
> > > > > -        } else {
> > > > > -            scope.put(extContext, managedBeanName, obj);
> > > > > -        }
> > > > > +               final String managedBeanName =
> > managedBean.getManagedBeanName ();
> > > > > +
> > > > > +               if (obj == null) {
> > > > > +                       if (log.isDebugEnabled())
> > > > > +                               log.debug("Variable '" +
> > managedBeanName + "' could not be resolved.");
> > > > > +               } else {
> > > > >
> > > > > -        if(obj==null && log.isDebugEnabled()) {
> > > > > -            log.debug("Variable '" + managedBeanName + "' could
> not
> > be resolved.");
> > > > > -        }
> > > > > -    }
> > > > > +                       String scopeKey =
> > managedBean.getManagedBeanScope();
> > > > > +
> > > > > +                       // find the scope handler object
> > > > > +                       Scope scope = (Scope)
> _scopes.get(scopeKey);
> > > > > +                       if (scope == null) {
> > > > > +                               log.error("Managed bean '" +
> > managedBeanName + "' has illegal scope: " + scopeKey);
> > > > > +                       } else {
> > > > > +                               scope.put(extContext,
> managedBeanName,
> > obj);
> > > > > +                       }
> > > > > +               }
> > > > > +
> > > > > +       }
> > > > >
> > > > >      // get the FacesContext from the ELContext
> > > > >      private FacesContext facesContext(ELContext context) {
> > > > >
> > > > > Added:
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedExceptionManagedBeanHandlerTestCase.java
> > > > > URL:
> >
> http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedExceptionManagedBeanHandlerTestCase.java?view=auto&rev=511230
> > > > >
> >
> ==============================================================================
> > > > > ---
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedExceptionManagedBeanHandlerTestCase.java
> > (added)
> > > > > +++
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedExceptionManagedBeanHandlerTestCase.java
> > Fri Feb 23 22:59:15 2007
> > > > > @@ -0,0 +1,88 @@
> > > > > +package org.apache.myfaces.config.annotation ;
> > > > > +
> > > > > +import org.apache.myfaces.config.ManagedBeanBuilder;
> > > > > +import
> > org.apache.myfaces.config.annotation.AnnotatedManagedBeanHandler;
> > > > > +import
> > org.apache.myfaces.config.impl.digester.elements.ManagedBean
> > ;
> > > > > +
> > > > > +import junit.framework.TestCase;
> > > > > +
> > > > > +/**
> > > > > + * @author Dennis Byrne
> > > > > + */
> > > > > +
> > > > > +public class
> > AnnotatedExceptionManagedBeanHandlerTestCase extends
> > TestCase {
> > > > > +
> > > > > +       protected AnnotatedManagedBean managedBean;
> > > > > +
> > > > > +       protected AnnotatedManagedBeanHandler handler;
> > > > > +
> > > > > +       protected ManagedBean managedBeanConf;
> > > > > +
> > > > > +       public void setUp() {
> > > > > +               managedBean = new AnnotatedManagedBean(new
> > Exception());
> > > > > +               managedBeanConf = new ManagedBean();
> > > > > +               handler = new
> > AnnotatedManagedBeanHandler(managedBean, managedBeanConf);
> > > > > +       }
> > > > > +
> > > > > +       public void testShouldNotBlowUpForNoneScope()
> > {
> > > > > +
> > > > > +               managedBeanConf.setScope(ManagedBeanBuilder.NONE);
> > > > > +
> > > > > +               boolean exceptionThrown = false;
> > > > > +
> > > > > +               try {
> > > > > +                       handler.run();
> > > > > +               } catch (Exception e) {
> > > > > +                       exceptionThrown = true;
> > > > > +               }
> > > > > +
> > > > > +
> > assertFalse(managedBean.isPostConstructCalled());
> > > > > +               assertFalse(exceptionThrown);
> > > > > +       }
> > > > > +
> > > > > +       public void testShouldBlowUpForRequestScope()
> > {
> > > > > +
> > > > > +               managedBeanConf.setScope(
> ManagedBeanBuilder.REQUEST);
> > > > > +
> > > > > +               boolean exceptionThrown = false;
> > > > > +
> > > > > +               try {
> > > > > +                       handler.run();
> > > > > +               } catch (Exception e) {
> > > > > +                       exceptionThrown = true;
> > > > > +               }
> > > > > +
> > > > > +               assertTrue(exceptionThrown);
> > > > > +       }
> > > > > +
> > > > > +       public void testShouldBlowUpForSessionScope()
> > {
> > > > > +
> > > > > +               managedBeanConf.setScope(
> ManagedBeanBuilder.SESSION);
> > > > > +
> > > > > +               boolean exceptionThrown = false;
> > > > > +
> > > > > +               try {
> > > > > +                       handler.run();
> > > > > +               } catch (Exception e) {
> > > > > +                       exceptionThrown = true;
> > > > > +               }
> > > > > +
> > > > > +               assertTrue(exceptionThrown);
> > > > > +       }
> > > > > +
> > > > > +       public void
> > testShouldBlowUpForApplicationScope() {
> > > > > +
> > > > > +
> > managedBeanConf.setScope(ManagedBeanBuilder.APPLICATION );
> > > > > +
> > > > > +               boolean exceptionThrown = false;
> > > > > +
> > > > > +               try {
> > > > > +                       handler.run();
> > > > > +               } catch (Exception e) {
> > > > > +                       exceptionThrown = true;
> > > > > +               }
> > > > > +
> > > > > +               assertTrue(exceptionThrown);
> > > > > +       }
> > > > > +
> > > > > +}
> > > > >
> > > > > Added:
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBean.java
> > > > > URL:
> >
> http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBean.java?view=auto&rev=511230
> > > > >
> >
> ==============================================================================
> > > > > ---
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBean.java
> > (added)
> > > > > +++
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBean.java
> > Fri Feb 23 22:59:15 2007
> > > > > @@ -0,0 +1,46 @@
> > > > > +package org.apache.myfaces.config.annotation ;
> > > > > +
> > > > > +import javax.annotation.PostConstruct;
> > > > > +import javax.annotation.PreDestroy;
> > > > > +
> > > > > +/**
> > > > > + * @author Dennis Byrne
> > > > > + */
> > > > > +
> > > > > +class AnnotatedManagedBean {
> > > > > +
> > > > > +       private boolean postConstructCalled = false; // using a
> stub
> > for a mock
> > > > > +
> > > > > +       private boolean preDestroyCalled = false; // using a stob
> for
> > a mock here
> > > > > +
> > > > > +       private Throwable throwable;
> > > > > +
> > > > > +       public AnnotatedManagedBean(Throwable throwable) {
> > > > > +               this.throwable = throwable;
> > > > > +       }
> > > > > +
> > > > > +       @PostConstruct
> > > > > +       public void postConstruct() throws Throwable {
> > > > > +               postConstructCalled = true;
> > > > > +
> > > > > +               if (throwable != null)
> > > > > +                       throw throwable;
> > > > > +       }
> > > > > +
> > > > > +       @PreDestroy
> > > > > +       public void preDestroy() throws Throwable {
> > > > > +               preDestroyCalled = true;
> > > > > +
> > > > > +               if (throwable != null)
> > > > > +                       throw throwable;
> > > > > +       }
> > > > > +
> > > > > +       boolean isPostConstructCalled() {
> > > > > +               return postConstructCalled;
> > > > > +       }
> > > > > +
> > > > > +       boolean isPreDestroyCalled() {
> > > > > +               return preDestroyCalled;
> > > > > +       }
> > > > > +
> > > > > +}
> > > > >
> > > > > Added:
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandlerTestCase.java
> > > > > URL:
> >
> http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandlerTestCase.java?view=auto&rev=511230
> > > > >
> >
> ==============================================================================
> > > > > ---
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandlerTestCase.java
> > (added)
> > > > > +++
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandlerTestCase.java
> > Fri Feb 23 22:59:15 2007
> > > > > @@ -0,0 +1,61 @@
> > > > > +package org.apache.myfaces.config.annotation;
> > > > > +
> > > > > +import junit.framework.TestCase;
> > > > > +
> > > > > +import org.apache.myfaces.config.ManagedBeanBuilder;
> > > > > +import
> > org.apache.myfaces.config.annotation.AnnotatedManagedBeanHandler;
> > > > > +import
> > org.apache.myfaces.config.impl.digester.elements.ManagedBean;
> > > > > +
> > > > > +/**
> > > > > + * @author Dennis Byrne
> > > > > + */
> > > > > +
> > > > > +public class AnnotatedManagedBeanHandlerTestCase
> > extends TestCase {
> > > > > +
> > > > > +       protected AnnotatedManagedBean managedBean;
> > > > > +       protected AnnotatedManagedBeanHandler handler;
> > > > > +       protected ManagedBean managedBeanConf;
> > > > > +
> > > > > +       public void setUp() {
> > > > > +               managedBean = new AnnotatedManagedBean(null);
> > > > > +               managedBeanConf = new ManagedBean();
> > > > > +               handler = new
> > AnnotatedManagedBeanHandler(managedBean, managedBeanConf);
> > > > > +       }
> > > > > +
> > > > > +       public void testShouldNotInvokeForNoneScope()
> > {
> > > > > +
> > > > > +               managedBeanConf.setScope(ManagedBeanBuilder.NONE);
> > > > > +               boolean threwUnchecked = handler.run();
> > > > > +
> > > > > +               assertFalse(threwUnchecked);
> > > > > +
> > assertFalse(managedBean.isPostConstructCalled());
> > > > > +       }
> > > > > +
> > > > > +       public void testShouldInvokeForRequestScope()
> > {
> > > > > +
> > > > > +               managedBeanConf.setScope(
> ManagedBeanBuilder.REQUEST);
> > > > > +               boolean threwUnchecked = handler.run();
> > > > > +
> > > > > +               assertFalse(threwUnchecked);
> > > > > +               assertTrue(
> > managedBean.isPostConstructCalled());
> > > > > +       }
> > > > > +
> > > > > +       public void testShouldInvokeForSessionScope()
> > {
> > > > > +
> > > > > +               managedBeanConf.setScope(
> ManagedBeanBuilder.SESSION);
> > > > > +               boolean threwUnchecked = handler.run();
> > > > > +
> > > > > +               assertFalse(threwUnchecked);
> > > > > +
> > assertTrue(managedBean.isPostConstructCalled());
> > > > > +       }
> > > > > +
> > > > > +       public void
> > testShouldInvokeForApplicationScope() {
> > > > > +
> > > > > +
> > managedBeanConf.setScope(ManagedBeanBuilder.APPLICATION);
> > > > > +               boolean threwUnchecked = handler.run ();
> > > > > +
> > > > > +               assertFalse(threwUnchecked);
> > > > > +
> > assertTrue(managedBean.isPostConstructCalled());
> > > > > +       }
> > > > > +
> > > > > +}
> > > > >
> > > > > Added:
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedRuntimeExceptionManagedBeanHandlerTestCase.java
> > > > > URL:
> >
> http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedRuntimeExceptionManagedBeanHandlerTestCase.java?view=auto&rev=511230
> > > > >
> >
> ==============================================================================
> > > > > ---
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedRuntimeExceptionManagedBeanHandlerTestCase.java
> > (added)
> > > > > +++
> >
> myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedRuntimeExceptionManagedBeanHandlerTestCase.java
> > Fri Feb 23 22:59:15 2007
> > > > > @@ -0,0 +1,61 @@
> > > > > +package org.apache.myfaces.config.annotation;
> > > > > +
> > > > > +import junit.framework.TestCase;
> > > > > +
> > > > > +import org.apache.myfaces.config.ManagedBeanBuilder;
> > > > > +import
> > org.apache.myfaces.config.annotation.AnnotatedManagedBeanHandler
> > ;
> > > > > +import
> > org.apache.myfaces.config.impl.digester.elements.ManagedBean;
> > > > > +
> > > > > +/**
> > > > > + * @author Dennis Byrne
> > > > > + */
> > > > > +
> > > > > +public class
> > AnnotatedRuntimeExceptionManagedBeanHandlerTestCase extends
> > TestCase {
> > > > > +
> > > > > +       protected AnnotatedManagedBean managedBean;
> > > > > +       protected AnnotatedManagedBeanHandler handler;
> > > > > +       protected ManagedBean managedBeanConf;
> > > > > +
> > > > > +       public void setUp() {
> > > > > +               managedBean = new AnnotatedManagedBean(new
> > RuntimeException());
> > > > > +               managedBeanConf = new ManagedBean();
> > > > > +               handler = new
> > AnnotatedManagedBeanHandler(managedBean, managedBeanConf);
> > > > > +       }
> > > > > +
> > > > > +       public void testShouldNotInvokeForNoneScope()
> > {
> > > > > +
> > > > > +               managedBeanConf.setScope(ManagedBeanBuilder.NONE);
> > > > > +               boolean threwUnchecked = handler.run();
> > > > > +
> > > > > +               assertFalse(threwUnchecked);
> > > > > +
> > assertFalse(managedBean.isPostConstructCalled());
> > > > > +       }
> > > > > +
> > > > > +       public void testShouldInvokeForRequestScope()
> > {
> > > > > +
> > > > > +               managedBeanConf.setScope(
> ManagedBeanBuilder.REQUEST);
> > > > > +               boolean threwUnchecked = handler.run();
> > > > > +
> > > > > +               assertTrue(threwUnchecked);
> > > > > +               assertTrue(
> > managedBean.isPostConstructCalled());
> > > > > +       }
> > > > > +
> > > > > +       public void testShouldInvokeForSessionScope()
> > {
> > > > > +
> > > > > +               managedBeanConf.setScope(
> ManagedBeanBuilder.SESSION);
> > > > > +               boolean threwUnchecked = handler.run();
> > > > > +
> > > > > +               assertTrue(threwUnchecked);
> > > > > +
> > assertTrue(managedBean.isPostConstructCalled());
> > > > > +       }
> > > > > +
> > > > > +       public void
> > testShouldInvokeForApplicationScope() {
> > > > > +
> > > > > +
> > managedBeanConf.setScope(ManagedBeanBuilder.APPLICATION);
> > > > > +               boolean threwUnchecked = handler.run ();
> > > > > +
> > > > > +               assertTrue(threwUnchecked);
> > > > > +
> > assertTrue(managedBean.isPostConstructCalled());
> > > > > +       }
> > > > > +
> > > > > +}
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Mathias
> > > >
> > >
> > >
> > >
> > >
> > --
> > Dennis Byrne
>
>
> --
> Mathias
>



-- 
Dennis Byrne

Mime
View raw message