avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject cvs commit: avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository ArtifactDatabase.java ArtifactDatabaseImpl.java InitialRepositoryFactory.java
Date Thu, 06 Nov 2003 23:53:06 GMT
akarasulu    2003/11/06 15:53:06

  Modified:    repository/spi/src/java/org/apache/avalon/repository
                        InitialRepositoryFactory.java
  Added:       repository/spi/src/java/org/apache/avalon/repository
                        ArtifactDatabase.java ArtifactDatabaseImpl.java
  Log:
  Check pointing some new classes for supporting artifact
  attributes obtained from a repository database.
  
  Revision  Changes    Path
  1.4       +17 -12    avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/InitialRepositoryFactory.java
  
  Index: InitialRepositoryFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/InitialRepositoryFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InitialRepositoryFactory.java	6 Nov 2003 06:31:10 -0000	1.3
  +++ InitialRepositoryFactory.java	6 Nov 2003 23:53:06 -0000	1.4
  @@ -78,6 +78,8 @@
    */
   public class InitialRepositoryFactory implements RepositoryFactory
   {
  +    /** the artifact name of the default repostory factory implemenation jar */
  +    public static final String DEFAULT_IMPL = "repository-impl" ;
       /** base property key for the urls of the required jars */
       public static final String URLS_BASE = "url" ;
       /** factory delegate implementation class name key */
  @@ -103,8 +105,21 @@
        * 
        * @throws RepositoryException
        */
  -    public InitialRepositoryFactory() throws RepositoryException
  +    public InitialRepositoryFactory( String a_implementation, String a_version )
  +        throws RepositoryException
       {
  +        /*
  +         * Gets the implementation's dependency descriptor from the repository
  +         * and generate a set of properties for it. 
  +         */
  +        // Get the api jar's build descriptor - this class is in the jar
  +        JarBuildDescriptor l_myBuild = JarBuildDescriptor.getJarBuildDescriptor(
  +            InitialRepositoryFactory.class.getClassLoader() ) ;
  +        JarDescriptor l_myJar = l_myBuild.getJarDescriptor() ;
  +        ArtifactDescriptor l_implDesc = new ArtifactDescriptor( l_myBuild
  +            .getJarDescriptor().getGroup(), a_implementation, "properties", 
  +            a_version ) ;
  +        
           /* 
            * Create the temporary directory to pull down files into
            */
  @@ -115,16 +130,6 @@
               l_tmpDir.mkdirs() ;
           }
           
  -        JarBuildDescriptor l_myBuild = JarBuildDescriptor.getJarBuildDescriptor(
  -            InitialRepositoryFactory.class.getClassLoader() ) ;
  -        
  -        /*
  -         * Now we want to figure out what implementation we are going to use
  -         * and instantiate the appropriate factory for that implementation.
  -         * 
  -         * Use our descriptor to access the appropriate release catelog for the 
  -         * entire group.
  -         */
           
           
           /*
  
  
  
  1.1                  avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/ArtifactDatabase.java
  
  Index: ArtifactDatabase.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.repository ;
  
  
  import javax.naming.directory.Attributes ;
  
  
  /**
   * Manages relational information associated with artifact attributes within the
   * repository presuming some attributes can be multivalued while others are 
   * single valued.
   *  
   * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
   * @author $Author: akarasulu $
   * @version $Revision: 1.1 $
   */
  public interface ArtifactDatabase
  {
      Attributes getArtifactAttributes( ArtifactDescriptor a_descriptor ) 
          throws RepositoryException ;
  }
  
  
  
  
  1.1                  avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/ArtifactDatabaseImpl.java
  
  Index: ArtifactDatabaseImpl.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.repository ;
  
  
  import java.net.MalformedURLException;
  import java.net.URL ;
  
  import java.io.IOException ; 
  import java.io.InputStream ;
  
  import java.util.HashMap;
  import java.util.Properties ;
  import java.util.Enumeration ;
  
  import javax.naming.directory.Attributes ;
  import javax.naming.directory.BasicAttributes ;
  
  
  /**
   * 
   * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
   * @author $Author: akarasulu $
   * @version $Revision: 1.1 $
   */
  public class ArtifactDatabaseImpl implements ArtifactDatabase
  {
      /** the base url of the remote repository */
      private final String m_remoteRepoBase ;
      /** not used but we can cache properties rather than dl everytime */
      private final HashMap m_artifactAttributeCache = new HashMap() ;
      
      
      /**
       * Creates an artifact database for a remote repository.
       * 
       * @param a_remoteRepoBase the base url of the remote repository
       */
      public ArtifactDatabaseImpl( String a_remoteRepoBase )
      {
          m_remoteRepoBase = a_remoteRepoBase ;
      }
      
      
      /**
       * @see org.apache.avalon.repository.ArtifactDatabase#
       * getArtifactAttributes(org.apache.avalon.repository.ArtifactDescriptor)
       */
      public Attributes getArtifactAttributes( ArtifactDescriptor a_descriptor )
          throws RepositoryException
      {
          URL l_url = null ;
          Attributes l_attrs = null ;
          
          try 
          {
              l_url = new URL( a_descriptor.getUrl( m_remoteRepoBase ) ) ;
              l_attrs = getAsAttributes( getProperties( l_url ) ) ;
          } 
          catch ( MalformedURLException e )
          {
              throw new RepositoryException( "Bad URL for artifact: " 
                  + a_descriptor.getSpecification(), e ) ;
          }
          catch ( IOException e )
          {
              throw new RepositoryException( "Failed to access properties file: " 
                  + l_url.toString(), e ) ;
          }
  
          return l_attrs ;
      }
  
      
      public static Attributes getAsAttributes( Properties a_props )
      {
          Attributes l_attrs = new BasicAttributes( false ) ;
          Enumeration l_list = a_props.propertyNames() ;
          
          while ( l_list.hasMoreElements() )
          {
              String l_key = ( String ) l_list.nextElement() ;
              
              if ( isEnumerated( l_key ) )
              {
                  String l_keyBase = getEnumeratedBase( l_key ) ;
                  l_attrs.put( l_keyBase, a_props.getProperty( l_key ) ) ;
              }
              
              l_attrs.put( l_key, a_props.getProperty( l_key ) ) ;
          }
          
          return l_attrs ;
      }
      
      
      /**
       * Gets the Properties in a remote properties file.
       * 
       * @param a_url the url to the properties file
       * @return the loaded properties for the file
       * @throws IOException if there is any problem loading the properties
       */
      public static Properties getProperties( URL a_url ) throws IOException
      {
          InputStream l_in = null ;
          Properties l_props = new Properties() ;
          l_in = a_url.openStream() ;
          l_props.load( l_in ) ;
          
          if ( l_in != null )
          {    
              l_in.close() ;
          }
          
          return l_props ;
      }
      
      
      /**
       * Detects whether or not a property key is of the multivalued enumeration 
       * kind.  A multivalued key simply enumerates values by appending a '.' and
       * a number after the dot: i.e. artifact.dependency.2 and artifact.alias.23
       * et. cetera.
       * 
       * @param a_key the property name or key
       * @return true if the property conforms to the enumerated property 
       * convention, false otherwise
       */
      public static boolean isEnumerated( String a_key )
      {
          int l_lastDot = a_key.lastIndexOf( '.' ) ;
          String l_lastComponent = null ;
          
          if ( -1 == l_lastDot )
          {
              return false ;
          }
  
          l_lastComponent = a_key.substring( l_lastDot + 1 ) ;
          
          try 
          {
              Integer.parseInt( l_lastComponent ) ;
          }
          catch ( NumberFormatException e )
          {
              return false ;
          }
          
          return true ;
      }
  
  
      /**
       * Gets the key base of an enumerated property using the multivalued 
       * property key naming convention.
       * 
       * @param a_key the enumerated key whose last name component is a number
       * @return the base name of the enumerated property
       */
      public static String getEnumeratedBase( String a_key )
      {
          int l_lastDot = a_key.lastIndexOf( '.' ) ;
          String l_base = null ;
          
          if ( -1 == l_lastDot )
          {
              return a_key ;
          }
  
          return a_key.substring( 0, l_lastDot ) ;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message