[jboss-cvs] jboss-seam/src/ioc/org/jboss/seam/ioc/spring ...

Norman Richards norman.richards at jboss.com
Mon Feb 19 14:53:06 EST 2007


  User: nrichards
  Date: 07/02/19 14:53:06

  Modified:    src/ioc/org/jboss/seam/ioc/spring   SeamFactoryBean.java
                        SeamTargetSource.java
  Log:
  myoung patch
  
  Revision  Changes    Path
  1.4       +133 -147  jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamFactoryBean.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamFactoryBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamFactoryBean.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- SeamFactoryBean.java	18 Feb 2007 23:09:34 -0000	1.3
  +++ SeamFactoryBean.java	19 Feb 2007 19:53:06 -0000	1.4
  @@ -1,31 +1,22 @@
   package org.jboss.seam.ioc.spring;
   
  -import java.util.ArrayList;
   import java.util.List;
   
  -import javax.servlet.http.HttpSessionActivationListener;
  -
  -import org.jboss.seam.Component;
  -import org.jboss.seam.InterceptionType;
   import org.jboss.seam.ScopeType;
  -import org.jboss.seam.core.Mutable;
  -import org.jboss.seam.intercept.Proxy;
   import org.springframework.aop.framework.DefaultAopProxyFactory;
   import org.springframework.aop.framework.ProxyFactory;
   import org.springframework.beans.factory.InitializingBean;
   import org.springframework.beans.factory.config.AbstractFactoryBean;
   
   /**
  - * Obtains an instance of a Seam Component in the current context
  - * given the name and other optional parameters. If proxy is set to
  - * true then return a scoped proxy of the seam component instance. Use
  - * <seam:instance/> to simplify use of this factory.
  + * Obtains an instance of a Seam Component in the current context given the name
  + * and other optional parameters. If proxy is set to true then return a scoped
  + * proxy of the seam component instance. Use <seam:instance/> to simplify
  + * use of this factory.
    *
    * @author youngm
    */
  -public class SeamFactoryBean 
  -    extends AbstractFactoryBean 
  -    implements InitializingBean
  +public class SeamFactoryBean extends AbstractFactoryBean implements InitializingBean
   {
       private ScopeType scope;
       private String name;
  @@ -53,6 +44,9 @@
           
           if (proxy) 
           {
  +         if(targetSource.getTargetClass() == null) {
  +            throw new IllegalStateException("Cannot use 'proxy' for an expression.");
  +         }
               // Not sure if I should allow people to change these proxy
               // parameters or not. We'll see what issues we get hard coding them.
               ProxyFactory pf = new ProxyFactory();
  @@ -63,23 +57,7 @@
               pf.setAopProxyFactory(new DefaultAopProxyFactory());
               pf.setTargetSource(this.targetSource);
               
  -            // Attempt to piece together all of the possible interfaces to apply
  -            // to our proxy.
  -            List<Class> interfaces = new ArrayList<Class>();
  -            Component component = targetSource.getComponent();
  -            if (component!=null && component.getInterceptionType() != InterceptionType.NEVER) 
  -            {
  -                if (component.getType().isSessionBean()) 
  -                {
  -                    interfaces.addAll(component.getBusinessInterfaces());
  -                } 
  -                else 
  -                {
  -                    interfaces.add(HttpSessionActivationListener.class);
  -                    interfaces.add(Mutable.class);
  -                }
  -                interfaces.add(Proxy.class);
  -            }
  +         List<Class> interfaces = targetSource.getSeamInterfaces();
               pf.setInterfaces(interfaces.toArray(new Class[interfaces.size()]));
               
               this.proxyInstance = pf.getProxy();
  @@ -88,7 +66,8 @@
       }
       
       /**
  -     * Return the current instance of a Seam component or the proxy if proxy was set to true.
  +    * Return the current instance of a Seam component or the proxy if proxy was
  +    * set to true.
        *
        * @see org.springframework.beans.factory.config.AbstractFactoryBean#createInstance()
        */
  @@ -104,10 +83,13 @@
               return targetSource.getTarget();
           }
       }
  +
       /**
        * Return the type of the component if available.
        *
  -     * @throws IllegalStateException if the component cannot be found or if seam has not yet been initialized.
  +    * @throws IllegalStateException
  +    *            if the component cannot be found or if seam has not yet been
  +    *            initialized.
        *
        * @see org.springframework.beans.factory.config.AbstractFactoryBean#getObjectType()
        */
  @@ -120,7 +102,8 @@
       /**
        * The name of the seam component to get an instance of. (required)
        *
  -     * @param name the name of the component
  +    * @param name
  +    *           the name of the component
        */
       public void setName(String name) 
       {
  @@ -130,7 +113,8 @@
       /**
        * The scope of the seam component (optional)
        *
  -     * @param scope the scope of the component
  +    * @param scope
  +    *           the scope of the component
        */
       public void setScope(ScopeType scope) 
       {
  @@ -138,12 +122,13 @@
       }
       
       /**
  -     * Should the factory create an instance of the component if one
  -     * doesn't already exist in this context. If null
  +    * Should the factory create an instance of the component if one doesn't
  +    * already exist in this context. If null
        *
        * Must always be true for STATELESS components.
        *
  -     * @param create do we create an instance if needed
  +    * @param create
  +    *           do we create an instance if needed
        */
       public void setCreate(Boolean create) 
       {
  @@ -151,10 +136,11 @@
       }
       
       /**
  -     * Should the factory wrap the component instance in a proxy so
  -     * the seam component can be safely injected into a singleton.
  +    * Should the factory wrap the component instance in a proxy so the seam
  +    * component can be safely injected into a singleton.
        *
  -     * @param proxy true to proxy the component
  +    * @param proxy
  +    *           true to proxy the component
        */
       public void setProxy(boolean proxy) 
       {
  
  
  
  1.5       +190 -113  jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamTargetSource.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamTargetSource.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamTargetSource.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- SeamTargetSource.java	18 Feb 2007 23:09:34 -0000	1.4
  +++ SeamTargetSource.java	19 Feb 2007 19:53:06 -0000	1.5
  @@ -1,18 +1,26 @@
   package org.jboss.seam.ioc.spring;
   
   import java.io.Serializable;
  +import java.util.ArrayList;
  +import java.util.List;
  +
  +import javax.servlet.http.HttpSessionActivationListener;
   
   import org.jboss.seam.Component;
  +import org.jboss.seam.InterceptionType;
   import org.jboss.seam.ScopeType;
   import org.jboss.seam.contexts.Contexts;
   import org.jboss.seam.contexts.Lifecycle;
   import org.jboss.seam.core.Expressions;
  +import org.jboss.seam.core.Mutable;
   import org.jboss.seam.core.Expressions.ValueBinding;
  +import org.jboss.seam.intercept.Proxy;
   import org.springframework.aop.TargetSource;
   
   /**
  - * A TargetSource for a seam component instance. Will obtain an instance given a name and optionally a scope and create.
  - * Used by the SeamFactoryBean to create a proxy for a requested seam component instance.
  + * A TargetSource for a seam component instance. Will obtain an instance given a
  + * name and optionally a scope and create. Used by the SeamFactoryBean to create
  + * a proxy for a requested seam component instance.
    *
    * @author youngm
    */
  @@ -24,11 +32,14 @@
       private Boolean create;
       private ValueBinding valueBinding;
   
  -    
       /**
  -     * @param name Name of the component: required
  -     * @param scope Name of the scope the component is in: optional
  -     * @param create Whether to create a new instance if one doesn't already exist: optional
  +    * @param name
  +    *           Name of the component: required
  +    * @param scope
  +    *           Name of the scope the component is in: optional
  +    * @param create
  +    *           Whether to create a new instance if one doesn't already exist:
  +    *           optional
        */
       public SeamTargetSource(String name, ScopeType scope, Boolean create) 
       {
  @@ -40,7 +51,8 @@
           this.scope = scope;
           this.create = create;
           
  -        if (name.startsWith("#")) {
  +      if (name.startsWith("#"))
  +      {
               this.valueBinding = Expressions.instance().createValueBinding(name);
           }
       }
  @@ -50,19 +62,28 @@
        *
        * @see org.springframework.aop.TargetSource#getTarget()
        */
  -    public Object getTarget() 
  -        throws Exception 
  +   public Object getTarget() throws Exception
  +   {
  +      if (valueBinding != null)
       {
  -        if (valueBinding != null) {
               return valueBinding.getValue();
  -        } else {
  -            if (scope == null && create == null) {
  +      }
  +      else
  +      {
  +         if (scope == null && create == null)
  +         {
                   return Component.getInstance(name);
  -            } else if (scope == null){
  +         }
  +         else if (scope == null)
  +         {
                   return Component.getInstance(name, create);
  -            } else if (create == null) {
  +         }
  +         else if (create == null)
  +         {
                   return Component.getInstance(name, scope);
  -            } else{
  +         }
  +         else
  +         {
                   return Component.getInstance(name, scope, create);
               }
           }
  @@ -75,11 +96,59 @@
        */
       public Class getTargetClass() 
       {
  -        if (valueBinding != null) {
  -            return valueBinding.getClass();
  -        } else {
  -            return getComponent().getBeanClass();
  +      Class trueClass = getTrueTargetClass();
  +      if(trueClass == null) {
  +         return null;
  +      }
  +      if (trueClass.isInterface())
  +      {
  +         return Object.class;
  +      }
  +      return trueClass;
  +   }
  +
  +   public Class getTrueTargetClass()
  +   {
  +      Component component = getComponent();
  +      if(component == null) {
  +         return null;
  +      }
  +      if (component.hasUnwrapMethod())
  +      {
  +         return component.getUnwrapMethod().getReturnType();
  +      }
  +      return component.getBeanClass();
  +   }
  +
  +   public List<Class> getSeamInterfaces()
  +   {
  +      List<Class> interfaces = new ArrayList<Class>();
  +      Class trueClass = getTrueTargetClass();
  +      if(trueClass == null) {
  +         return null;
  +      }
  +      // if the true class is an interface then add it
  +      if (trueClass.isInterface())
  +      {
  +         interfaces.add(trueClass);
  +      }
  +      Component component = getComponent();
  +      // Attempt to piece together all of the possible interfaces to apply
  +      // to our proxy.
  +      if (component.getInterceptionType() != InterceptionType.NEVER)
  +      {
  +         if (component.getType().isSessionBean())
  +         {
  +            interfaces.addAll(component.getBusinessInterfaces());
           }
  +         else
  +         {
  +            interfaces.add(HttpSessionActivationListener.class);
  +            interfaces.add(Mutable.class);
  +         }
  +         interfaces.add(Proxy.class);
  +      }
  +      return interfaces;
       }
   
       /**
  @@ -89,25 +158,33 @@
        */
       public Component getComponent() 
       {
  -        if (valueBinding == null) {
  +      if (valueBinding != null)
  +      {
               return null; 
  -        } else {
  +      }
  +      else
  +      {
               // TODO reuse
               boolean unmockApplication = false;
  -            if (!Contexts.isApplicationContextActive()) {
  +         if (!Contexts.isApplicationContextActive())
  +         {
                   Lifecycle.mockApplication();
                   unmockApplication = true;
               }
  -            try {
  +         try
  +         {
                   Component component = Component.forName(name);
                   if (component == null) 
                   {
  -                    throw new IllegalStateException("Cannot find targetClass for seam component: " + name
  -                            + ".  Make sure Seam is being configured before Spring.");
  +               throw new IllegalStateException("Cannot find targetClass for seam component: "
  +                        + name + ".  Make sure Seam is being configured before Spring.");
                   }
                   return component;
  -            } finally {
  -                if (unmockApplication) {
  +         }
  +         finally
  +         {
  +            if (unmockApplication)
  +            {
                       Lifecycle.unmockApplication();
                   }
               }
  
  
  



More information about the jboss-cvs-commits mailing list