weaver      2004/06/23 11:30:08

  Modified:    components/cm/src/java/org/apache/jetspeed/components/adapters
                        StandardDelegationStrategy.java
                        InterceptorAdapter.java
                        ThreadLocalDelegationStrategy.java
                        DelegationStrategy.java
                        AbstractDelegationStrategy.java
  Log:
  JS2-46
  
  Revision  Changes    Path
  1.2       +12 -5     
jakarta-jetspeed-2/components/cm/src/java/org/apache/jetspeed/components/adapters/StandardDelegationStrategy.java
  
  Index: StandardDelegationStrategy.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/cm/src/java/org/apache/jetspeed/components/adapters/StandardDelegationStrategy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardDelegationStrategy.java   24 May 2004 21:27:44 -0000      1.1
  +++ StandardDelegationStrategy.java   23 Jun 2004 18:30:08 -0000      1.2
  @@ -22,17 +22,24 @@
   public class StandardDelegationStrategy extends AbstractDelegationStrategy
   {
   
  -    private Object delegatedInstance;
  +     private Object instance;
       
  -       protected Object getDelegatedInstance()
  +    public Object get()
       {
  -         return delegatedInstance;
  +       if(instance != null)
  +       {
  +         return instance;
  +       }
  +       else
  +       {
  +           return adapter.getComponentInstance();
  +       }
       }
   
   
  -    protected void setDelegatedInstance( Object instance )
  +    public void set( Object instance )
       {
  -        delegatedInstance  = instance;
  +       this.instance  = instance;
       }
   
   }
  
  
  
  1.2       +24 -41    
jakarta-jetspeed-2/components/cm/src/java/org/apache/jetspeed/components/adapters/InterceptorAdapter.java
  
  Index: InterceptorAdapter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/cm/src/java/org/apache/jetspeed/components/adapters/InterceptorAdapter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InterceptorAdapter.java   24 May 2004 21:27:44 -0000      1.1
  +++ InterceptorAdapter.java   23 Jun 2004 18:30:08 -0000      1.2
  @@ -15,16 +15,16 @@
    */
   package org.apache.jetspeed.components.adapters;
   
  -import java.lang.reflect.Proxy;
  -
   import org.picocontainer.ComponentAdapter;
   import org.picocontainer.PicoInitializationException;
   import org.picocontainer.PicoIntrospectionException;
   import org.picocontainer.defaults.AssignabilityRegistrationException;
  -import org.picocontainer.defaults.ImplementationHidingComponentAdapter;
  -import org.picocontainer.defaults.InterfaceFinder;
  +import org.picocontainer.defaults.DecoratingComponentAdapter;
   import org.picocontainer.defaults.NotConcreteRegistrationException;
  -import org.picocontainer.defaults.Swappable;
  +
  +import com.thoughtworks.proxy.factory.StandardProxyFactory;
  +import com.thoughtworks.proxy.toys.hotswap.HotSwapping;
  +import com.thoughtworks.proxy.toys.multicast.ClassHierarchyIntrospector;
   
   /**
    * InterceptorAdaptor
  @@ -32,63 +32,46 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor </a>
    * @version $Id$
    */
  -public class InterceptorAdapter extends ImplementationHidingComponentAdapter // 
