org.apache.http.conn.scheme
public final class: Scheme [javadoc |
source]
java.lang.Object
org.apache.http.conn.scheme.Scheme
Encapsulates specifics of a protocol scheme such as "http" or "https".
Schemes are identified by lowercase names.
Supported schemes are typically collected in a
SchemeRegistry .
For example, to configure support for "https://" URLs,
you could write code like the following:
Scheme https = new Scheme("https", new MySecureSocketFactory(), 443);
SchemeRegistry.DEFAULT.register(https);
| Constructor: |
public Scheme(String name,
SocketFactory factory,
int port) {
if (name == null) {
throw new IllegalArgumentException
("Scheme name may not be null");
}
if (factory == null) {
throw new IllegalArgumentException
("Socket factory may not be null");
}
if ((port < = 0) || (port > 0xffff)) {
throw new IllegalArgumentException
("Port is invalid: " + port);
}
this.name = name.toLowerCase(Locale.ENGLISH);
this.socketFactory = factory;
this.defaultPort = port;
this.layered = (factory instanceof LayeredSocketFactory);
}
Creates a new scheme.
Whether the created scheme allows for layered connections
depends on the class of factory. Parameters:
name - the scheme name, for example "http".
The name will be converted to lowercase.
factory - the factory for creating sockets for communication
with this scheme
port - the default port for this scheme
|
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from org.apache.http.conn.scheme.Scheme Detail: |
public final boolean equals(Object obj) {
if (obj == null) return false;
if (this == obj) return true;
if (!(obj instanceof Scheme)) return false;
Scheme s = (Scheme) obj;
return (name.equals(s.name) &&
defaultPort == s.defaultPort &&
layered == s.layered &&
socketFactory.equals(s.socketFactory)
);
}
Compares this scheme to an object. |
public final int getDefaultPort() {
return defaultPort;
}
Obtains the default port. |
public final String getName() {
return name;
}
|
public final SocketFactory getSocketFactory() {
return socketFactory;
}
|
public int hashCode() {
int hash = LangUtils.HASH_SEED;
hash = LangUtils.hashCode(hash, this.defaultPort);
hash = LangUtils.hashCode(hash, this.name);
hash = LangUtils.hashCode(hash, this.layered);
hash = LangUtils.hashCode(hash, this.socketFactory);
return hash;
}
Obtains a hash code for this scheme. |
public final boolean isLayered() {
return layered;
}
Indicates whether this scheme allows for layered connections. |
public final int resolvePort(int port) {
return port < = 0 ? defaultPort : port;
}
Resolves the correct port for this scheme.
Returns the given port if it is valid, the default port otherwise. |
public final String toString() {
if (stringRep == null) {
StringBuilder buffer = new StringBuilder();
buffer.append(this.name);
buffer.append(':');
buffer.append(Integer.toString(this.defaultPort));
stringRep = buffer.toString();
}
return stringRep;
}
Return a string representation of this object. |