예제 #1
0
void MSMap::PropertySetter (Local<String> property, Local<Value> value, const AccessorInfo& info) {
  MSMap *map = ObjectWrap::Unwrap<MSMap>(info.Holder());
  v8::String::AsciiValue n(property);
  if (strcmp(*n, "width") == 0) {
    map->this_->width = value->Int32Value();
  } else if (strcmp(*n, "height") == 0) {
    map->this_->height = value->Int32Value();
  } else if (strcmp(*n, "maxsize") == 0) {
    map->this_->maxsize = value->Int32Value();
  } else if (strcmp(*n, "units") == 0) {
    int32_t units = value->Int32Value();
    if (units >= MS_INCHES && units <= MS_NAUTICALMILES) {
      map->this_->units = (MS_UNITS) units;
    }
  } else if (strcmp(*n, "resolution") == 0) {
    map->this_->resolution = value->NumberValue();
  } else if (strcmp(*n, "defresolution") == 0) {
    map->this_->defresolution = value->NumberValue();
  } else if (strcmp(*n, "name") == 0) {
    REPLACE_STRING(map->this_->name, value);
  } else if (strcmp(*n, "imagetype") == 0) {
    REPLACE_STRING(map->this_->imagetype, value);
  } else if (strcmp(*n, "shapepath") == 0) {
    REPLACE_STRING(map->this_->shapepath, value);
  } else if (strcmp(*n, "projection") == 0) {
    v8::String::AsciiValue _v_(value->ToString());
    msLoadProjectionString(&(map->this_->projection), *_v_);
  } else if (strcmp(*n, "mappath") == 0) {
    REPLACE_STRING(map->this_->mappath, value);
  }
}
예제 #2
0
void setHeight(Local<String> property, Local<Value> value,
		const AccessorInfo& info) {
	Local<Object> self = info.Holder();
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	void* ptr = wrap->Value();
#ifdef DEBUG
	LOGI("Setting height to %d", value->Int32Value());
#endif
	static_cast<BGJSView*>(ptr)->height = value->Int32Value();
}
예제 #3
0
파일: v8base.cpp 프로젝트: pgmsoul/GitLib
	bool PointJsToC(v8::Handle<Value> value,cs::Twin* r){
		HandleScope store;
		if(!value->IsObject()) return false;
		Local<Object> vObj = value->ToObject();
		Local<Value> vx = vObj->Get(String::New("x"));
		if(vx->IsUndefined()) return false;
		Local<Value> vy = vObj->Get(String::New("y"));
		if(vy->IsUndefined()) return false;
		r->x = vx->Int32Value();
		r->y = vy->Int32Value();
		return true;
	}
