org.jruby.Ruby.getJRubyClassLoader()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中org.jruby.Ruby.getJRubyClassLoader方法的一些代码示例,展示了Ruby.getJRubyClassLoader的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.getJRubyClassLoader方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:getJRubyClassLoader

Ruby.getJRubyClassLoader介绍

暂无

代码示例

代码示例来源:origin: org.jruby/jruby-complete

@Override
  protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
    return Class.forName(desc.getName(), true, runtime.getJRubyClassLoader());
  }
}

代码示例来源:origin: org.jruby/jruby-core

@Override
  protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
    return Class.forName(desc.getName(), true, runtime.getJRubyClassLoader());
  }
}

代码示例来源:origin: org.jruby/jruby-complete

protected Class<?> resolveClass(ObjectStreamClass desc)
    throws IOException, ClassNotFoundException
  {
    String name = desc.getName();
    try {
      return Class.forName(name, false, runtime.getJRubyClassLoader());
    } catch (ClassNotFoundException ex) {
      return super.resolveClass(desc);
    }
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

protected Class<?> resolveClass(ObjectStreamClass desc)
    throws IOException, ClassNotFoundException
  {
    String name = desc.getName();
    try {
      return Class.forName(name, false, runtime.getJRubyClassLoader());
    } catch (ClassNotFoundException ex) {
      return super.resolveClass(desc);
    }
  }
}

代码示例来源:origin: org.jruby/jruby-core

public static URL getResourceURL(Ruby runtime, String location) {
  if (location.startsWith(URI_CLASSLOADER)) {
    return runtime.getJRubyClassLoader().getResource(location.substring(URI_CLASSLOADER.length() + 1));
  }
  try {
    return new URL(location.replaceFirst("^" + URI, ""));
  }
  catch (MalformedURLException e) {
    throw new AssertionError("BUG in " + URLResource.class, e);
  }
}

代码示例来源:origin: org.jruby/jruby-complete

