private T downcast()

in src/main/java/org/openvasp/client/model/VaspMessage.java [258:277]


    private <T> T downcast(final TypeDescriptor type, final Class<T> clazz) {
        checkState(header != null);
        checkState(header.messageType != null);

        if (!type.equals(header.messageType)) {
            throw new VaspException(
                    "Cannot cast the message of type '%s' to class %s",
                    header.messageType.getIdStr(),
                    clazz.getSimpleName());
        }

        if (!clazz.isInstance(this)) {
            throw new VaspException(
                    "Cannot cast %s => %s",
                    getClass().getSimpleName(),
                    clazz.getSimpleName());
        }

        return clazz.cast(this);
    }