void DBOperationHelper_NonVO(Handle<Object> spec, KeyOperation & op) {
  HandleScope scope;

  Local<Value> v;
  Local<Object> o;

  setKeysInOp(spec, op);
  
  v = spec->Get(HELPER_ROW_BUFFER);
  if(! v->IsNull()) {
    o = v->ToObject();
    op.row_buffer = V8BINDER_UNWRAP_BUFFER(o);
  }
  
  v = spec->Get(HELPER_ROW_RECORD);
  if(! v->IsNull()) {
    o = v->ToObject();
    const Record * record = unwrapPointer<const Record *>(o);
    op.row_record = record;

    v = spec->Get(HELPER_BLOBS);
    if(v->IsObject()) {
      if(op.opcode == 1) {
        op.nblobs = op.createBlobReadHandles(record);
      } else {
        op.nblobs = op.createBlobWriteHandles(v->ToObject(), record);
      }
    }
  }
  
  v = spec->Get(HELPER_LOCK_MODE);
  if(! v->IsNull()) {
    int intLockMode = v->Int32Value();
    op.lmode = static_cast<NdbOperation::LockMode>(intLockMode);
  }

  v = spec->Get(HELPER_COLUMN_MASK);
  if(! v->IsNull()) {
    Array *maskArray = Array::Cast(*v);
    for(unsigned int m = 0 ; m < maskArray->Length() ; m++) {
      Local<Value> colId = maskArray->Get(m);
      op.useColumn(colId->Int32Value());
    }
  }

  DEBUG_PRINT("Non-VO %s -- mask: %u lobs: %d", op.getOperationName(), 
              op.u.maskvalue, op.nblobs);
}
예제 #5
0
void Base_SetA(Local<String> property, Local<Value> value, const AccessorInfo& info)
{
    Base* ptr = GetObjectPtr(info.This());
    assert(ptr);

    ptr->a = value->Int32Value();
}
예제 #6
0
파일: main.cpp 프로젝트: pgmsoul/JSApp
int __stdcall wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow){
	int rt = -1;
	initContext();
	HandleScope store;
	runJSRes(IDR_JS_STRUCT,L"app.lib");
	Handle<Value> result = runJSFile(L"main.js",L"utf-8");
	if(!result.IsEmpty()){//只有出错的时候才会返回Empty, 否则即使没有返回值, result仍然是Undefined.
		Local<Object> gObj = getGlobal();
		Local<Function> main = GetJSVariant<Function>(gObj,L"main");
		if(main.IsEmpty()){
			//InnerMsg(L"没有发现 main 函数",MT_ERROR);
		}else if(!main->IsFunction()){
			//InnerMsg(L"main 不是函数",MT_ERROR);
		}else{
			TryCatch err;
			Handle<Value> args[1];
			args[0] = String::New((uint16_t*)lpCmdLine);
			Local<Value> r = main->Call(gObj,1,args);
			if(!err.Exception().IsEmpty()){
				ReportError(err);
			}else
				rt = r->Int32Value();
		}
	}
	releaseContext();
	return rt;
}
예제 #7
0
bool v8test_eval()
{
    BEGINTEST();

    HandleScope handle_scope;
    Persistent<Context> context = Context::New();
    Context::Scope context_scope(context);

    Local<Object> qmlglobal = Object::New();
    qmlglobal->Set(String::New("a"), Integer::New(1922));

    Local<Script> script = Script::Compile(String::New("eval(\"a\")"), NULL, NULL, 
                                           Handle<String>(), Script::QmlMode);
    
    TryCatch tc;
    Local<Value> result = script->Run(qmlglobal);

    VERIFY(!tc.HasCaught());
    VERIFY(result->Int32Value() == 1922);

cleanup:
    context.Dispose();

    ENDTEST();
}
예제 #8
0
void UiWindow::SetTop(Local<String> property, Local<Value> value, const PropertyCallbackInfo<void>& info) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);
    UiWindow* _this = Unwrap<UiWindow>(info.This());
    WindowRect rect = _this->GetWindowRect();
    rect.Top = value->Int32Value();
    _this->SetWindowRect(rect);
}
예제 #9
0
static void WriteTestVal(Local<String> propname, Local<Value> v, const AccessorInfo &info) {
  do_check_true(!propname.IsEmpty());
  do_check_true(v->IsInt32());
  do_check_true(!info.Data().IsEmpty());
  do_check_true(info.Data()->IsInt32());
  test_val = v->Int32Value();
  int offset = info.Data()->Int32Value();
  test_val += offset;
}
예제 #10
0
파일: v8base.cpp 프로젝트: pgmsoul/GitLib
	//*,{
	//	"type":"class",
	//	"name":"Point",
	//	"text":"Point 对象是一个纯 Javascript 对象,包含两个数字属性。Size 和 Point 是同一个对象的两个名称。",
	//	"member":[
	//	{
	//		"type":"property",
	//		"name":"x",
	//		"objtype":"integer",
	//		"text":"x 属性,一般表示横坐标位置或宽度。"
	//	},
	//	{
	//		"type":"property",
	//		"name":"y",
	//		"objtype":"integer",
	//		"text":"y 属性,一般表示纵坐标位置或高度。"
	//	},
	//	{
	//		"type":"function",
	//		"name":"move(dx,dy)",
	//		"text":"调整 x 和 y 属性的值。",
	//		"param":[
	//			{
	//				"type":"integer",
	//				"name":"dx",
	//				"text":"x 将会加上这个值。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"dy",
	//				"text":"y 将会加上这个值。"
	//			}
	//		],
	//		"return":{
	//			"type":"void",
	//			"text":"函数没有返回值。"
	//		}
	//	}
	//	]
	//}
	//,{
	//	"type":"class",
	//	"name":"Rect",
	//	"text":"Rect 对象是一个纯 Javascript 对象,包含四个数字属性。",
	//	"member":[
	//	{
	//		"type":"property",
	//		"name":"left",
	//		"objtype":"integer",
	//		"text":"左边界。"
	//	},
	//	{
	//		"type":"property",
	//		"name":"top",
	//		"objtype":"integer",
	//		"text":"上边界。"
	//	},
	//	{
	//		"type":"property",
	//		"name":"right",
	//		"objtype":"integer",
	//		"text":"右边界。"
	//	},
	//	{
	//		"type":"property",
	//		"name":"bottom",
	//		"objtype":"integer",
	//		"text":"下边界。"
	//	},
	//	{
	//		"type":"function",
	//		"name":"ptInRect(x,[y])",
	//		"text":"(x,y)所代表的点是否在这个矩形内,如果不传 y 参数,表示不考虑 y,只考虑 x。",
	//		"param":[
	//			{
	//				"type":"integer",
	//				"name":"x",
	//				"text":"点的 x 坐标。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"[y]",
	//				"text":"点的 y 坐标。"
	//			}
	//		],
	//		"return":{
	//			"type":"boolean",
	//			"text":"如果点在矩形内返回 true,否则返回 false。"
	//		},
	//		"remark":[
	//			"矩形的左边界和上边界上的点算矩形内部,但是右边界和下边界不算矩形内部。"
	//		]
	//	},
	//	{
	//		"type":"function",
	//		"name":"getLocation()",
	//		"text":"获取矩形的位置,也就是左上角的坐标。",
	//		"param":[
	//		],
	//		"return":{
	//			"type":"Point",
	//			"text":"返回一个 Point 对象。"
	//		}
	//	},
	//	{
	//		"type":"function",
	//		"name":"setLocation([x],[y])",
	//		"text":"设置矩形的位置,这个函数会改变矩形 4 个属性的值,但是保持大小不变。",
	//		"param":[
	//			{
	//				"type":"integer",
	//				"name":"[x]",
	//				"text":"新位置的 x 坐标,如果此值为 undefined,矩形的 left 和 right 不变。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"[y]",
	//				"text":"新位置的 y 坐标,如果此值为 undefined,矩形的 top 和 bottom 不变。"
	//			}
	//		],
	//		"return":{
	//			"type":"void",
	//			"text":"函数没有返回值。"
	//		}
	//	},
	//	{
	//		"type":"function",
	//		"name":"setSize",
	//		"text":"设置矩形的大小,这个函数通过调整 right 和 bottom 来调整矩形的大小。",
	//		"param":[
	//			{
	//				"type":"integer",
	//				"name":"[width]",
	//				"text":"矩形新的宽度,如果此值为 undefined,矩形的宽度不变。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"[height]",
	//				"text":"矩形新的高度,如果此值为 undefined,矩形的高度不变。"
	//			}
	//		],
	//		"return":{
	//			"type":"void",
	//			"text":"这个函数没有返回值。"
	//		}
	//	},
	//	{
	//		"type":"function",
	//		"name":"getSize",
	//		"text":"获取矩形的大小。",
	//		"param":[
	//		],
	//		"return":{
	//			"type":"Size",
	//			"text":"返回一个 Size 对象。"
	//		}
	//	},
	//	{
	//		"type":"function",
	//		"name":"positive",
	//		"text":"通过交换 left 和 right 或者 top 和 bottom 的值来保证,left 总是小于等于 right,top 总是小于等于 bottom。",
	//		"param":[
	//		],
	//		"return":{
	//			"type":"void",
	//			"text":"这个函数没有返回值。"
	//		}
	//	},
	//	{
	//		"type":"function",
	//		"name":"setValue(left,top,right,bottom)",
	//		"text":"设置矩形的 4 个属性,这个函数直接设置,不做任何检测。",
	//		"param":[
	//			{
	//				"type":"integer",
	//				"name":"left",
	//				"text":"要设置的 left 属性值。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"top",
	//				"text":"要设置的 top 属性值。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"right",
	//				"text":"要设置的 right 属性值。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"bottom",
	//				"text":"要设置的 bottom 属性值。"
	//			}
	//		],
	//		"return":{
	//			"type":"void",
	//			"text":"这个函数没有返回值。"
	//		}
	//	}
	//	]
	//}//*
	bool RectJsToC(v8::Handle<Value> value,cs::Rect* r){
		HandleScope store;
		if(!value->IsObject()) return false;
		Local<Object> vObj = value->ToObject();
		Local<Value> vl = vObj->Get(String::New("left"));
		if(vl->IsUndefined()) return false;
		Local<Value> vt = vObj->Get(String::New("top"));
		if(vt->IsUndefined()) return false;
		Local<Value> vr = vObj->Get(String::New("right"));
		if(vr->IsUndefined()) return false;
		Local<Value> vb = vObj->Get(String::New("bottom"));
		if(vb->IsUndefined()) return false;
		r->left = vl->Int32Value();
		r->top = vt->Int32Value();
		r->right = vr->Int32Value();
		r->bottom = vb->Int32Value();
		return true;
	}
