public class ReferenceManager
extends java.lang.Object
The reference manager is a singleton class which is responsible for deriving reference URI's into references at runtime.
Raw reference factories (which are capable of actually creating fully qualified reference objects) are added with the addFactory() method. The most common method of doing so is to implement the PrefixedRootFactory as either a full class, or an anonymous inner class, providing the roots available in the current environment and the code for constructing a reference from them.
RootTranslators (which rely on other factories) are used to describe that a particular reference style (generally a high level reference like "jr://media/" or "jr://images/" should be translated to another available reference in this environment like "jr://file/". Root Translators do not directly derive references, but rather translate them to what the reference should look like in the current circumstances.
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList<ReferenceFactory> |
factories |
private static ReferenceManager |
instance |
private java.util.ArrayList<RootTranslator> |
sessionTranslators |
private java.util.ArrayList<RootTranslator> |
translators |
Modifier | Constructor and Description |
---|---|
private |
ReferenceManager() |
Modifier and Type | Method and Description |
---|---|
static ReferenceManager |
_() |
void |
addReferenceFactory(ReferenceFactory factory)
Adds a factory for deriving reference URI's into references
|
void |
addRootTranslator(RootTranslator translator)
Adds a new Translator to the current environment.
|
void |
addSessionRootTranslator(RootTranslator translator)
Adds a root translator that is maintained over the course of a session.
|
void |
clearSession()
Wipes out all of the translators being maintained in the current session (IE: Any translators
added via "addSessionRootTranslator".
|
Reference |
DeriveReference(java.lang.String uri)
Derives a global reference from a URI in the current environment.
|
Reference |
DeriveReference(java.lang.String uri,
Reference context)
Derives a reference from a URI in the current environment.
|
Reference |
DeriveReference(java.lang.String uri,
java.lang.String context)
Derives a reference from a URI in the current environment.
|
private ReferenceFactory |
derivingRoot(java.lang.String uri) |
ReferenceFactory[] |
getFactories() |
private java.lang.String |
getPrettyPrintException(java.lang.String uri) |
static boolean |
isRelative(java.lang.String URI) |
boolean |
removeReferenceFactory(ReferenceFactory factory) |
private static ReferenceManager instance
private java.util.ArrayList<RootTranslator> translators
private java.util.ArrayList<ReferenceFactory> factories
private java.util.ArrayList<RootTranslator> sessionTranslators
public static ReferenceManager _()
public ReferenceFactory[] getFactories()
public void addRootTranslator(RootTranslator translator)
translator
- public void addReferenceFactory(ReferenceFactory factory)
factory
- A raw ReferenceFactory capable of creating
a reference.public boolean removeReferenceFactory(ReferenceFactory factory)
public Reference DeriveReference(java.lang.String uri) throws InvalidReferenceException
uri
- The URI representing a global reference.InvalidReferenceException
- If the current reference could
not be derived by the current environmentpublic Reference DeriveReference(java.lang.String uri, Reference context) throws InvalidReferenceException
uri
- The URI representing a reference.context
- A reference which provides context for any
relative reference accessors.InvalidReferenceException
- If the current reference could
not be derived by the current environmentpublic Reference DeriveReference(java.lang.String uri, java.lang.String context) throws InvalidReferenceException
uri
- The URI representing a reference.context
- A reference URI which provides context for any
relative reference accessors.InvalidReferenceException
- If the current reference could
not be derived by the current environment, or if the context URI
is not valid in the current environment.public void addSessionRootTranslator(RootTranslator translator)
translator
- A Root Translator that will be added to the current sessionpublic void clearSession()
private ReferenceFactory derivingRoot(java.lang.String uri) throws InvalidReferenceException
InvalidReferenceException
private java.lang.String getPrettyPrintException(java.lang.String uri)
public static boolean isRelative(java.lang.String URI)
URI
-