mcconnell 2003/11/17 00:09:12
Modified: repository/api/src/java/org/apache/avalon/repository
ArtifactDescriptor.java
Log:
Change to usage an embedded artifact reference.
Revision Changes Path
1.3 +112 -87
avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/ArtifactDescriptor.java
Index: ArtifactDescriptor.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/ArtifactDescriptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ArtifactDescriptor.java 9 Nov 2003 09:13:58 -0000 1.2
+++ ArtifactDescriptor.java 17 Nov 2003 08:09:12 -0000 1.3
@@ -62,56 +62,54 @@
* @author $Author$
* @version $Revision$
*/
-public class ArtifactDescriptor implements Serializable
+public class ArtifactDescriptor extends Artifact
{
/** the name of the artifact */
- private String m_name = null ;
+ private final String m_name ;
+
/** the type of the artifact */
- private String m_type = null ;
+ private final String m_type ;
+
/** the group of the artifact */
- private String m_group = null ;
+ private final String m_group ;
+
/** the version of the artifact */
- private String m_version = null ;
+ private final String m_version ;
/** 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 ;
-
+ /** the artifact's string specification holding all artifact parameters */
+ private transient ArtifactReference m_reference = null ;
// ------------------------------------------------------------------------
// 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
+ * @param spec the specification string
*/
- public ArtifactDescriptor( String a_spec )
+ public ArtifactDescriptor( String spec )
throws ParseException
{
- if ( null == a_spec )
- {
- throw new NullPointerException( "a_spec arg must not be null" ) ;
- }
+ if ( null == spec ) throw new NullPointerException( "spec" );
- m_spec = a_spec ;
+ m_spec = spec ;
m_type = "jar" ;
-
- int l_colon = a_spec.indexOf( ':' ) ;
+
+ int l_colon = spec.indexOf( ':' ) ;
if ( -1 == l_colon )
{
throw new ParseException( "Malformed Merlin artifact specification:"
+ " no colon in specification.", 0 ) ;
}
- int l_semiColon = a_spec.indexOf( ';' ) ;
+ int l_semiColon = spec.indexOf( ';' ) ;
if ( -1 == l_semiColon )
{
throw new ParseException( "Malformed Merlin artifact specification:"
@@ -123,10 +121,11 @@
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+1, l_semiColon ) ;
- m_version = a_spec.substring( l_semiColon+1 ) ;
+
+ m_group = spec.substring( 0, l_colon ) ;
+ m_name = spec.substring( l_colon+1, l_semiColon ) ;
+ m_version = spec.substring( l_semiColon+1 ) ;
+
}
@@ -143,22 +142,22 @@
{
if ( null == a_group )
{
- throw new NullPointerException( "a_group must not be null" ) ;
+ throw new NullPointerException( "group" ) ;
}
if ( null == a_name )
{
- throw new NullPointerException( "a_name must not be null" ) ;
+ throw new NullPointerException( "name" ) ;
}
if ( null == a_type )
{
- throw new NullPointerException( "a_type must not be null" ) ;
+ throw new NullPointerException( "type" ) ;
}
if ( null == a_version )
{
- throw new NullPointerException( "a_version must not be null" ) ;
+ throw new NullPointerException( "version" ) ;
}
m_name = a_name ;
@@ -181,17 +180,15 @@
return m_group ;
}
-
/**
* @param a_group The group to set.
*/
- public void setGroup( String a_group )
- {
- m_isDirty = true ;
- m_group = a_group ;
- }
+ //public void setGroup( String a_group )
+ //{
+ // m_isDirty = true ;
+ // m_group = a_group ;
+ //}
-
/**
* @return Returns the name.
*/
@@ -204,11 +201,11 @@
/**
* @param a_name The name to set.
*/
- public void setName( String a_name )
- {
- m_isDirty = true ;
- m_name = a_name ;
- }
+ //public void setName( String a_name )
+ //{
+ // m_isDirty = true ;
+ // m_name = a_name ;
+ //}
/**
@@ -220,14 +217,16 @@
*/
public String getRootRelativePath()
{
- StringBuffer l_buf = new StringBuffer( m_group ) ;
- l_buf.append( '/' ) ;
- l_buf.append( m_name ) ;
- l_buf.append( '-' ) ;
- l_buf.append( m_version ) ;
- l_buf.append( '.' ) ;
- l_buf.append( m_type ) ;
- return l_buf.toString() ;
+ return getReference().getFilename();
+
+ //StringBuffer l_buf = new StringBuffer( m_group ) ;
+ //l_buf.append( '/' ) ;
+ //l_buf.append( m_name ) ;
+ //l_buf.append( '-' ) ;
+ //l_buf.append( m_version ) ;
+ //l_buf.append( '.' ) ;
+ //l_buf.append( m_type ) ;
+ //return l_buf.toString() ;
}
@@ -243,11 +242,11 @@
/**
* @param a_type The type to set.
*/
- public void setType( String a_type )
- {
- m_isDirty = true ;
- m_type = a_type ;
- }
+ //public void setType( String a_type )
+ //{
+ // m_isDirty = true ;
+ // m_type = a_type ;
+ //}
/**
@@ -262,17 +261,34 @@
/**
* @param a_version The version to set.
*/
- public void setVersion( String a_version )
- {
- m_isDirty = true ;
- m_version = a_version ;
- }
+ //public void setVersion( String a_version )
+ //{
+ // m_isDirty = true ;
+ // m_version = a_version ;
+ //}
// ------------------------------------------------------------------------
// Convenient Functionality Offered by Descriptor
// ------------------------------------------------------------------------
+ /**
+ * Gets the reference for this ArtifactDescriptor.
+ *
+ * @return the artifact specification
+ */
+ public ArtifactReference getReference()
+ {
+ if ( null == m_reference )
+ {
+ m_reference =
+ new ArtifactReference(
+ m_group + SEP + m_type + "s",
+ m_name + "-" + m_version + "." + m_type );
+ }
+ return m_reference;
+ }
+
/**
* Gets the artifact specification for this ArtifactDescriptor.
@@ -281,10 +297,11 @@
*/
public String getSpecification()
{
- if ( null == m_spec || m_isDirty )
+ //if ( null == m_spec || m_isDirty )
+ if ( null == m_spec )
{
m_spec = createSpecification( m_group, m_name, m_version ) ;
- m_isDirty = false ;
+ //m_isDirty = false ;
}
return m_spec ;
@@ -309,18 +326,25 @@
*/
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() ;
+
+ return getReference().getPath();
+
+ //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 ) ;
+ //
+ //if( ( m_version != null ) && ( !m_version.equals("") ) )
+ //{
+ // l_buf.append( '-' ) ;
+ // l_buf.append( m_version ) ;
+ // l_buf.append( ".jar" ) ;
+ //}
+ //
+ //return l_buf.toString() ;
}
@@ -330,25 +354,26 @@
* @param a_repository the base URL to the repository
* @return the full URL to the artifact
*/
- public String getUrl( String a_repository )
+ public String getURL( String a_repository )
{
- StringBuffer l_buf = new StringBuffer( a_repository ) ;
- String l_relative = getRelativePath( '/' ) ;
+ return getReference().getURL( a_repository );
+
+ //StringBuffer l_buf = new StringBuffer( a_repository ) ;
+ //String l_relative = getRelativePath( '/' ) ;
- if ( '/' == l_buf.charAt( l_buf.length() - 1 ) )
- {
- l_buf.append( getRelativePath( '/' ) ) ;
- }
- else
- {
- l_buf.append( '/' ) ;
- l_buf.append( getRelativePath( '/' ) ) ;
- }
+ //if ( '/' == l_buf.charAt( l_buf.length() - 1 ) )
+ //{
+ // l_buf.append( getRelativePath( '/' ) ) ;
+ //}
+ //else
+ //{
+ // l_buf.append( '/' ) ;
+ // l_buf.append( getRelativePath( '/' ) ) ;
+ //}
- return l_buf.toString() ;
+ //return l_buf.toString() ;
}
-
// ------------------------------------------------------------------------
// Utility Functions
// ------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]