You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/04/10 12:52:34 UTC

cvs commit: jakarta-avalon-excalibur/threadcontext/src/java/org/apache/excalibur/threadcontext/impl DefaultThreadContextPolicy.java

donaldp     02/04/10 03:52:34

  Modified:    threadcontext/src/java/org/apache/excalibur/threadcontext
                        DefaultThreadContextPolicy.java
  Added:       threadcontext/src/java/org/apache/excalibur/threadcontext/impl
                        DefaultThreadContextPolicy.java
  Log:
  Move implementation to separate package in preparation for major revamp.
  
  Revision  Changes    Path
  1.3       +3 -77     jakarta-avalon-excalibur/threadcontext/src/java/org/apache/excalibur/threadcontext/DefaultThreadContextPolicy.java
  
  Index: DefaultThreadContextPolicy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/threadcontext/src/java/org/apache/excalibur/threadcontext/DefaultThreadContextPolicy.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultThreadContextPolicy.java	9 Apr 2002 09:20:54 -0000	1.2
  +++ DefaultThreadContextPolicy.java	10 Apr 2002 10:52:34 -0000	1.3
  @@ -8,86 +8,12 @@
   package org.apache.excalibur.threadcontext;
   
   /**
  - * Default <code>ThreadContextPolicy</code> that just maintains the
  - * ContextClassLoader <code>ThreadLocal</code> variable. This is a useful
  - * class to extend for those wanting to write their own Policy.
  + * deprecated DefaultThreadContextPolicy.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  + * @deprecated Use org.apache.excalibur.threadcontext.impl.DefaultThreadContextPolicy instead.
    */
   public class DefaultThreadContextPolicy
  -    implements ThreadContextPolicy
  +    extends org.apache.excalibur.threadcontext.impl.DefaultThreadContextPolicy
   {
  -    /**
  -     * The activate method is called when the ThreadContext
  -     * is associated with a thread. This method sets the ContextClassLoader
  -     * if CLASSLOADER key is present in context.
  -     *
  -     * @param accessor the accessor to retrieve values from ThreadContext
  -     */
  -    public void activate( final ThreadContextAccessor accessor )
  -    {
  -        final ClassLoader classLoader = (ClassLoader)get( accessor, CLASSLOADER, null, ClassLoader.class );
  -        if( null != classLoader ) 
  -        {
  -            Thread.currentThread().setContextClassLoader( classLoader );
  -        }
  -    }
  -
  -    /**
  -     * The deactivate method is called when the ThreadContext is
  -     * dis-associated with a thread.
  -     *
  -     * @param accessor the accessor to retrieve values from ThreadContext
  -     */
  -    public void deactivate( final ThreadContextAccessor accessor )
  -    {
  -    }
  -
  -    /**
  -     * Verify that the key/value pair is valid.
  -     *
  -     * @param key The key
  -     * @param value the value
  -     * @exception IllegalArgumentException if pair is not valid
  -     */
  -    public void verifyKeyValue( final String key, final Object value )
  -        throws IllegalArgumentException
  -    {
  -        if( key.equals( CLASSLOADER ) && !( value instanceof ClassLoader ) )
  -        {
  -            throw new IllegalArgumentException( "Key " + key + " must be of type " +
  -                                                ClassLoader.class.getName() );
  -        }
  -    }
  -
  -    /**
  -     * Get a value for specified key, using specified default if none present
  -     * and making sure value is of specified type.
  -     *
  -     * @param key the key used to lookup value
  -     * @param defaultValue the default value if the key does not specify value
  -     * @param type the expected type of value
  -     * @return the value
  -     */
  -    protected Object get( final ThreadContextAccessor accessor,
  -                          final String key,
  -                          final Object defaultValue,
  -                          final Class type )
  -    {
  -        Object result = defaultValue;
  -
  -        if( accessor.containsKey( key ) )
  -        {
  -            result = accessor.get( key );
  -        }
  -
  -        if( null != result && !type.isInstance( result ) )
  -        {
  -            throw new IllegalArgumentException( "Key " + key + " expected to access " +
  -                                                type.getName() + " but got " +
  -                                                result.getClass().getName() );
  -        }
  -
  -        return result;
  -    }
   }
  
  
  
  1.1                  jakarta-avalon-excalibur/threadcontext/src/java/org/apache/excalibur/threadcontext/impl/DefaultThreadContextPolicy.java
  
  Index: DefaultThreadContextPolicy.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.threadcontext.impl;
  
  import org.apache.excalibur.threadcontext.ThreadContextPolicy;
  import org.apache.excalibur.threadcontext.ThreadContextAccessor;
  
  /**
   * Default <code>ThreadContextPolicy</code> that just maintains the
   * ContextClassLoader <code>ThreadLocal</code> variable. This is a useful
   * class to extend for those wanting to write their own Policy.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class DefaultThreadContextPolicy
      implements ThreadContextPolicy
  {
      /**
       * The activate method is called when the ThreadContext
       * is associated with a thread. This method sets the ContextClassLoader
       * if CLASSLOADER key is present in context.
       *
       * @param accessor the accessor to retrieve values from ThreadContext
       */
      public void activate( final ThreadContextAccessor accessor )
      {
          final ClassLoader classLoader = (ClassLoader)get( accessor, CLASSLOADER, null, ClassLoader.class );
          if( accessor.containsKey( CLASSLOADER ) ) 
          {
              Thread.currentThread().setContextClassLoader( classLoader );
          }
      }
  
      /**
       * The deactivate method is called when the ThreadContext is
       * dis-associated with a thread.
       *
       * @param accessor the accessor to retrieve values from ThreadContext
       */
      public void deactivate( final ThreadContextAccessor accessor )
      {
      }
  
      /**
       * Verify that the key/value pair is valid.
       *
       * @param key The key
       * @param value the value
       * @exception IllegalArgumentException if pair is not valid
       */
      public void verifyKeyValue( final String key, final Object value )
          throws IllegalArgumentException
      {
          if( key.equals( CLASSLOADER ) && !( value instanceof ClassLoader ) )
          {
              throw new IllegalArgumentException( "Key " + key + " must be of type " +
                                                  ClassLoader.class.getName() );
          }
      }
  
      /**
       * Get a value for specified key, using specified default if none present
       * and making sure value is of specified type.
       *
       * @param key the key used to lookup value
       * @param defaultValue the default value if the key does not specify value
       * @param type the expected type of value
       * @return the value
       */
      protected Object get( final ThreadContextAccessor accessor,
                            final String key,
                            final Object defaultValue,
                            final Class type )
      {
          Object result = defaultValue;
  
          if( accessor.containsKey( key ) )
          {
              result = accessor.get( key );
          }
  
          if( null != result && !type.isInstance( result ) )
          {
              throw new IllegalArgumentException( "Key " + key + " expected to access " +
                                                  type.getName() + " but got " +
                                                  result.getClass().getName() );
          }
  
          return result;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>