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 2003/04/06 21:26:43 UTC
cvs commit: avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/appliance ApplianceHandler.java Handler.java
mcconnell 2003/04/06 12:26:43
Added: merlin/assembly/src/java/org/apache/avalon/assembly/appliance
ApplianceHandler.java
Removed: merlin/assembly/src/java/org/apache/avalon/assembly/appliance
Handler.java
Log:
Renamed Handler to ApplianceHandler.
Revision Changes Path
1.1 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/appliance/ApplianceHandler.java
Index: ApplianceHandler.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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", "Avalon", 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 (INCLUDING, 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.assembly.appliance;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
/**
* <p>A URL handler for the appliance protocol.<p>
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
*/
public class ApplianceHandler extends URLStreamHandler
{
/**
* The appliance manager.
*/
private ApplianceRepository m_manager;
private boolean debug = false;
/**
* Creation of a new handler.
* @param host the host domain name
* @param appliance the appliance
*/
public ApplianceHandler( ApplianceRepository manager )
{
m_manager = manager;
}
/**
* 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 ApplianceURLConnection( url, m_manager );
}
/**
* Parses the string representation of a <code>URL</code> into a
* <code>URL</code> object.
* e.g. native:/root/myService
* <p>
* If there is any inherited context, then it has already been
* copied into the <code>URL</code> argument.
*
* @param url the <code>URL</code> to receive the result of parsing
* the spec.
* @param spec the <code>String</code> representing the URL that
* must be parsed.
* @param start the character index at which to begin parsing. This is
* just past the '<code>:</code>' (if there is one) that
* specifies the determination of the protocol name.
* @param limit the character position to stop parsing at. This is the
* end of the string or the position of the
* "<code>#</code>" character, if present. All information
* after the sharp sign indicates an anchor.
*/
protected void parseURL( URL url, String spec, int start, int limit )
{
//
// get the ref component
// (from # to the end of the spec)
//
String ref = url.getRef();
String remainder = spec.substring( start, limit );
int refLoc = spec.indexOf( "#", start );
if( refLoc > -1 )
{
ref = spec.substring( refLoc + 1 );
remainder = spec.substring( start, refLoc );
}
//
// get the query component
// (from ? to the end of the remainder)
//
String query = url.getQuery();
int queryLoc = remainder.indexOf( "?" );
if( queryLoc > -1 )
{
query = remainder.substring( queryLoc + 1, remainder.length() );
remainder = remainder.substring( 0, queryLoc );
}
//
// get the path component
// (from / to the end of the remainder)
//
String path = url.getPath();
if( remainder.startsWith( "//" ) )
{
remainder = remainder.substring( 2, remainder.length() );
}
int pathLoc = remainder.indexOf( "/" );
if( pathLoc > -1 )
{
path = remainder.substring( pathLoc, remainder.length() );
remainder = remainder.substring( 0, pathLoc );
}
else
{
path = path + remainder;
}
//
// set the URL parameters
//
String user = url.getUserInfo();
String host = url.getHost();
if( host == null )
{
host = "localhost";
}
int port = url.getPort();
if( port == -1 )
{
port = getDefaultPort();
}
//
// create authority string dependending of non-default port reference
//
String authority = null;
if( port == getDefaultPort() )
{
authority = host;
}
else
{
authority = host + ":" + port;
}
setURL( url, "appliance", host, port, authority, user, path, query, ref );
if( debug )
{
System.out.println( "BASE: " + url );
System.out.println( "HOST: " + host );
System.out.println( "PORT: " + port );
System.out.println( "AUTHORITY: " + authority );
System.out.println( "USER: " + user );
System.out.println( "PATH: " + path );
System.out.println( "QUERY: " + query );
System.out.println( "REF: " + ref );
}
}
/**
* Retuns the default port.
* @return int the default port value of 0
*/
protected int getDefaultPort()
{
return 0;
}
/**
* Returns the URL in a string form.
* @param url to the URL to externalize
* @return String the external form of the URL
*/
protected String toExternalForm( URL url )
{
StringBuffer result = new StringBuffer( url.getProtocol() );
result.append( "://" );
result.append( url.getHost() );
if( url.getUserInfo() != null )
{
result.append( "@" );
result.append( url.getUserInfo() );
}
if( url.getFile() != null )
{
result.append( url.getFile() );
}
if( url.getRef() != null )
{
result.append( "#" );
result.append( url.getRef() );
}
return result.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org