Package org.apache.sis.metadata
Class StateChanger
Invokes
ModifiableMetadata.transitionTo(ModifiableMetadata.State)
recursively on metadata elements.- Since:
- 0.3
- Version:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.metadata.MetadataVisitor
MetadataVisitor.Filter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Cloner
The cloner, created when first needed.private ModifiableMetadata.State
The state to apply on all metadata objects.private static final ThreadLocal
<StateChanger> TheStateChanger
instance in current use.Fields inherited from class org.apache.sis.metadata.MetadataVisitor
SKIP_SIBLINGS
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Object
Returns the given object, or a copy of the given object, with its state changed.(package private) static void
applyTo
(ModifiableMetadata.State target, ModifiableMetadata metadata) Applies a state change on the given metadata object.private void
applyToAll
(Object[] array) Recursively changes the state of all elements in the given array.(package private) final ThreadLocal
<StateChanger> creator()
Returns the thread-local variable that created thisStateChanger
instance.(package private) MetadataVisitor.Filter
preVisit
(PropertyAccessor accessor) NotifiesMetadataVisitor
that we want to visit all writable properties.(package private) final Object
Invoked for metadata instances on which to apply a change of state.Methods inherited from class org.apache.sis.metadata.MetadataVisitor
getCurrentPropertyPath, result, setCurrentProperty, walk
-
Field Details
-
VISITORS
TheStateChanger
instance in current use. The clean way would have been to pass the instance in argument toModifiableMetadata.transitionTo(ModifiableMetadata.State)
. But above-cited method ix public and we do not want to exposeStateChanger
in public API. This thread-local is a workaround for that situation. -
target
The state to apply on all metadata objects. -
cloner
The cloner, created when first needed.
-
-
Constructor Details
-
StateChanger
private StateChanger()Creates a newStateChanger
instance.
-
-
Method Details
-
applyTo
Applies a state change on the given metadata object. This is the implementationModifiableMetadata.transitionTo(ModifiableMetadata.State)
public method.This is conceptually an instance (non-static) method. But the
this
value is not known by the caller, because doing otherwise would force us to give public visibility to classes that we want to keep package-private. TheVISITORS
thread local variable is used as a workaround for providingthis
instance without makingStateChanger
public. -
creator
Returns the thread-local variable that created thisStateChanger
instance.ThreadLocal.remove()
will be invoked afterMetadataVisitor
finished to walk through the given metadata and all its children.- Overrides:
creator
in classMetadataVisitor<Boolean>
-
preVisit
NotifiesMetadataVisitor
that we want to visit all writable properties.- Overrides:
preVisit
in classMetadataVisitor<Boolean>
- Parameters:
accessor
- ignored.- Returns:
MetadataVisitor.Filter.WRITABLE
, for iterating over all writable properties.
-
visit
Invoked for metadata instances on which to apply a change of state.- Specified by:
visit
in classMetadataVisitor<Boolean>
- Parameters:
type
- ignored (can benull
).object
- the object to transition to a different state.- Returns:
- the given object or a copy of the given object with its state changed.
- Throws:
CloneNotSupportedException
-
applyToAll
Recursively changes the state of all elements in the given array.- Throws:
CloneNotSupportedException
-
applyTo
Returns the given object, or a copy of the given object, with its state changed. This method performs the following heuristic tests:- If the specified object is an instance of
ModifiableMetadata
, thenModifiableMetadata.transitionTo(ModifiableMetadata.State)
is invoked on that object. - Otherwise, if the object is a collection, then the content is copied into a new collection of similar type, with values replaced by their unmodifiable variant.
- Otherwise, if the object implements the
Cloneable
interface, then a clone is returned. - Otherwise, the object is assumed immutable and returned unchanged.
- Parameters:
object
- the object to transition to a different state.- Returns:
- the given object or a copy of the given object with its state changed.
- Throws:
CloneNotSupportedException
- If the specified object is an instance of
-