XNIO API 2.1.0.CR2

org.jboss.xnio
Class Option<T>

java.lang.Object
  extended by org.jboss.xnio.Option<T>
Type Parameters:
T - the option value type
All Implemented Interfaces:
Serializable

public abstract class Option<T>
extends Object
implements Serializable

A strongly-typed option to configure an aspect of a service or connection. Options are immutable and use identity comparisons and hash codes. Options should always be declared as public static final members in order to support serialization.

See Also:
Serialized Form

Nested Class Summary
static class Option.SetBuilder
          A builder for an immutable option set.
 
Method Summary
abstract  T cast(Object o)
          Return the given object as the type of this option.
static Option<?> fromString(String name, ClassLoader classLoader)
          Get an option from a string name, using the given classloader.
 String getName()
          Get the name of this option.
abstract  T parseValue(String string)
          Parse a string value for this option.
protected  Object readResolve()
          Resolve this instance for serialization.
static
<T> Option<Sequence<T>>
sequence(Class<?> declClass, String name, Class<T> elementType)
          Create an option with a sequence type.
static Option.SetBuilder setBuilder()
          Create a builder for an immutable option set.
static
<T> Option<T>
simple(Class<?> declClass, String name, Class<T> type)
          Create an option with a simple type.
 String toString()
          Get a human-readible string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

simple

public static <T> Option<T> simple(Class<?> declClass,
                                   String name,
                                   Class<T> type)
Create an option with a simple type. The class object given must represent some immutable type, otherwise unexpected behavior may result.

Parameters:
declClass - the declaring class of the option
name - the (field) name of this option
type - the class of the value associated with this option
Returns:
the option instance

sequence

public static <T> Option<Sequence<T>> sequence(Class<?> declClass,
                                               String name,
                                               Class<T> elementType)
Create an option with a sequence type. The class object given must represent some immutable type, otherwise unexpected behavior may result.

Parameters:
declClass - the declaring class of the option
name - the (field) name of this option
elementType - the class of the sequence element value associated with this option
Returns:
the option instance

getName

public String getName()
Get the name of this option.

Returns:
the option name

toString

public String toString()
Get a human-readible string representation of this object.

Overrides:
toString in class Object
Returns:
the string representation

fromString

public static Option<?> fromString(String name,
                                   ClassLoader classLoader)
                            throws IllegalArgumentException
Get an option from a string name, using the given classloader. If the classloader is null, the bootstrap classloader will be used.

Parameters:
name - the option string
classLoader - the class loader
Returns:
the option
Throws:
IllegalArgumentException - if the given option name is not valid

cast

public abstract T cast(Object o)
                throws ClassCastException
Return the given object as the type of this option. If the cast could not be completed, an exception is thrown.

Parameters:
o - the object to cast
Returns:
the cast object
Throws:
ClassCastException - if the object is not of a compatible type

parseValue

public abstract T parseValue(String string)
                      throws IllegalArgumentException
Parse a string value for this option.

Parameters:
string - the string
Returns:
the parsed value
Throws:
IllegalArgumentException - if the argument could not be parsed

readResolve

protected final Object readResolve()
                            throws ObjectStreamException
Resolve this instance for serialization.

Returns:
the resolved object
Throws:
ObjectStreamException - if the object could not be resolved

setBuilder

public static Option.SetBuilder setBuilder()
Create a builder for an immutable option set.

Returns:
the builder

XNIO API 2.1.0.CR2

Copyright © 2010 JBoss, a division of Red Hat, Inc.