# SerializeOptions.java

    /*
    ** Module   : SerializeOptions.java
    ** Abstract : Options related to serialized temp-table data.
    **
    ** Copyright (c) 2017-2022, Golden Code Development Corporation.
    **
    ** -#- -I- --Date-- ---------------------------------Description---------------------------------
    ** 001 ECF 20171016 Created initial version.
    ** 002 OM  20181114 Made serializeName mutable.
    ** 003 HC  20190301 Extended XmlNodeType with other possible values.
    ** 004 CA  20191203 Made XmlNodeType class public.
    ** 005 OM  20010121 Allow the field members be mutable.
    **     CA  20221006 Refactored TableMapper for temp-tables to keep a cache of LegacyTableInfo and the mutable
    **                  state in MutableFieldInfo, for the actual TempTable instance. Refs #6825
    */

    /*
    ** This program is free software: you can redistribute it and/or modify
    ** it under the terms of the GNU Affero General Public License as
    ** published by the Free Software Foundation, either version 3 of the
    ** License, or (at your option) any later version.
    **
    ** This program is distributed in the hope that it will be useful,
    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    ** GNU Affero General Public License for more details.
    **
    ** You may find a copy of the GNU Affero GPL version 3 at the following
    ** location: https://www.gnu.org/licenses/agpl-3.0.en.html
    **
    ** Additional terms under GNU Affero GPL version 3 section 7:
    **
    **   Under Section 7 of the GNU Affero GPL version 3, the following additional
    **   terms apply to the works covered under the License.  These additional terms
    **   are non-permissive additional terms allowed under Section 7 of the GNU
    **   Affero GPL version 3 and may not be removed by you.
    **
    **   0. Attribution Requirement.
    **
    **     You must preserve all legal notices or author attributions in the covered
    **     work or Appropriate Legal Notices displayed by works containing the covered
    **     work.  You may not remove from the covered work any author or developer
    **     credit already included within the covered work.
    **
    **   1. No License To Use Trademarks.
    **
    **     This license does not grant any license or rights to use the trademarks
    **     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
    **     of Golden Code Development Corporation. You are not authorized to use the
    **     name Golden Code, FWD, or the names of any author or contributor, for
    **     publicity purposes without written authorization.
    **
    **   2. No Misrepresentation of Affiliation.
    **
    **     You may not represent yourself as Golden Code Development Corporation or FWD.
    **
    **     You may not represent yourself for publicity purposes as associated with
    **     Golden Code Development Corporation, FWD, or any author or contributor to
    **     the covered work, without written authorization.
    **
    **   3. No Misrepresentation of Source or Origin.
    **
    **     You may not represent the covered work as solely your work.  All modified
    **     versions of the covered work must be marked in a reasonable way to make it
    **     clear that the modified work is not originating from Golden Code Development
    **     Corporation or FWD.  All modified versions must contain the notices of
    **     attribution required in this license.
    */

    package com.goldencode.p2j.persist.serial;

    /**
     * Options related to serialized temp-table data.
     */
    public class SerializeOptions
    {
       /** Modes for reading serialized data into a temp-table */
       public static enum Read
       {
          APPEND,
          EMPTY,
          MERGE,
          REPLACE,
       }

       /** Modes for verifying XML data being read into a temp-table */
       public static enum Verify
       {
          IGNORE,
          LOOSE,
          STRICT,
       }

       /** Type of XML nodes for serialized data */
       public static enum XmlNodeType
       {
          ELEMENT,
          ATTRIBUTE,
          HIDDEN,
          TEXT
       }

       /** Should this field be omitted from serialized output? */
       private  boolean serializeHidden;

       /** Name of field in serialized output (overrides field name). */
       private String serializeName;

       /** XML schema data type of field. */
       private String xmlDataType;

       /** Name of element or attribute representing field in XML output. */
       private String xmlNodeName;

       /** Node type of field in XML output. */
       private XmlNodeType xmlNodeType;

       /**
        * Constructor.
        *
        * @param   serializeHidden
        *          Should this field be omitted from serialized output?
        * @param   serializeName
        *          Name of field in serialized output (overrides field name).
        * @param   xmlDataType
        *          XML schema data type of field
        * @param   xmlNodeName
        *          Name of element or attribute representing field in XML output.
        * @param   xmlNodeType
        *          Node type of field in XML output (overrides {@code serializeName}).
        */
       public SerializeOptions(boolean serializeHidden,
                               String serializeName,
                               String xmlDataType,
                               String xmlNodeName,
                               String xmlNodeType)
       {
          this.serializeHidden = serializeHidden;
          this.serializeName = serializeName == null ? null : serializeName.intern();;
          this.xmlDataType = xmlDataType == null ? null : xmlDataType.intern();
          this.xmlNodeName = xmlNodeName == null ? null : xmlNodeName.intern();
          this.xmlNodeType = XmlNodeType.valueOf(xmlNodeType.toUpperCase());
       }

       /**
        * Initialize this mutable info from the field's definition.
        *
        * @param    opts
        *           The options as they appear at the field's definition, from the temp-table.
        */
       public SerializeOptions(SerializeOptions opts)
       {
          this.serializeHidden = opts.serializeHidden;
          this.serializeName = (opts.serializeName == null ? null : opts.serializeName.intern());
          this.xmlDataType = (opts.xmlDataType == null ? null : opts.xmlDataType.intern());
          this.xmlNodeName = (opts.xmlNodeName == null ? null : opts.xmlNodeName.intern());
          this.xmlNodeType = opts.xmlNodeType;
       }

       /**
        * Get the value of the serialize-hidden flag.
        *
        * @return  {@code true} if the associated field is not included in serialization, else {@code false}.
        */
       public boolean isSerializeHidden()
       {
          return serializeHidden;
       }

       /**
        * Sets the value of the serialize-hidden flag.
        *
        * @param   serializeHidden
        *          {@code true} if the associated field is not included in serialization, else {@code false}.
        */
       public void setSerializeHidden(boolean serializeHidden)
       {
          this.serializeHidden = serializeHidden;
       }

       /**
        * Get the name of the field in serialized output (overrides field name in table).
        *
        * @return  Serialize name.
        */
       public String getSerializeName()
       {
          return serializeName;
       }

       /**
        * Set the name of the field in serialized output (overrides field name in table).
        *
        * @param   sName
        *          The new serialize name.
        */
       public void  setSerializeName(String sName)
       {
          serializeName = sName;
       }

       /**
        * Get the XML schema data type of the associated field.
        *
        * @return  XML schema data type.
        */
       public String getXmlDataType()
       {
          return xmlDataType;
       }

       /**
        * Sets the XML schema data type of the associated field.
        *
        * @param   xmlDataType
        *          The new XML schema data type.
        */
       public void setXmlDataType(String xmlDataType)
       {
          this.xmlDataType = xmlDataType;
       }

       /**
        * Get the node name of the field in XML output (overrides serialize-name and field name in table).
        *
        * @return  XML node name.
        */
       public String getXmlNodeName()
       {
          return xmlNodeName;
       }

       /**
        * Sets the node name of the field in XML output (overrides serialize-name and field name in table).
        *
        * @param   xmlNodeName
        *          The new XML node name.
        */
       public void setXmlNodeName(String xmlNodeName)
       {
          this.xmlNodeName = xmlNodeName;
       }

       /**
        * Get the node type (element or attribute) in XML output.
        *
        * @return  XML node type.
        */
       public XmlNodeType getXmlNodeType()
       {
          return xmlNodeType;
       }

       /**
        * Sets the node type (element or attribute) in XML output.
        *
        * @param   xmlNodeType
        *          The new XML node type.
        */
       public void setXmlNodeType(XmlNodeType xmlNodeType)
       {
          this.xmlNodeType = xmlNodeType;
       }
    }