All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.unbound.kmip.response.ResponseMessage Maven / Gradle / Ivy

Go to download

This is a collection of JAVA libraries that implement Unbound cryptographic classes for JAVA provider, PKCS11 wrapper, cryptoki, and advapi

There is a newer version: 42761
Show newest version
package com.unbound.kmip.response;

import com.unbound.common.Log;
import com.unbound.kmip.KMIP;
import com.unbound.kmip.KMIPConvertException;
import com.unbound.kmip.KMIPConverter;

import java.util.ArrayList;

/**
 * Created by valery.osheter on 19-Nov-15.
 */
public class ResponseMessage
{
  public ResponseHeader header = new ResponseHeader();

  public ArrayList batch = new ArrayList<>();

  public ResponseMessage()
  {
    header.version.major = 1;
    header.version.minor = 0;
  }

  public void convert(KMIPConverter converter) throws KMIPConvertException
  {
    int begin = converter.convertBegin(KMIP.Tag.ResponseMessage);
    header.convert(converter);
//    int count = converter.isWrite() ? batch.size() : header.batch_count;

    if (converter.isWrite())
    {
      for (ResponseItem item : batch) ResponseItem.convert(converter, item);
    }
    else
    {
      for (int i = 0; i < header.batchCount; i++)
      {
        ResponseItem item = ResponseItem.convert(converter, null);
        batch.add(item);
      }
    }

    converter.convertEnd(begin);
  }

  public void add(ResponseItem responseItem, byte[] uid)
  {

    if (responseItem.operation == KMIP.Operation.Poll)
    {
      if (((PollResponse) responseItem).responseItem != null)
      {
        add(((PollResponse) responseItem).responseItem);
        return;
      }
    }

    responseItem.responseUID = uid;
    batch.add(responseItem);
    header.batchCount++;
  }

  public void add(ResponseItem responseItem)
  {
    add(responseItem, null);
  }

  public void clear()
  {
    batch.clear();
    header.batchCount = 0;
  }

  public void log()
  {
    Log log = Log.func("ResponseMessage").end();
    for (ResponseItem item : batch)
    {
      if (item.resultStatus ==0) item.log();
      else item.logStatus();
    }
    log.leave();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy