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: 5951 $ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
    Author:
    Assaf Arkin, Keith Visco
    See Also:
    Resolver
    • Constructor Summary

      Constructors 
      Constructor Description
      ResolvableReference​(java.lang.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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ResolvableReference

        public ResolvableReference​(java.lang.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 Detail

      • 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.
      • 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