Esempio n. 1
0
NPError
NPP_Initialize(void)
{
  JavaVMInitArgs vm_args;
  jint ext_id;
 
  if (g_inited) 
	  return NPERR_NO_ERROR;
  if (g_jvmp_context != NULL) 
	return NPERR_NO_ERROR;
  JVMP_ShmInit(1);
  if (loadPluginDLL() != JNI_TRUE)
	return NPERR_GENERIC_ERROR;
  memset(&vm_args, 0, sizeof(vm_args));
  vm_args.version = JNI_VERSION_1_2;
  (g_jvmp_context->JVMP_GetDefaultJavaVMInitArgs)(&vm_args);
  if (initJVM(&g_jvm, &g_ctx, &vm_args) != JNI_TRUE) 
    return NPERR_GENERIC_ERROR;
  if ((g_jvmp_context->JVMP_RegisterExtension)
	  (g_ctx, 
	   "/ws/wf/build/unix/libwf_netscape4.so", 
	   &ext_id) != JNI_TRUE)
	return NPERR_GENERIC_ERROR;
  return DoDirtyInit();
}
JavaVM* getJVM()
{
   if (_pVMJvm == NULL)
      initJVM();

   if (_pVMJvm == NULL)
      throw std::runtime_error("getJVM: no JVM.");

   return _pVMJvm;
}
Esempio n. 3
0
void b1_handler(GtkWidget *widget) 
{
  void* handle;

  if (!loadPluginLibrary(&handle)) return;
  memset(&vm_args, 0, sizeof(vm_args));
  if (!initJVM(&jvm, &env, &vm_args)) {
    return;
  };
};
NS_IMETHODIMP 
nsPluggableJVM::StartupJVM(const char *classPath, 
			   nsPluggableJVMStatus *status,
			   jlong sup)
{
  JavaVMInitArgs vm_args;
  jint res;
  OJI_LOG("nsPluggableJVM::StartupJVM");
  *status = nsPluggableJVMStatus_Failed;
  if (sup == nsnull) return NS_ERROR_FAILURE;
  const char* plugin_home = getenv("WFHOME");
  if (plugin_home == NULL) {
    OJI_LOG("Env variable JAVA_PLUGIN_HOME not set");
    return NS_ERROR_FAILURE;
  }
  if (NS_FAILED(loadPluginDLL(plugin_home))) 
    return NS_ERROR_FAILURE;
  memset(&vm_args, 0, sizeof(vm_args));
  vm_args.version = JNI_VERSION_1_2;
  // XXX: add classpath here
  if (NS_FAILED(initJVM(&m_ctx, &vm_args))) 
    return NS_ERROR_FAILURE;
  // initialize capability mechanism 
  JVMP_SecurityCap cap;
  JVMP_FORBID_ALL_CAPS(cap);
  JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_SYSTEM);
  JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_SYSEVENT)
  JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_EVENT);
  JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_CALL);
  jbyte** prins;
  jint    pnum = 2;
  jint*   plen;
  if (!newPrincipalsFromStrings(&prins, &plen, 
				pnum, "CAPS", "MOZILLA"))
    return JNI_FALSE;
  if ((m_jvmp_context->JVMP_EnableCapabilities)
      (m_ctx, &cap, pnum, plen, prins) != JNI_TRUE) 
    {
      OJI_LOG("Can\'t enable caps");
      return JNI_FALSE;
    };
  deletePrincipals(prins, plen, pnum);
  SetConsoleVisibility(PR_TRUE);
  char* ext_dll = PR_GetLibraryName(plugin_home, LIBEXT);
  OJI_LOG2("JVMP_RegisterExtension: %s", ext_dll);
  res = (m_jvmp_context->JVMP_RegisterExtension)(m_ctx, 
						 ext_dll,
						 &m_extID,
						 sup);
  PR_Free(ext_dll);
  if (res != JNI_TRUE || m_extID == 0) return NS_ERROR_FAILURE;  
  OJI_LOG("JVMP_RegisterExtension OK");
  *status = nsPluggableJVMStatus_Running;
  return NS_OK;
}
Esempio n. 5
0
SEXP RJgd_initLib(SEXP cp) {
	JNIEnv *env = getJNIEnv();
	int i, l;
	
	if (!jvm) {
		initJVM(jarClassPath);
		env = getJNIEnv();
	}
	if (!env) error("missing JNIEnv");
	
	if (!isString(cp)) {
		error("cp is not a string vector");
	}
	l = LENGTH(cp);
	for (i = 0; i < l; i++) {
		SEXP elt = STRING_ELT(cp, i);
		if (elt != R_NaString) {
			addJClassPath(env, CHAR_UTF8(elt));
		}
	}
	
	return R_NilValue;
}
JOI_RetCode JavaObjectInterface::init(char *className,
                                      jclass          &javaClass,
                                      JavaMethodInit* JavaMethods, 
                                      Int32           howManyMethods,
                                      bool            methodsInitialized)
{
  if (isInitialized_)
    return JOI_OK;
    
  JOI_RetCode retCode = JOI_OK;
    
  // Make sure the JVM environment is set up correctly.
  jclass lJavaClass;
  retCode = initJVM();
  if (retCode != JOI_OK)
    return retCode;
        
  if (methodsInitialized == FALSE || javaObj_ == NULL)
  {
    if (javaClass == 0)
    {
       lJavaClass = jenv_->FindClass(className); 
       if (jenv_->ExceptionCheck()) 
       {
          getExceptionDetails();
          QRLogger::log(CAT_SQL_HDFS_JNI_TOP, LL_ERROR, "Exception in FindClass(%s).", className);
          return JOI_ERROR_FINDCLASS;
       }
       if (lJavaClass == 0) 
       {
           QRLogger::log(CAT_SQL_HDFS_JNI_TOP, LL_ERROR, "Error in FindClass(%s).", className);
           return JOI_ERROR_FINDCLASS;
       }
       javaClass = (jclass)jenv_->NewGlobalRef(lJavaClass);
       jenv_->DeleteLocalRef(lJavaClass);  
    }
    // Initialize the method pointers.
    if (!methodsInitialized)
    {
      for (int i=0; i<howManyMethods; i++)
      {
        JavaMethods[i].jm_full_name = new (heap_) NAString(className, heap_);
        JavaMethods[i].jm_full_name->append('.', 1);
        JavaMethods[i].jm_full_name->append(JavaMethods[i].jm_name);
        JavaMethods[i].methodID = jenv_->GetMethodID(javaClass, 
                                                     JavaMethods[i].jm_name, 
                                                     JavaMethods[i].jm_signature);
        if (JavaMethods[i].methodID == 0 || jenv_->ExceptionCheck())
        { 
          getExceptionDetails();
          QRLogger::log(CAT_SQL_HDFS_JNI_TOP, LL_ERROR, "Error in GetMethod(%s).", JavaMethods[i].jm_name);
          return JOI_ERROR_GETMETHOD;
        }      
      }
    }
    
    if (javaObj_ == NULL)
    {
      // Allocate an object of the Java class, and call its constructor.
      // The constructor must be the first entry in the methods array.
      jobject jObj = jenv_->NewObject(javaClass, JavaMethods[0].methodID);
      if (jObj == 0 || jenv_->ExceptionCheck())
      { 
        getExceptionDetails();
        QRLogger::log(CAT_SQL_HDFS_JNI_TOP, LL_ERROR, "Error in NewObject() for class %s.", className);
        return JOI_ERROR_NEWOBJ;
      }
      javaObj_ = jenv_->NewGlobalRef(jObj);
      jenv_->DeleteLocalRef(jObj);
    }
  }  
  
  isInitialized_ = true;
  return JOI_OK;
}
Esempio n. 7
0
Rboolean createJavaGD(newJavaGDDesc *xd) {
	jclass jc = 0;
	jobject jo = 0;
	
	JNIEnv *env=getJNIEnv();
	
    if (!jvm) {
        initJVM(jarClassPath);
        env=getJNIEnv();
    }
    
    if (!env) return FALSE;
    
	char *customClass = getenv("RJGD_CLASS_NAME");
	if (!customClass) { 
		//customClass = "org.rosuda.javaGD.JavaGD";
		customClass = "de.walware.rj.server.gd.JavaGD";
	}
	
	if (!jcGDInterface) {
		jclass jc = getJClass(env, "org.rosuda.javaGD.GDInterface", (RJ_ERROR_RERROR | RJ_GLOBAL_REF));
		jmGDInterfaceActivate = getJMethod(env, jc, "gdActivate", "()V", RJ_ERROR_RERROR);
		jmGDInterfaceCircle = getJMethod(env, jc, "gdCircle", "(DDD)V", RJ_ERROR_RERROR);
		jmGDInterfaceClip = getJMethod(env, jc, "gdClip", "(DDDD)V", RJ_ERROR_RERROR);
		jmGDInterfaceClose = getJMethod(env, jc, "gdClose", "()V", RJ_ERROR_RERROR);
		jmGDInterfaceDeactivate = getJMethod(env, jc, "gdDeactivate", "()V", RJ_ERROR_RERROR);
		jmGDInterfaceGetPPI = getJMethod(env, jc, "gdPPI", "()[D", RJ_ERROR_RERROR);
		jmGDInterfaceInit = getJMethod(env, jc, "gdInit", "(DDIDD)[D", RJ_ERROR_RERROR);
		jmGDInterfaceLocator = getJMethod(env, jc, "gdLocator", "()[D", RJ_ERROR_RERROR);
		jmGDInterfaceLine = getJMethod(env, jc, "gdLine", "(DDDD)V", RJ_ERROR_RERROR);
		jmGDInterfaceMetricInfo = getJMethod(env, jc, "gdMetricInfo", "(I)[D", RJ_ERROR_RERROR);
		jmGDInterfaceMode = getJMethod(env, jc, "gdMode", "(I)V", RJ_ERROR_RERROR);
		jmGDInterfaceNewPage = getJMethod(env, jc, "gdNewPage", "()V", RJ_ERROR_RERROR);
		jmGDInterfaceNewPageConfirm = getJMethod(env, jc, "gdNewPageConfirm", "()Z", RJ_ERROR_RERROR);
		jmGDInterfaceOpen = getJMethod(env, jc, "gdOpen", "(I)V", RJ_ERROR_RERROR);
		jmGDInterfacePolygon = getJMethod(env, jc, "gdPolygon", "(I[D[D)V", RJ_ERROR_RERROR);
		jmGDInterfacePolyline = getJMethod(env, jc, "gdPolyline", "(I[D[D)V", RJ_ERROR_RERROR);
		jmGDInterfaceRect = getJMethod(env, jc, "gdRect", "(DDDD)V", RJ_ERROR_RERROR);
		jmGDInterfaceSize = getJMethod(env, jc, "gdSize", "()[D", RJ_ERROR_RERROR);
		jmGDInterfaceStrWidth = getJMethod(env, jc, "gdStrWidth", "(Ljava/lang/String;)D", RJ_ERROR_RERROR);
		jmGDInterfaceText = getJMethod(env, jc, "gdText", "(DDLjava/lang/String;DD)V", RJ_ERROR_RERROR);
		jmGDInterfaceSetColor = getJMethod(env, jc, "gdcSetColor", "(I)V", RJ_ERROR_RERROR);
		jmGDInterfaceSetFill = getJMethod(env, jc, "gdcSetFill", "(I)V", RJ_ERROR_RERROR);
		jmGDInterfaceSetLine = getJMethod(env, jc, "gdcSetLine", "(DI)V", RJ_ERROR_RERROR);
		jmGDInterfaceSetFont = getJMethod(env, jc, "gdcSetFont", "(DDDILjava/lang/String;)V", RJ_ERROR_RERROR);
		jcGDInterface = jc;
	}
	
	jc = getJClass(env, customClass, (RJ_ERROR_RERROR | RJ_GLOBAL_REF));
	{	jmethodID jm = (*env)->GetMethodID(env, jc, "<init>", "()V");
		if (!jm) {
			(*env)->DeleteLocalRef(env, jc);  
			handleJError(env, RJ_ERROR_RERROR, "Cannot find default constructor for GD class '%s'.", customClass);
		}
		jo = (*env)->NewObject(env, jc, jm);
		if (!jo) {
			(*env)->DeleteLocalRef(env, jc);  
			handleJError(env, RJ_ERROR_RERROR, "Cannot instantiate object of GD class '%s'.", customClass);
		}
	}
	
	xd->talk = (*env)->NewGlobalRef(env, jo);
	(*env)->DeleteLocalRef(env, jo);
	xd->talkClass = jc;
	
	if (!xd->talk) {
		chkX(env);
		gdWarning("Rjgd_NewDevice: talk is null");
		return FALSE;
	}
	
	return TRUE;
}
bool isHBaseAvailable()
{
  static bool sv_class_initialized = false;
  static bool sv_methods_initialized = false;
  static jclass sv_jclass_class;

  char lv_class_name[] = "CheckHBase";
  jthrowable jexception;

  if (initJVM() != TestJOI_OK) {
    exit(1);
  }
  
  if (! sv_class_initialized) {

    sv_jclass_class = _tlp_jenv->FindClass(lv_class_name); 

    if (_tlp_jenv->ExceptionCheck()) {
      _tlp_jenv->ExceptionDescribe();
      _tlp_jenv->ExceptionClear();
      exit(1);
    }
  
    if (sv_jclass_class == 0) {
      exit(1);
    }

    sv_class_initialized = true;

  }

  if (! sv_methods_initialized) {

    CheckHBJavaMethods_[JM_ISHBASEAVAILABLE].jm_name      = "isHBaseAvailable";
    CheckHBJavaMethods_[JM_ISHBASEAVAILABLE].jm_signature = "()Z";
    CheckHBJavaMethods_[JM_ISHBASEAVAILABLE].methodID     = 
      _tlp_jenv->GetStaticMethodID(sv_jclass_class,
				   CheckHBJavaMethods_[JM_ISHBASEAVAILABLE].jm_name.data(),
				   CheckHBJavaMethods_[JM_ISHBASEAVAILABLE].jm_signature.data());

    if (CheckHBJavaMethods_[JM_ISHBASEAVAILABLE].methodID == 0 || _tlp_jenv->ExceptionCheck()) { 
      _tlp_jenv->ExceptionDescribe();
      _tlp_jenv->ExceptionClear();
      exit(1);
    }      

    sv_methods_initialized = true;
  }

  jlong j_tid = 100;         ;
  jboolean jv_ret = _tlp_jenv->CallStaticBooleanMethod(sv_jclass_class,
						       CheckHBJavaMethods_[JM_ISHBASEAVAILABLE].methodID);

  jexception = _tlp_jenv->ExceptionOccurred();
  if(jexception) {
    _tlp_jenv->ExceptionDescribe();
    _tlp_jenv->ExceptionClear();
    exit(1);
  }

  return jv_ret;
}
JOI_RetCode JavaObjectInterfaceTM::init(char*           className, 
                                      jclass          &javaClass,
                                      JavaMethodInit* JavaMethods, 
                                      int32           howManyMethods,
                                      bool            methodsInitialized)
{
  if (isInitialized_)
    return JOI_OK;
  
  JOI_RetCode retCode = JOI_OK;
    
  // Make sure the JVM environment is set up correctly.
  retCode = initJVM();
  if (retCode != JOI_OK)
    return retCode;
        
  if (methodsInitialized == false || javaObj_ == NULL)
  {
    // Initialize the class pointer
    jclass javaClass = _tlp_jenv->FindClass(className); 
    if (_tlp_jenv->ExceptionCheck()) 
    {
      fprintf(stderr,"FindClass failed. javaClass %p.\n", javaClass);
      _tlp_jenv->ExceptionDescribe();
      _tlp_jenv->ExceptionClear();
      return JOI_ERROR_FINDCLASS;
    }
    
    if (javaClass == 0) 
    {
      return JOI_ERROR_FINDCLASS;
    }
    
    // Initialize the method pointers.
    if (!methodsInitialized)
    {
      for (int i=0; i<howManyMethods; i++)
      {
        JavaMethods[i].methodID = _tlp_jenv->GetMethodID(javaClass, 
                                                     JavaMethods[i].jm_name.data(), 
                                                     JavaMethods[i].jm_signature.data());
        if (JavaMethods[i].methodID == 0 || _tlp_jenv->ExceptionCheck())
        { 
          fprintf(stderr,"GetMethodID failed returning error. javaClass %p, i %d, "
                 "name %s, signature %s.\n", javaClass, i, 
                 JavaMethods[i].jm_name.data(), JavaMethods[i].jm_signature.data());
          _tlp_jenv->ExceptionDescribe();
          _tlp_jenv->ExceptionClear();
          _tlp_jenv->DeleteLocalRef(javaClass);  
          return JOI_ERROR_GETMETHOD;
        }      
      }
    }
    
    if (javaObj_ == NULL)
    {
      // Allocate an object of the Java class, and call its constructor.
      // The constructor must be the first entry in the methods array.
      javaObj_ = _tlp_jenv->NewObject(javaClass, JavaMethods[0].methodID);
      if (javaObj_ == 0 || _tlp_jenv->ExceptionCheck())
      { 
        _tlp_jenv->ExceptionDescribe();
        _tlp_jenv->ExceptionClear();
        _tlp_jenv->DeleteLocalRef(javaClass);  
        return JOI_ERROR_NEWOBJ;
      }
      javaObj_ = _tlp_jenv->NewGlobalRef(javaObj_);
    }
       
    _tlp_jenv->DeleteLocalRef(javaClass);  
  }  
  
  isInitialized_ = true;
  return JOI_OK;
}
Esempio n. 10
0
int initJavaGD(newJavaGDDesc* xd) {
    JNIEnv *env=getJNIEnv();

    if (!jvm) {
        initJVM(jarClassPath);
        env=getJNIEnv();
    }
            
    if (!env) return -1;
    
    {
      jobject o = 0;
      int releaseO = 1;
      jmethodID mid;
      jclass c=0;
      char *customClass=getenv("JAVAGD_CLASS_NAME");
      if (!getenv("JAVAGD_USE_RJAVA")) {
	if (customClass) { c=(*env)->FindClass(env, customClass); chkX(env); }
	if (!c) { c=(*env)->FindClass(env, "org/rosuda/javaGD/JavaGD"); chkX(env); }
	if (!c) { c=(*env)->FindClass(env, "JavaGD"); chkX(env); }
      }
      if (!c) {
	/* use rJava to instantiate the JavaGD class */
	SEXP cl;
	int  te;
	if (!customClass || !*customClass) customClass="org/rosuda/javaGD/JavaGD";
	/* require(rJava) to make sure it's loaded */
	cl = R_tryEval(lang2(install("require"), install("rJava")), R_GlobalEnv, &te);
	if (te == 0 && asLogical(cl)) { /* rJava is available and loaded */
	  /* if .jniInitialized is FALSE then no one actually loaded rJava before, so */
	  cl = eval(lang2(install(".jnew"), mkString(customClass)), R_GlobalEnv);
	  chkX(env);
	  if (cl != R_NilValue && inherits(cl, "jobjRef")) {
	    o = (jobject) R_ExternalPtrAddr(GET_SLOT(cl, install("jobj")));
	    releaseO = 0;
	    c = (*env)->GetObjectClass(env, o);
	  }
	}
      }
      if (!c && !o) error("Cannot find JavaGD class.");
      if (!o) {
	mid=(*env)->GetMethodID(env, c, "<init>", "()V");
        if (!mid) {
            (*env)->DeleteLocalRef(env, c);  
            error("Cannot find default JavaGD contructor.");
        }
        o=(*env)->NewObject(env, c, mid);
        if (!o) {
	  (*env)->DeleteLocalRef(env, c);  
	  error("Connot instantiate JavaGD object.");
        }
      }

      xd->talk = (*env)->NewGlobalRef(env, o);
      xd->talkClass = (*env)->NewGlobalRef(env, c);
      (*env)->DeleteLocalRef(env, c);
      if (releaseO) (*env)->DeleteLocalRef(env, o);
    }
    
    return 0;
}