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 ClonerThe cloner, created when first needed.private ModifiableMetadata.StateThe state to apply on all metadata objects.private static final ThreadLocal<StateChanger>TheStateChangerinstance in current use.Fields inherited from class org.apache.sis.metadata.MetadataVisitor
SKIP_SIBLINGS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate ObjectReturns the given object, or a copy of the given object, with its state changed.(package private) static voidapplyTo(ModifiableMetadata.State target, ModifiableMetadata metadata) Applies a state change on the given metadata object.private voidapplyToAll(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 thisStateChangerinstance.(package private) MetadataVisitor.FilterpreVisit(PropertyAccessor accessor) NotifiesMetadataVisitorthat we want to visit all writable properties.(package private) final ObjectInvoked 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
TheStateChangerinstance 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 exposeStateChangerin 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 newStateChangerinstance.
-
-
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
thisvalue 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. TheVISITORSthread local variable is used as a workaround for providingthisinstance without makingStateChangerpublic. -
creator
Returns the thread-local variable that created thisStateChangerinstance.ThreadLocal.remove()will be invoked afterMetadataVisitorfinished to walk through the given metadata and all its children.- Overrides:
creatorin classMetadataVisitor<Boolean>
-
preVisit
NotifiesMetadataVisitorthat we want to visit all writable properties.- Overrides:
preVisitin 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:
visitin 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
Cloneableinterface, 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
-