DecoratingComponentAdapterFactory
  +public class InterceptorAdapter extends DecoratingComponentAdapter
   {
       private Class delegationStrategyClass;
  -    
  +    protected StandardProxyFactory proxyFactory;
  +
       public InterceptorAdapter( ComponentAdapter delegate, Class 
delegationStrategyClass )
       {
           super(delegate);
           this.delegationStrategyClass = delegationStrategyClass;
  +        this.proxyFactory = new StandardProxyFactory();
       }
  -    private final InterfaceFinder interfaceFinder = new InterfaceFinder();
   
  -    public Object getComponentInstance() throws PicoInitializationException,
  -            PicoIntrospectionException, AssignabilityRegistrationException,
  -            NotConcreteRegistrationException
  +    public Object getComponentInstance() throws PicoInitializationException, 
PicoIntrospectionException,
  +            AssignabilityRegistrationException, NotConcreteRegistrationException
       {
  -        Class[] interfaces;
  -        if (getDelegate().getComponentKey() instanceof Class
  -                && ((Class) getDelegate().getComponentKey()).isInterface())
  +
  +        Class[] proxyTypes;
  +        if (getComponentKey() instanceof Class && proxyFactory.canProxy((Class) 
getComponentKey()))
           {
  -            // If the compo
  -            interfaces = new Class[]{(Class) getDelegate().getComponentKey()};
  +            proxyTypes = new Class[]{(Class) getComponentKey()};
           }
           else
           {
  -            interfaces = interfaceFinder.getInterfaces(getDelegate()
  -                    .getComponentImplementation());
  -        }
  -        Class[] swappableAugmentedInterfaces = new Class[interfaces.length + 1];
  -        swappableAugmentedInterfaces[interfaces.length] = Swappable.class;
  -        System.arraycopy(interfaces, 0, swappableAugmentedInterfaces, 0,
  -                interfaces.length);
  -        if (interfaces.length == 0)
  -        {
  -            throw new PicoIntrospectionException(
  -                    "Can't hide implementation for "
  -                            + getDelegate().getComponentImplementation()
  -                                    .getName()
  -                            + ". It doesn't implement any interfaces.");
  +            proxyTypes = 
ClassHierarchyIntrospector.addIfClassProxyingSupportedAndNotObject(
  +                    getComponentImplementation(), 
getComponentImplementation().getInterfaces(), proxyFactory);
           }
  -        
  +
           final DelegationStrategy delegationStrategy;
           try
           {
               delegationStrategy = (DelegationStrategy) 
delegationStrategyClass.newInstance();
  -            delegationStrategy.setAdapter(this);
  +            delegationStrategy.setAdapter(this.getDelegate());
  +            return HotSwapping.object(proxyTypes, proxyFactory, delegationStrategy, 
true);
           }
           catch (Exception e)
           {
  -            throw new PicoInitializationException("Error while creating new 
DelegationStartegy instance: "+e.toString(), e);
  +            throw new PicoInitializationException("Error while creating new 
DelegationStartegy instance: "
  +                    + e.toString(), e);
           }
  -        
  -        return Proxy.newProxyInstance(getClass().getClassLoader(),
  -                swappableAugmentedInterfaces, delegationStrategy);
  -    }
   
  -    Object getDelegatedComponentInstance()
  -    {
  -        return super.getComponentInstance();
  +        
       }
   }
  
  
  
  1.2       +14 -3     
jakarta-jetspeed-2/components/cm/src/java/org/apache/jetspeed/components/adapters/ThreadLocalDelegationStrategy.java
  
  Index: ThreadLocalDelegationStrategy.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/cm/src/java/org/apache/jetspeed/components/adapters/ThreadLocalDelegationStrategy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ThreadLocalDelegationStrategy.java        24 May 2004 21:27:44 -0000      1.1
  +++ ThreadLocalDelegationStrategy.java        23 Jun 2004 18:30:08 -0000      1.2
  @@ -27,15 +27,26 @@
       /* (non-Javadoc)
        * @see 
org.apache.jetspeed.components.AbstractDelegationStrategy#getDelegatedInstance()
        */
  -    protected Object getDelegatedInstance()
  +    public Object get()
       {        
  -        return localInstance.get();
  +        Object useInstance = localInstance.get();
  +        if(useInstance != null)
  +        {
  +            return useInstance;
  +        }
  +        else
  +        {
  +            useInstance = adapter.getComponentInstance();
  +            set(useInstance);
  +            return useInstance;
  +        }
  +        
       }
   
       /* (non-Javadoc)
        * @see 
org.apache.jetspeed.components.AbstractDelegationStrategy#setDelegatedInstance(java.lang.Object)
        */
  -    protected void setDelegatedInstance( Object instance )
  +    public void set( Object instance )
       {
           localInstance.set(instance);
       }
  
  
  
  1.2       +4 -4      
jakarta-jetspeed-2/components/cm/src/java/org/apache/jetspeed/components/adapters/DelegationStrategy.java
  
  Index: DelegationStrategy.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/cm/src/java/org/apache/jetspeed/components/adapters/DelegationStrategy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DelegationStrategy.java   24 May 2004 21:27:44 -0000      1.1
  +++ DelegationStrategy.java   23 Jun 2004 18:30:08 -0000      1.2
  @@ -15,17 +15,17 @@
    */
   package org.apache.jetspeed.components.adapters;
   
  -import java.lang.reflect.InvocationHandler;
  +import org.picocontainer.ComponentAdapter;
   
  -import org.picocontainer.defaults.Swappable;
  +import com.thoughtworks.proxy.toys.delegate.ObjectReference;
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
    *
    */
  -public interface DelegationStrategy extends InvocationHandler, Swappable
  +public interface DelegationStrategy extends ObjectReference
   {
  -    void setAdapter(InterceptorAdapter adapter);
  +    void setAdapter(ComponentAdapter adapter);
       
   
   }
  
  
  
  1.2       +3 -58     
jakarta-jetspeed-2/components/cm/src/java/org/apache/jetspeed/components/adapters/AbstractDelegationStrategy.java
  
  Index: AbstractDelegationStrategy.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/cm/src/java/org/apache/jetspeed/components/adapters/AbstractDelegationStrategy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractDelegationStrategy.java   24 May 2004 21:27:44 -0000      1.1
  +++ AbstractDelegationStrategy.java   23 Jun 2004 18:30:08 -0000      1.2
  @@ -15,77 +15,22 @@
    */
   package org.apache.jetspeed.components.adapters;
   
  -import java.lang.reflect.Method;
  +import org.picocontainer.ComponentAdapter;
   
  -import org.picocontainer.defaults.InterfaceFinder;
  -import org.picocontainer.defaults.Swappable;
   
   public abstract class AbstractDelegationStrategy implements DelegationStrategy
   {
   
  -    private InterceptorAdapter adapter;
  +    protected ComponentAdapter adapter;
       
  -    public Object invoke( Object proxy, Method method, Object[] args )
  -            throws Throwable
  -    {
  -        if(adapter == null)
  -        {
  -            throw new IllegalStateException("InterceptorAdapter cannot be null.  
You must call setAdapter() before calling invoke().");
  -        }
  -        
  -        //System.out.println("Invoking method: " + method);
  -        Class declaringClass = method.getDeclaringClass();
  -        if (declaringClass.equals(Object.class))
  -        {
  -            if (method.equals(InterfaceFinder.hashCode))
  -            {
  -                // Return the hashCode of ourself, as Proxy.newProxyInstance()
  -                // may
  -                // return cached proxies. We want a unique hashCode for each
  -                // created proxy!
  -                return new Integer(System
  -                        .identityHashCode(AbstractDelegationStrategy.this));
  -            }
  -            if (method.equals(InterfaceFinder.equals))
  -            {
  -                return new Boolean(proxy == args[0]);
  -            }
  -            // If it's any other method defined by Object, call on ourself.
  -            return method.invoke(AbstractDelegationStrategy.this, args);
  -        }
  -        else if (declaringClass.equals(Swappable.class))
  -        {
  -            return method.invoke(this, args);
  -        }
  -        else
  -        {
  -            if (getDelegatedInstance() == null)
  -            {
  -                setDelegatedInstance(adapter.getDelegatedComponentInstance());
  -            }
  -            return method.invoke(getDelegatedInstance(), args);
  -        }
  -    }
  -
  -    public Object __hotSwap( Object newSubject )
  -    {
  -        Object result = getDelegatedInstance();
  -        setDelegatedInstance(newSubject);
  -        return result;
  -    }
  -
       /*
        * (non-Javadoc)
        * 
        * @see 
org.apache.jetspeed.components.DelegationStrategy#setAdapter(org.picocontainer.ComponentAdapter)
        */
  -    public void setAdapter( InterceptorAdapter adapter )
  +    public void setAdapter( ComponentAdapter adapter )
       {
           this.adapter = adapter;
   
       }
  -
  -    protected abstract Object getDelegatedInstance();
  -   
  -    protected abstract void setDelegatedInstance( Object instance );
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to