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​(String elementName,
                                  int elementIndex,
                                  Element element)
      • doVisitEnd

        protected void doVisitEnd​(String elementName,
                                  int elementIndex,
                                  Resource resource)
      • doVisitStart

        protected void doVisitStart​(String elementName,
                                    int elementIndex,
                                    Element element)
      • doVisitStart

        protected void doVisitStart​(String elementName,
                                    int elementIndex,
                                    Resource resource)
      • doVisitListStart

        protected void doVisitListStart​(String elementName,
                                        List<? extends Visitable> visitables,
                                        Class<?> type)
      • doVisitListEnd

        protected void doVisitListEnd​(String elementName,
                                      List<? extends Visitable> visitables,
                                      Class<?> type)
      • getResult

        public T getResult()
        Retrieve a copy of the resource last visited.
        Returns:
        null if no object has been visited yet
        Throws:
        ClassCastException - if the copied object cannot be cast to type T
      • getPath

        public final 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.
      • getBuilder

        protected Builder<?> getBuilder()
      • delete

        protected void delete()
      • markDirty

        protected void markDirty()
      • markListDirty

        protected void markListDirty()
      • convertToCodeSubtype

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