Package org.jibx.util

Class HolderBase

  • Direct Known Subclasses:
    SchemaHolder

    public abstract class HolderBase
    extends java.lang.Object
    Base class for external data used in constructing a namespaced file which may reference other files of the same type. This class tracks both the referenced files and the corresponding namespace references, assigning prefixes for the latter as appropriate. The namespace associated with this file is always given the prefix 'tns', while those used for other files get prefixes of the form 'ns1', 'ns2', etc.
    Author:
    Dennis M. Sosnoski
    • Constructor Summary

      Constructors 
      Constructor Description
      HolderBase​(java.lang.String uri)
      Constructor for a file being generated.
      HolderBase​(java.lang.String uri, java.lang.String name)
      Constructor for an existing file.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract void addNamespaceDecl​(java.lang.String prefix, java.lang.String uri)
      Subclass hook method to handle adding a namespace declaration.
      void addReference​(HolderBase ref)
      Record a reference from this file to another file of the same type.
      void finish()
      Implementation method for subclasses to complete the construction of the file.
      java.lang.String getFileName()
      Get the file name to be used for this file.
      java.lang.String getNamespace()
      Get namespace URI associated with this file.
      java.lang.String getPrefix​(java.lang.String uri)
      Get the prefix for a namespace URI.
      java.util.Set getReferences()
      Get the set of references from this file to other files of the same type.
      boolean isExistingFile()
      Check if file already exists.
      boolean isModifiable()
      Check if file is modifiable.
      void setFileName​(java.lang.String name)
      Set the file name to be used for this file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • m_namespace

        private final java.lang.String m_namespace
      • m_nsPrefixMap

        private final java.util.Map m_nsPrefixMap
      • m_finished

        private boolean m_finished
      • m_existingFile

        private boolean m_existingFile
      • m_fileName

        private java.lang.String m_fileName
      • m_referenceSet

        private java.util.Set m_referenceSet
    • Constructor Detail

      • HolderBase

        public HolderBase​(java.lang.String uri)
        Constructor for a file being generated.
        Parameters:
        uri - (null if no-namespace binding)
      • HolderBase

        public HolderBase​(java.lang.String uri,
                          java.lang.String name)
        Constructor for an existing file.
        Parameters:
        uri - (null if no-namespace binding)
        name - file name
    • Method Detail

      • isExistingFile

        public boolean isExistingFile()
        Check if file already exists.
        Returns:
        true if existing file, false if not
      • isModifiable

        public boolean isModifiable()
        Check if file is modifiable. This will always be false for an existing file, and will be set false for new files when finish() is called.
        Returns:
        true if file is modifiable, false if not
      • getPrefix

        public java.lang.String getPrefix​(java.lang.String uri)
        Get the prefix for a namespace URI. The first time this is called for a particular namespace URI a prefix is assigned and returned. This assumes that the default namespace is always the no-namespace.
        Parameters:
        uri -
        Returns:
        prefix
      • addNamespaceDecl

        protected abstract void addNamespaceDecl​(java.lang.String prefix,
                                                 java.lang.String uri)
        Subclass hook method to handle adding a namespace declaration. The implementation of this method needs to set up the namespace declaration for output in the generated XML.
        Parameters:
        prefix -
        uri -
      • getNamespace

        public java.lang.String getNamespace()
        Get namespace URI associated with this file.
        Returns:
        namespace (null if no-namespace)
      • getFileName

        public java.lang.String getFileName()
        Get the file name to be used for this file.
        Returns:
        name (null if not set)
      • setFileName

        public void setFileName​(java.lang.String name)
        Set the file name to be used for this file.
        Parameters:
        name -
      • addReference

        public void addReference​(HolderBase ref)
        Record a reference from this file to another file of the same type. This adds the reference to the set of references. Self-references are ignored.
        Parameters:
        ref -
      • getReferences

        public java.util.Set getReferences()
        Get the set of references from this file to other files of the same type.
        Returns:
        references
      • finish

        public void finish()
        Implementation method for subclasses to complete the construction of the file. This includes processing references to other files, as well as any other components of the file which need to be finalized. This method must be called after all references have been added, allowing the subclass to add any necessary structures to the file representation. Subclasses must call the base class implementation when their processing is completed.