net.dpml.lang
Class Strategy

java.lang.Object
  extended by net.dpml.lang.Strategy
All Implemented Interfaces:
Comparable<Strategy>
Direct Known Subclasses:
AntlibStrategy, ComponentStrategy

public abstract class Strategy
extends Object
implements Comparable<Strategy>

Abstract component deployment strategy.

Version:
2.0.1
Author:
Digital Product Management Laboratory

Constructor Summary
protected Strategy(ClassLoader classloader)
          Creation of a new deployment strategy.
 
Method Summary
 int compareTo(Strategy strategy)
          Compares a supplied strategy with this strategy.
abstract  void encode(Buffer buffer, String key)
          Write the strategy to the supplied buffer in XML format.
 ClassLoader getClassLoader()
          Return the classloader establised by the strategy implementation.
abstract
<T> T
getContentForClass(Class<T> c)
          Return a value assignable to the supplied type or null if the type cannot be resolved from this strategy.
abstract
<T> T
getInstance(Class<T> type)
          Instantiate a service returning an instance assigned to the supplied type.
abstract  String getName()
          Return the short name of this strategy.
abstract  int getPriority()
          Return the priority assigned to this strategy.
abstract  void initialize(ServiceRegistry registry)
          Composite strategies are strategy implementations that contain subidary strategies.
abstract  boolean isaCandidate(Class<?> type)
          Return true if this strategy is a candidate with result to the supply of an instance assignable to the supplied type.
static Strategy load(Class<?> subject, ServiceRegistry registry, String name)
          Creation of a new management strategy.
static Strategy load(ClassLoader classloader, ServiceRegistry registry, URI uri, String name)
          Load a strategy defined by the supplied uri, name, classloader and service registry, and return a value assignable to the supplied type.
static Strategy load(URI uri)
          Load a strategy defined by the supplied uri.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Strategy

protected Strategy(ClassLoader classloader)
Creation of a new deployment strategy.

Parameters:
classloader - the classloader
Method Detail

load

public static Strategy load(Class<?> subject,
                            ServiceRegistry registry,
                            String name)
                     throws Exception
Creation of a new management strategy.

Parameters:
subject - the implementation class to be managed
registry - the service registry
name - the path under which the strategy will be established
Returns:
the management strategy
Throws:
Exception - if a general loading error occurs

load

public static Strategy load(URI uri)
                     throws Exception,
                            NullPointerException
Load a strategy defined by the supplied uri.

Parameters:
uri - the source uri to a part definition
Returns:
the strategy
Throws:
Exception - if a general loading error occurs
NullPointerException - if the uri argument is null

load

public static Strategy load(ClassLoader classloader,
                            ServiceRegistry registry,
                            URI uri,
                            String name)
                     throws Exception,
                            NullPointerException
Load a strategy defined by the supplied uri, name, classloader and service registry, and return a value assignable to the supplied type.

Parameters:
classloader - the anchor classloader
registry - the service registry
uri - the source uri to a part definition
name - the path under which the strategy will be established
Returns:
an instance of the supplied type
Throws:
Exception - if a general loading error occurs
NullPointerException - if the uri argument is null

getClassLoader

public ClassLoader getClassLoader()
Return the classloader establised by the strategy implementation.

Returns:
the classloader

getPriority

public abstract int getPriority()
Return the priority assigned to this strategy.

Returns:
the priority value

isaCandidate

public abstract boolean isaCandidate(Class<?> type)
Return true if this strategy is a candidate with result to the supply of an instance assignable to the supplied type.

Parameters:
type - the requested type
Returns:
type if this strategy is a condidate

getInstance

public abstract <T> T getInstance(Class<T> type)
Instantiate a service returning an instance assigned to the supplied type.

Parameters:
type - the return type
Returns:
an instance of the type

encode

public abstract void encode(Buffer buffer,
                            String key)
                     throws IOException
Write the strategy to the supplied buffer in XML format.

Parameters:
buffer - the output buffer
key - the optional identifying key
Throws:
IOException - if an IO error occurs

initialize

public abstract void initialize(ServiceRegistry registry)
Composite strategies are strategy implementations that contain subidary strategies. During lookup operations, a subsidiary strategy may request a service from the enclosing strategy. To enable traversal from a subsidary to enclosing context a service registry shall be provided to all subsidiary strategies.

Parameters:
registry - the service registry

getName

public abstract String getName()
Return the short name of this strategy.

Returns:
the name

compareTo

public int compareTo(Strategy strategy)
Compares a supplied strategy with this strategy. If the supplied strategy has a priority greater than this strategy the returned value is 1, otherwise if the supplied strategy has a priority lower than this strategy then the return value is -1,otherwise the returned value is 0.

Specified by:
compareTo in interface Comparable<Strategy>
Parameters:
strategy - the strategy to evaluate relative to this strategy
Returns:
the priority comparative index

getContentForClass

public abstract <T> T getContentForClass(Class<T> c)
                              throws IOException
Return a value assignable to the supplied type or null if the type cannot be resolved from this strategy.

Parameters:
c - the target class
Returns:
an instance of the class or null
Throws:
IOException - if an IO error occurs