Class ElementChangeRecorder
This implementation caches locally the state of an element tree at the time
the recorder begins recording. When endRecording() is called,
creates a delta tree over the cached state and the new state.
Clients can use this class as it stands or subclass it as circumstances warrant.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidbeginRecording(IElement inputElement) Begins recording changes in the element tree rooted at the given input element, reporting the changes to a new instance of default delta builder.final voidbeginRecording(IElement inputElement, IElementDeltaBuilder deltaBuilder) Begins recording changes in the element tree rooted at the given input element, reporting the changes to the given delta builder.voidbeginRecording(IElement inputElement, IElementDeltaBuilder deltaBuilder, int maxDepth) Begins recording changes in the element tree rooted at the given input element for the specified maximum depth, reporting the changes to the given delta builder.Ends the current recording and returns a delta builder with the consolidated changes between the state of the element tree at the time the recording was started and its current state.protected voidfindContentChange(Object oldBody, Object newBody, IElement element) Finds whether the given element has had a content change.protected final IElementDeltaBuilderReturns the current delta builder.protected final IElementReturns the current input element.protected final intReturns the current maximum depth.final booleanReturns whether this change recorder is currently recording.protected IElementDeltaBuildernewDeltaBuilder(IElement element) Returns a new instance of default delta builder rooted at the given element.protected voidrecordBody(Object body, IElement element) Remembers the given body for the given element.
-
Constructor Details
-
ElementChangeRecorder
public ElementChangeRecorder()
-
-
Method Details
-
isRecording
public final boolean isRecording()Returns whether this change recorder is currently recording.- Returns:
trueif this change recorder is recording, andfalseotherwise
-
beginRecording
Begins recording changes in the element tree rooted at the given input element, reporting the changes to a new instance of default delta builder. The delta builder is rooted at the given input element.- Parameters:
inputElement- notnull
-
beginRecording
Begins recording changes in the element tree rooted at the given input element, reporting the changes to the given delta builder. The delta builder may benull, in which case a new instance of default delta builder rooted at the given input element will be used.- Parameters:
inputElement- notnulldeltaBuilder- may benull
-
beginRecording
Begins recording changes in the element tree rooted at the given input element for the specified maximum depth, reporting the changes to the given delta builder. The delta builder may benull, in which case a new instance of default delta builder rooted at the given input element will be used.- Parameters:
inputElement- notnulldeltaBuilder- may benullmaxDepth- the maximum depth the recorder should look into (>= 0)
-
endRecording
Ends the current recording and returns a delta builder with the consolidated changes between the state of the element tree at the time the recording was started and its current state.- Returns:
- a delta builder with the consolidated changes
(never
null) - Throws:
IllegalStateException- if this recorder is not recording
-
getInputElement
Returns the current input element.- Returns:
- the current input element
-
getDeltaBuilder
Returns the current delta builder.- Returns:
- the current delta builder
-
getMaxDepth
protected final int getMaxDepth()Returns the current maximum depth.- Returns:
- the current maximum depth
-
newDeltaBuilder
Returns a new instance of default delta builder rooted at the given element.This implementation returns a new instance of
ElementDelta.Builder. The root delta is created via theElementDelta.Factoryregistered in the element's model context. If no delta factory is registered, a new instance ofElementDeltais used.- Parameters:
element- nevernull- Returns:
- a new instance of default delta builder (never
null)
-
recordBody
Remembers the given body for the given element. Subclasses may override this method, but must make sure to call the super implementation. This method is not intended to be invoked by subclasses.- Parameters:
body- nevernullelement- nevernull
-
findContentChange
Finds whether the given element has had a content change. Subclasses may override this method, but are not intended to invoke it.Implementations can compare the given bodies and, if there are differences (excepting children), insert an appropriate change delta (such as
F_CONTENT) for the given element into the delta tree being built. Implementations should not take changes in children into account.This implementation invokes
((Body)newBody)..findContentChange((Body)oldBody, element, getDeltaBuilder())- Parameters:
oldBody- the old version of the element's body (nevernull)newBody- the new version of the element's body (nevernull)element- the element whose bodies are to be compared (nevernull)
-