Class CopyingVisitor<T extends Visitable>
- java.lang.Object
-
- org.linuxforhealth.fhir.model.visitor.DefaultVisitor
-
- org.linuxforhealth.fhir.model.visitor.CopyingVisitor<T>
-
- Type Parameters:
T
- The type to copy. Only visitables of this type should be visited.
- All Implemented Interfaces:
Visitor
- Direct Known Subclasses:
AddingVisitor
,DeletingVisitor
,EncodingVisitor
,InsertingVisitor
,MovingVisitor
,ReferenceMappingVisitor
,ReplacingVisitor
@NotThreadSafe public class CopyingVisitor<T extends Visitable> extends DefaultVisitor
Copy a Resource or Element. Because model objects are immutable, by default this will return a reference to the exact same object that was originally visited. However, subclasses may override this class in order to modify the copied Resource or Element by setting new values on the current builder via ({@link BuilderWrapper#getBuilder()) and marking it dirty via ({@link BuilderWrapper#markDirty())). Note: this class is NOT threadsafe. Only one object should be visited at a time.
-
-
Field Summary
-
Fields inherited from class org.linuxforhealth.fhir.model.visitor.DefaultVisitor
visitChildren
-
-
Constructor Summary
Constructors Constructor Description CopyingVisitor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Code
convertToCodeSubtype(Visitable parent, java.lang.String elementName, Code value)
protected void
delete()
protected void
doVisitEnd(java.lang.String elementName, int elementIndex, Resource resource)
protected void
doVisitEnd(java.lang.String elementName, int elementIndex, Element element)
protected void
doVisitListEnd(java.lang.String elementName, java.util.List<? extends Visitable> visitables, java.lang.Class<?> type)
protected void
doVisitListStart(java.lang.String elementName, java.util.List<? extends Visitable> visitables, java.lang.Class<?> type)
protected void
doVisitStart(java.lang.String elementName, int elementIndex, Resource resource)
protected void
doVisitStart(java.lang.String elementName, int elementIndex, Element element)
protected Builder<?>
getBuilder()
protected java.util.List<Visitable>
getList()
java.lang.String
getPath()
Get the FHIRPath path of the Resource or Element currently being visited.T
getResult()
Retrieve a copy of the resource last visited.protected void
markDirty()
protected void
markListDirty()
void
postVisit(Resource resource)
void
postVisit(Element element)
protected void
replace(Resource.Builder builder)
protected void
replace(Element.Builder builder)
void
reset()
Reset the state of the CopyingVisitor.void
visitEnd(java.lang.String elementName, int index, Resource resource)
Subclasses may override doVisitEndvoid
visitEnd(java.lang.String elementName, int index, Element element)
Subclasses may override doVisitEndvoid
visitEnd(java.lang.String elementName, java.util.List<? extends Visitable> visitables, java.lang.Class<?> type)
Subclasses may override doVisitListEndvoid
visitStart(java.lang.String elementName, int index, Resource resource)
Subclasses may override doVisitStartvoid
visitStart(java.lang.String elementName, int index, Element element)
Subclasses may override doVisitStartvoid
visitStart(java.lang.String elementName, java.util.List<? extends Visitable> visitables, java.lang.Class<?> type)
Subclasses may override doVisitListStart-
Methods inherited from class org.linuxforhealth.fhir.model.visitor.DefaultVisitor
preVisit, preVisit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
-
-
-
-
Method Detail
-
doVisitEnd
protected void doVisitEnd(java.lang.String elementName, int elementIndex, Element element)
-
doVisitEnd
protected void doVisitEnd(java.lang.String elementName, int elementIndex, Resource resource)
-
doVisitStart
protected void doVisitStart(java.lang.String elementName, int elementIndex, Element element)
-
doVisitStart
protected void doVisitStart(java.lang.String elementName, int elementIndex, Resource resource)
-
doVisitListStart
protected void doVisitListStart(java.lang.String elementName, java.util.List<? extends Visitable> visitables, java.lang.Class<?> type)
-
doVisitListEnd
protected void doVisitListEnd(java.lang.String elementName, java.util.List<? extends Visitable> visitables, java.lang.Class<?> type)
-
getResult
public T getResult()
Retrieve a copy of the resource last visited.- Returns:
- null if no object has been visited yet
- Throws:
java.lang.ClassCastException
- if the copied object cannot be cast to type T
-
getPath
public final java.lang.String getPath()
Get the FHIRPath path of the Resource or Element currently being visited. This method is primarily for subclasses but can also be used externally to retrieve a path to the Resource or Element that was being visited when an Exception occurs.- Returns:
- The path of the Resource or Element currently being visited, the path that was being visited when an exception was thrown, or null if there is no Resource or Element being visited.
-
reset
public final void reset()
Reset the state of the CopyingVisitor. Invoke this method when visiting has failed and you want to clear the state in order to re-use the visitor.
-
visitStart
public final void visitStart(java.lang.String elementName, int index, Element element)
Subclasses may override doVisitStart- Specified by:
visitStart
in interfaceVisitor
- Overrides:
visitStart
in classDefaultVisitor
-
visitStart
public final void visitStart(java.lang.String elementName, int index, Resource resource)
Subclasses may override doVisitStart- Specified by:
visitStart
in interfaceVisitor
- Overrides:
visitStart
in classDefaultVisitor
-
visitEnd
public final void visitEnd(java.lang.String elementName, int index, Element element)
Subclasses may override doVisitEnd- Specified by:
visitEnd
in interfaceVisitor
- Overrides:
visitEnd
in classDefaultVisitor
-
visitEnd
public final void visitEnd(java.lang.String elementName, int index, Resource resource)
Subclasses may override doVisitEnd- Specified by:
visitEnd
in interfaceVisitor
- Overrides:
visitEnd
in classDefaultVisitor
-
visitStart
public void visitStart(java.lang.String elementName, java.util.List<? extends Visitable> visitables, java.lang.Class<?> type)
Subclasses may override doVisitListStart- Specified by:
visitStart
in interfaceVisitor
- Overrides:
visitStart
in classDefaultVisitor
-
visitEnd
public void visitEnd(java.lang.String elementName, java.util.List<? extends Visitable> visitables, java.lang.Class<?> type)
Subclasses may override doVisitListEnd- Specified by:
visitEnd
in interfaceVisitor
- Overrides:
visitEnd
in classDefaultVisitor
-
postVisit
public void postVisit(Element element)
- Specified by:
postVisit
in interfaceVisitor
- Overrides:
postVisit
in classDefaultVisitor
-
postVisit
public void postVisit(Resource resource)
- Specified by:
postVisit
in interfaceVisitor
- Overrides:
postVisit
in classDefaultVisitor
-
getBuilder
protected Builder<?> getBuilder()
-
getList
protected java.util.List<Visitable> getList()
-
replace
protected void replace(Resource.Builder builder)
-
replace
protected void replace(Element.Builder builder)
-
delete
protected void delete()
-
markDirty
protected void markDirty()
-
markListDirty
protected void markListDirty()
-
-