org.exolab.castor.xml.schema

Class ResolvableReference


public final class ResolvableReference
extends java.lang.Object

Implements a reference to an object that will be resolved at a later time using some resolver mechanism. A resolvable reference can be created in both resolved and unresolved states. Resolvable references are immutable by definition.

A resolverable reference has two states: resolved and unresolved. When in the resolved state, the reference will always return the same resolved object. When in the unresolved state, the first time the object is requested, it will be resolved and returned. At that point the reference becomes resolved and the same object is returned in subsequent requests.

The following example creates a resolved and unresolved objects and then resolved the two:

 ResolvableReference resolved, unresolved;

 resolved = new ResolvableReference( myObject );
 unresolved = new ResolvableReference( "id", resolver );
 if ( resolved.get() == myObject )
   ; // This will always be true
 if ( unresolved.get() == resolver.resolve( "id" ) )
   ; // This will always be true
 

Version:
$Revision: 1.1.1.1 $ $Date: 2003/03/03 07:09:33 $
Authors:
Assaf Arkin
Keith Visco
See Also:
Resolver

Constructor Summary

ResolvableReference(String id, Resolver resolver)
Constructs a resolvable reference for the named object.
ResolvableReference(Referable referent)
Constructs a resolvable reference for the given object.

Method Summary

Referable
get()
Called to resolve the object and return it.
boolean
resolvable()
Determines whether or not the reference can be resolved at the time this method is called.

Constructor Details

ResolvableReference

public ResolvableReference(String id,
                           Resolver resolver)
Constructs a resolvable reference for the named object. This reference will be resolved on demand by calling the resolver with the specified identifier. The object need not be resolvable until the get() method is called.
Parameters:
id - The object's identifier
resolver - The resolve to use

ResolvableReference

public ResolvableReference(Referable referent)
Constructs a resolvable reference for the given object. This reference will always resolve to the specified referent.
Parameters:
referent - The object to resolve to

Method Details

get

public Referable get()
Called to resolve the object and return it. The returned object must be cast to the proper class. If a referent was specified in the constructor, that referent will be returned. If an identifier was specified, the resolved will be called to resolve the object. The resolver will be called only the first time this method is called. Subsequent calls will return the same object.

Null is returned if the object was resolved to null.

Returns:
The resolved object

resolvable

public boolean resolvable()
Determines whether or not the reference can be resolved at the time this method is called. A call to this method does not guarantee a null value will not be returned by a call to the get() method.

Intalio Inc. (C) 1999-2003. All rights reserved http://www.intalio.com