renamed SchemeSet to SchemeRegistry

git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@504209 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Roland Weber 2007-02-06 17:24:38 +00:00
parent dc2b5d84df
commit da98973e4d
10 changed files with 66 additions and 65 deletions

View File

@ -49,7 +49,7 @@ import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.apache.http.conn.Scheme;
import org.apache.http.conn.SchemeSet;
import org.apache.http.conn.SchemeRegistry;
import org.apache.http.conn.SocketFactory;
import org.apache.http.conn.PlainSocketFactory;
import org.apache.http.conn.ClientConnectionManager;
@ -147,7 +147,7 @@ public class ClientExecuteRequest {
// Register the "http" protocol scheme, it is required
// by the default operator to look up socket factories.
SocketFactory sf = PlainSocketFactory.getSocketFactory();
SchemeSet.DEFAULT.register(new Scheme("http", sf, 80));
SchemeRegistry.DEFAULT.register(new Scheme("http", sf, 80));
// Prepare parameters.
// Since this example doesn't use the full core framework,

View File

@ -45,7 +45,7 @@ import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpExecutionContext;
import org.apache.http.conn.Scheme;
import org.apache.http.conn.SchemeSet;
import org.apache.http.conn.SchemeRegistry;
import org.apache.http.conn.SocketFactory;
import org.apache.http.conn.PlainSocketFactory;
import org.apache.http.conn.HostConfiguration;
@ -84,7 +84,7 @@ public class ManagerConnectDirect {
* The scheme set.
* Instantiated in {@link #setup setup}.
*/
private static SchemeSet supportedSchemes;
private static SchemeRegistry supportedSchemes;
/**
@ -154,7 +154,7 @@ public class ManagerConnectDirect {
private final static ClientConnectionManager createManager() {
return new ThreadSafeClientConnManager(getParams()) {
//@@@ we need a better way to pass in the SchemeSet or operator
//@@@ need better way to pass in the SchemeRegistry or operator
protected ClientConnectionOperator createConnectionOperator() {
return new DefaultClientConnectionOperator(supportedSchemes);
}
@ -170,7 +170,7 @@ public class ManagerConnectDirect {
// Register the "http" protocol scheme, it is required
// by the default operator to look up socket factories.
supportedSchemes = new SchemeSet();
supportedSchemes = new SchemeRegistry();
SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));

View File

@ -45,7 +45,7 @@ import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpExecutionContext;
import org.apache.http.conn.Scheme;
import org.apache.http.conn.SchemeSet;
import org.apache.http.conn.SchemeRegistry;
import org.apache.http.conn.SocketFactory;
import org.apache.http.conn.PlainSocketFactory;
import org.apache.http.conn.ssl.SSLSocketFactory;
@ -85,7 +85,7 @@ public class ManagerConnectProxy {
* The scheme set.
* Instantiated in {@link #setup setup}.
*/
private static SchemeSet supportedSchemes;
private static SchemeRegistry supportedSchemes;
/**
@ -181,7 +181,7 @@ public class ManagerConnectProxy {
private final static ClientConnectionManager createManager() {
return new ThreadSafeClientConnManager(getParams()) {
//@@@ we need a better way to pass in the SchemeSet or operator
//@@@ need better way to pass in the SchemeRegistry or operator
protected ClientConnectionOperator createConnectionOperator() {
return new DefaultClientConnectionOperator(supportedSchemes);
}
@ -197,7 +197,7 @@ public class ManagerConnectProxy {
// Register the "http" and "https" protocol schemes, they are
// required by the default operator to look up socket factories.
supportedSchemes = new SchemeSet();
supportedSchemes = new SchemeRegistry();
SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));
sf = SSLSocketFactory.getSocketFactory();

View File

@ -45,7 +45,7 @@ import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpExecutionContext;
import org.apache.http.conn.Scheme;
import org.apache.http.conn.SchemeSet;
import org.apache.http.conn.SchemeRegistry;
import org.apache.http.conn.SocketFactory;
import org.apache.http.conn.PlainSocketFactory;
import org.apache.http.conn.OperatedClientConnection;
@ -82,7 +82,7 @@ public class OperatorConnectDirect {
* The scheme set.
* Instantiated in {@link #setup setup}.
*/
private static SchemeSet supportedSchemes;
private static SchemeRegistry supportedSchemes;
/**
@ -146,7 +146,7 @@ public class OperatorConnectDirect {
// Register the "http" protocol scheme, it is required
// by the default operator to look up socket factories.
supportedSchemes = new SchemeSet();
supportedSchemes = new SchemeRegistry();
SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));

View File

@ -45,7 +45,7 @@ import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpExecutionContext;
import org.apache.http.conn.Scheme;
import org.apache.http.conn.SchemeSet;
import org.apache.http.conn.SchemeRegistry;
import org.apache.http.conn.SocketFactory;
import org.apache.http.conn.PlainSocketFactory;
import org.apache.http.conn.ssl.SSLSocketFactory;
@ -83,7 +83,7 @@ public class OperatorConnectProxy {
* The scheme set.
* Instantiated in {@link #setup setup}.
*/
private static SchemeSet supportedSchemes;
private static SchemeRegistry supportedSchemes;
/**
@ -178,7 +178,7 @@ public class OperatorConnectProxy {
// Register the "http" and "https" protocol schemes, they are
// required by the default operator to look up socket factories.
supportedSchemes = new SchemeSet();
supportedSchemes = new SchemeRegistry();
SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));
sf = SSLSocketFactory.getSocketFactory();

View File

@ -40,7 +40,8 @@ import org.apache.http.util.LangUtils;
/**
* Encapsulates specifics of a protocol scheme such as "http" or "https".
* Schemes are identified by lowercase names.
* Supported schemes are typically collected in a {@link SchemeSet SchemeSet}.
* Supported schemes are typically collected in a
* {@link SchemeRegistry SchemeRegistry}.
*
* <p>
* For example, to configure support for "https://" URLs,
@ -48,7 +49,7 @@ import org.apache.http.util.LangUtils;
* </p>
* <pre>
* Scheme https = new Scheme("https", new MySecureSocketFactory(), 443);
* SchemeSet.DEFAULT.register(https);
* SchemeRegistry.DEFAULT.register(https);
* </pre>
*
* @author <a href="mailto:rolandw at apache.org">Roland Weber</a>

View File

@ -50,27 +50,27 @@ import java.util.Collections;
*
* @since 4.0
*/
public final class SchemeSet {
public final class SchemeRegistry {
/**
* A default scheme set.
* A default scheme registry.
* It is empty by default, but can be initialized by any application.
* The default scheme set should only be used by applications that
* know for sure that this class is NOT shared with any other applications.
* For example a Servlet, Portlet or EJB should not rely on being the
* only user of this class.
*/
public final static SchemeSet DEFAULT = new SchemeSet();
public final static SchemeRegistry DEFAULT = new SchemeRegistry();
/** The available schemes in this set. */
/** The available schemes in this registry. */
private final Map registeredSchemes;
/**
* Creates a new, empty scheme set.
* Creates a new, empty scheme registry.
*/
public SchemeSet() {
public SchemeRegistry() {
registeredSchemes = Collections.synchronizedMap(new HashMap());
}
@ -115,7 +115,7 @@ public final class SchemeSet {
/**
* Registers a scheme in this set.
* Registers a scheme.
* The scheme can later be retrieved by it's name
* using {@link #getScheme getScheme} or {@link #get get}.
*
@ -134,7 +134,7 @@ public final class SchemeSet {
/**
* Unregisters a scheme from this set.
* Unregisters a scheme.
*
* @param name the name of the scheme to unregister (in lowercase)
*
@ -163,5 +163,5 @@ public final class SchemeSet {
}
} // class SchemeSet
} // class SchemeRegistry

View File

@ -41,7 +41,7 @@ import org.apache.http.params.HttpConnectionParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.conn.Scheme;
import org.apache.http.conn.SchemeSet;
import org.apache.http.conn.SchemeRegistry;
import org.apache.http.conn.SocketFactory;
import org.apache.http.conn.SecureSocketFactory;
import org.apache.http.conn.OperatedClientConnection;
@ -51,7 +51,7 @@ import org.apache.http.conn.ClientConnectionOperator;
/**
* Default implementation of a
* {@link ClientConnectionOperator ClientConnectionOperator}.
* It uses a {@link SchemeSet SchemeSet} to look up
* It uses a {@link SchemeRegistry SchemeRegistry} to look up
* {@link SocketFactory SocketFactory} objects.
*
* @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
@ -67,12 +67,12 @@ public class DefaultClientConnectionOperator
/** The scheme set for looking up socket factories. */
protected SchemeSet schemeSet;
protected SchemeRegistry schemeRegistry;
/**
* Creates a new client connection operator.
* Uses {@link SchemeSet#DEFAULT SchemeSet.DEFAULT}
* Uses {@link SchemeRegistry#DEFAULT SchemeRegistry.DEFAULT}
* as the scheme set.
*/
public DefaultClientConnectionOperator() {
@ -83,10 +83,10 @@ public class DefaultClientConnectionOperator
* Creates a new client connection operator for the given scheme set.
*
* @param schemes the scheme set, or <code>null</code> to use
* {@link SchemeSet#DEFAULT SchemeSet.DEFAULT}
* {@link SchemeRegistry#DEFAULT SchemeRegistry.DEFAULT}
*/
public DefaultClientConnectionOperator(SchemeSet schemes) {
schemeSet = (schemes != null) ? schemes : SchemeSet.DEFAULT;
public DefaultClientConnectionOperator(SchemeRegistry schemes) {
schemeRegistry = (schemes != null) ? schemes : SchemeRegistry.DEFAULT;
}
@ -119,7 +119,7 @@ public class DefaultClientConnectionOperator
InetAddress local = null;
//@@@ TODO: deal with local address stuff (from context?)
final Scheme schm = schemeSet.getScheme(target.getSchemeName());
final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
if (schm == null) {
throw new IllegalArgumentException
("Unknown scheme '" + target.getSchemeName() +
@ -169,7 +169,7 @@ public class DefaultClientConnectionOperator
("Connection must be open.");
}
final Scheme schm = schemeSet.getScheme(target.getSchemeName());
final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
if (schm == null) {
throw new IllegalArgumentException
("Unknown scheme '" + target.getSchemeName() +

View File

@ -41,7 +41,7 @@ import org.apache.http.conn.HostConfiguration;
import org.apache.http.conn.HttpConnectionManager;
import org.apache.http.conn.HttpHostConnection;
import org.apache.http.conn.Scheme;
import org.apache.http.conn.SchemeSet;
import org.apache.http.conn.SchemeRegistry;
import org.apache.http.conn.SecureSocketFactory;
import org.apache.http.conn.SocketFactory;
import org.apache.http.impl.SocketHttpClientConnection;
@ -131,7 +131,7 @@ public class DefaultHttpHostConnection
}
// Determine the type of the connection
Scheme scheme = SchemeSet.DEFAULT.getScheme(host.getSchemeName());
Scheme scheme = SchemeRegistry.DEFAULT.getScheme(host.getSchemeName());
SocketFactory socketFactory = scheme.getSocketFactory();
boolean secure = (socketFactory instanceof SecureSocketFactory);
boolean proxied = (proxyHost != null);
@ -151,10 +151,10 @@ public class DefaultHttpHostConnection
port = scheme.getDefaultPort();
}
if (secure && proxied) {
scheme = SchemeSet.DEFAULT.getScheme("http");
scheme = SchemeRegistry.DEFAULT.getScheme("http");
socketFactory = scheme.getSocketFactory();
} else {
scheme = SchemeSet.DEFAULT.getScheme(target.getSchemeName());
scheme = SchemeRegistry.DEFAULT.getScheme(target.getSchemeName());
}
socketFactory = scheme.getSocketFactory();
Socket socket = socketFactory.connectSocket(
@ -194,7 +194,7 @@ public class DefaultHttpHostConnection
LOG.debug("Secure tunnel to " + host);
}
Scheme scheme = SchemeSet.DEFAULT.getScheme(host.getSchemeName());
Scheme scheme = SchemeRegistry.DEFAULT.getScheme(host.getSchemeName());
SocketFactory socketFactory = scheme.getSocketFactory();
boolean secure = (socketFactory instanceof SecureSocketFactory);
boolean proxied = (proxyHost != null);

View File

@ -40,7 +40,7 @@ import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit tests for {@link Scheme} and {@link SchemeSet}.
* Unit tests for {@link Scheme} and {@link SchemeRegistry}.
*
* @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
* @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
@ -108,7 +108,7 @@ public class TestScheme extends TestCase {
}
public void testRegisterUnregister() {
SchemeSet schmset = new SchemeSet();
SchemeRegistry schmreg = new SchemeRegistry();
Scheme http = new Scheme
("http", PlainSocketFactory.getSocketFactory(), 80);
@ -117,18 +117,18 @@ public class TestScheme extends TestCase {
Scheme myhttp = new Scheme
("http", PlainSocketFactory.getSocketFactory(), 80);
assertNull(schmset.register(myhttp));
assertNull(schmset.register(https));
assertSame(myhttp, schmset.register(http));
assertSame(http, schmset.getScheme("http"));
assertSame(https, schmset.getScheme("https"));
assertNull(schmreg.register(myhttp));
assertNull(schmreg.register(https));
assertSame(myhttp, schmreg.register(http));
assertSame(http, schmreg.getScheme("http"));
assertSame(https, schmreg.getScheme("https"));
schmset.unregister("http");
schmset.unregister("https");
schmreg.unregister("http");
schmreg.unregister("https");
assertNull(schmset.get("http")); // get() does not throw exception
assertNull(schmreg.get("http")); // get() does not throw exception
try {
schmset.getScheme("http"); // getScheme() does throw exception
schmreg.getScheme("http"); // getScheme() does throw exception
fail("IllegalStateException should have been thrown");
} catch (IllegalStateException ex) {
// expected
@ -137,9 +137,9 @@ public class TestScheme extends TestCase {
public void testIterator() {
SchemeSet schmset = new SchemeSet();
SchemeRegistry schmreg = new SchemeRegistry();
Iterator iter = schmset.getSchemeNames();
Iterator iter = schmreg.getSchemeNames();
assertNotNull(iter);
assertFalse(iter.hasNext());
@ -148,10 +148,10 @@ public class TestScheme extends TestCase {
Scheme https = new Scheme
("https", SSLSocketFactory.getSocketFactory(), 443);
schmset.register(http);
schmset.register(https);
schmreg.register(http);
schmreg.register(https);
iter = schmset.getSchemeNames();
iter = schmreg.getSchemeNames();
assertNotNull(iter);
assertTrue(iter.hasNext());
@ -167,10 +167,10 @@ public class TestScheme extends TestCase {
else
fail("unexpected name in iterator: " + name);
assertNotNull(schmset.get(name));
assertNotNull(schmreg.get(name));
iter.remove();
assertTrue(iter.hasNext());
assertNull(schmset.get(name));
assertNull(schmreg.get(name));
name = (String) iter.next();
assertFalse(iter.hasNext());
@ -183,31 +183,31 @@ public class TestScheme extends TestCase {
fail("unexpected name in iterator: " + name);
}
assertNotNull(schmset.get(name));
assertNotNull(schmreg.get(name));
}
public void testIllegalRegisterUnregister() {
SchemeSet schmset = new SchemeSet();
SchemeRegistry schmreg = new SchemeRegistry();
try {
schmset.register(null);
schmreg.register(null);
fail("IllegalArgumentException should have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
try {
schmset.unregister(null);
schmreg.unregister(null);
fail("IllegalArgumentException should have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
try {
schmset.get(null);
schmreg.get(null);
fail("IllegalArgumentException should have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
try {
schmset.getScheme(null);
schmreg.getScheme(null);
fail("IllegalArgumentException should have been thrown");
} catch (IllegalArgumentException ex) {
// expected