Class XMLTagWriter

  • Direct Known Subclasses:
    SimpleTagWriter

    public abstract class XMLTagWriter
    extends java.lang.Object
    Base class of XML tag writer classes.

    This class provides the following functionality:

    • Constructor Summary

      Constructors 
      Constructor Description
      XMLTagWriter​(XMLTagWriter parent)
      Creates a new optional tag writer.
      XMLTagWriter​(XMLTagWriter parent, boolean mandatory)
      Creates a new tag writer which is either optional or mandatory.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addSubTagWriter​(XMLTagWriter tagWriter)
      Here you can add or replace an sub-XMLTagWriter to this XMLTagWriter.
      void addSubTagWriter​(XMLTagWriter tagWriter, java.lang.String type)
      Here you can add or replace an sub-XMLTagWriter to this XMLTagWriter.
      void addSubTagWriter​(java.lang.String tagName, java.util.Map typeMap)
      Here you can add or replace an sub-XMLTagWriter to this XMLTagWriter.
      protected void debug​(java.lang.String message)
      Logging method.
      protected void error​(java.lang.String message)
      Logging method.
      java.util.Collection getAllSubTagWriter()
      Returns all tagwriter of this XMLTagWriter
      protected java.util.Map getAttributesMap​(java.lang.Object object)
      Overwrite this method, if you want to specify xml attributes at the actual tag.
      protected XMLWriter getEnclosingWriter()  
      protected XMLTagWriter getParent()
      Returns the parent of this XMLTagWriter
      XMLTagWriter getSubTagWriter​(java.lang.String tagName)
      Returns the XMLTagWriter with the given tagName
      XMLTagWriter getSubTagWriter​(java.lang.String tagName, java.lang.String type)
      Returns the XMLTagWriter with the given tagName.
      protected java.util.Map getSubTagWriterMap​(boolean create)  
      protected abstract java.lang.String getTagName()
      Override to provide a name for the actual tag to be written.
      protected void info​(java.lang.String message)
      Logging method.
      protected boolean isDebugEnabled()
      Logging method.
      protected boolean isErrorEnabled()
      Logging method.
      protected boolean isInfoEnabled()
      Logging method.
      boolean isMandatory()
      Returns true if the tag is mandatory which means a non-null value must be provided when writing it.
      protected boolean isWarnEnabled()
      Logging method.
      protected void warn​(java.lang.String message)
      Logging method.
      void write​(org.znerd.xmlenc.XMLOutputter xmlOut, java.lang.Object object)
      This method write the start- and endtag of your tag.
      protected abstract void writeContent​(org.znerd.xmlenc.XMLOutputter xmlOut, java.lang.Object object)
      Here you can write out the data to the given XMLOutputter.
      • Methods inherited from class java.lang.Object

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

      • XMLTagWriter

        public XMLTagWriter​(XMLTagWriter parent)
        Creates a new optional tag writer.
        Parameters:
        parent - the parent XMLTagWriter of this instance, optional
      • XMLTagWriter

        public XMLTagWriter​(XMLTagWriter parent,
                            boolean mandatory)
        Creates a new tag writer which is either optional or mandatory. Mandatory tag writer report an error when trying to export a null value!
        Parameters:
        parent - the parent XMLTagWriter of this instance
        mandatory - true if this is a mandatory tag, false otherwise
    • Method Detail

      • getEnclosingWriter

        protected XMLWriter getEnclosingWriter()
      • isInfoEnabled

        protected boolean isInfoEnabled()
        Logging method.
      • isDebugEnabled

        protected boolean isDebugEnabled()
        Logging method.
      • isWarnEnabled

        protected boolean isWarnEnabled()
        Logging method.
      • isErrorEnabled

        protected boolean isErrorEnabled()
        Logging method.
      • info

        protected void info​(java.lang.String message)
        Logging method.
      • debug

        protected void debug​(java.lang.String message)
        Logging method.
      • warn

        protected void warn​(java.lang.String message)
        Logging method.
      • error

        protected void error​(java.lang.String message)
        Logging method.
      • getTagName

        protected abstract java.lang.String getTagName()
        Override to provide a name for the actual tag to be written.
      • writeContent

        protected abstract void writeContent​(org.znerd.xmlenc.XMLOutputter xmlOut,
                                             java.lang.Object object)
                                      throws java.io.IOException
        Here you can write out the data to the given XMLOutputter. This method is called to fill in the content between the start and end tag.
        Parameters:
        xmlOut - the XMLOutputter to write to
        object - the data object provided by the parent tag writer, may be null
        Throws:
        java.io.IOException
      • getAttributesMap

        protected java.util.Map getAttributesMap​(java.lang.Object object)
        Overwrite this method, if you want to specify xml attributes at the actual tag. The name of the attribute has to be the key of the Map.
        Parameters:
        object - the data object provided by the parent tag writer, may be null
        Returns:
        the attributes Map
      • write

        public final void write​(org.znerd.xmlenc.XMLOutputter xmlOut,
                                java.lang.Object object)
                         throws XMLWriteException
        This method write the start- and endtag of your tag. It calls the method writeContent(XMLOutputter, Object) to fill in data between these two tags.
        Parameters:
        xmlOut - the XMLOutputter to write to
        object - the data object, it depends on the parent what kind of object you get here
        Throws:
        XMLWriteException
      • getParent

        protected XMLTagWriter getParent()
        Returns the parent of this XMLTagWriter
        Returns:
        the parent XMLTagWriter or null if no parent was declared
      • getSubTagWriterMap

        protected java.util.Map getSubTagWriterMap​(boolean create)
      • addSubTagWriter

        public void addSubTagWriter​(XMLTagWriter tagWriter)
        Here you can add or replace an sub-XMLTagWriter to this XMLTagWriter.
        Parameters:
        tagWriter - the new XMLTagWriter
      • addSubTagWriter

        public void addSubTagWriter​(XMLTagWriter tagWriter,
                                    java.lang.String type)
        Here you can add or replace an sub-XMLTagWriter to this XMLTagWriter. If you have more than one subtagwriter with the same tagname, than you have to specify a type for the tagwriter, so you can indentify it in the getSubTagWriter-method.
        Parameters:
        tagWriter - tagWriter the new XMLTagWriter
        type - the type of this XMLTagWriter
      • addSubTagWriter

        public void addSubTagWriter​(java.lang.String tagName,
                                    java.util.Map typeMap)
        Here you can add or replace an sub-XMLTagWriter to this XMLTagWriter. If you have more than one subtagwriter with the same tagname, than you have to specify a type for the tagwriter, so you can indentify it in the getSubTagWriter-method.
        Parameters:
        tagName - name of the tag
        typeMap - key of the Map is a type (String) and value is a XMLTagWriter
      • getAllSubTagWriter

        public java.util.Collection getAllSubTagWriter()
        Returns all tagwriter of this XMLTagWriter
        Returns:
        all tagwriter of this XMLTagWriter
      • getSubTagWriter

        public XMLTagWriter getSubTagWriter​(java.lang.String tagName)
        Returns the XMLTagWriter with the given tagName
        Parameters:
        tagName - name of the tag
        Returns:
        the XMLTagWriter with the given tagName
        Throws:
        java.lang.IllegalArgumentException - if no XMLTagWriter was found for the given tag name
      • getSubTagWriter

        public XMLTagWriter getSubTagWriter​(java.lang.String tagName,
                                            java.lang.String type)
        Returns the XMLTagWriter with the given tagName.
        Parameters:
        tagName - name of the tag
        type - type of the XMLTagWriter
        Returns:
        the XMLTagWriter with the given tagName
        Throws:
        java.lang.IllegalArgumentException - if no XMLTagWriter was found for the given tag name and type
      • isMandatory

        public boolean isMandatory()
        Returns true if the tag is mandatory which means a non-null value must be provided when writing it.