JNIEXPORT void JNICALL
Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeString
(JNIEnv *env, jobject jobject, jstring jKey, jstring jValue)
{
    if (!jKey)
    {
        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid Attribute name!");
        return;
    }

    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
                                         jobject);
    if (!resource)
    {
        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
        return;
    }

    std::string key = env->GetStringUTFChars(jKey, NULL);
    std::string value = env->GetStringUTFChars(jValue, NULL);
    SimulatorResourceModel::Attribute att;
    att.setName(key);
    att.setValue(value);
    resource->addAttribute(att);
}
bool simulatorResourceAttributeToCpp(JNIEnv *env, jobject jAttribute,
                                     SimulatorResourceModel::Attribute &attribute)
{
    if (!jAttribute)
        return false;

    static jfieldID nameFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceAttributeCls,
                              "mName", "Ljava/lang/String;");
    static jfieldID valueFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceAttributeCls,
                               "mValue", "Lorg/oic/simulator/AttributeValue;");
    static jfieldID propertyFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceAttributeCls,
                                  "mProperty", "Lorg/oic/simulator/AttributeProperty;");

    jstring jAttributeName = (jstring) env->GetObjectField(jAttribute, nameFID);
    jobject jAttributeValue = env->GetObjectField(jAttribute, valueFID);
    jobject jAttributeProperty = env->GetObjectField(jAttribute, propertyFID);

    if (!jAttributeName || !jAttributeValue)
        return false;

    JniString attrName(env, jAttributeName);
    SimulatorResourceModel::ValueVariant value = JniAttributeValue::toCpp(env, jAttributeValue);

    attribute.setName(attrName.get());
    attribute.setValue(value);
    if (jAttributeProperty)
    {
        SimulatorResourceModel::AttributeProperty property = JniAttributeProperty::toCpp(env,
                jAttributeProperty);
        attribute.setProperty(property);
    }

    return true;
}