You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/02/11 16:08:58 UTC

cvs commit: jakarta-avalon/src/proposal/resolver Query.java Resolver.java ResolverException.java Token.java

bloritsch    02/02/11 07:08:58

  Modified:    src/java/org/apache/avalon/framework/logger NullLogger.java
  Added:       src/java/org/apache/avalon/framework/logger
                        PrimordialLogger.java
               src/proposal/resolver Query.java Resolver.java
                        ResolverException.java Token.java
  Log:
  add resolver proposal
  
  Revision  Changes    Path
  1.2       +1 -1      jakarta-avalon/src/java/org/apache/avalon/framework/logger/NullLogger.java
  
  Index: NullLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/framework/logger/NullLogger.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NullLogger.java	5 Feb 2002 18:07:51 -0000	1.1
  +++ NullLogger.java	11 Feb 2002 15:08:58 -0000	1.2
  @@ -88,6 +88,6 @@
   
       public Logger getChildLogger(String name)
       {
  -        return new NullLogger();
  +        return this;
       }
   }
  
  
  
  1.1                  jakarta-avalon/src/java/org/apache/avalon/framework/logger/PrimordialLogger.java
  
  Index: PrimordialLogger.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.avalon.framework.logger;
  
  
  /**
   * Logger sending everything to the standard output streams.
   * This is mainly for the cases when you have a utility that
   * does not have a logger to supply.
   *
   * @author <a href="mailto:leo.sutic@inspireinfrastructure.com">Leo Sutic</a>
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public final class PrimordialLogger implements Logger
  {
      public final static int LEVEL_DEBUG = 0;
      public final static int LEVEL_INFO = 1;
      public final static int LEVEL_WARN = 2;
      public final static int LEVEL_ERROR = 3;
      public final static int LEVEL_FATAL = 4;
      public final static int LEVEL_DISABLED = 5;
  
      private final int m_logLevel;
  
      /**
       * Creates a new ConsoleLogger with the priority set to DEBUG.
       */
      public PrimordialLogger()
      {
          this( LEVEL_DEBUG );
      }
  
      /**
       * Creates a new ConsoleLogger.
       */
      public PrimordialLogger( final int logLevel )
      {
          m_logLevel = logLevel;
      }
  
      public void debug( final String message )
      {
          debug( message, null );
      }
  
      public void debug( final String message, final Throwable throwable )
      {
          if ( m_logLevel <= LEVEL_DEBUG )
          {
              System.out.print( "[DEBUG] " );
              System.out.println( message );
  
              if ( null != throwable )
              {
                  throwable.printStackTrace( System.out );
              }
          }
      }
  
      public boolean isDebugEnabled()
      {
          return m_logLevel <= LEVEL_DEBUG;
      }
  
      public void info( final String message )
      {
          info( message, null );
      }
  
      public void info( final String message, final Throwable throwable )
      {
          if ( m_logLevel <= LEVEL_INFO )
          {
              System.out.print( "[INFO] " );
              System.out.println( message );
  
              if ( null != throwable )
              {
                  throwable.printStackTrace( System.out );
              }
          }
      }
  
      public boolean isInfoEnabled()
      {
          return m_logLevel <= LEVEL_INFO;
      }
  
      public void warn( final String message )
      {
          warn( message, null );
      }
  
      public void warn(final String message, final Throwable throwable)
      {
          if ( m_logLevel <= LEVEL_WARN )
          {
              System.out.print( "[WARNING] " );
              System.out.println( message );
  
              if ( null != throwable )
              {
                  throwable.printStackTrace( System.out );
              }
          }
      }
  
      public boolean isWarnEnabled()
      {
          return m_logLevel <= LEVEL_WARN;
      }
  
      public void error( final String message )
      {
          error( message, null );
      }
  
      public void error( final String message, final Throwable throwable )
      {
          if ( m_logLevel <= LEVEL_ERROR )
          {
              System.out.print( "[ERROR] " );
              System.out.println( message );
  
              if ( null != throwable )
              {
                  throwable.printStackTrace( System.out );
              }
          }
      }
  
      public boolean isErrorEnabled()
      {
          return m_logLevel <= LEVEL_ERROR;
      }
  
      public void fatalError( final String message )
      {
          fatalError( message, null );
      }
  
      public void fatalError( final String message, final Throwable throwable )
      {
          if ( m_logLevel <= LEVEL_FATAL )
          {
              System.out.print( "[FATAL ERROR] " );
              System.out.println( message );
  
              if ( null != throwable )
              {
                  throwable.printStackTrace( System.out );
              }
          }
      }
  
      public boolean isFatalErrorEnabled()
      {
          return m_logLevel <= LEVEL_FATAL;
      }
  
      public Logger getChildLogger( final String name )
      {
          return this;
      }
  }
  
  
  
  1.1                  jakarta-avalon/src/proposal/resolver/Query.java
  
  Index: Query.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.avalon.framework.service;
  
  import org.apache.avalon.framework.context.Context;
  
  /**
   * A <code>Query</code> will identify all the objects needed for a specific lookup.
   * The <code>Query</code> will help the resolver obtain reference to the necessary
   * objects in order.  In other words, if we asked for three objects, the order of
   * the objects returned by the <code>Resolver</code> will match the order that the
   * keys were added to the <code>Query</code> object.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public interface Query
  {
      Integer COMPONENT = new Integer(0x01);
      Integer SERVICE   = new Integer(0x02);
      Integer OBJECT    = new Integer(0x04);
  
      /**
       * Add a lookup key.  The Lookup key consists of an enumerated type, and the key
       * value.  That way, we can ensure that the object you get is the proper type.
       */
      void addKey( int type, String value );
  
      /**
       * You can add further hints, or attributes to the query that can help the
       * <code>Resolver</code> get the specific instance you want.  It is important
       * to note that the attributes do apply to all the key values.  The
       * <code>Resolver</code> does have the right to ignore any or all of the
       * attributes if it wants.
       */
      void addAttribute( Object name, Object value );
  
      /**
       * This obtains a reference to the attribute context used by the
       * code>Resolver</code>.  The context uses resolveable entryies to determine
       * the keys, and what types they are.
       */
      Context queryContext();
  }
  
  
  
  1.1                  jakarta-avalon/src/proposal/resolver/Resolver.java
  
  Index: Resolver.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.avalon.framework.service;
  
  /**
   * A <code>Resolver</code> will resolve one or more objects and return a token.
   * The responsibility of the Resolver is to get all references identified by the
   * <code>Query</code> object and return a <code>Token</code>.  The <code>Token</code>
   * then is responsible for releasing any objects that need to be returned to a
   * pool or properly decommissioned.
   *
   * <p>The types of objects returned by the Resolver are usually components and services,
   * but can be any arbitrary type.</p>
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public interface Resolver
  {
      /**
       * Resolve an <code>Object</code>/<code>Component</code>/<code>Service</code>
       * from a lookup parameter.  The Lookup parameter has a core value and attributes
       * associated with it.
       */
      Token lookup( Query query )
          throws ResolverException;
  }
  
  
  
  1.1                  jakarta-avalon/src/proposal/resolver/ResolverException.java
  
  Index: ResolverException.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.avalon.framework.service;
  
  import org.apache.avalon.framework.CascadingException;
  
  /**
   * The exception thrown to indicate a problem with resolver or the resolver query.
   * It is usually thrown by Resolver.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public class ResolverException
      extends CascadingException
  {
      /**
       * Construct a new <code>ResolverException</code> instance.
       *
       * @param message the exception message
       * @param throwable the throwable
       */
      public ResolverException( final String message, final Throwable throwable )
      {
          super( message, throwable );
      }
  
      /**
       * Construct a new <code>ResolverException</code> instance.
       *
       * @param message the exception message
       */
      public ResolverException( final String message )
      {
          super( message, null );
      }
  }
  
  
  
  1.1                  jakarta-avalon/src/proposal/resolver/Token.java
  
  Index: Token.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.avalon.framework.service;
  
  /**
   * A <code>Token</code> is responsible for returning the actual Objects requested
   * from the <code>Resolver</code>.  It is also responsible for collectively returnning
   * all the requested tokens back to the <code>Resolver</code> if they are pooled
   * or otherwise managed resources.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public interface Token
  {
      /**
       * Obtain the actual references from the query.  The order of references must match
       * the order of keys in the Query object.
       */
      Object[] references();
  
      /**
       * Releases the hold on all the referenced objects.  The <code>Token</code> is no
       * longer usable, and should be discarded after this method is called.
       */
      void release();
  }
  
  
  

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