public static URL getResourceURL(Ruby runtime, String location) {
  if (location.startsWith(URI_CLASSLOADER)) {
    return runtime.getJRubyClassLoader().getResource(location.substring(URI_CLASSLOADER.length() + 1));
  }
  try {
    return new URL(location.replaceFirst("^" + URI, ""));
  }
  catch (MalformedURLException e) {
    throw new AssertionError("BUG in " + URLResource.class, e);
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public Class loadJavaClass(String className) throws ClassNotFoundException {
  Class primitiveClass;
  if ((primitiveClass = PRIMITIVE_CLASSES.get(className)) == null) {
    if (!Ruby.isSecurityRestricted()) {
      return Class.forName(className, true, runtime.getJRubyClassLoader());
    }
    return Class.forName(className);
  }
  return primitiveClass;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public Class loadJavaClass(String className) throws ClassNotFoundException {
  Class primitiveClass;
  if ((primitiveClass = PRIMITIVE_CLASSES.get(className)) == null) {
    if (!Ruby.isSecurityRestricted()) {
      return Class.forName(className, true, runtime.getJRubyClassLoader());
    }
    return Class.forName(className);
  }
  return primitiveClass;
}

代码示例来源:origin: org.jruby/jruby-complete

/**
 * @return the configured {@link org.jruby.runtime.profile.ProfilingService} class.
 */
@SuppressWarnings( "unchecked" )
private Class<? extends ProfilingService> loadServiceClass() {
  ClassLoader cl = getRuntime().getJRubyClassLoader();
  try {
    return (Class<? extends ProfilingService>) cl.loadClass( getServiceClassName() );
  } catch (ClassNotFoundException e) {
    throw new RuntimeException( "Can't load service service class. " + e.getClass().getSimpleName() + ": " + e.getMessage() );
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public static JavaProxyClass getProxyClass(Ruby runtime, Class superClass,
    Class[] interfaces, Set names) throws InvocationTargetException {
  Ruby save = runtimeTLS.get();
  runtimeTLS.set(runtime);
  try {
    ClassLoader loader = runtime.getJRubyClassLoader();
    
    return runtime.getJavaProxyClassFactory().newProxyClass(runtime, loader, null, superClass, interfaces, names);
  } finally {
    runtimeTLS.set(save);
  }
}

代码示例来源:origin: org.jruby/jruby-complete

public void defineAnnotatedMethod(Class clazz, String name) {
  // FIXME: This is probably not very efficient, since it loads all methods for each call
  boolean foundMethod = false;
  for (Method method : clazz.getDeclaredMethods()) {
    if (method.getName().equals(name) && defineAnnotatedMethod(method, MethodFactory.createFactory(getRuntime().getJRubyClassLoader()))) {
      foundMethod = true;
    }
  }
  if (!foundMethod) {
    throw new RuntimeException("No JRubyMethod present for method " + name + "on class " + clazz.getName());
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public void defineAnnotatedMethod(Class clazz, String name) {
  // FIXME: This is probably not very efficient, since it loads all methods for each call
  boolean foundMethod = false;
  for (Method method : clazz.getDeclaredMethods()) {
    if (method.getName().equals(name) && defineAnnotatedMethod(method, MethodFactory.createFactory(getRuntime().getJRubyClassLoader()))) {
      foundMethod = true;
    }
  }
  if (!foundMethod) {
    throw new RuntimeException("No JRubyMethod present for method " + name + "on class " + clazz.getName());
  }
}

代码示例来源:origin: org.jruby/jruby-complete

private void doSetContextClassLoader(Ruby runtime) {
  // set thread context JRuby classloader here, for the main thread
  try {
    Thread.currentThread().setContextClassLoader(runtime.getJRubyClassLoader());
  } catch (SecurityException se) {
    // can't set TC classloader
    if (runtime.getInstanceConfig().isVerbose()) {
      config.getError().println("WARNING: Security restrictions disallowed setting context classloader for main thread.");
    }
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

private void doSetContextClassLoader(Ruby runtime) {
  // set thread context JRuby classloader here, for the main thread
  try {
    Thread.currentThread().setContextClassLoader(runtime.getJRubyClassLoader());
  } catch (SecurityException se) {
    // can't set TC classloader
    if (runtime.getInstanceConfig().isVerbose()) {
      config.getError().println("WARNING: Security restrictions disallowed setting context classloader for main thread.");
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(module = true, rest = true, optional = 1) // (loader = JRuby.runtime.jruby_class_loader)
public static IRubyObject set_context_class_loader(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
  final ClassLoader loader;
  if (args.length == 0 || args[0] == context.nil) {
    loader = context.runtime.getJRubyClassLoader();
  }
  else {
    loader = JavaUtil.unwrapJavaObject(args[0]);
  }
  java.lang.Thread.currentThread().setContextClassLoader(loader);
  return Java.wrapJavaObject(context.runtime, loader); // reference0
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/**
 * Try to compile the code associated with the given Node, returning an
 * instance of the successfully-compiled Script or null if the script could
 * not be compiled.
 *
 * @param node The node to attempt to compiled
 * @return an instance of the successfully-compiled Script, or null.
 */
public Script tryCompile(Node node) {
  return tryCompile(node, null, new JRubyClassLoader(getJRubyClassLoader()), false);
}

代码示例来源:origin: org.jruby/jruby-complete

/**
 * Try to compile the code associated with the given Node, returning an
 * instance of the successfully-compiled Script or null if the script could
 * not be compiled.
 *
 * @param node The node to attempt to compiled
 * @return an instance of the successfully-compiled Script, or null.
 */
public Script tryCompile(Node node) {
  return tryCompile((RootNode) node, new ClassDefiningJRubyClassLoader(getJRubyClassLoader())).script();
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public void load(Ruby runtime, boolean wrap) {
    try {
      URL jarFile = resource.getURL();

      // Make Java class files in the jar reachable from Ruby
      runtime.getJRubyClassLoader().addURL(jarFile);
    } catch (IOException e) {
      throw runtime.newIOErrorFromException(e);
    }
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public void load(Ruby runtime, boolean wrap) {
    try {
      URL jarFile = resource.getURL();

      // Make Java class files in the jar reachable from Ruby
      runtime.getJRubyClassLoader().addURL(jarFile);
    } catch (IOException e) {
      throw runtime.newIOErrorFromException(e);
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod
public IRubyObject each(Block block) {
  final ThreadContext context = getRuntime().getCurrentContext();
  URL[] urls = context.runtime.getJRubyClassLoader().getURLs();
  for(int i=0,j=urls.length;i<j;i++) {
    block.yield(context, context.runtime.newString(urls[i].toString()));
  }
  return context.nil;
}

相关文章

微信公众号

最新文章

更多

Ruby类方法