public class HeapImpl extends Object implements Heap
Modifier and Type | Field and Description |
---|---|
protected PropertyResolver |
propertyResolver
Resolves tokens.
|
Constructor and Description |
---|
HeapImpl(HeapImpl parent,
Name name)
Builds a new heap that is a child of the given heap.
|
HeapImpl(HeapImpl parent,
Name name,
PropertyResolver propertyResolver)
Builds a new heap that is a child of the given heap.
|
HeapImpl(Name name)
Builds a root heap (will be referenced by children but has no parent itself).
|
Modifier and Type | Method and Description |
---|---|
void |
addDefaultDeclaration(JsonValue object)
Add a default JsonValue object declaration in this heap.
|
void |
destroy()
Destroys the objects on the heap and dereferences all associated objects.
|
<T> T |
get(String name,
Class<T> type)
Returns an object from the heap with a specified name, or
null if no such object exists. |
<T> List<T> |
getAll(Class<T> type)
Returns all objects from the heap or its parent (if any), with the
specified type or an empty list if no such object exists.
|
Handler |
getHandler()
Returns the
Handler object referenced by the handler top-level attribute. |
Name |
getName()
Returns the name of this heap.
|
Bindings |
getProperties()
Returns the properties from this heap and its parents if any.
|
JsonValue |
init(JsonValue originalConfig,
String... reservedFieldNames)
Initializes the heap using the given configuration.
|
void |
put(String name,
Object object)
Puts an object into the heap.
|
<T> T |
resolve(JsonValue reference,
Class<T> type)
Resolves a mandatory object with the specified reference.
|
<T> T |
resolve(JsonValue reference,
Class<T> type,
boolean optional)
Resolves an object with the specified reference, optionally or not.
|
void |
start()
Allocate all objects using each heaplet instance's configuration.
|
protected PropertyResolver propertyResolver
public HeapImpl(Name name)
PropertyResolver
.name
- local name of this heappublic HeapImpl(HeapImpl parent, Name name)
parent
- parent heap (never null
).name
- local name of this heappublic HeapImpl(HeapImpl parent, Name name, PropertyResolver propertyResolver)
parent
- parent heap.name
- local name of this heap (never null
)propertyResolver
- initial property resolver to use (never null
)public Name getName()
Heap
public JsonValue init(JsonValue originalConfig, String... reservedFieldNames) throws HeapException
originalConfig
- the configuration root.reservedFieldNames
- the names of reserved top level fields in the originalConfig which
should not be parsed as global decorators.HeapException
- if an exception occurs initializing the heap.JsonValueException
- if the configuration object is malformed.public void start() throws HeapException
HeapException
- if any object cannot be created.public void addDefaultDeclaration(JsonValue object)
init(JsonValue, String...)
: values provided after init() has
been called will be ignored.
Notice that if the caller add 2 declarations with the same name, that will ends up with an exception thrown
when heap will be initialized.object
- Object declaration (has to contains a name attribute)public <T> List<T> getAll(Class<T> type) throws HeapException
Heap
getAll
in interface Heap
T
- expected type of the heap objecttype
- expected type to search for in the heap or its parent (if
any).HeapException
- if an exception occurred during the creation of a heap object
or any of its dependencies.public <T> T get(String name, Class<T> type) throws HeapException
Heap
null
if no such object exists.get
in interface Heap
T
- expected type of the heap objectname
- the name of the object in the heap to be retrieved.type
- expected type of the heap objectnull
if no such object exists.HeapException
- if an exception occurred during creation of the heap object or any of its dependencies.public <T> T resolve(JsonValue reference, Class<T> type) throws HeapException
Heap
JsonValueException
is thrown. If the reference is an inline object
declaration, an anonymous object is added to the heap and returned.
Equivalent to:
heap.resolve(reference, type, false);
resolve
in interface Heap
T
- expected instance typereference
- a JSON value containing the name of the heap object to retrieve.type
- the expected type of the heap object.HeapException
- if there was an exception creating the heap object or any of its dependencies.public <T> T resolve(JsonValue reference, Class<T> type, boolean optional) throws HeapException
Heap
JsonValueException
is thrown.resolve
in interface Heap
T
- expected instance typereference
- a JSON value containing either the name of the heap object to retrieve or an inline declaration.type
- the expected type of the heap object.optional
- Accept or not a JsonValue that contains null.null
if name contains null
.HeapException
- if there was an exception creating the heap object or any of its dependencies.public void put(String name, Object object)
name
- name of the object to be put into the heap.object
- the object to be put into the heap.public void destroy()
destroy
method for each object in the heap to provide a
chance for system resources to be freed.public Handler getHandler() throws HeapException
Handler
object referenced by the handler top-level attribute.
The returned object is fully decorated (including top-level reference decorations).Handler
object referenced by the handler top-level attributeHeapException
- if object resolution failedpublic Bindings getProperties()
Heap
getProperties
in interface Heap
Copyright 2011-2017 ForgeRock AS.