/*
* Class:     org_iotivity_base_OcRepresentation
* Method:    getValueN
* Signature: (Ljava/lang/String;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValueN
(JNIEnv *env, jobject thiz, jstring jKey)
{
    LOGD("OcRepresentation_getValue");
    if (!jKey)
    {
        ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
        return nullptr;
    }
    OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
    if (!rep)
    {
        return nullptr;
    }

    std::string key = env->GetStringUTFChars(jKey, nullptr);

    AttributeValue attrValue;
    if (!rep->getAttributeValue(key.c_str(), attrValue))
    {
        ThrowOcException(JNI_NO_SUCH_KEY, " attribute key does not exist");
        return nullptr;
    }
    return boost::apply_visitor(JObjectConverter(env), attrValue);
}