Class CopyingVisitor<T extends Visitable>

  • 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.
    • Constructor Detail

      • CopyingVisitor

        public CopyingVisitor()
    • 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 interface Visitor
        Overrides:
        visitStart in class DefaultVisitor
      • visitEnd

        public final void visitEnd​(java.lang.String elementName,
                                   int index,
                                   Element element)
        Subclasses may override doVisitEnd
        Specified by:
        visitEnd in interface Visitor
        Overrides:
        visitEnd in class DefaultVisitor
      • visitEnd

        public final void visitEnd​(java.lang.String elementName,
                                   int index,
                                   Resource resource)
        Subclasses may override doVisitEnd
        Specified by:
        visitEnd in interface Visitor
        Overrides:
        visitEnd in class DefaultVisitor
      • 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 interface Visitor
        Overrides:
        visitStart in class DefaultVisitor
      • 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 interface Visitor
        Overrides:
        visitEnd in class DefaultVisitor
      • getBuilder

        protected Builder<?> getBuilder()
      • getList

        protected java.util.List<Visitable> getList()
      • delete

        protected void delete()
      • markDirty

        protected void markDirty()
      • markListDirty

        protected void markListDirty()
      • convertToCodeSubtype

        protected Code convertToCodeSubtype​(Visitable parent,
                                            java.lang.String elementName,
                                            Code value)