jvalue JPStringType::convertToJava(HostRef* obj) { TRACE_IN("JPStringType::convertToJava"); JPCleaner cleaner; jvalue v; if (JPEnv::getHost()->isNone(obj)) { v.l = NULL; return v; } if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } if (JPEnv::getHost()->isObject(obj)) { JPObject* o = JPEnv::getHost()->asObject(obj); JPClass* oc = o->getClass(); if (oc->getName().getSimpleName() == "java.lang.String") { v.l = o->getObject(); return v; } } JCharString wstr = JPEnv::getHost()->stringAsJCharString(obj); jchar* jstr = new jchar[wstr.length()+1]; jstr[wstr.length()] = 0; for (size_t i = 0; i < wstr.length(); i++) { jstr[i] = (jchar)wstr[i]; } jstring res = JPEnv::getJava()->NewString(jstr, (jint)wstr.length()); delete[] jstr; v.l = res; return v; TRACE_OUT; }
EMatchType JPStringType::canConvertToJava(HostRef* obj) { TRACE_IN("JPStringType::canConvertToJava"); JPCleaner cleaner; if (obj == NULL || JPEnv::getHost()->isNone(obj)) { return _implicit; } if (JPEnv::getHost()->isString(obj)) { return _exact; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_string) { return _exact; } } if (JPEnv::getHost()->isObject(obj)) { JPObject* o = JPEnv::getHost()->asObject(obj); JPClass* oc = o->getClass(); if (oc->getName().getSimpleName() == "java.lang.String") { return _exact; } } return _none; TRACE_OUT; }
EMatchType JPClass::canConvertToJava(HostRef* obj) { if (JPEnv::getHost()->isNone(obj)) { return _implicit; } JPCleaner cleaner; string simpleName = m_Name.getSimpleName(); if (simpleName == "java.lang.Byte" || simpleName == "java.lang.Short" || simpleName == "java.lang.Integer") { if (JPEnv::getHost()->isInt(obj)) { return _explicit; } } if (simpleName == "java.lang.Long" && JPEnv::getHost()->isLong(obj)) { return _explicit; } if (simpleName == "java.lang.Float" || simpleName == "java.lang.Double") { if (JPEnv::getHost()->isFloat(obj)) { return _explicit; } } if (JPEnv::getHost()->isObject(obj)) { JPObject* o = JPEnv::getHost()->asObject(obj); JPClass* oc = o->getClass(); if (oc == this) { // hey, this is me! :) return _exact; } if (JPEnv::getJava()->IsAssignableFrom(oc->m_Class, m_Class)) { return _implicit; } } if (JPEnv::getHost()->isProxy(obj)) { JPProxy* proxy = JPEnv::getHost()->asProxy(obj); // Check if any of the interfaces matches ... vector<jclass> itf = proxy->getInterfaces(); for (unsigned int i = 0; i < itf.size(); i++) { if (JPEnv::getJava()->IsAssignableFrom(itf[i], m_Class)) { return _implicit; } } } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName o = JPEnv::getHost()->getWrapperTypeName(obj); if (o.getSimpleName() == m_Name.getSimpleName()) { return _exact; } } if (m_Name.getSimpleName() == "java.lang.Object") { // arrays are objects if (JPEnv::getHost()->isArray(obj)) { return _implicit; } // Strings are objects too if (JPEnv::getHost()->isString(obj)) { return _implicit; } // Class are objects too if (JPEnv::getHost()->isClass(obj) || JPEnv::getHost()->isArrayClass(obj)) { return _implicit; } // Let'a allow primitives (int, long, float and boolean) to convert implicitly too ... if (JPEnv::getHost()->isInt(obj)) { return _implicit; } if (JPEnv::getHost()->isLong(obj)) { return _implicit; } if (JPEnv::getHost()->isFloat(obj)) { return _implicit; } if (JPEnv::getHost()->isBoolean(obj)) { return _implicit; } } return _none; }