XNIO API 2.0.0.GA

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:
java.io.Serializable

public abstract class Option<T>
extends java.lang.Object
implements java.io.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(java.lang.Object o)
          Return the given object as the type of this option.
static Option<?> fromString(java.lang.String name, java.lang.ClassLoader classLoader)
          Get an option from a string name, using the given classloader.
 java.lang.String getName()
          Get the name of this option.
abstract  T parseValue(java.lang.String string)
          Parse a string value for this option.
protected  java.lang.Object readResolve()
          Resolve this instance for serialization.
static
<T> Option<Sequence<T>>
sequence(java.lang.Class<?> declClass, java.lang.String name, java.lang.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(java.lang.Class<?> declClass, java.lang.String name, java.lang.Class<T> type)
          Create an option with a simple type.
 java.lang.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(java.lang.Class<?> declClass,
                                   java.lang.String name,
                                   java.lang.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(java.lang.Class<?> declClass,
                                               java.lang.String name,
                                               java.lang.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 java.lang.String getName()
Get the name of this option.

Returns:
the option name

toString

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

Overrides:
toString in class java.lang.Object
Returns:
the string representation

fromString

public static Option<?> fromString(java.lang.String name,
                                   java.lang.ClassLoader classLoader)
                            throws java.lang.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:
java.lang.IllegalArgumentException - if the given option name is not valid

cast

public abstract T cast(java.lang.Object o)
                throws java.lang.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:
java.lang.ClassCastException - if the object is not of a compatible type

parseValue

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

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

readResolve

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

Returns:
the resolved object
Throws:
java.io.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.0.0.GA

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