public void startElement(String uri, String localName, String qName, Attributes attrs)
      throws SAXException {
    try {
      // Common XML Attributes
      String attrId = null;
      // HostNode Attributes
      String attrDescription = null;
      String attrHostName = null;
      // HostNode References
      ICFCrmClusterObj refCluster = null;
      // Attribute Extraction
      String attrLocalName;
      int numAttrs;
      int idxAttr;
      final String S_ProcName = "startElement";
      final String S_LocalName = "LocalName";

      assert qName.equals("HostNode");

      CFCrmSaxLoader saxLoader = (CFCrmSaxLoader) getParser();
      if (saxLoader == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "getParser()");
      }

      ICFCrmSchemaObj schemaObj = saxLoader.getSchemaObj();
      if (schemaObj == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()");
      }

      // Instantiate an edit buffer for the parsed information
      ICFCrmHostNodeEditObj editBuff =
          (ICFCrmHostNodeEditObj) schemaObj.getHostNodeTableObj().newInstance().beginEdit();

      // Extract Attributes
      numAttrs = attrs.getLength();
      for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
        attrLocalName = attrs.getLocalName(idxAttr);
        if (attrLocalName.equals("Id")) {
          if (attrId != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrId = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("Description")) {
          if (attrDescription != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrDescription = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("HostName")) {
          if (attrHostName != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrHostName = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("schemaLocation")) {
          // ignored
        } else {
          throw CFLib.getDefaultExceptionFactory()
              .newUnrecognizedAttributeException(
                  getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName);
        }
      }

      // Ensure that required attributes have values
      if (attrDescription == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "Description");
      }
      if (attrHostName == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "HostName");
      }

      // Save named attributes to context
      CFLibXmlCoreContext curContext = getParser().getCurContext();
      curContext.putNamedValue("Id", attrId);
      curContext.putNamedValue("Description", attrDescription);
      curContext.putNamedValue("HostName", attrHostName);

      // Convert string attributes to native Java types
      // and apply the converted attributes to the editBuff.

      Integer natId;
      if ((attrId != null) && (attrId.length() > 0)) {
        natId = new Integer(Integer.parseInt(attrId));
      } else {
        natId = null;
      }
      String natDescription = attrDescription;
      editBuff.setRequiredDescription(natDescription);

      String natHostName = attrHostName;
      editBuff.setRequiredHostName(natHostName);

      // Get the scope/container object

      CFLibXmlCoreContext parentContext = curContext.getPrevContext();
      Object scopeObj;
      if (parentContext != null) {
        scopeObj = parentContext.getNamedValue("Object");
      } else {
        scopeObj = null;
      }

      // Resolve and apply required Container reference

      if (scopeObj == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "scopeObj");
      } else if (scopeObj instanceof ICFCrmClusterObj) {
        refCluster = (ICFCrmClusterObj) scopeObj;
        editBuff.setRequiredContainerCluster(refCluster);
      } else {
        throw CFLib.getDefaultExceptionFactory()
            .newUnsupportedClassException(
                getClass(), S_ProcName, "scopeObj", scopeObj, "ICFCrmClusterObj");
      }

      CFCrmSaxLoader.LoaderBehaviourEnum loaderBehaviour = saxLoader.getHostNodeLoaderBehaviour();
      ICFCrmHostNodeEditObj editHostNode = null;
      ICFCrmHostNodeObj origHostNode =
          (ICFCrmHostNodeObj)
              schemaObj
                  .getHostNodeTableObj()
                  .readHostNodeByHostNameIdx(
                      refCluster.getRequiredId(), editBuff.getRequiredHostName());
      if (origHostNode == null) {
        editHostNode = editBuff;
      } else {
        switch (loaderBehaviour) {
          case Insert:
            break;
          case Update:
            editHostNode = (ICFCrmHostNodeEditObj) origHostNode.beginEdit();
            editHostNode.setRequiredDescription(editBuff.getRequiredDescription());
            editHostNode.setRequiredHostName(editBuff.getRequiredHostName());
            break;
          case Replace:
            editHostNode = (ICFCrmHostNodeEditObj) origHostNode.beginEdit();
            editHostNode.delete();
            editHostNode.endEdit();
            origHostNode = null;
            editHostNode = editBuff;
            break;
        }
      }

      if (editHostNode != null) {
        if (origHostNode != null) {
          editHostNode.update();
        } else {
          origHostNode = (ICFCrmHostNodeObj) editHostNode.create();
        }
        editHostNode.endEdit();
      }

      curContext.putNamedValue("Object", origHostNode);
    } catch (RuntimeException e) {
      throw new RuntimeException(
          "Near "
              + getParser().getLocationInfo()
              + ": Caught and rethrew "
              + e.getClass().getName()
              + " - "
              + e.getMessage(),
          e);
    } catch (Error e) {
      throw new Error(
          "Near "
              + getParser().getLocationInfo()
              + ": Caught and rethrew "
              + e.getClass().getName()
              + " - "
              + e.getMessage(),
          e);
    }
  }
  public void startElement(String uri, String localName, String qName, Attributes attrs)
      throws SAXException {
    try {
      // Common XML Attributes
      String attrId = null;
      // AttachmentData Attributes
      String attrContactId = null;
      String attrAttachment = null;
      // AttachmentData References
      ICFCrmTenantObj refTenant = null;
      ICFCrmAttachmentObj refAttachment = null;
      // Attribute Extraction
      String attrLocalName;
      int numAttrs;
      int idxAttr;
      final String S_ProcName = "startElement";
      final String S_LocalName = "LocalName";

      assert qName.equals("AttachmentData");

      CFCrmSaxLoader saxLoader = (CFCrmSaxLoader) getParser();
      if (saxLoader == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "getParser()");
      }

      ICFCrmSchemaObj schemaObj = saxLoader.getSchemaObj();
      if (schemaObj == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()");
      }

      // Instantiate an edit buffer for the parsed information
      ICFCrmAttachmentDataEditObj editBuff =
          (ICFCrmAttachmentDataEditObj)
              schemaObj.getAttachmentDataTableObj().newInstance().beginEdit();

      // Extract Attributes
      numAttrs = attrs.getLength();
      for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
        attrLocalName = attrs.getLocalName(idxAttr);
        if (attrLocalName.equals("Id")) {
          if (attrId != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrId = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("ContactId")) {
          if (attrContactId != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrContactId = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("Attachment")) {
          if (attrAttachment != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrAttachment = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("schemaLocation")) {
          // ignored
        } else {
          throw CFLib.getDefaultExceptionFactory()
              .newUnrecognizedAttributeException(
                  getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName);
        }
      }

      // Ensure that required attributes have values
      if ((attrContactId == null) || (attrContactId.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "ContactId");
      }

      // Save named attributes to context
      CFLibXmlCoreContext curContext = getParser().getCurContext();
      curContext.putNamedValue("Id", attrId);
      curContext.putNamedValue("ContactId", attrContactId);
      curContext.putNamedValue("Attachment", attrAttachment);

      // Convert string attributes to native Java types
      // and apply the converted attributes to the editBuff.

      Integer natId;
      if ((attrId != null) && (attrId.length() > 0)) {
        natId = new Integer(Integer.parseInt(attrId));
      } else {
        natId = null;
      }
      long natContactId = Long.parseLong(attrContactId);
      editBuff.setRequiredContactId(natContactId);

      byte[] natAttachment;
      if (attrAttachment == null) {
        natAttachment = null;
      } else if (attrAttachment.length() <= 0) {
        natAttachment = new byte[0];
      } else {
        natAttachment = Base64.decodeBase64(attrAttachment.getBytes());
      }
      editBuff.setOptionalAttachment(natAttachment);

      // Get the scope/container object

      CFLibXmlCoreContext parentContext = curContext.getPrevContext();
      Object scopeObj;
      if (parentContext != null) {
        scopeObj = parentContext.getNamedValue("Object");
      } else {
        scopeObj = null;
      }

      // Resolve and apply required Container reference

      if (scopeObj == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "scopeObj");
      } else if (scopeObj instanceof ICFCrmAttachmentObj) {
        refAttachment = (ICFCrmAttachmentObj) scopeObj;
        editBuff.setRequiredContainerAttachment(refAttachment);
        refTenant = (ICFCrmTenantObj) editBuff.getRequiredOwnerTenant();
      } else {
        throw CFLib.getDefaultExceptionFactory()
            .newUnsupportedClassException(
                getClass(), S_ProcName, "scopeObj", scopeObj, "ICFCrmAttachmentObj");
      }

      // Resolve and apply Owner reference

      if (refTenant == null) {
        if (scopeObj instanceof ICFCrmTenantObj) {
          refTenant = (ICFCrmTenantObj) scopeObj;
          editBuff.setRequiredOwnerTenant(refTenant);
        } else {
          throw CFLib.getDefaultExceptionFactory()
              .newNullArgumentException(getClass(), S_ProcName, 0, "Owner<Tenant>");
        }
      }

      ICFCrmAttachmentDataObj origAttachmentData;
      ICFCrmAttachmentDataEditObj editAttachmentData = editBuff;
      origAttachmentData = (ICFCrmAttachmentDataObj) editAttachmentData.create();
      editAttachmentData.endEdit();

      curContext.putNamedValue("Object", origAttachmentData);
    } catch (RuntimeException e) {
      throw new RuntimeException(
          "Near "
              + getParser().getLocationInfo()
              + ": Caught and rethrew "
              + e.getClass().getName()
              + " - "
              + e.getMessage(),
          e);
    } catch (Error e) {
      throw new Error(
          "Near "
              + getParser().getLocationInfo()
              + ": Caught and rethrew "
              + e.getClass().getName()
              + " - "
              + e.getMessage(),
          e);
    }
  }