Example #1
0
//------------------------------------------------------------------------------
// Real Evaluate()
//------------------------------------------------------------------------------
Real MathElement::Evaluate()
{
   #ifdef DEBUG_EVALUATE
   MessageInterface::ShowMessage
      ("MathElement::Evaluate() this='%s', refObjectName='%s', refObject=<%p>, "
       "elementType=%d\n", GetName().c_str(), refObjectName.c_str(), refObject, elementType);
   #endif
   
   // If this MathElement is function Input, just return since it is handled in
   // the FunctionRunner
   
   if (isFunctionInput)
      throw MathException("MathElement::Evaluate() Function input should "
                          "not be handled here");
   
   if (refObject)
   {
      #ifdef DEBUG_EVALUATE
      MessageInterface::ShowMessage
         ("   refObject=<%p><%p>'%s'\n", refObject, refObject->GetTypeName().c_str(),
          refObject->GetName().c_str());
      #endif
      
      ElementWrapper *wrapper = FindWrapper(refObjectName);
      
      if (elementType == Gmat::REAL_TYPE || elementType == Gmat::RMATRIX_TYPE)
      {
         #ifdef DEBUG_EVALUATE
         MessageInterface::ShowMessage
            ("   wrapper type=%d, desc='%s'\n", wrapper->GetWrapperType(),
             wrapper->GetDescription().c_str());
         #endif
         ///@note ArrayWrapper::EvaluateReal() returns 1x1 matrix as real number
         realValue = wrapper->EvaluateReal();
      }
      else
      {
         throw MathException
            ("MathElement::Evaluate() Cannot Evaluate MathElementType of \"" +
             refObjectName + "\"");
      }
      
      #ifdef DEBUG_EVALUATE
      MessageInterface::ShowMessage
         ("MathElement::Evaluate() It's a parameter: %s realValue = %f\n",
          refObject->GetName().c_str(), realValue);
      #endif
      
      return realValue;
   }
   else
   {
      #ifdef DEBUG_EVALUATE
      MessageInterface::ShowMessage
         ("MathElement::Evaluate() It's a number: realValue = %f\n", realValue);
      #endif
      
      return realValue;
   }
}
Example #2
0
JNIEXPORT jstring JNICALL Java_org_openqa_selenium_ie_InternetExplorerElement_getValue
  (JNIEnv *env, jobject obj)
{
	ElementWrapper* wrapper = getWrapper(env, obj);

	return wstring2jstring(env, wrapper->getValue());
}
Example #3
0
//------------------------------------------------------------------------------
bool MathTree::Validate(std::string &msg)
{
   #ifdef DEBUG_VALIDATE
   MessageInterface::ShowMessage
      ("MathTree::Validate() entered, theWrapperMap=<%p>\n", theWrapperMap);
   #endif
   
   bool retval = true;
   msg = "";
   std::string errmsg = "Cannot use object ";
   
   if (theWrapperMap)
   {
      WrapperMap::iterator iter = theWrapperMap->begin();
      while (iter != theWrapperMap->end())
      {
         ElementWrapper *ew = iter->second;
         #ifdef DEBUG_VALIDATE
         MessageInterface::ShowMessage
            ("   name = '%s', wrapper = <%p>\n", (iter->first).c_str(), ew);
         #endif
         if (ew)
         {
            Gmat::WrapperDataType wrapperType = ew->GetWrapperType();
            #ifdef DEBUG_VALIDATE
            MessageInterface::ShowMessage("   wrapper type = %d\n", wrapperType);
            #endif
            
            // Check for invalid wrapper type
            if (wrapperType == Gmat::STRING_WT || wrapperType == Gmat::STRING_OBJECT_WT ||
                wrapperType == Gmat::OBJECT_WT || wrapperType == Gmat::BOOLEAN_WT ||
                wrapperType == Gmat::ON_OFF_WT || wrapperType == Gmat::UNKNOWN_WRAPPER_TYPE)
            {
               #ifdef DEBUG_VALIDATE
               MessageInterface::ShowMessage
                  ("   '%s' has invalid wrapper type = %d\n", (iter->first).c_str(), wrapperType);
               #endif
               errmsg = errmsg + "\"" + iter->first + "\", ";
               retval = false;
            }
         }
         
         ++iter;
      }
   }
   
   if (!retval)
   {
      // Remove last , from the errmsg
      errmsg = GmatStringUtil::RemoveLastString(errmsg, ", ");
      msg = errmsg + " in a math equation.";
   }
   
   #ifdef DEBUG_VALIDATE
   MessageInterface::ShowMessage
      ("MathTree::Validate() returning %d, msg = '%s'\n", retval, msg.c_str());
   #endif
   
   return retval;
}
ElementWrapper EventWrapper::GetCurrentElement() const
{
	ElementWrapper wrapper;
	wrapper.setElement(m_pEvent->GetCurrentElement());

	return wrapper;
}
Example #5
0
JNIEXPORT void JNICALL Java_org_openqa_selenium_ie_InternetExplorerElement_doSendKeys
  (JNIEnv *env, jobject obj, jstring newValue)
{
	ElementWrapper* wrapper = getWrapper(env, obj);
	wchar_t* converted = (wchar_t*) env->GetStringChars(newValue, NULL);
	wrapper->sendKeys(converted);
}
Example #6
0
JNIEXPORT jlong JNICALL Java_org_openqa_selenium_ie_InternetExplorerElement_getIePointer
  (JNIEnv *env, jobject obj)
{
	ElementWrapper* wrapper = getWrapper(env, obj);

	return (jlong) wrapper->getParent();
}
Example #7
0
JNIEXPORT jstring JNICALL Java_org_openqa_selenium_ie_InternetExplorerElement_getAttribute
  (JNIEnv *env, jobject obj, jstring attributeName)
{
	ElementWrapper* wrapper = getWrapper(env, obj);

	const wchar_t* converted = (wchar_t*) env->GetStringChars(attributeName, NULL);
	return wstring2jstring(env, wrapper->getAttribute(converted));
}
Example #8
0
JNIEXPORT void JNICALL Java_org_openqa_selenium_ie_InternetExplorerElement_setSelected
  (JNIEnv *env, jobject obj)
{
	ElementWrapper* wrapper = getWrapper(env, obj);
	try {
		wrapper->setSelected();
	} catch (const char *message) {
		throwUnsupportedOperationException(env, message);
	}
}
Example #9
0
JNIEXPORT void JNICALL Java_org_openqa_selenium_ie_InternetExplorerElement_submit
  (JNIEnv *env, jobject obj)
{
	ElementWrapper* wrapper = getWrapper(env, obj);
	try {
		wrapper->submit();
	} catch (const char* message) {
		throwNoSuchElementException(env, message);
	}
}
Example #10
0
//------------------------------------------------------------------------------
// bool MatrixEvaluate()
//------------------------------------------------------------------------------
Rmatrix MathElement::MatrixEvaluate()
{
   #ifdef DEBUG_EVALUATE
   MessageInterface::ShowMessage
      ("MathElement::MatrixEvaluate() this='%s', refObjectName='%s', refObject=<%p>, "
       "elementType=%d\n", GetName().c_str(), refObjectName.c_str(), refObject, elementType);
   #endif
   
   // If this MathElement is function Input, just return since it is handled in
   // the FunctionRunner
   
   if (isFunctionInput)
      throw MathException("MathElement::MatrixEvaluate() Function input should "
                          "not be handled here");
   
   if (elementType == Gmat::RMATRIX_TYPE)
   {
      if (refObject)
      {
         #ifdef DEBUG_EVALUATE
         Rmatrix rmat = refObject->GetRmatrix();
         MessageInterface::ShowMessage
            ("MathElement::MatrixEvaluate() It's an Array: %s matVal =\n%s\n",
             refObject->GetName().c_str(), rmat.ToString().c_str());
         #endif
         
         ElementWrapper *wrapper = FindWrapper(refObjectName);
         return wrapper->EvaluateArray();
      }
      else
      {
         #ifdef DEBUG_EVALUATE
         MessageInterface::ShowMessage
            ("MathElement::MatrixEvaluate() It's a Rmatrix. matVal =\n%s\n",
             matrix.ToString().c_str());
         #endif
         
         return matrix;
      }
   }
   else
   {
      Real rval = Evaluate();
      
      #ifdef DEBUG_EVALUATE
      MessageInterface::ShowMessage
         ("MathElement::MatrixEvaluate() It's a number: rval = %f\n", rval);
      #endif
      
      // Set matrix 1x1 and return
      Rmatrix rmat(1, 1, rval);
      return rmat;
      //throw MathException("MathElement::MatrixEvaluate() Invalid matrix");
   }
}
Example #11
0
JNIEXPORT jlong JNICALL Java_org_openqa_selenium_ie_InternetExplorerElement_getElementNode
  (JNIEnv *env, jobject obj) 
{
	ElementWrapper* wrapper = getWrapper(env, obj);

	IHTMLDOMNode* node;
	CComPtr<IHTMLElement> element(wrapper->getWrappedElement());
	element.QueryInterface(&node);

	return (jlong) node;
}
Example #12
0
JNIEXPORT jobject JNICALL Java_org_openqa_selenium_ie_InternetExplorerElement_getSize
  (JNIEnv *env, jobject obj) 
{
	ElementWrapper* wrapper = getWrapper(env, obj);
	long width = wrapper->getWidth();
	long height = wrapper->getHeight();

	jclass pointClass = env->FindClass("java/awt/Dimension");
	jmethodID cId = env->GetMethodID(pointClass, "<init>", "(II)V");

	return env->NewObject(pointClass, cId, width, height);
}
Example #13
0
JNIEXPORT jobject JNICALL Java_org_openqa_selenium_ie_InternetExplorerElement_getLocation
  (JNIEnv *env, jobject obj)
{
	ElementWrapper* wrapper = getWrapper(env, obj);
	long x = wrapper->getX();
	long y = wrapper->getY();

	jclass pointClass = env->FindClass("java/awt/Point");
	jmethodID cId = env->GetMethodID(pointClass, "<init>", "(II)V");
	
	return env->NewObject(pointClass, cId, x, y);
}
Example #14
0
void GlobalUtility::Set()
{
	Module::instance().getScriptInterface().PushDocumentTable(mVM, m_pDoc);
	SQRESULT sqr;

	if (m_pSelf)
	{
		ElementWrapper wrapper;
		wrapper.setElement(m_pSelf);

		//Add the global slot self
		sq_pushstring(mVM, "self", -1);
		sqr = sqb::Push<ElementWrapper>(mVM, wrapper);

		ROCKETSQUIRREL_ASSERT(SQ_SUCCEEDED(sqr));

		sqr = sq_newslot(mVM, -3, false);

		ROCKETSQUIRREL_ASSERT(SQ_SUCCEEDED(sqr));

		mSelfSet = true;
	}

	if (m_pEvt)
	{
		EventWrapper wrapper(m_pEvt);

		//Add the global slot event
		sq_pushstring(mVM, "event", -1);
		sqr = sqb::Push<EventWrapper>(mVM, wrapper);

		ROCKETSQUIRREL_ASSERT(SQ_SUCCEEDED(sqr));

		sqr = sq_newslot(mVM, -3, false);

		ROCKETSQUIRREL_ASSERT(SQ_SUCCEEDED(sqr));

		mEvtSet = true;
	}

	sq_poptop(mVM);
}
Example #15
0
//@cond PRIVATE
QString extractContent(const ElementWrapper& wrapper)
{
    if (wrapper.isNull())
        return QString();
    
    QList<QDomElement> list = wrapper.elementsByTagNameNS(contentNameSpace(), QLatin1String("encoded"));

    if (!list.isEmpty())
        return list.first().text().trimmed();

    list = wrapper.elementsByTagNameNS(xhtmlNamespace(), QLatin1String("body"));

    if (!list.isEmpty())
        return ElementWrapper::childNodesAsXML(list.first()).trimmed();

    list = wrapper.elementsByTagNameNS(xhtmlNamespace(), QLatin1String("div"));

    if (!list.isEmpty())
        return ElementWrapper::childNodesAsXML(list.first()).trimmed();

    return QString();
}
Example #16
0
JNIEXPORT void JNICALL Java_org_openqa_selenium_ie_InternetExplorerElement_getChildrenOfTypeNatively
  (JNIEnv *env, jobject obj, jobject list, jstring tagName)
{
	jclass listClass = env->FindClass("java/util/List");
	jmethodID addId = env->GetMethodID(listClass, "add", "(Ljava/lang/Object;)Z");

	jclass ieeClass = env->FindClass("org/openqa/selenium/ie/InternetExplorerElement");
	jmethodID cId = env->GetMethodID(ieeClass, "<init>", "(J)V");

	const wchar_t* converted = (wchar_t*) env->GetStringChars(tagName, NULL);
	ElementWrapper* wrapper = getWrapper(env, obj);
	const std::vector<ElementWrapper*>* elements = wrapper->getChildrenWithTagName(converted);

	std::vector<ElementWrapper*>::const_iterator end = elements->end();
	std::vector<ElementWrapper*>::const_iterator cur = elements->begin();

	while(cur < end)
	{
		ElementWrapper* wrapper = *cur;
		jobject wrapped = env->NewObject(ieeClass, cId, wrapper);
		env->CallVoidMethod(list, addId, wrapped);
		cur++;
	}
}
Example #17
0
//------------------------------------------------------------------------------
// bool GmatFunction::Execute(ObjectInitializer *objInit, bool reinitialize)
//------------------------------------------------------------------------------
bool GmatFunction::Execute(ObjectInitializer *objInit, bool reinitialize)
{
   if (!fcs) return false;
   if (!objInit) return false;
   
   #ifdef DEBUG_TRACE
   static Integer callCount = 0;
   callCount++;      
   clock_t t1 = clock();
   ShowTrace(callCount, t1, wxT("GmatFunction::Execute() entered"));
   #endif
   
   #ifdef DEBUG_FUNCTION_EXEC
   MessageInterface::ShowMessage
      (wxT("======================================================================\n")
       wxT("GmatFunction::Execute() entered for '%s'\n   internalCS is <%p>, ")
       wxT("reinitialize = %d\n"), functionName.c_str(), internalCoordSys, reinitialize);
   #endif
   
   GmatCommand *current = fcs;
   GmatCommand *last = NULL;
   
   // We want to initialize local objects with new object map,
   // so do it everytime (loj: 2008.09.26)
   // This causes to slow down function execution, so initialize if necessary
   if (reinitialize)
      objectsInitialized = false;
   
   // Reinitialize CoordinateSystem to fix bug 1599 (LOJ: 2009.11.05)
   // Reinitialize Parameters to fix bug 1519 (LOJ: 2009.09.16)
   if (objectsInitialized)
   {
      if (!objInit->InitializeObjects(true, Gmat::COORDINATE_SYSTEM))
         throw FunctionException
            (wxT("Failed to re-initialize Parameters in the \"") + functionName + wxT("\""));
      if (!objInit->InitializeObjects(true, Gmat::PARAMETER))
         throw FunctionException
            (wxT("Failed to re-initialize Parameters in the \"") + functionName + wxT("\""));
   }
   
   // Go through each command in the sequence and execute.
   // Once it gets to a real command, initialize local and automatic objects.
   while (current)
   {
      // Call to IsNextAFunction is necessary for branch commands in particular
      #ifdef DEBUG_FUNCTION_EXEC
      MessageInterface::ShowMessage
         (wxT("......Function executing <%p><%s> [%s]\n"), current, current->GetTypeName().c_str(),
          current->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
      MessageInterface::ShowMessage(wxT("      objectsInitialized=%d\n"), objectsInitialized);
      #endif
      
      last = current;
      
      if (!objectsInitialized)
      {
         // Since we don't know where actual mission sequence starts, just check
         // for command that is not NoOp, Create, Global, and GMAT with equation.
         // Can we have simple command indicating beginning of the sequence,
         // such as BeginSequence? (loj: 2008.06.19)
         // @todo: Now we have BeginMissionSequence, but not all functions have it,
         // so check it first otherwise do in the old way. (loj: 2010.07.16)
         Function *func = current->GetCurrentFunction();
         bool isEquation = false;
         wxString cmdType = current->GetTypeName();
         if (func && cmdType == wxT("GMAT"))
            if (((Assignment*)current)->GetMathTree() != NULL)
               isEquation = true;
         
         if (cmdType != wxT("NoOp") && cmdType != wxT("Create") && cmdType != wxT("Global"))
         {
            bool beginInit = true;            
            if (cmdType == wxT("GMAT") && !isEquation)
               beginInit = false;

            if (cmdType == wxT("BeginMissionSequence") || cmdType == wxT("BeginScript"))
               beginInit = true;
            
            if (beginInit)
            {
               objectsInitialized = true;
               validator->HandleCcsdsEphemerisFile(objectStore, true);
               #ifdef DEBUG_FUNCTION_EXEC
               MessageInterface::ShowMessage
                  (wxT("============================ Initializing LocalObjects at current\n")
                   wxT("%s\n"), current->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
               #endif
               InitializeLocalObjects(objInit, current, true);
            }
         }
      }
      
      // Now execute the function sequence
      try
      {
         #ifdef DEBUG_FUNCTION_EXEC
         MessageInterface::ShowMessage
            (wxT("Now calling <%p>[%s]->Execute()\n"), current->GetTypeName().c_str(),
             current->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
         #endif
         
         if (!(current->Execute()))
            return false;
      }
      catch (BaseException &e)
      {
         // If it is user interrupt, rethrow (loj: 2008.10.16)
         // How can we tell if it is thrown by Stop command?
         // For now just find the phrase wxT("interrupted by Stop command")
         wxString msg = e.GetFullMessage();
         if (msg.find(wxT("interrupted by Stop command")) != msg.npos)
         {
            #ifdef DEBUG_FUNCTION_EXEC
            MessageInterface::ShowMessage
               (wxT("*** Interrupted by Stop commaned, so re-throwing...\n"));
            #endif
            throw;
         }
         
         if (e.IsFatal())
         {
            #ifdef DEBUG_FUNCTION_EXEC
            MessageInterface::ShowMessage
               (wxT("*** The exception is fatal, so re-throwing...\n"));
            #endif
            // Add command line to error message (LOJ: 2010.04.13)
            throw FunctionException
               (wxT("In ") + current->GetGeneratingString(Gmat::NO_COMMENTS) + wxT(", ") +
                e.GetFullMessage());
            //throw;
         }
         
         // Let's try initialzing local objects here again (2008.10.14)
         try
         {
            #ifdef DEBUG_FUNCTION_EXEC
            MessageInterface::ShowMessage
               (wxT("============================ Reinitializing LocalObjects at current\n")
                wxT("%s\n"), current->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
            #endif
            
            InitializeLocalObjects(objInit, current, false);
            
            #ifdef DEBUG_FUNCTION_EXEC
            MessageInterface::ShowMessage
               (wxT("......Function re-executing <%p><%s> [%s]\n"), current,
                current->GetTypeName().c_str(),
                current->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
            #endif
            
            if (!(current->Execute()))
               return false;
         }
         catch (HardwareException &he)
         {
            // Ignore for hardware exception since spacecraft is associated with Thruster
            // but Thruster binds with Tank later in the fcs
         }
         catch (BaseException &be)
         {
            throw FunctionException
               (wxT("During initialization of local objects before \"") +
                current->GetGeneratingString(Gmat::NO_COMMENTS) + wxT("\", ") +
                e.GetFullMessage());
         }
      }
      
      // If current command is BranchCommand and still executing, continue to next
      // command in the branch (LOJ: 2009.03.24)
      if (current->IsOfType(wxT("BranchCommand")) && current->IsExecuting())
      {
         #ifdef DEBUG_FUNCTION_EXEC
         MessageInterface::ShowMessage
            (wxT("In Function '%s', still executing current command is <%p><%s>\n"),
             functionName.c_str(), current, current ? current->GetTypeName().c_str() : wxT("NULL"));
         #endif
         
         continue;
      }
      
      current = current->GetNext();
      
      #ifdef DEBUG_FUNCTION_EXEC
      MessageInterface::ShowMessage
         (wxT("In Function '%s', the next command is <%p><%s>\n"), functionName.c_str(),
          current, current ? current->GetTypeName().c_str() : wxT("NULL"));
      #endif
   }
   
   // Set ObjectMap from the last command to Validator in order to create
   // valid output wrappers (loj: 2008.11.12)
   validator->SetObjectMap(last->GetObjectMap());
   
   #ifdef DEBUG_FUNCTION_EXEC
   MessageInterface::ShowMessage
      (wxT("   Now about to create %d output wrapper(s) to set results, objectsInitialized=%d\n"),
       outputNames.size(), objectsInitialized);
   #endif
   
   // create output wrappers and put into map
   GmatBase *obj;
   wrappersToDelete.clear();
   for (unsigned int jj = 0; jj < outputNames.size(); jj++)
   {
      if (!(obj = FindObject(outputNames.at(jj))))
      {
         wxString errMsg = wxT("Function: Output \"") + outputNames.at(jj);
         errMsg += wxT(" not found for function \"") + functionName + wxT("\"");
         throw FunctionException(errMsg);
      }
      wxString outName = outputNames.at(jj);
      ElementWrapper *outWrapper =
         validator->CreateElementWrapper(outName, false, false);
      #ifdef DEBUG_MORE_MEMORY
      MessageInterface::ShowMessage
         (wxT("+++ GmatFunction::Execute() *outWrapper = validator->")
          wxT("CreateElementWrapper(%s), <%p> '%s'\n"), outName.c_str(), outWrapper,
          outWrapper->GetDescription().c_str());
      #endif
      
      outWrapper->SetRefObject(obj);
      
      // nested CallFunction crashes if old outWrappers are deleted here. (loj: 2008.11.24)
      // so collect here and delete when FunctionRunner completes.
      wrappersToDelete.push_back(outWrapper);         
      
      // Set new outWrapper
      outputArgMap[outName] = outWrapper;
      #ifdef DEBUG_FUNCTION_EXEC // --------------------------------------------------- debug ---
         MessageInterface::ShowMessage(wxT("GmatFunction: Output wrapper created for %s\n"),
                                       (outputNames.at(jj)).c_str());
      #endif // -------------------------------------------------------------- end debug ---
   }
   
   #ifdef DEBUG_FUNCTION_EXEC
   MessageInterface::ShowMessage
      (wxT("GmatFunction::Execute() exiting true for '%s'\n"), functionName.c_str());
   #endif
   
   #ifdef DEBUG_TRACE
   ShowTrace(callCount, t1, wxT("GmatFunction::Execute() exiting"), true);
   #endif
   
   return true; 
}
Example #18
0
JNIEXPORT jobject JNICALL Java_org_openqa_selenium_ie_InternetExplorerDriver_doExecuteScript
  (JNIEnv *env, jobject obj, jstring script, jobjectArray args)
{
	InternetExplorerDriver* wrapper = getIe(env, obj);

	// Convert the args into something we can use elsewhere.
	jclass numberClazz = env->FindClass("java/lang/Number");
	jclass booleanClazz = env->FindClass("java/lang/Boolean");
	jclass stringClazz = env->FindClass("java/lang/String");
	jclass elementClazz = env->FindClass("org/openqa/selenium/ie/InternetExplorerElement");

	jmethodID longValue = env->GetMethodID(numberClazz, "longValue", "()J");
	jmethodID booleanValue = env->GetMethodID(booleanClazz, "booleanValue", "()Z");
	jfieldID elementPointer = env->GetFieldID(elementClazz, "nodePointer", "J");

	jsize length = env->GetArrayLength(args);


	SAFEARRAYBOUND bounds;
	bounds.cElements = length;
	bounds.lLbound = 0;
	SAFEARRAY* convertedItems = SafeArrayCreate(VT_VARIANT, 1, &bounds);
	
	LONG index[1];
	for (jsize i = 0; i < length; i++) {
		index[0] = i;
		VARIANT dest;
		VariantInit(&dest);

		jobject arrayObject = env->GetObjectArrayElement(args, i);
		jclass objClazz = env->GetObjectClass(arrayObject);
		
		if (env->IsInstanceOf(arrayObject, numberClazz)) {
			jlong value = env->CallLongMethod(arrayObject, longValue);

			dest.vt = VT_I4;
			dest.lVal = (LONG) value;
		} else if (env->IsInstanceOf(arrayObject, stringClazz)) {
			wchar_t *converted = (wchar_t *)env->GetStringChars((jstring) arrayObject, 0);
			std::wstring value(converted);
			env->ReleaseStringChars((jstring) arrayObject, (jchar*) converted);

			dest.vt = VT_BSTR;
			dest.bstrVal = SysAllocString(value.c_str());
		} else if (env->IsInstanceOf(arrayObject, booleanClazz)) {
			bool value = env->CallBooleanMethod(arrayObject, booleanValue) == JNI_TRUE;

			dest.vt = VT_BOOL;
			dest.boolVal = value;
		} else if (env->IsInstanceOf(arrayObject, elementClazz)) {
			ElementWrapper* element = (ElementWrapper*) env->GetLongField(arrayObject, elementPointer);
			
			dest.vt = VT_DISPATCH;
			dest.pdispVal = element->getWrappedElement();
		}

		SafeArrayPutElement(convertedItems, &i, &dest);
	}

	const wchar_t* converted = (wchar_t *)env->GetStringChars(script, 0);
	VARIANT result;
	VariantInit(&result);
	wrapper->executeScript(converted, convertedItems, &result);
	env->ReleaseStringChars(script, (jchar*) converted);

	// TODO (simon): Does this clear everything properly?
	SafeArrayDestroy(convertedItems);

	if (result.vt == VT_BSTR) {
		return wstring2jstring(env, bstr2wstring(result.bstrVal));
	} else if (result.vt == VT_DISPATCH) {
		// Attempt to create a new webelement
		CComQIPtr<IHTMLDOMNode> node(result.pdispVal);
		if (!node) {
			cerr << "Cannot convert response to node. Attempting to convert to string" << endl;
			return wstring2jstring(env, variant2wchar(result));
		}

		ElementWrapper* element = new ElementWrapper(wrapper, node);

		jclass clazz = env->FindClass("org/openqa/selenium/ie/InternetExplorerElement");
		jmethodID cId = env->GetMethodID(clazz, "<init>", "(J)V");

		return env->NewObject(clazz, cId, (jlong) element);
	} else if (result.vt == VT_BOOL) {
		jclass clazz = env->FindClass("java/lang/Boolean");
		jmethodID cId = env->GetMethodID(clazz, "<init>", "(Z)V");

		return env->NewObject(clazz, cId, (jboolean) (result.boolVal == VARIANT_TRUE));
	} else if (result.vt == VT_I4) {
		jclass clazz = env->FindClass("java/lang/Long");
		jmethodID cId = env->GetMethodID(clazz, "<init>", "(J)V");
		return env->NewObject(clazz, cId, (jlong) result.lVal);
	} else if (result.vt == VT_I8) {
		jclass clazz = env->FindClass("java/lang/Long");
		jmethodID cId = env->GetMethodID(clazz, "<init>", "(J)V");
		return env->NewObject(clazz, cId, (jlong) result.dblVal);
	} else if (result.vt == VT_USERDEFINED) {
		jclass newExcCls;
		env->ExceptionDescribe();
		env->ExceptionClear();
		newExcCls = env->FindClass("java/lang/RuntimeException");
		jmethodID cId = env->GetMethodID(newExcCls, "<init>", "(Ljava/lang/String;)V");

		jstring message = wstring2jstring(env, bstr2wstring(result.bstrVal));

		jobject exception;
		if (message) {
			exception = env->NewObject(newExcCls, cId, message);
		} else {
			cout << "Falling back" << endl;
			exception = env->NewObject(newExcCls, cId, (jstring) "Cannot extract cause of error");
		}

		env->Throw((jthrowable) exception);
		return NULL;
	}

	cerr << "Unknown variant type. Will attempt to coerce to string: " << result.vt << endl;
	return wstring2jstring(env, variant2wchar(result));
}
Example #19
0
JNIEXPORT jboolean JNICALL Java_org_openqa_selenium_ie_InternetExplorerElement_isSelected
  (JNIEnv *env, jobject obj)
{
	ElementWrapper* wrapper = getWrapper(env, obj);
	return wrapper->isSelected() ? JNI_TRUE : JNI_FALSE;
}
Example #20
0
JNIEXPORT void JNICALL Java_org_openqa_selenium_ie_InternetExplorerElement_clear
  (JNIEnv *env, jobject obj)
{
	ElementWrapper* wrapper = getWrapper(env, obj);
	wrapper->clear();
}