You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2004/01/16 02:29:54 UTC
cvs commit: avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl AbstractURLConnection.java BlockHandler.java BlockURLConnection.java ArtifactHandler.java ArtifactURLConnection.java DefaultCriteria.java
mcconnell 2004/01/15 17:29:54
Modified: merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
DefaultContainmentModel.java
merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl
ArtifactHandler.java ArtifactURLConnection.java
DefaultCriteria.java
Added: merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl
AbstractURLConnection.java BlockHandler.java
BlockURLConnection.java
Log:
Addition of block url handler.
Revision Changes Path
1.19 +3 -2 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java
Index: DefaultContainmentModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- DefaultContainmentModel.java 16 Jan 2004 00:09:12 -0000 1.18
+++ DefaultContainmentModel.java 16 Jan 2004 01:29:54 -0000 1.19
@@ -1279,7 +1279,8 @@
private ContainmentModel createContainmentModel( String name, URL url )
throws ModelException
{
- if( url.getProtocol().equals( "artifact" ) )
+ if( url.getProtocol().equals( "artifact" )
+ || url.getProtocol().equals( "block" ) )
{
try
{
1.2 +0 -1 avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/ArtifactHandler.java
Index: ArtifactHandler.java
===================================================================
RCS file: /home/cvs/avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/ArtifactHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ArtifactHandler.java 16 Jan 2004 00:09:12 -0000 1.1
+++ ArtifactHandler.java 16 Jan 2004 01:29:54 -0000 1.2
@@ -57,7 +57,6 @@
import org.apache.avalon.repository.Repository;
-
/**
* Repository URL protocol handler.
*/
1.2 +15 -55 avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/ArtifactURLConnection.java
Index: ArtifactURLConnection.java
===================================================================
RCS file: /home/cvs/avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/ArtifactURLConnection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ArtifactURLConnection.java 16 Jan 2004 00:09:12 -0000 1.1
+++ ArtifactURLConnection.java 16 Jan 2004 01:29:54 -0000 1.2
@@ -63,98 +63,58 @@
/**
* Repository URL protocol handler.
*/
-public class ArtifactURLConnection extends URLConnection
+public class ArtifactURLConnection extends AbstractURLConnection
{
/**
- * the url
- */
- private URL m_url;
-
- /**
* Creation of a new handler.
- * @param context the initial context
+ * @param url the url to establish a connection with
+ * @param type the default type if no type specified
* @exception NullPointerException if the supplied repository argument is null
*/
ArtifactURLConnection( URL url )
throws NullPointerException, IOException
{
super( url );
-
- String path = url.getPath();
- int i = path.lastIndexOf( "/" );
- if( i<0 )
- {
- final String error =
- "Artifact specification does not contain a [group]/[name] seperator.";
- throw new MalformedURLException( error );
- }
- m_url = url;
}
- public void connect()
+ /**
+ * Return the Artifact specified by this URL.
+ * @return the artifact instance
+ */
+ public Object getContent() throws IOException
{
- // nothing to do
+ return super.getContent( "jar" );
}
/**
* Return the Artifact specified by this URL.
* @return the artifact instance
*/
- public Object getContent() throws IOException
+ protected Object getContent( String defaultType ) throws IOException
{
try
{
- final String path = m_url.getPath();
+ final String path = getURL().getPath();
final int i = path.lastIndexOf( "/" );
final String group = path.substring( 0, i );
final String name = path.substring( i+1 );
- final String type = getType( url );
final String version = getVersion( url );
+ final String type = getType( getURL(), defaultType );
return Artifact.createArtifact( group, name, version, type );
}
catch( Throwable e )
{
final String error =
- "Unexpected exception while resolving url [" + m_url + "].";
+ "Unexpected exception while resolving url [" + getURL() + "].";
throw new CascadingIOException( error );
}
}
- /**
- * Return the Artifact specified by this URL.
- * @param classes a set of classes (ignored)
- * @return the artifact instance
- */
- public Object getContent( Class[] classes ) throws IOException
+ private String getType( URL url, String type )
{
- return getContent();
+ return getQueryField( url, "type", type );
}
- private String getVersion( URL url )
- {
- return getQueryField( url, "version", null );
- }
- private String getType( URL url )
- {
- return getQueryField( url, "type", "jar" );
- }
- private String getQueryField( URL url, String field, String fallback )
- {
- String query = url.getQuery();
- if( null != query )
- {
- StringTokenizer tokenizer = new StringTokenizer( query, "&" );
- while( tokenizer.hasMoreElements() )
- {
- String token = tokenizer.nextToken();
- if( token.startsWith( field + "=" ) )
- {
- return token.substring( (field.length() + 1) );
- }
- }
- }
- return fallback;
- }
}
1.14 +6 -2 avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultCriteria.java
Index: DefaultCriteria.java
===================================================================
RCS file: /home/cvs/avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultCriteria.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DefaultCriteria.java 16 Jan 2004 00:09:12 -0000 1.13
+++ DefaultCriteria.java 16 Jan 2004 01:29:54 -0000 1.14
@@ -708,7 +708,11 @@
private URL resolveURL( File base, String value ) throws Exception
{
- if( value.startsWith( "artifact:" ) )
+ if( value.startsWith( "block:" ) )
+ {
+ return new URL( null, value, new BlockHandler() );
+ }
+ else if( value.startsWith( "artifact:" ) )
{
return new URL( null, value, new ArtifactHandler() );
}
1.1 avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/AbstractURLConnection.java
Index: AbstractURLConnection.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.merlin.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.net.MalformedURLException;
import java.util.StringTokenizer;
import org.apache.avalon.repository.Artifact;
import org.apache.avalon.activation.appliance.CascadingIOException;
/**
* Repository URL protocol handler.
*/
public abstract class AbstractURLConnection extends URLConnection
{
/**
* Creation of a new handler.
* @param url the url to establish a connection with
* @param type the default type if no type specified
* @exception NullPointerException if the supplied repository argument is null
*/
AbstractURLConnection( URL url )
throws NullPointerException, IOException
{
super( url );
String path = url.getPath();
int i = path.lastIndexOf( "/" );
if( i<0 )
{
final String error =
"Artifact specification does not contain a [group]/[name] seperator.";
throw new MalformedURLException( error );
}
}
public void connect()
{
// nothing to do
}
/**
* Return the Artifact specified by this URL.
* @param type the artifact type
* @return the artifact instance
*/
protected Object getContent( String type ) throws IOException
{
try
{
final String path = getURL().getPath();
final int i = path.lastIndexOf( "/" );
final String group = path.substring( 0, i );
final String name = path.substring( i+1 );
final String version = getVersion( url );
return Artifact.createArtifact( group, name, version, type );
}
catch( Throwable e )
{
final String error =
"Unexpected exception while resolving url [" + super.getURL() + "].";
throw new CascadingIOException( error );
}
}
/**
* Return the Artifact specified by this URL.
* @param classes a set of classes (ignored)
* @return the artifact instance
*/
public Object getContent( Class[] classes ) throws IOException
{
return getContent();
}
protected String getVersion( URL url )
{
return getQueryField( url, "version", null );
}
protected String getQueryField( URL url, String field, String fallback )
{
String query = url.getQuery();
if( null != query )
{
StringTokenizer tokenizer = new StringTokenizer( query, "&" );
while( tokenizer.hasMoreElements() )
{
String token = tokenizer.nextToken();
if( token.startsWith( field + "=" ) )
{
return token.substring( (field.length() + 1) );
}
}
}
return fallback;
}
}
1.1 avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/BlockHandler.java
Index: BlockHandler.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.merlin.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
/**
* Repository URL protocol handler.
*/
public class BlockHandler extends URLStreamHandler
{
/**
* Opens a connection to the specified URL.
*
* @param url A URL to open a connection to.
* @return The established connection.
* @throws IOException If a connection failure occurs.
*/
protected URLConnection openConnection( final URL url )
throws IOException
{
return new BlockURLConnection( url );
}
protected int getDefaultPort()
{
return 0;
}
protected String toExternalForm( URL url )
{
StringBuffer result = new StringBuffer( "block:" );
if (url.getFile() != null )
{
result.append(url.getFile());
}
if (url.getQuery() != null )
{
result.append("?");
result.append(url.getQuery());
}
if (url.getRef() != null )
{
result.append("#");
result.append(url.getRef());
}
return result.toString();
}
}
1.1 avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/BlockURLConnection.java
Index: BlockURLConnection.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.merlin.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.net.MalformedURLException;
import java.util.StringTokenizer;
import org.apache.avalon.repository.Artifact;
import org.apache.avalon.activation.appliance.CascadingIOException;
/**
* Repository URL protocol handler.
*/
public class BlockURLConnection extends AbstractURLConnection
{
/**
* Creation of a new handler.
* @param url the url to establish a connection with
* @param type the default type if no type specified
* @exception NullPointerException if the supplied repository argument is null
*/
BlockURLConnection( URL url )
throws IOException
{
super( url );
}
/**
* Return the Artifact specified by this URL.
* @return the artifact instance
*/
public Object getContent() throws IOException
{
return super.getContent( "block" );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org