public ServerCertificate unmarshall(StaxUnmarshallerContext context) throws Exception {
    ServerCertificate serverCertificate = new ServerCertificate();
    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    if (context.isStartOfDocument()) targetDepth += 2;

    while (true) {
      XMLEvent xmlEvent = context.nextEvent();
      if (xmlEvent.isEndDocument()) return serverCertificate;

      if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
        if (context.testExpression("ServerCertificateMetadata", targetDepth)) {
          serverCertificate.setServerCertificateMetadata(
              ServerCertificateMetadataStaxUnmarshaller.getInstance().unmarshall(context));
          continue;
        }
        if (context.testExpression("CertificateBody", targetDepth)) {
          serverCertificate.setCertificateBody(
              StringStaxUnmarshaller.getInstance().unmarshall(context));
          continue;
        }
        if (context.testExpression("CertificateChain", targetDepth)) {
          serverCertificate.setCertificateChain(
              StringStaxUnmarshaller.getInstance().unmarshall(context));
          continue;
        }
      } else if (xmlEvent.isEndElement()) {
        if (context.getCurrentDepth() < originalDepth) {
          return serverCertificate;
        }
      }
    }
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;

    if (obj instanceof ServerCertificate == false) return false;
    ServerCertificate other = (ServerCertificate) obj;

    if (other.getServerCertificateMetadata() == null ^ this.getServerCertificateMetadata() == null)
      return false;
    if (other.getServerCertificateMetadata() != null
        && other.getServerCertificateMetadata().equals(this.getServerCertificateMetadata())
            == false) return false;
    if (other.getCertificateBody() == null ^ this.getCertificateBody() == null) return false;
    if (other.getCertificateBody() != null
        && other.getCertificateBody().equals(this.getCertificateBody()) == false) return false;
    if (other.getCertificateChain() == null ^ this.getCertificateChain() == null) return false;
    if (other.getCertificateChain() != null
        && other.getCertificateChain().equals(this.getCertificateChain()) == false) return false;
    return true;
  }