예제 #11
0
long NativeWindow::JSResult(){
  Local<Value> result = v8handle_->Get(String::NewSymbol("result"));
  if (result->IsUndefined() || result->IsNull()) {
    return 0;
  } else {
    v8handle_->Set(String::NewSymbol("result"), Undefined());
    return result->Int32Value();
  }
}
예제 #12
0
void SetPointY(Local<String> property, 
			   Local<Value> value,
			   const PropertyCallbackInfo<Value>& info)
{
	Local<Object> self = info.Holder();
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	void* ptr = wrap->Value();
	static_cast<Point*>(ptr)->y_ = value->Int32Value();
}
예제 #13
0
void jsMyClassSetNumber(
	Local<String> property,
	Local<Value> value,
	const PropertyCallbackInfo<void>& info)
{
	Local<Object> self = info.Holder();
	ObjectWrap* pMyClass = ObjectWrap::Unwrap<ObjectWrap>(self);
	static_cast<MyClass*>(pMyClass)->setNumber(value->Int32Value());
}
예제 #14
0
void UiWindow::SetState(Local<String> property, Local<Value> value, const PropertyCallbackInfo<void>& info) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);
    UiWindow* _this = Unwrap<UiWindow>(info.This());
    if (value->IsNumber()) {
        WINDOW_STATE state = (WINDOW_STATE)value->Int32Value();
        _this->SetState(state);
    }
}
예제 #15
0
void ODBCResult::FetchModeSetter(Local<String> property, Local<Value> value, const AccessorInfo &info) {
  HandleScope scope;

  ODBCResult *obj = ObjectWrap::Unwrap<ODBCResult>(info.Holder());
  
  if (value->IsNumber()) {
    obj->m_fetchMode = value->Int32Value();
  }
}
예제 #16
0
static void SetLocationPort(Local<String> name, Local<Value> val, const AccessorInfo& info)
{
    Local<Object> self = info.This();
    Local<Value> x = self->GetInternalField(0);
    Local<External> wrap = Local<External>::Cast(x);
    void* ptr = wrap->Value();

    jsLocation* url = static_cast<jsLocation*>(ptr);
    url->url.port = val->Int32Value();
}
예제 #17
0
Handle<Value> DBOperationHelper_NonVO(const Arguments &args) {
  HandleScope scope;
  Operation op;

  const Local<Object> spec = args[0]->ToObject();
  Local<Value> v;
  Local<Object> o;

  setKeysInOp(spec, op);
  
  v = spec->Get(HELPER_ROW_BUFFER);
  if(! v->IsNull()) {
    o = v->ToObject();
    op.row_buffer = V8BINDER_UNWRAP_BUFFER(o);
  }
  
  v = spec->Get(HELPER_ROW_RECORD);
  if(! v->IsNull()) {
    o = v->ToObject();
    op.row_record = unwrapPointer<const Record *>(o);
  }
  
  v = spec->Get(HELPER_LOCK_MODE);
  if(! v->IsNull()) {
    int intLockMode = v->Int32Value();
    op.lmode = static_cast<NdbOperation::LockMode>(intLockMode);
  }

  v = spec->Get(HELPER_COLUMN_MASK);
  if(! v->IsNull()) {
    Array *maskArray = Array::Cast(*v);
    for(unsigned int m = 0 ; m < maskArray->Length() ; m++) {
      Local<Value> colId = maskArray->Get(m);
      op.useColumn(colId->Int32Value());
    }
  }
  
  int opcode = args[1]->Int32Value();
  NdbTransaction *tx = unwrapPointer<NdbTransaction *>(args[2]->ToObject());
  DEBUG_PRINT("Non-VO opcode: %d mask: %u", opcode, op.u.maskvalue);

  return scope.Close(buildNdbOperation(op, opcode, tx));
}
예제 #18
0
void Msg_Struct::build_http_msg_buffer(Isolate* isolate, v8::Local<v8::Object> object, std::string &str) {
    std::stringstream stream;
    for(std::vector<Field_Info>::const_iterator iter = field_vec().begin();
            iter != field_vec().end(); iter++) {
        stream.str("");
        stream << "\"" << iter->field_name << "\":";
        Local<Value> value = object->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, iter->field_name.c_str(), NewStringType::kNormal).ToLocalChecked()).ToLocalChecked();
        if(iter->field_type == "int8" || iter->field_type == "int16" ||
                iter->field_type == "int32") {
            int32_t val = 0;
            if (value->IsInt32()) {
                val = value->Int32Value(isolate->GetCurrentContext()).FromJust();
            }
            stream << val << ",";
        }
        else if(iter->field_type == "int64") {
            int64_t val = 0;
            if (value->IsNumber()) {
                val = value->NumberValue(isolate->GetCurrentContext()).FromJust();
            }
            stream << val << ",";
        }
        else if(iter->field_type == "double") {
            double val = 0;
            if (value->IsNumber()) {
                val = value->NumberValue(isolate->GetCurrentContext()).FromJust();
            }
            stream << val << ",";
        }
        else if(iter->field_type == "bool") {
            bool val = 0;
            if (value->IsBoolean()) {
                val = value->BooleanValue(isolate->GetCurrentContext()).FromJust();
            }
            stream << val << ",";
        }
        else if(iter->field_type == "string") {
            if (value->IsString()) {
                String::Utf8Value str(value->ToString(isolate->GetCurrentContext()).ToLocalChecked());
                stream << "\"" << ToCString(str) << "\",";
            } else {
                stream << "\"\",";
            }
        }
        else {
            LOG_ERROR("Can not find the field_type:%s, struct_name:%s", iter->field_type.c_str(), struct_name().c_str());
        }

        str += stream.str();
    }
}
static void Set_DialogState_height(Local<String> property, Local<Value> value, const AccessorInfo& info)
{
    HandleScope scope;

    Local<Object> self = info.Holder();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    if (wrap.IsEmpty())
        return;

    DialogState *tmp = (DialogState *) wrap->Value();
    if (tmp == NULL)
        return;

    if (!value.IsEmpty() && value->IsNumber())
        tmp->setHeight(value->Int32Value());
}
예제 #20
0
int Settings::getInteger(const char* property, int defaultValue = 0) {
  Local<Value> tmp = get(property);
  return (tmp->IsNumber())? tmp->Int32Value() : defaultValue;
}
예제 #21
0
void FieldAccessor::SetJavaField(Isolate *isolate, const Local<Object>& target, const Local<Value>& value, FieldCallbackData *fieldData)
{
	JEnv env;

	HandleScope handleScope(isolate);
	auto runtime = Runtime::GetRuntime(isolate);
	auto objectManager = runtime->GetObjectManager();

	JniLocalRef targetJavaObject;

	const auto& fieldTypeName = fieldData->signature;
	auto isStatic = fieldData->isStatic;

	auto isPrimitiveType = fieldTypeName.size() == 1;
	auto isFieldArray = fieldTypeName[0] == '[';

	if (fieldData->fid == nullptr)
	{
		auto fieldJniSig = isPrimitiveType
							? fieldTypeName
								:
								(isFieldArray
									? fieldTypeName
										:
										("L" + fieldTypeName + ";"));

		if (isStatic)
		{
			fieldData->clazz = env.FindClass(fieldData->declaringType);
			assert(fieldData->clazz != nullptr);
			fieldData->fid = env.GetStaticFieldID(fieldData->clazz, fieldData->name, fieldJniSig);
			assert(fieldData->fid != nullptr);
		}
		else
		{
			fieldData->clazz = env.FindClass(fieldData->declaringType);
			assert(fieldData->clazz != nullptr);
			fieldData->fid = env.GetFieldID(fieldData->clazz, fieldData->name, fieldJniSig);
			assert(fieldData->fid != nullptr);
		}
	}

	if (!isStatic)
	{
		targetJavaObject = objectManager->GetJavaObjectByJsObject(target);

		if (targetJavaObject.IsNull())
		{
			stringstream ss;
			ss << "Cannot access property '" << fieldData->name << "' because there is no corresponding Java object";
			throw NativeScriptException(ss.str());
		}
	}

	auto fieldId = fieldData->fid;
	auto clazz = fieldData->clazz;

	if (isPrimitiveType)
	{
		switch (fieldTypeName[0])
		{
			case 'Z': //bool
			{
				//TODO: validate value is a boolean before calling
				if (isStatic)
				{
					env.SetStaticBooleanField(clazz, fieldId, value->BooleanValue());
				}
				else
				{
					env.SetBooleanField(targetJavaObject, fieldId, value->BooleanValue());
				}
				break;
			}
			case 'B': //byte
			{
				//TODO: validate value is a byte before calling
				if (isStatic)
				{
					env.SetStaticByteField(clazz, fieldId, value->Int32Value());
				}
				else
				{
					env.SetByteField(targetJavaObject, fieldId, value->Int32Value());
				}
				break;
			}
			case 'C': //char
			{
				//TODO: validate value is a single char
				String::Utf8Value stringValue(value->ToString());
				JniLocalRef value(env.NewStringUTF(*stringValue));
				const char* chars = env.GetStringUTFChars(value, 0);

				if (isStatic)
				{
					env.SetStaticCharField(clazz, fieldId, chars[0]);
				}
				else
				{
					env.SetCharField(targetJavaObject, fieldId, chars[0]);
				}
				env.ReleaseStringUTFChars(value, chars);
				break;
			}
			case 'S': //short
			{
				//TODO: validate value is a short before calling
				if (isStatic)
				{
					env.SetStaticShortField(clazz, fieldId, value->Int32Value());
				}
				else
				{
					env.SetShortField(targetJavaObject, fieldId, value->Int32Value());
				}
				break;
			}
			case 'I': //int
			{
				//TODO: validate value is a int before calling
				if (isStatic)
				{
					env.SetStaticIntField(clazz, fieldId, value->Int32Value());
				}
				else
				{
					env.SetIntField(targetJavaObject, fieldId, value->Int32Value());
				}
				break;

			}
			case 'J': //long
			{
				jlong longValue = static_cast<jlong>(ArgConverter::ConvertToJavaLong(value));
				if (isStatic)
				{
					env.SetStaticLongField(clazz, fieldId, longValue);
				}
				else
				{
					env.SetLongField(targetJavaObject, fieldId, longValue);
				}
				break;
			}
			case 'F': //float
			{
				if (isStatic)
				{
					env.SetStaticFloatField(clazz, fieldId, static_cast<jfloat>(value->NumberValue()));
				}
				else
				{
					env.SetFloatField(targetJavaObject, fieldId, static_cast<jfloat>(value->NumberValue()));
				}
				break;
			}
			case 'D': //double
			{
				if (isStatic)
				{
					env.SetStaticDoubleField(clazz, fieldId, value->NumberValue());
				}
				else
				{
					env.SetDoubleField(targetJavaObject, fieldId, value->NumberValue());
				}
				break;
			}
			default:
				{
		stringstream ss;
				ss << "(InternalError): in FieldAccessor::SetJavaField: Unknown field type: '" << fieldTypeName[0] << "'";
				throw NativeScriptException(ss.str());
			}
		}
	}
	else
	{
		bool isString = fieldTypeName == "java/lang/String";
		JniLocalRef result;

		if (!value->IsNull())
		{
			if (isString)
			{
				//TODO: validate valie is a string;
				result = ConvertToJavaString(value);
			}
			else
			{
				auto objectWithHiddenID = value->ToObject();
				result = objectManager->GetJavaObjectByJsObject(objectWithHiddenID);
			}
		}

		if (isStatic)
		{
			env.SetStaticObjectField(clazz, fieldId, result);
		}
		else
		{
			env.SetObjectField(targetJavaObject, fieldId, result);
		}
	}
}
void FieldAccessor::SetJavaField(const Local<Object>& target, const Local<Value>& value, FieldCallbackData *fieldData)
{
	JEnv env;

	auto isolate = Isolate::GetCurrent();
	HandleScope handleScope(isolate);

	jweak targetJavaObject;

	const auto& fieldTypeName = fieldData->signature;
	auto isStatic = fieldData->isStatic;

	auto isPrimitiveType = fieldTypeName.size() == 1;
	auto isFieldArray = fieldTypeName[0] == '[';


	if (fieldData->fid == nullptr)
	{
		auto fieldJniSig = isPrimitiveType
								? fieldTypeName
								: (isFieldArray
									? fieldTypeName
									: ("L" + fieldTypeName + ";"));

		if (isStatic)
		{
			fieldData->clazz = env.FindClass(fieldData->declaringType);
			assert(fieldData->clazz != nullptr);
			fieldData->fid = env.GetStaticFieldID(fieldData->clazz, fieldData->name, fieldJniSig);
			assert(fieldData->fid != nullptr);
		}
		else
		{
			fieldData->clazz = env.FindClass(fieldData->declaringType);
			assert(fieldData->clazz != nullptr);
			fieldData->fid = env.GetFieldID(fieldData->clazz, fieldData->name, fieldJniSig);
			assert(fieldData->fid != nullptr);
		}
	}

	if (!isStatic)
	{
		targetJavaObject = objectManager->GetJavaObjectByJsObject(target);
	}

	auto fieldId = fieldData->fid;
	auto clazz = fieldData->clazz;

	if (isPrimitiveType)
	{
		switch (fieldTypeName[0])
		{
			case 'Z': //bool
			{
				//TODO: validate value is a boolean before calling
				if (isStatic)
				{
					env.SetStaticBooleanField(clazz, fieldId, value->BooleanValue());
				}
				else
				{
					env.SetBooleanField(targetJavaObject, fieldId, value->BooleanValue());
				}
				break;
			}
			case 'B': //byte
			{
				//TODO: validate value is a byte before calling
				if (isStatic)
				{
					env.SetStaticByteField(clazz, fieldId, value->Int32Value());
				}
				else
				{
					env.SetByteField(targetJavaObject, fieldId, value->Int32Value());
				}
				break;
			}
			case 'C': //char
			{
				//TODO: validate value is a single char
				String::Utf8Value stringValue(value->ToString());
				JniLocalRef value(env.NewStringUTF(*stringValue));
				const char* chars = env.GetStringUTFChars(value, 0);

				if (isStatic)
				{
					env.SetStaticCharField(clazz, fieldId, chars[0]);
				}
				else
				{
					env.SetCharField(targetJavaObject, fieldId, chars[0]);
				}
				env.ReleaseStringUTFChars(value, chars);
				break;
			}
			case 'S': //short
			{
				//TODO: validate value is a short before calling
				if (isStatic)
				{
					env.SetStaticShortField(clazz, fieldId, value->Int32Value());
				}
				else
				{
					env.SetShortField(targetJavaObject, fieldId, value->Int32Value());
				}
				break;
			}
			case 'I': //int
			{
				//TODO: validate value is a int before calling
				if (isStatic)
				{
					env.SetStaticIntField(clazz, fieldId, value->Int32Value());
				}
				else
				{
					env.SetIntField(targetJavaObject, fieldId, value->Int32Value());
				}
				break;

			}
			case 'J': //long
			{
				jlong longValue = static_cast<jlong>(ArgConverter::ConvertToJavaLong(value));
				if (isStatic)
				{
					env.SetStaticLongField(clazz, fieldId, longValue);
				}
				else
				{
					env.SetLongField(targetJavaObject, fieldId, longValue);
				}
				break;
			}
			case 'F': //float
			{
				if (isStatic)
				{
					env.SetStaticFloatField(clazz, fieldId, static_cast<jfloat>(value->NumberValue()));
				}
				else
				{
					env.SetFloatField(targetJavaObject, fieldId, static_cast<jfloat>(value->NumberValue()));
				}
				break;
			}
			case 'D': //double
			{
				if (isStatic)
				{
					env.SetStaticDoubleField(clazz, fieldId, value->NumberValue());
				}
				else
				{
					env.SetDoubleField(targetJavaObject, fieldId, value->NumberValue());
				}
				break;
			}
			default:
			{
				// TODO:
				ASSERT_FAIL("Unknown field type");
				break;
			}
		}
	}
	else
	{
		bool isString = fieldTypeName == "java/lang/String";
		jobject result = nullptr;

		if(!value->IsNull()) {
			if (isString)
			{
				//TODO: validate valie is a string;
				result = ConvertToJavaString(value);
			}
			else
			{
				auto objectWithHiddenID = value->ToObject();
				result =objectManager->GetJavaObjectByJsObject(objectWithHiddenID);
			}
		}

		if (isStatic)
		{
			env.SetStaticObjectField(clazz, fieldId, result);
		}
		else
		{
			env.SetObjectField(targetJavaObject, fieldId, result);
		}

		if (isString)
		{
			env.DeleteLocalRef(result);
		}
	}
}
예제 #23
0
    // notification.protocol=
    static void SetProtocol(Local<String> property, Local<Value> value, const AccessorInfo& info) {
      RCSwitchNode* rcswitchNode_instance = node::ObjectWrap::Unwrap<RCSwitchNode>(info.Holder());

      if(value->IsInt32())
        rcswitchNode_instance->rcswitch.setProtocol(value->Int32Value());
    }
