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

cn.teleinfo.idpointer.sdk.core.ResolutionResponse Maven / Gradle / Ivy

Go to download

基于Java语言开发的工业互联网标识解析体系客户端软件开发工具包,应用通过集成 id-pointer-sdk,快速对接标识解析、标识注册、标识维护等功能服务。

The newest version!
/**********************************************************************\
 © COPYRIGHT 2019 Corporation for National Research Initiatives (CNRI);
                        All rights reserved.

        The HANDLE.NET software is made available subject to the
      Handle.Net Public License Agreement, which may be obtained at
          http://hdl.handle.net/20.1000/112 or hdl:20.1000/112
\**********************************************************************/

package cn.teleinfo.idpointer.sdk.core;

public class ResolutionResponse extends AbstractResponse {

    public byte handle[];
    public byte values[][];

    public ResolutionResponse(byte handle[], byte values[][]) {
        super(OC_RESOLUTION, AbstractMessage.RC_SUCCESS);
        this.handle = handle;
        this.values = values;
    }

    public ResolutionResponse(AbstractRequest req, byte handle[], byte clumps[][]) throws HandleException {
        super(req, AbstractMessage.RC_SUCCESS);
        this.handle = handle;
        this.values = clumps;
    }

    public ResolutionResponse(AbstractRequest req, byte handle[], HandleValue[] handleValues) throws HandleException {
        super(req, AbstractMessage.RC_SUCCESS);
        this.handle = handle;
        this.values = new byte[handleValues.length][];
        for (int i = 0; i < handleValues.length; i++) {
            values[i] = Encoder.encodeHandleValue(handleValues[i]);
        }
    }

    public HandleValue[] getHandleValues() throws HandleException {
        HandleValue retValues[] = new HandleValue[values.length];
        for (int i = 0; i < retValues.length; i++) {
            retValues[i] = new HandleValue();
            Encoder.decodeHandleValue(values[i], 0, retValues[i]);
        }
        return retValues;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer(super.toString());
        sb.append(' ');
        if (handle == null) sb.append(String.valueOf(handle));
        else sb.append(Util.decodeString(handle));
        sb.append("\n");

        if (values != null) {
            try {
                HandleValue vals[] = getHandleValues();
                for (HandleValue val : vals) {
                    sb.append("   ");
                    sb.append(String.valueOf(val));
                    sb.append('\n');
                }
            } catch (HandleException e) {
            }
        }
        return sb.toString();
    }

    @Override
    public boolean shouldEncrypt() {
        if (!hasEqualOrGreaterVersion(2, 8)) return false;
        if (values == null) return false;
        try {
            for (HandleValue value : getHandleValues()) {
                if (!value.publicRead) return true;
            }
        } catch (HandleException e) {
            return true;
        }
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy