akarasulu 2003/11/02 09:02:37
Added: merlin/repository/spi/src/java/org/apache/avalon/repository
ArtifactDescriptor.java
Log:
Adding ArtifactDescriptor which is not yet used.
Revision Changes Path
1.1
avalon/merlin/repository/spi/src/java/org/apache/avalon/repository/ArtifactDescriptor.java
Index: ArtifactDescriptor.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 [EMAIL PROTECTED]
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.io.Serializable ;
import java.text.ParseException ;
import java.net.URL ;
import java.net.MalformedURLException ;
/**
* A bean which uniquely describes a repository artifact.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: akarasulu $
* @version $Revision: 1.1 $
*/
public class ArtifactDescriptor implements Serializable
{
/** the name of the artifact */
private String m_name = null ;
/** the type of the artifact */
private String m_type = null ;
/** the group of the artifact */
private String m_group = null ;
/** the version of the artifact */
private String m_version = null ;
/** the artifact's string specification holding all artifact parameters */
private transient String m_spec = null ;
/** a dirty flag to track changes for rebuild of spec string */
private transient boolean m_isDirty = true ;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
/**
* Creates a descriptor by breaking apart a Merlin artifact specification
* String into its various components. The type of the descriptor is
* automatically presumed to be of the jar type. Merlin represents a jar
* artifact using the following syntax: [group]:[artifact];[version].
*
* @param a_spec the specification string
*/
public ArtifactDescriptor( String a_spec )
throws ParseException
{
m_spec = a_spec ;
m_type = "jar" ;
int l_colon = a_spec.indexOf( ':' ) ;
if ( -1 == l_colon )
{
throw new ParseException( "Malformed Merlin artifact specification:"
+ " no colon in specification.", 0 ) ;
}
int l_semiColon = a_spec.indexOf( ';' ) ;
if ( -1 == l_semiColon )
{
throw new ParseException( "Malformed Merlin artifact specification:"
+ " no semi-colon in specification.", 0 ) ;
}
if ( l_colon >= l_semiColon )
{
throw new ParseException( "Malformed Merlin artifact specification:"
+ " colon index greater than semicolon index", 0 ) ;
}
m_group = a_spec.substring( 0, l_colon ) ;
m_name = a_spec.substring( l_colon, l_semiColon ) ;
m_version = a_spec.substring( l_semiColon ) ;
}
/**
* Creates an artifact descriptor using the components of a specification.
*
* @param a_group the group of the artifact
* @param a_name the name of the artifact
* @param a_type the type of the artifact
* @param a_version the version of the artifact
*/
public ArtifactDescriptor( String a_group, String a_name, String a_type,
String a_version )
{
if ( null == a_group )
{
throw new NullPointerException( "a_group" ) ;
}
if ( null == a_name )
{
throw new NullPointerException( "a_name" ) ;
}
if ( null == a_type )
{
throw new NullPointerException( "a_type" ) ;
}
if ( null == a_version )
{
throw new NullPointerException( "a_version" ) ;
}
m_name = a_name ;
m_type = a_type ;
m_group = a_group ;
m_version = a_version ;
}
// ------------------------------------------------------------------------
// bean accessors & mutators
// ------------------------------------------------------------------------
/**
* @return Returns the group.
*/
public String getGroup()
{
return m_group ;
}
/**
* @param a_group The group to set.
*/
public void setGroup( String a_group )
{
m_isDirty = true ;
m_group = a_group ;
}
/**
* @return Returns the name.
*/
public String getName()
{
return m_name ;
}
/**
* @param a_name The name to set.
*/
public void setName( String a_name )
{
m_isDirty = true ;
m_name = a_name ;
}
/**
* @return Returns the type.
*/
public String getType()
{
return m_type ;
}
/**
* @param a_type The type to set.
*/
public void setType( String a_type )
{
m_isDirty = true ;
m_type = a_type ;
}
/**
* @return Returns the version.
*/
public String getVersion()
{
return m_version ;
}
/**
* @param a_version The version to set.
*/
public void setVersion( String a_version )
{
m_isDirty = true ;
m_version = a_version ;
}
// ------------------------------------------------------------------------
// Convenient Functionality Offered by Descriptor
// ------------------------------------------------------------------------
/**
* Gets the artifact specification for this ArtifactDescriptor.
*
* @return the artifact specification
*/
public String getSpecification()
{
if ( null == m_spec || m_isDirty )
{
m_spec = createSpecification( m_group, m_name, m_version ) ;
m_isDirty = false ;
}
return m_spec ;
}
/**
* Returns the artifact specification String.
*
* @see java.lang.Object#toString()
*/
public String toString()
{
return getSpecification() ;
}
/**
* Gets the relative path to an artifact without a URL base. The returned
* URL path component represents the path to the artifact within a local or
* remote repository.
*/
public String getRelativePath( char a_separator )
{
StringBuffer l_buf = new StringBuffer() ;
l_buf.append( m_group ) ;
l_buf.append( a_separator ) ;
l_buf.append( "jars" ) ;
l_buf.append( a_separator ) ;
l_buf.append( m_name ) ;
l_buf.append( '-' ) ;
l_buf.append( m_version ) ;
l_buf.append( ".jar" ) ;
return l_buf.toString() ;
}
/**
* Gets the URL to the artifact given a base URL for the repository.
*
* @param a_repository the base URL to the repository
* @return the full URL to the artifact
*/
public URL getUrl( URL a_repository )
throws MalformedURLException
{
StringBuffer l_buf = new StringBuffer( a_repository.toExternalForm() ) ;
String l_relative = getRelativePath( '/' ) ;
if ( '/' == l_buf.charAt( l_buf.length() - 1 ) )
{
l_buf.append( getRelativePath( '/' ) ) ;
}
else
{
l_buf.append( '/' ) ;
l_buf.append( getRelativePath( '/' ) ) ;
}
return new URL( l_buf.toString() ) ;
}
// ------------------------------------------------------------------------
// Utility Functions
// ------------------------------------------------------------------------
/**
* Creates the specification for an artifact given the components of it's
* specification parameters.
*
* @param a_group the group of the artifact
* @param a_name the name of the artifact
* @param a_version the version of the artifact
*
* @return the composed specification String
*/
public static String createSpecification( String a_group, String a_name,
String a_version )
{
StringBuffer l_buf = new StringBuffer() ;
l_buf.append( a_group ) ;
l_buf.append( ':' ) ;
l_buf.append( a_name ) ;
l_buf.append( ';' ) ;
l_buf.append( a_version ) ;
return l_buf.toString() ;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]