예제 #24
0
void Window::SetHeight(Local<String> property, Local<Value> value, const AccessorInfo& info) {
  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
  window->SetHeight(value->Int32Value());
}
예제 #25
0
DBScanHelper::DBScanHelper(const Arguments &args) : 
  nbounds(0),
  isIndexScan(false)
{
  DEBUG_MARKER(UDEB_DEBUG);

  Local<Value> v;

  const Local<Object> spec = args[0]->ToObject();
  int opcode = args[1]->Int32Value();
  tx = unwrapPointer<NdbTransaction *>(args[2]->ToObject());

  lmode = NdbOperation::LM_CommittedRead;
  scan_options = & options;
  options.optionsPresent = 0ULL;

  v = spec->Get(SCAN_TABLE_RECORD);
  if(! v->IsNull()) {
    Local<Object> o = v->ToObject();
    row_record = unwrapPointer<const Record *>(o);
  }

  v = spec->Get(SCAN_INDEX_RECORD);
  if(! v->IsNull()) {
    Local<Object> o = v->ToObject();
    isIndexScan = true;
    key_record = unwrapPointer<const Record *>(o);
  }
  
  v = spec->Get(SCAN_LOCK_MODE);
  if(! v->IsNull()) {
    int intLockMode = v->Int32Value();
    lmode = static_cast<NdbOperation::LockMode>(intLockMode);
  }

  // SCAN_BOUNDS is an array of BoundHelpers  
  v = spec->Get(SCAN_BOUNDS);
  if(v->IsArray()) {
    Local<Object> o = v->ToObject();
    while(o->Has(nbounds)) {
      nbounds++; 
    }
    bounds = new NdbIndexScanOperation::IndexBound *[nbounds];
    for(int i = 0 ; i < nbounds ; i++) {
      Local<Object> b = o->Get(i)->ToObject();
      bounds[i] = unwrapPointer<NdbIndexScanOperation::IndexBound *>(b);
    }
  }

  v = spec->Get(SCAN_OPTION_FLAGS);
  if(! v->IsNull()) {
    options.scan_flags = v->Uint32Value();
    options.optionsPresent |= NdbScanOperation::ScanOptions::SO_SCANFLAGS;
  }
  
  v = spec->Get(SCAN_OPTION_BATCH_SIZE);
  if(! v->IsNull()) {
    options.batch = v->Uint32Value();
    options.optionsPresent |= NdbScanOperation::ScanOptions::SO_BATCH;
  }
  
  v = spec->Get(SCAN_OPTION_PARALLELISM);
  if(! v->IsNull()) {
    options.parallel = v->Uint32Value();
    options.optionsPresent |= NdbScanOperation::ScanOptions::SO_PARALLEL;
  }
  
  v = spec->Get(SCAN_FILTER_CODE);
  if(! v->IsNull()) {
    Local<Object> o = v->ToObject();
    options.interpretedCode = unwrapPointer<NdbInterpretedCode *>(o);
    options.optionsPresent |= NdbScanOperation::ScanOptions::SO_INTERPRETED;
  }

  /* Scanning delete requires key info */
  if(opcode == OP_SCAN_DELETE) {
    options.scan_flags |= NdbScanOperation::SF_KeyInfo;
    options.optionsPresent |= NdbScanOperation::ScanOptions::SO_SCANFLAGS;    
  }
  
  /* Done defining the object */
}
예제 #26
0
파일: Conv.cpp 프로젝트: Armen138/anode
int Conv::ToJavaSequence(JNIEnv *jniEnv, Handle<Value> val, int componentType, jarray *jVal) {
  Local<Object> oVal;
  Local<Value> vLength;
  if(val.IsEmpty() || val->IsNull() || val->IsUndefined()) {
    *jVal = 0;
    return OK;
  }
  if(!val->IsObject())
    return ErrorType;
  
  oVal = val->ToObject();
  vLength = oVal->Get(sLength);
  if(vLength.IsEmpty() || !vLength->IsNumber())
    return ErrorType;
  
  jarray ob;
  jint len = vLength->Int32Value();
  if(isJavaObject(componentType)) {
    jclass componentClass;
    if(isInterfaceOrDict(componentType)) {
      Interface *interface = env->getInterface(getClassId(componentType));
      componentClass = interface->getDeclaredClass();
    } else {
      switch(componentType) {
        default:
          return ErrorType;
        case TYPE_STRING:
          componentClass = jni.java.lang.String.class_;
          break;
        case TYPE_DATE:
          componentClass = jni.java.util.Date.class_;
          break;
        case TYPE_OBJECT:
          componentClass = jni.anode.js.JSObject.class_;
          break;
      }
    }
    ob = jniEnv->NewObjectArray(len, componentClass, 0);
    if(ob) {
      int res = OK;
      for(int i = 0; i < len; i++) {
        jobject item;
        res = ToJavaObject(jniEnv, oVal->Get(i), componentType, &item);
        if(res != OK) break;
        jniEnv->SetObjectArrayElement((jobjectArray)ob, i, item);
        jniEnv->DeleteLocalRef(item);
      }
    }
  } else {
    switch(componentType) {
      default:
        return ErrorType;
      case TYPE_BYTE:
        ob = jniEnv->NewByteArray(len);
        if(ob) {
          /* FIXME: see if this case can be optimised */
          jbyte *buf = jniEnv->GetByteArrayElements((jbyteArray)ob, 0);
          for(int i = 0; i < len; i++)
            buf[i] = (jbyte)oVal->Get(i)->Uint32Value();
          
          jniEnv->ReleaseByteArrayElements((jbyteArray)ob, buf, 0);
          break;
        }
      case TYPE_INT:
        ob = jniEnv->NewIntArray(len);
        if(ob) {
          jint *buf = jniEnv->GetIntArrayElements((jintArray)ob, 0);
          for(int i = 0; i < len; i++)
            buf[i] = oVal->Get(i)->Int32Value();
          
          jniEnv->ReleaseIntArrayElements((jintArray)ob, buf, 0);
          break;
        }
      case TYPE_LONG:
        ob = jniEnv->NewLongArray(len);
        if(ob) {
          jlong *buf = jniEnv->GetLongArrayElements((jlongArray)ob, 0);
          for(int i = 0; i < len; i++)
            buf[i] = oVal->Get(i)->IntegerValue();
          
          jniEnv->ReleaseLongArrayElements((jlongArray)ob, buf, 0);
          break;
        }
      case TYPE_DOUBLE:
        ob = jniEnv->NewDoubleArray(len);
        if(ob) {
          jdouble *buf = jniEnv->GetDoubleArrayElements((jdoubleArray)ob, 0);
          if(!buf) return ErrorMem;
          for(int i = 0; i < len; i++)
            buf[i] = oVal->Get(i)->NumberValue();
          
          jniEnv->ReleaseDoubleArrayElements((jdoubleArray)ob, buf, 0);
          break;
        }
    }
  }
  if(ob) {
    *jVal = ob;
    return OK;
  }
  if(jniEnv->ExceptionCheck())
    jniEnv->ExceptionClear();
  return ErrorVM;
}
예제 #27
0
Handle<Value>
Session::Request(const Arguments& args)
{
    HandleScope scope;

    if (args.Length() < 1 || !args[0]->IsString()) {
        return ThrowException(Exception::Error(String::New(
                "Service URI string must be provided as first parameter.")));
    }
    if (args.Length() < 2 || !args[1]->IsString()) {
        return ThrowException(Exception::Error(String::New(
                "String request name must be provided as second parameter.")));
    }
    if (args.Length() < 3 || !args[2]->IsObject()) {
        return ThrowException(Exception::Error(String::New(
                "Object containing request parameters must be provided "
                "as third parameter.")));
    }
    if (args.Length() < 4 || !args[3]->IsInt32()) {
        return ThrowException(Exception::Error(String::New(
                "Integer correlation identifier must be provided "
                "as fourth parameter.")));
    }
    if (args.Length() >= 5 && !args[4]->IsUndefined() && !args[4]->IsString()) {
        return ThrowException(Exception::Error(String::New(
                "Optional request label must be a string.")));
    }
    if (args.Length() > 5) {
        return ThrowException(Exception::Error(String::New(
                "Function expects at most five arguments.")));
    }

    int cidi = args[3]->Int32Value();

    Session* session = ObjectWrap::Unwrap<Session>(args.This());

    BLPAPI_EXCEPTION_TRY

    Local<String> uri = args[0]->ToString();
    String::AsciiValue uriv(uri);

    blpapi::Service service = session->d_session->getService(*uriv);

    Local<String> name = args[1]->ToString();
    String::Utf8Value namev(name);

    blpapi::Request request = service.createRequest(*namev);

    // Loop over object properties, appending/setting into the request.
    Local<Object> obj = args[2]->ToObject();
    Local<Array> props = obj->GetPropertyNames();

    for (std::size_t i = 0; i < props->Length(); ++i) {
        // Process the key.
        Local<Value> keyval = props->Get(i);
        Local<String> key = keyval->ToString();
        String::Utf8Value keyv(key);

        // Process the value.
        //
        // The values present on the outer object are marshalled into the
        // blpapi::Request by setting values using 'set'.  Arrays indicate
        // values which should be marshalled using 'append'.
        Local<Value> val = obj->Get(keyval);
        if (val->IsString()) {
            Local<String> s = val->ToString();
            String::Utf8Value valv(s);
            request.set(*keyv, *valv);
        } else if (val->IsBoolean()) {
            request.set(*keyv, val->BooleanValue());
        } else if (val->IsNumber()) {
            request.set(*keyv, val->NumberValue());
        } else if (val->IsInt32()) {
            request.set(*keyv, val->Int32Value());
        } else if (val->IsUint32()) {
            request.set(*keyv,
                static_cast<blpapi::Int64>(val->Uint32Value()));
        } else if (val->IsDate()) {
            blpapi::Datetime dt;
            mkdatetime(&dt, val);
            request.set(*keyv, dt);
        } else if (val->IsArray()) {
            // Arrays are marshalled into the blpapi::Request by appending
            // value types using the key of the array in the outer object.
            Local<Object> subarray = val->ToObject();
            int jmax = Array::Cast(*val)->Length();
            for (int j = 0; j < jmax; ++j) {
                Local<Value> subval = subarray->Get(j);
                // Only strings, booleans, and numbers are marshalled.
                if (subval->IsString()) {
                    Local<String> s = subval->ToString();
                    String::Utf8Value subvalv(s);
                    request.append(*keyv, *subvalv);
                } else if (subval->IsBoolean()) {
                    request.append(*keyv, subval->BooleanValue());
                } else if (subval->IsNumber()) {
                    request.append(*keyv, subval->NumberValue());
                } else if (subval->IsInt32()) {
                    request.append(*keyv, subval->Int32Value());
                } else if (subval->IsUint32()) {
                    request.append(*keyv,
                        static_cast<blpapi::Int64>(subval->Uint32Value()));
                } else if (subval->IsDate()) {
                    blpapi::Datetime dt;
                    mkdatetime(&dt, subval);
                    request.append(*keyv, dt);
                } else {
                    return ThrowException(Exception::Error(String::New(
                                "Array contains invalid value type.")));
                }
            }
        } else {
            return ThrowException(Exception::Error(String::New(
                        "Object contains invalid value type.")));
        }
    }

    blpapi::CorrelationId cid(cidi);

    if (args.Length() == 5) {
        String::Utf8Value labelv(args[4]->ToString());
        session->d_session->sendRequest(request, session->d_identity,
                                        cid, 0, *labelv, labelv.length());
    } else {
        session->d_session->sendRequest(request, session->d_identity, cid);
    }

    BLPAPI_EXCEPTION_CATCH_RETURN

    return scope.Close(Integer::New(cidi));
}
예제 #28
0
Handle<Value>
Session::subscribe(const Arguments& args, bool resubscribe)
{
    HandleScope scope;

    if (args.Length() < 1 || !args[0]->IsArray()) {
        return ThrowException(Exception::Error(String::New(
                "Array of subscription information must be provided.")));
    }
    if (args.Length() >= 2 && !args[1]->IsUndefined() && !args[1]->IsString()) {
        return ThrowException(Exception::Error(String::New(
                "Optional subscription label must be a string.")));
    }
    if (args.Length() > 2) {
        return ThrowException(Exception::Error(String::New(
                "Function expects at most two arguments.")));
    }

    blpapi::SubscriptionList sl;

    Local<Object> o = args[0]->ToObject();
    for (std::size_t i = 0; i < Array::Cast(*(args[0]))->Length(); ++i) {
        Local<Value> v = o->Get(i);
        if (!v->IsObject()) {
            return ThrowException(Exception::Error(String::New(
                        "Array elements must be objects "
                        "containing subscription information.")));
        }
        Local<Object> io = v->ToObject();

        // Process 'security' string
        Local<Value> iv = io->Get(String::New("security"));
        if (!iv->IsString()) {
            return ThrowException(Exception::Error(String::New(
                        "Property 'security' must be a string.")));
        }
        String::Utf8Value secv(iv);
        if (0 == secv.length()) {
            return ThrowException(Exception::Error(String::New(
                        "Property 'security' must be a string.")));
        }

        // Process 'fields' array
        iv = io->Get(String::New("fields"));
        if (!iv->IsArray()) {
            return ThrowException(Exception::Error(String::New(
                        "Property 'fields' must be an array of strings.")));
        }
        std::string fields;
        formFields(&fields, iv->ToObject());

        // Process 'options' array
        iv = io->Get(String::New("options"));
        if (!iv->IsUndefined() && !iv->IsNull() && !iv->IsObject()) {
            return ThrowException(Exception::Error(String::New(
                        "Property 'options' must be an object containing "
                        "whose keys and key values will be configured as "
                        "options.")));
        }
        std::string options;
        formOptions(&options, iv);

        // Process 'correlation' int or string
        iv = io->Get(String::New("correlation"));
        if (!iv->IsInt32()) {
            return ThrowException(Exception::Error(String::New(
                        "Property 'correlation' must be an integer.")));
        }
        int correlation = iv->Int32Value();

        sl.add(*secv, fields.c_str(), options.c_str(),
               blpapi::CorrelationId(correlation));
    }

    Session* session = ObjectWrap::Unwrap<Session>(args.This());

    BLPAPI_EXCEPTION_TRY
    if (args.Length() == 2) {
        Local<String> s = args[1]->ToString();
        String::Utf8Value labelv(s);
        if (resubscribe)
            session->d_session->resubscribe(sl, *labelv, labelv.length());
        else
            session->d_session->subscribe(sl, *labelv, labelv.length());
    } else {
        if (resubscribe)
            session->d_session->resubscribe(sl);
        else
            session->d_session->subscribe(sl);
    }
    BLPAPI_EXCEPTION_CATCH_RETURN

    return scope.Close(args.This());
}
예제 #29
0
/*-----------------------------------------------------------------------------
 * Parse options
 */
