com.sun.jna.Native.cacheOptions()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(153)

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

Native.cacheOptions介绍

暂无

代码示例

代码示例来源:origin: net.java.dev.jna/jna

private static Map<String, Object> cacheOptions(Class<?> cls, Map<String, ?> options, Object proxy) {
  Map<String, Object> libOptions = new HashMap<String, Object>(options);
  libOptions.put(_OPTION_ENCLOSING_LIBRARY, cls);
  typeOptions.put(cls, libOptions);
  if (proxy != null) {
    libraries.put(cls, new WeakReference<Object>(proxy));
  }
  // If it's a direct mapping, AND implements a Library interface,
  // cache the library interface as well, so that any nested
  // classes get the appropriate associated options
  if (!cls.isInterface()
    && Library.class.isAssignableFrom(cls)) {
    Class<?> ifaces[] = cls.getInterfaces();
    for (Class<?> ifc : ifaces) {
      if (Library.class.isAssignableFrom(ifc)) {
        cacheOptions(ifc, libOptions, proxy);
        break;
      }
    }
  }
  return libOptions;
}

代码示例来源:origin: net.java.dev.jna/jna

/**
 * Provided for improved compatibility between JNA 4.X and 5.X
 *
 * @see Native#load(java.lang.String, java.lang.Class, java.util.Map)
 */
@Deprecated
public static <T> T loadLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) {
  if (!Library.class.isAssignableFrom(interfaceClass)) {
    // Maybe still possible if the caller is not using generics?
    throw new IllegalArgumentException("Interface (" + interfaceClass.getSimpleName() + ")"
        + " of library=" + name + " does not extend " + Library.class.getSimpleName());
  }
  Library.Handler handler = new Library.Handler(name, interfaceClass, options);
  ClassLoader loader = interfaceClass.getClassLoader();
  Object proxy = Proxy.newProxyInstance(loader, new Class[] {interfaceClass}, handler);
  cacheOptions(interfaceClass, options, proxy);
  return interfaceClass.cast(proxy);
}

代码示例来源:origin: net.java.dev.jna/jna

/** Load a library interface from the given shared library, providing
 * the explicit interface class and a map of options for the library.
 * If no library options are detected the map is interpreted as a map
 * of Java method names to native function names.<p>
 * If <code>name</code> is null, attempts to map onto the current process.
 * Native libraries loaded via this method may be found in
 * <a href="NativeLibrary.html#library_search_paths">several locations</a>.
 * @param <T> Type of expected wrapper
 * @param name Library base name
 * @param interfaceClass The implementation wrapper interface
 * @param options Map of library options
 * @return an instance of the requested interface, mapped to the indicated
 * native library.
 * @throws UnsatisfiedLinkError if the library cannot be found or
 * dependent libraries are missing.
 */
public static <T extends Library> T load(String name, Class<T> interfaceClass, Map<String, ?> options) {
  if (!Library.class.isAssignableFrom(interfaceClass)) {
    // Maybe still possible if the caller is not using generics?
    throw new IllegalArgumentException("Interface (" + interfaceClass.getSimpleName() + ")"
        + " of library=" + name + " does not extend " + Library.class.getSimpleName());
  }
  Library.Handler handler = new Library.Handler(name, interfaceClass, options);
  ClassLoader loader = interfaceClass.getClassLoader();
  Object proxy = Proxy.newProxyInstance(loader, new Class[] {interfaceClass}, handler);
  cacheOptions(interfaceClass, options, proxy);
  return interfaceClass.cast(proxy);
}

代码示例来源:origin: net.java.dev.jna/jna

libraryOptions.put(Library.OPTION_STRING_ENCODING, lookupField(mappingClass, "STRING_ENCODING", String.class));
libraryOptions = cacheOptions(mappingClass, libraryOptions, null);

代码示例来源:origin: net.java.dev.jna/jna

TypeMapper mapper = (TypeMapper) options.get(Library.OPTION_TYPE_MAPPER);
boolean allowObjects = Boolean.TRUE.equals(options.get(Library.OPTION_ALLOW_OBJECTS));
options = cacheOptions(cls, options, null);

代码示例来源:origin: org.elasticsearch/jna

private static Map<String, Object> cacheOptions(Class<?> cls, Map<String, ?> options, Object proxy) {
  Map<String, Object> libOptions = new HashMap<String, Object>(options);
  libOptions.put(_OPTION_ENCLOSING_LIBRARY, cls);
  synchronized(libraries) {
    typeOptions.put(cls, libOptions);
    if (proxy != null) {
      libraries.put(cls, new WeakReference<Object>(proxy));
    }
    // If it's a direct mapping, AND implements a Library interface,
    // cache the library interface as well, so that any nested
    // classes get the appropriate associated options
    if (!cls.isInterface()
      && Library.class.isAssignableFrom(cls)) {
      Class<?> ifaces[] = cls.getInterfaces();
      for (Class<?> ifc : ifaces) {
        if (Library.class.isAssignableFrom(ifc)) {
          cacheOptions(ifc, libOptions, proxy);
          break;
        }
      }
    }
  }
  return libOptions;
}

代码示例来源:origin: org.elasticsearch/jna

/** Load a library interface from the given shared library, providing
 * the explicit interface class and a map of options for the library.
 * If no library options are detected the map is interpreted as a map
 * of Java method names to native function names.<p>
 * If <code>name</code> is null, attempts to map onto the current process.
 * Native libraries loaded via this method may be found in
 * <a href="NativeLibrary.html#library_search_paths">several locations</a>.
 * @param <T> Type of expected wrapper
 * @param name Library base name
 * @param interfaceClass The implementation wrapper interface
 * @param options Map of library options
 * @return an instance of the requested interface, mapped to the indicated
 * native library.
 * @throws UnsatisfiedLinkError if the library cannot be found or
 * dependent libraries are missing.
 */
public static <T> T loadLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) {
  if (!Library.class.isAssignableFrom(interfaceClass)) {
    throw new IllegalArgumentException("Interface (" + interfaceClass.getSimpleName() + ")"
        + " of library=" + name + " does not extend " + Library.class.getSimpleName());
  }
  Library.Handler handler = new Library.Handler(name, interfaceClass, options);
  ClassLoader loader = interfaceClass.getClassLoader();
  Object proxy = Proxy.newProxyInstance(loader, new Class[] {interfaceClass}, handler);
  cacheOptions(interfaceClass, options, proxy);
  return interfaceClass.cast(proxy);
}

代码示例来源:origin: org.elasticsearch/jna

libraryOptions.put(Library.OPTION_STRING_ENCODING, lookupField(mappingClass, "STRING_ENCODING", String.class));
libraryOptions = cacheOptions(mappingClass, libraryOptions, null);

代码示例来源:origin: org.elasticsearch/jna

TypeMapper mapper = (TypeMapper) options.get(Library.OPTION_TYPE_MAPPER);
boolean allowObjects = Boolean.TRUE.equals(options.get(Library.OPTION_ALLOW_OBJECTS));
options = cacheOptions(cls, options, null);

相关文章

Native类方法