bool ConnectParseOptions(Local<Object> options, ConnectRequest* request)
{
  // Get options data
  std::vector<std::string> optionNames = cvv8::CastFromJS<std::vector<std::string> >(options->GetPropertyNames());
  for (size_t i = 0; i < optionNames.size(); i++)
  {
    char* optionName = (char*)(optionNames[i].c_str());
    Local<Value> optionValue = options->Get(String::NewSymbol(optionName));

    if (optionValue->IsUndefined())
    {
      continue;
    }

    if (tva_str_casecmp(optionName, "username") == 0)
    {
      String::AsciiValue val(optionValue->ToString());
      request->username = strdup(*val);
    }
    else if (tva_str_casecmp(optionName, "password") == 0)
    {
      String::AsciiValue val(optionValue->ToString());
      request->password = strdup(*val);
    }
    else if (tva_str_casecmp(optionName, "tmx") == 0)
    {
      if (optionValue->IsString())
      {
        String::AsciiValue val(optionValue->ToString());
        request->primaryTmx = strdup(*val);
      }
      else if (optionValue->IsArray())
      {
        Handle<Array> tmxs = Handle<Array>::Cast(optionValue);
        char** p_tmx = &request->primaryTmx;
        Local<Value> element;
        
        element = tmxs->Get(0);
        if (!element->IsUndefined())
        {
          String::AsciiValue tmx(element->ToString());
          *p_tmx = strdup(*tmx);
          p_tmx = &request->secondaryTmx;
        }

        if (tmxs->Length() > 1)
        {
          element = tmxs->Get(1);
          if (!element->IsUndefined())
          {
            String::AsciiValue tmx(element->ToString());
            *p_tmx = strdup(*tmx);
          }
        }
      }
    }
    else if (tva_str_casecmp(optionName, "name") == 0)
    {
      String::AsciiValue val(optionValue->ToString());
      request->gdClientName = strdup(*val);
    }
    else if (tva_str_casecmp(optionName, "timeout") == 0)
    {
      request->timeout = optionValue->Int32Value() * 1000;
    }
    else if (tva_str_casecmp(optionName, "gdMaxOut") == 0)
    {
      request->gdMaxOut = optionValue->Int32Value();
    }
    else if (tva_str_casecmp(optionName, "config") == 0)
    {
      if (optionValue->IsObject())
      {
        Local<Object> config = Local<Object>::Cast(optionValue);
        std::vector<std::string> configNames = cvv8::CastFromJS<std::vector<std::string> >(config->GetPropertyNames());
        for (size_t j = 0; j < configNames.size(); j++)
        {
          char* configName = (char*)(configNames[j].c_str());
          Local<Value> configValue = config->Get(String::NewSymbol(configName));

          if (configValue->IsUndefined())
          {
            continue;
          }

          for (size_t c = 0; c < NUM_PARAMS; c++)
          {
            ConnectConfigParam* cp = &g_connectConfig[c];
            if (tva_str_casecmp(configName, cp->jsName) == 0)
            {
              switch (cp->configType)
              {
              case ConfigTypeBool:
                {
                  bool bVal;
                  if (configValue->IsBoolean())
                  {
                    bVal = configValue->BooleanValue();
                  }
                  else if (configValue->IsNumber())
                  {
                    bVal = (configValue->NumberValue() != 0);
                  }
                  else if (configValue->IsString())
                  {
                    String::AsciiValue bStrVal(config->ToString());
                    bVal = (tva_str_casecmp(*bStrVal, "true") == 0);
                  }

                  tvaAppCfgSet(cp->tvaParam, &bVal, (TVA_INT32)sizeof(bVal));
                }
                break;

              case ConfigTypeInt:
                {
                  int intVal = configValue->Int32Value();
                  tvaAppCfgSet(cp->tvaParam, &intVal, (TVA_INT32)sizeof(intVal));
                }
                break;

              case ConfigTypeString:
                {
                  String::AsciiValue strVal(configValue->ToString());
                  tvaAppCfgSet(cp->tvaParam, *strVal, (TVA_INT32)strlen(*strVal));
                }
                break;

              case ConfigTypeCustom:
                if (cp->tvaParam == TVA_APPCFG_DATA_TRANSPORT_TYPE)
                {
                  TVA_DATATRANSPORT_TYPE transportType = TVA_DATATRANSPORT_UDP;

                  if (configValue->IsString())
                  {
                    String::AsciiValue strVal(config->ToString());
                    if (tva_str_casecmp(*strVal, "TCP"))
                    {
                      transportType = TVA_DATATRANSPORT_TCP;
                    }
                    else if (tva_str_casecmp(*strVal, "SSL"))
                    {
                      transportType = TVA_DATATRANSPORT_SSL;
                    }
                  }
                  else if (configValue->IsNumber())
                  {
                    int numVal = (int)configValue->NumberValue();
                    if ((numVal == TVA_DATATRANSPORT_TCP) || (numVal == TVA_DATATRANSPORT_SSL))
                    {
                      transportType = (TVA_DATATRANSPORT_TYPE)numVal;
                    }
                  }

                  tvaAppCfgSet(cp->tvaParam, &transportType, (TVA_INT32)sizeof(transportType));
                }
                break;
              }

              break;
            }
          }
        }
      }
    }
  }

  // Make sure required arguments were specified
  if (!request->username || !request->password || !request->primaryTmx)
  {
    return false;
  }

  return true;
}
bool JsArgToArrayConverter::ConvertArg(const Local<Value>& arg, int index)
{
	bool success = false;
	stringstream s;

	JEnv env;

	Type returnType = JType::getClassType(m_return_type);

	if (arg.IsEmpty())
	{
		s << "Cannot convert empty JavaScript object";
		success = false;
	}
	else if (arg->IsInt32() && (returnType == Type::Int || returnType == Type::Null))
	{
		jint value = arg->Int32Value();
		JniLocalRef javaObject(JType::NewInt(env, value));
		SetConvertedObject(env, index, javaObject);

		success = true;
	}
	else if (arg->IsNumber() || arg->IsNumberObject())
	{
		double d = arg->NumberValue();
		int64_t i = (int64_t)d;
		bool isInteger = d == i;

		if (isInteger)
		{
			jobject obj;

			//if returnType is long it will cast to long
			//if there is no return type specified it will cast to int
			//because default return type is null (ref type)
			if ((INT_MIN <= i) && (i <= INT_MAX) && (returnType == Type::Int || returnType == Type::Null))
			{
				obj = JType::NewInt(env, (jint)d);
			}
			else /*isLong*/
			{
				obj = JType::NewLong(env, (jlong)d);
			}

			JniLocalRef javaObject(obj);
			SetConvertedObject(env, index, javaObject);

			success = true;
		}
		else
		{
			jobject obj;

			//if returnType is double it will cast to double
			//if there is no return type specified it will cast to float
			//because default return type is null (ref type)
			if((FLT_MIN <= d) && (d <= FLT_MAX) && (returnType == Type::Float || returnType == Type::Null)) {
				obj = JType::NewFloat(env, (jfloat)d);
			}
			else {/*isDouble*/
				obj = JType::NewDouble(env, (jdouble)d);
			}

			JniLocalRef javaObject(obj);
			SetConvertedObject(env, index, javaObject);

			success = true;
		}
	}
	else if (arg->IsBoolean())
	{
		jboolean value = arg->BooleanValue();
		JniLocalRef javaObject(JType::NewBoolean(env, value));
		SetConvertedObject(env, index, javaObject);
		success = true;
	}
	else if (arg->IsBooleanObject())
	{
		auto boolObj = Local<BooleanObject>::Cast(arg);
		jboolean value = boolObj->BooleanValue() ? JNI_TRUE : JNI_FALSE;
		JniLocalRef javaObject(JType::NewBoolean(env, value));
		SetConvertedObject(env, index, javaObject);

		success = true;
	}
	else if (arg->IsString() || arg->IsStringObject())
	{
		JniLocalRef stringObject(ConvertToJavaString(arg));
		SetConvertedObject(env, index, stringObject);

		success = true;
	}
	else if (arg->IsObject())
	{
		auto objectWithHiddenID = arg->ToObject();

		auto hidden = objectWithHiddenID->GetHiddenValue(V8StringConstants::GetMarkedAsLong());
		if (!hidden.IsEmpty())
		{
			jlong value = 0;
			if (hidden->IsString())
			{
				auto strValue = ConvertToString(hidden->ToString());
				value = atoll(strValue.c_str());
			}
			else if (hidden->IsInt32())
			{
				value = hidden->ToInt32()->Int32Value();
			}

			JniLocalRef javaObject(JType::NewLong(env, value));
			SetConvertedObject(env, index, javaObject);
			return true;
		}

		hidden = objectWithHiddenID->GetHiddenValue(V8StringConstants::GetMarkedAsByte());
		if (!hidden.IsEmpty())
		{
			jbyte value = 0;
			if (hidden->IsString())
			{
				string value = ConvertToString(hidden->ToString());
				int byteArg = atoi(value.c_str());
				value = (jbyte)byteArg;
			}
			else if (hidden->IsInt32())
			{
				int byteArg = hidden->ToInt32()->Int32Value();
				value = (jbyte)byteArg;
			}

			JniLocalRef javaObject(JType::NewByte(env, value));
			SetConvertedObject(env, index, javaObject);
			return true;
		}

		hidden = objectWithHiddenID->GetHiddenValue(V8StringConstants::GetMarkedAsShort());
		if (!hidden.IsEmpty())
		{
			jshort value = 0;
			if (hidden->IsString())
			{
				string value = ConvertToString(hidden->ToString());
				int shortArg = atoi(value.c_str());
				value = (jshort)shortArg;
			}
			else if (hidden->IsInt32())
			{
				jlong shortArg = hidden->ToInt32()->Int32Value();
				value = (jshort)shortArg;
			}

			JniLocalRef javaObject(JType::NewShort(env, value));
			SetConvertedObject(env, index, javaObject);
			return true;
		}

		hidden = objectWithHiddenID->GetHiddenValue(V8StringConstants::GetMarkedAsDouble());
		if (!hidden.IsEmpty())
		{
			jdouble value = 0;
			if (hidden->IsNumber())
			{
				double doubleArg = hidden->ToNumber()->NumberValue();
				value = (jdouble)doubleArg;
			}

			JniLocalRef javaObject(JType::NewDouble(env, value));
			SetConvertedObject(env, index, javaObject);
			return true;
		}

		hidden = objectWithHiddenID->GetHiddenValue(V8StringConstants::GetMarkedAsFloat());
		if (!hidden.IsEmpty())
		{
			jfloat value = 0;
			if (hidden->IsNumber())
			{
				double floatArg = hidden->ToNumber()->NumberValue();
				value = (jfloat)floatArg;
			}

			JniLocalRef javaObject(JType::NewFloat(env, value));
			SetConvertedObject(env, index, javaObject);
			return true;
		}

		hidden = objectWithHiddenID->GetHiddenValue(V8StringConstants::GetMarkedAsChar());
		if (!hidden.IsEmpty())
		{
			jchar value = '\0';
			if (hidden->IsString())
			{
				string str = ConvertToString(hidden->ToString());
				value = (jchar)str[0];
			}

			JniLocalRef javaObject(JType::NewChar(env, value));
			SetConvertedObject(env, index, javaObject);
			return true;
		}

		jweak obj = ObjectManager::GetJavaObjectByJsObjectStatic(objectWithHiddenID);
		success = obj != nullptr;
		if (success)
		{
			SetConvertedObject(env, index, obj, true);
		}
		else
		{
			s << "Cannot convert JavaScript object with id " << objectWithHiddenID->GetIdentityHash() << " at index " << index;
		}
	}
	else if (arg->IsUndefined() || arg->IsNull())
	{
		SetConvertedObject(env, index, nullptr);
		success = true;
	}
	else
	{
		s << "Cannot convert JavaScript object at index " << index;
		success = false;
	}

	if (!success)
	{
		m_error.index = index;
		m_error.msg = s.str();
	}

	return success;
}