public static java.lang.ClassLoader latestUserDefinedLoader() { // testing shows that it is cheaper the get the full stack trace and then look at a few frames than getting the frames individually #if !WINRT StackTrace trace = new StackTrace(2, false); for (int i = 0; i < trace.FrameCount; i++) { StackFrame frame = trace.GetFrame(i); MethodBase method = frame.GetMethod(); if (method == null) { continue; } Type type = method.DeclaringType; if (type != null) { TypeWrapper tw = ClassLoaderWrapper.GetWrapperFromType(type); if (tw != null) { ClassLoaderWrapper classLoader = tw.GetClassLoader(); AssemblyClassLoader acl = classLoader as AssemblyClassLoader; if (acl == null || acl.GetAssembly(tw) != typeof(object).Assembly) { java.lang.ClassLoader javaClassLoader = classLoader.GetJavaClassLoader(); if (javaClassLoader != null) { return(javaClassLoader); } } } } } #endif return(null); }
public static java.lang.Class defineClass1(java.lang.ClassLoader thisClassLoader, string name, byte[] b, int off, int len, java.security.ProtectionDomain pd, string source) { // it appears the source argument is only used for trace messages in HotSpot. We'll just ignore it for now. Profiler.Enter("ClassLoader.defineClass"); try { try { ClassLoaderWrapper classLoaderWrapper = ClassLoaderWrapper.GetClassLoaderWrapper(thisClassLoader); ClassFile classFile = new ClassFile(b, off, len, name, classLoaderWrapper.ClassFileParseOptions, null); if (name != null && classFile.Name != name) { #if !FIRST_PASS throw new java.lang.NoClassDefFoundError(name + " (wrong name: " + classFile.Name + ")"); #endif } TypeWrapper type = classLoaderWrapper.DefineClass(classFile, pd); return(type.ClassObject); } catch (RetargetableJavaException x) { throw x.ToJava(); } } finally { Profiler.Leave("ClassLoader.defineClass"); } }
public static java.lang.Class findLoadedClass0(java.lang.ClassLoader thisClassLoader, string name) { #if FIRST_PASS return(null); #else if (name == null) { return(null); } if (thisClassLoader == null) { ClassLoaderWrapper loader = ClassLoaderWrapper.GetClassLoaderWrapper(thisClassLoader); TypeWrapper tw = loader.FindLoadedClass(name); return(tw != null ? tw.ClassObject : null); } Object temp = thisClassLoader.loadedClassesMap.get(name); if (temp == null) { ClassLoaderWrapper loader = ClassLoaderWrapper.GetClassLoaderWrapper(thisClassLoader); TypeWrapper tw = loader.FindLoadedClass(name); java.lang.Class tmp = (tw != null ? tw.ClassObject : null); if (tmp != null) { thisClassLoader.loadedClassesMap.putIfAbsent(name, tmp); } return(tmp); } else { return((java.lang.Class)temp); } #endif }
public static void RegisterAssembly(Assembly assembly, bool bindJVM, java.lang.ClassLoader classLoader) { lock (typeof(Registry)) { JNIEnv env = JNIEnv.ThreadEnv; try { var types = assembly.GetTypes(); foreach (Type type in types) { RegisterType(type, bindJVM, env, classLoader); } } catch (ReflectionTypeLoadException ex) { if (Bridge.Setup.Debug) { Console.WriteLine(ex); Console.WriteLine(); foreach (var exception in ex.LoaderExceptions) { Console.WriteLine(exception); Console.WriteLine(); } } throw; } } }
private static void BindJvm(RegistryRecord record, JNIEnv env, java.lang.ClassLoader classLoader) { RegisterClass(record, env, classLoader); if (record.CLRProxy != null) { if (record.IsJVMClass || Bridge.Setup.BindCLRTypes) { RegisterStaticAndMethods(record, env); if (record.IsDelegate) { MethodInfo methodInfo = record.CLRInterface.GetMethod("Invoke"); ParameterInfo[] parameterInfo = methodInfo.GetParameters(); Type[] param = new Type[parameterInfo.Length]; for (int i = 0; i < param.Length; i++) { param[i] = parameterInfo[i].ParameterType; } record.JVMDelegateInvoke = record.CLRProxy.GetMethod("Invoke", param); } } if (initialized && Bridge.Setup.BindStatic) { RegisterTypeOf(record, env); } } if (initialized) { if (Bridge.Setup.BindNative && record.CLRWrapper != null) { RegisterNative(record.CLRWrapperInitMethod, env, record.JVMProxy, record.JVMInterface); } RegisterClassToMap(record); record.JVMBound = true; } }
/*public DotnetClassTypeResolver(List imports) : base(null) { new DotnetClassTypeResolver(imports, null); }*/ public DotnetClassTypeResolver(List imports, ClassLoader appDomain) : base(null, null) { this.imports = imports; if (this.appDomain == null) { this.appDomain = AppDomain.CurrentDomain; } }
public static java.lang.Class defineClass2(java.lang.ClassLoader thisClassLoader, string name, java.nio.ByteBuffer bb, int off, int len, java.security.ProtectionDomain pd, string source) { #if FIRST_PASS return(null); #else byte[] buf = new byte[bb.remaining()]; bb.get(buf); return(defineClass1(thisClassLoader, name, buf, 0, buf.Length, pd, source)); #endif }
public static java.lang.Class findLoadedClass0(java.lang.ClassLoader thisClassLoader, string name) { if (name == null) { return(null); } ClassLoaderWrapper loader = ClassLoaderWrapper.GetClassLoaderWrapper(thisClassLoader); TypeWrapper tw = loader.FindLoadedClass(name); return(tw != null ? tw.ClassObject : null); }
/// <summary> /// Find a package by name in the callers {@code ClassLoader} instance. /// The callers {@code ClassLoader} instance is used to find the package /// instance corresponding to the named class. If the callers /// {@code ClassLoader} instance is null then the set of packages loaded /// by the system {@code ClassLoader} instance is searched to find the /// named package. <para> /// /// Packages have attributes for versions and specifications only if the class /// loader created the package instance with the appropriate attributes. Typically, /// those attributes are defined in the manifests that accompany the classes. /// /// </para> /// </summary> /// <param name="name"> a package name, for example, java.lang. </param> /// <returns> the package of the requested name. It may be null if no package /// information is available from the archive or codebase. </returns> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @CallerSensitive public static Package getPackage(String name) public static Package GetPackage(String name) { ClassLoader l = ClassLoader.GetClassLoader(Reflection.CallerClass); if (l != reflect.AnnotatedElement_Fields.Null) { return(l.GetPackage(name)); } else { return(GetSystemPackage(name)); } }
internal virtual void LoadLibrary0(Class fromClass, String libname) { lock (this) { SecurityManager security = System.SecurityManager; if (security != null) { security.CheckLink(libname); } if (libname.IndexOf((int)System.IO.Path.DirectorySeparatorChar) != -1) { throw new UnsatisfiedLinkError("Directory separator should not appear in library name: " + libname); } ClassLoader.LoadLibrary(fromClass, libname, false); } }
internal virtual void Load0(Class fromClass, String filename) { lock (this) { SecurityManager security = System.SecurityManager; if (security != null) { security.CheckLink(filename); } if (!((new File(filename)).Absolute)) { throw new UnsatisfiedLinkError("Expecting an absolute path of the library: " + filename); } ClassLoader.LoadLibrary(fromClass, filename, true); } }
public static java.lang.Class findBootstrapClass(java.lang.ClassLoader thisClassLoader, string name) { #if FIRST_PASS return(null); #else TypeWrapper tw; try { tw = ClassLoaderWrapper.GetBootstrapClassLoader().LoadClassByDottedNameFast(name); } catch (RetargetableJavaException x) { throw x.ToJava(); } return(tw != null ? tw.ClassObject : null); #endif }
private static void RegisterClass(RegistryRecord record, JNIEnv env, java.lang.ClassLoader classLoader) { string package = record.CLRInterface.Namespace; string className = record.CLRInterface.Name; string interfaceName = record.JVMName; string proxyName; string staticName; if (record.IsJVMClass) { staticName = GetStaticName(package, className, true); proxyName = null; } else if (record.IsInterface) { proxyName = GetProxyName(package, className, true); staticName = GetStaticName(package, className, true); } else if (record.IsDelegate) { proxyName = GetProxyName(package, className, true); staticName = interfaceName; } else { proxyName = interfaceName; staticName = interfaceName; } if (Bridge.Setup.BindCLRTypes || record.IsJVMClass) { record.JVMInterface = LoadClass(interfaceName, env, classLoader); } if (Bridge.Setup.BindStatic) { record.JVMStatic = LoadClass(staticName, env, classLoader); if (proxyName != null) { record.JVMProxy = LoadClass(proxyName, env, classLoader); record.JVMConstructor = GetJVMConstructor(env, record.JVMProxy); knownJVMProxies[record.JVMProxy] = record; knownJVM[record.JVMProxy] = record; } } }
private static void RegisterType(Type type, bool bindJVM, JNIEnv env, java.lang.ClassLoader classLoader) { if (Bridge.Setup.VeryVerbose) { Console.WriteLine("Registration : " + type.FullName); } RegistryRecord record = null; RegisterWrapper(type, ref record); RegisterInterfaceProxy(type, ref record); RegisterClassProxy(type, ref record); if (record != null) { if (bindJVM && !record.JVMBound) { BindJvm(record, env, classLoader); } } }
public static java.lang.Class getPrecompiledProxy(java.lang.ClassLoader classLoader, string proxyName, java.lang.Class[] interfaces) { AssemblyClassLoader acl = ClassLoaderWrapper.GetClassLoaderWrapper(classLoader) as AssemblyClassLoader; if (acl == null) { return(null); } TypeWrapper[] wrappers = new TypeWrapper[interfaces.Length]; for (int i = 0; i < wrappers.Length; i++) { wrappers[i] = TypeWrapper.FromClass(interfaces[i]); } // TODO support multi assembly class loaders Type type = acl.MainAssembly.GetType(TypeNameUtil.GetProxyName(wrappers)); if (type == null) { return(null); } TypeWrapper tw = CompiledTypeWrapper.newInstance(proxyName, type); TypeWrapper tw2 = acl.RegisterInitiatingLoader(tw); if (tw != tw2) { return(null); } // we need to explicitly register the type, because the type isn't visible by normal means tw.GetClassLoader().SetWrapperForType(type, tw); TypeWrapper[] wrappers2 = tw.Interfaces; if (wrappers.Length != wrappers.Length) { return(null); } for (int i = 0; i < wrappers.Length; i++) { if (wrappers[i] != wrappers2[i]) { return(null); } } return(tw.ClassObject); }
private java.lang.ClassLoader createClassLoader() { java.io.File[] jarFiles = this.getGroovyClasspath(); java.net.URL[] jarFilesAsURLs = new java.net.URL[jarFiles.Length]; for (int i = 0; i < jarFiles.Length; i++) { jarFilesAsURLs[i] = jarFiles[i].toURI().toURL(); } java.net.URLClassLoader urlClassLoader = new java.net.URLClassLoader(jarFilesAsURLs, java.lang.ClassLoader.getSystemClassLoader()); java.lang.Class groovyClassLoaderClass = java.lang.Class.forName("groovy.lang.GroovyClassLoader", true, urlClassLoader); java.lang.reflect.Method addClassPathMethod = groovyClassLoaderClass.getMethod("addClasspath", java.lang.Class.forName("java.lang.String")); java.lang.ClassLoader groovyClassLoader = (java.lang.ClassLoader)groovyClassLoaderClass.newInstance(); foreach (java.io.File file in jarFiles) { addClassPathMethod.invoke(groovyClassLoader, file.getAbsolutePath()); } this._groovyClassLoaderClass = groovyClassLoaderClass; return(groovyClassLoader); }
/// <summary> /// Get the package for the specified class. /// The class's class loader is used to find the package instance /// corresponding to the specified class. If the class loader /// is the bootstrap class loader, which may be represented by /// {@code null} in some implementations, then the set of packages /// loaded by the bootstrap class loader is searched to find the package. /// <para> /// Packages have attributes for versions and specifications only /// if the class loader created the package /// instance with the appropriate attributes. Typically those /// attributes are defined in the manifests that accompany /// the classes. /// /// </para> /// </summary> /// <param name="c"> the class to get the package of. </param> /// <returns> the package of the class. It may be null if no package /// information is available from the archive or codebase. </returns> internal static Package GetPackage(Class c) { String name = c.Name; int i = name.LastIndexOf('.'); if (i != -1) { name = name.Substring(0, i); ClassLoader cl = c.ClassLoader; if (cl != reflect.AnnotatedElement_Fields.Null) { return(cl.GetPackage(name)); } else { return(GetSystemPackage(name)); } } else { return(reflect.AnnotatedElement_Fields.Null); } }
private static Class LoadClass(string name, ClassLoader classLoader, JNIEnv env) { Class res = null; if (classLoader == null) { classLoader = systemClassLoader; string rn = name.Replace('.', '/'); res = env.FindClassNoThrow(rn); } if (classLoader != null && res==null) { try { res = classLoader.loadClass(name); } catch (Throwable th) { throw new JNIException("Can't load java class for " + name + " from classLoader " + classLoader, th); } } return res; }
public static void setClassLoader(ClassLoader classLoader) { lock ((object) ClassLiteral<ObjectUtilities>.Value) ObjectUtilities.classLoader = classLoader; }
public static java.lang.Class defineClass0(java.lang.ClassLoader thisClassLoader, string name, byte[] b, int off, int len, java.security.ProtectionDomain pd) { return(defineClass1(thisClassLoader, name, b, off, len, pd, null)); }
/// <summary> /// Sets the context ClassLoader for this Thread. /// </summary> public void setContextClassLoader(ClassLoader cl) { }
public static java.lang.Class defineClass(object thisUnsafe, string name, byte[] buf, int offset, int length, java.lang.ClassLoader cl, java.security.ProtectionDomain pd) { return(Java_java_lang_ClassLoader.defineClass1(cl, name.Replace('/', '.'), buf, offset, length, pd, null)); }
public static int[] getLookupCacheForClassLoader(java.lang.ClassLoader loader, string name) { return(null); }
static Registry() { JNIEnv env = JNIEnv.ThreadEnv; RegisterType(typeof (Class), true, env); RegisterType(typeof (Object), true, env); RegisterType(typeof (String), true, env); RegisterType(typeof (__Type), true, env); RegisterType(typeof (__Object), true, env); RegisterType(typeof (__String), true, env); RegisterType(typeof (__IClrProxy), true, env); initialized = true; BindJvm(knownCLR[typeof (Class)], env); BindJvm(knownCLR[typeof (Object)], env); BindJvm(knownCLR[typeof (String)], env); BindJvm(knownCLR[typeof (__Type)], env); BindJvm(knownCLR[typeof (__Object)], env); BindJvm(knownCLR[typeof (__String)], env); BindJvm(knownCLR[typeof (__IClrProxy)], env); RegisterType(typeof (Boolean), true, env); RegisterType(typeof (Byte), true, env); RegisterType(typeof (Character), true, env); RegisterType(typeof (Short), true, env); RegisterType(typeof (Integer), true, env); RegisterType(typeof (Long), true, env); RegisterType(typeof (Float), true, env); RegisterType(typeof (Double), true, env); RegisterPrimitiveType("boolean", typeof (bool), typeof (Boolean)); RegisterPrimitiveType("byte", typeof (byte), typeof (Byte)); RegisterPrimitiveType("char", typeof (char), typeof (Character)); RegisterPrimitiveType("short", typeof (short), typeof (Short)); RegisterPrimitiveType("int", typeof (int), typeof (Integer)); RegisterPrimitiveType("long", typeof (long), typeof (Long)); RegisterPrimitiveType("float", typeof (float), typeof (Float)); RegisterPrimitiveType("double", typeof (double), typeof (Double)); RegisterPrimitiveType("void", typeof (void), null); Convertor.boolObject = env.GetStaticMethodID(Boolean.staticClass, "valueOf", "(Z)Ljava/lang/Boolean;"); Convertor.byteObject = env.GetStaticMethodID(Byte.staticClass, "valueOf", "(B)Ljava/lang/Byte;"); Convertor.charObject = env.GetStaticMethodID(Character.staticClass, "valueOf", "(C)Ljava/lang/Character;"); Convertor.shortObject = env.GetStaticMethodID(Short.staticClass, "valueOf", "(S)Ljava/lang/Short;"); Convertor.intObject = env.GetStaticMethodID(Integer.staticClass, "valueOf", "(I)Ljava/lang/Integer;"); Convertor.longObject = env.GetStaticMethodID(Long.staticClass, "valueOf", "(J)Ljava/lang/Long;"); Convertor.doubleObject = env.GetStaticMethodID(Double.staticClass, "valueOf", "(D)Ljava/lang/Double;"); Convertor.floatObject = env.GetStaticMethodID(Float.staticClass, "valueOf", "(F)Ljava/lang/Float;"); Convertor.boolValue = env.GetMethodID(Boolean.staticClass, "booleanValue", "()Z"); Convertor.byteValue = env.GetMethodID(Byte.staticClass, "byteValue", "()B"); Convertor.charValue = env.GetMethodID(Character.staticClass, "charValue", "()C"); Convertor.shortValue = env.GetMethodID(Short.staticClass, "shortValue", "()S"); Convertor.intValue = env.GetMethodID(Integer.staticClass, "intValue", "()I"); Convertor.longValue = env.GetMethodID(Long.staticClass, "longValue", "()J"); Convertor.doubleValue = env.GetMethodID(Double.staticClass, "doubleValue", "()D"); Convertor.floatValue = env.GetMethodID(Float.staticClass, "floatValue", "()F"); RegisterType(typeof(__Bridge), true, env); RegisterType(typeof(__Exception), true, env); RegisterType(typeof(Throwable), true, env); RegisterType(typeof(__IJvmProxy), true, env); RegisterType(typeof(ClassLoader), true, env); systemClassLoader = ClassLoader.getSystemClassLoader(); }
/// <summary> /// Returns the <code>Class</code> object associated with the class or /// interface with the given string name, using the given class loader. /// </summary> public Class forName(string @name, bool @initialize, ClassLoader @loader) { return(default(Class)); }
public static void resolveClass0(java.lang.ClassLoader thisClassLoader, java.lang.Class clazz) { // no-op }
public GroovyClassManager(java.io.File groovyHome) { this._groovyHome = groovyHome; this._classLoader = this.createClassLoader(); }
/* * Construct a package using the attributes from the specified manifest. * * @param name the package name * @param man the optional manifest for the package * @param url the optional code source url for the package */ private Package(String name, Manifest man, URL url, ClassLoader loader) { String path = name.Replace('.', '/') + "/"; String @sealed = reflect.AnnotatedElement_Fields.Null; String specTitle = reflect.AnnotatedElement_Fields.Null; String specVersion = reflect.AnnotatedElement_Fields.Null; String specVendor = reflect.AnnotatedElement_Fields.Null; String implTitle = reflect.AnnotatedElement_Fields.Null; String implVersion = reflect.AnnotatedElement_Fields.Null; String implVendor = reflect.AnnotatedElement_Fields.Null; URL sealBase = reflect.AnnotatedElement_Fields.Null; Attributes attr = man.GetAttributes(path); if (attr != reflect.AnnotatedElement_Fields.Null) { specTitle = attr.GetValue(Attributes.Name.SPECIFICATION_TITLE); specVersion = attr.GetValue(Attributes.Name.SPECIFICATION_VERSION); specVendor = attr.GetValue(Attributes.Name.SPECIFICATION_VENDOR); implTitle = attr.GetValue(Attributes.Name.IMPLEMENTATION_TITLE); implVersion = attr.GetValue(Attributes.Name.IMPLEMENTATION_VERSION); implVendor = attr.GetValue(Attributes.Name.IMPLEMENTATION_VENDOR); @sealed = attr.GetValue(Attributes.Name.SEALED); } attr = man.MainAttributes; if (attr != reflect.AnnotatedElement_Fields.Null) { if (specTitle == reflect.AnnotatedElement_Fields.Null) { specTitle = attr.GetValue(Attributes.Name.SPECIFICATION_TITLE); } if (specVersion == reflect.AnnotatedElement_Fields.Null) { specVersion = attr.GetValue(Attributes.Name.SPECIFICATION_VERSION); } if (specVendor == reflect.AnnotatedElement_Fields.Null) { specVendor = attr.GetValue(Attributes.Name.SPECIFICATION_VENDOR); } if (implTitle == reflect.AnnotatedElement_Fields.Null) { implTitle = attr.GetValue(Attributes.Name.IMPLEMENTATION_TITLE); } if (implVersion == reflect.AnnotatedElement_Fields.Null) { implVersion = attr.GetValue(Attributes.Name.IMPLEMENTATION_VERSION); } if (implVendor == reflect.AnnotatedElement_Fields.Null) { implVendor = attr.GetValue(Attributes.Name.IMPLEMENTATION_VENDOR); } if (@sealed == reflect.AnnotatedElement_Fields.Null) { @sealed = attr.GetValue(Attributes.Name.SEALED); } } if ("true".Equals(@sealed, StringComparison.CurrentCultureIgnoreCase)) { sealBase = url; } PkgName = name; this.SpecTitle = specTitle; this.SpecVersion = specVersion; this.SpecVendor = specVendor; this.ImplTitle = implTitle; this.ImplVersion = implVersion; this.ImplVendor = implVendor; this.SealBase = sealBase; this.Loader = loader; }
/// <summary> /// Construct a package instance with the specified version /// information. </summary> /// <param name="name"> the name of the package </param> /// <param name="spectitle"> the title of the specification </param> /// <param name="specversion"> the version of the specification </param> /// <param name="specvendor"> the organization that maintains the specification </param> /// <param name="impltitle"> the title of the implementation </param> /// <param name="implversion"> the version of the implementation </param> /// <param name="implvendor"> the organization that maintains the implementation </param> internal Package(String name, String spectitle, String specversion, String specvendor, String impltitle, String implversion, String implvendor, URL sealbase, ClassLoader loader) { PkgName = name; ImplTitle = impltitle; ImplVersion = implversion; ImplVendor = implvendor; SpecTitle = spectitle; SpecVersion = specversion; SpecVendor = specvendor; SealBase = sealbase; this.Loader = loader; }
private static void RegisterClass(RegistryRecord record, ClassLoader classLoader, JNIEnv env) { string package = record.CLRInterface.Namespace; string className = record.CLRInterface.Name; string interfaceName = record.JVMName; string proxyName; string staticName; if (record.IsJVMClass) { staticName = GetStaticName(package, className, true); proxyName = null; } else if (record.IsInterface) { proxyName = GetProxyName(package, className, true); staticName = GetStaticName(package, className, true); } else if (record.IsDelegate) { proxyName = GetProxyName(package, className, true); staticName = interfaceName; } else { proxyName = interfaceName; staticName = interfaceName; } if (Bridge.Setup.BindCLRTypes || record.IsJVMClass) { record.JVMInterface = LoadClass(interfaceName, classLoader, env); } if (Bridge.Setup.BindStatic) { record.JVMStatic = LoadClass(staticName, classLoader, env); if (proxyName != null) { record.JVMProxy = LoadClass(proxyName, classLoader, env); record.JVMConstructor = GetJVMConstructor(env, record.JVMProxy); knownJVMProxies[record.JVMProxy] = record; knownJVM[record.JVMProxy] = record; } } }
public static ResourceBundle getBundle(string baseName, Locale locale, ClassLoader loader) { return ResourceBundle.getBundle(baseName, locale, loader); }
private static void RegisterType(Type type, bool bindJVM, ClassLoader classLoader, JNIEnv env) { if (Bridge.Setup.VeryVerbose) { Console.WriteLine("Registration : " + type.FullName); } RegistryRecord record = null; RegisterWrapper(type, ref record); RegisterInterfaceProxy(type, ref record); RegisterClassProxy(type, ref record); if (record != null) { if (bindJVM && !record.JVMBound) { BindJvm(record, classLoader, env); } } }
/// <summary> /// Establishes the default bindings of <code>type</code> to /// <code>classname</code>. /// </summary> static public void registerEditorKitForContentType(string @type, string @classname, ClassLoader @loader) { }
public static java.net.URL[] getLookupCacheURLs(java.lang.ClassLoader loader) { return(null); }
/// <summary> /// The value of <code>get(uidClassID)</code> must be the /// <code>String</code> name of a /// class that implements the corresponding <code>ComponentUI</code> /// class. /// </summary> public Class getUIClass(string @uiClassID, ClassLoader @uiClassLoader) { return default(Class); }
public static bool knownToNotExist0(java.lang.ClassLoader loader, string className) { return(false); }
/// <summary> /// Creates a new instance of URLClassLoader for the specified /// URLs and parent class loader. /// </summary> public virtual URLClassLoader newInstance(URL[] @urls, ClassLoader @parent) { return default(URLClassLoader); }
public static void LoadAndRegisterAssemblyFrom(File assemblyFile, ClassLoader classLoader) { string assemblyPath = new Uri(assemblyFile.getCanonicalFile().toURI().toString()).LocalPath; Assembly assembly; if (System.IO.File.Exists(assemblyPath)) { assembly = Assembly.LoadFrom(assemblyPath); } else { string current = Path.Combine(homeDir, assemblyPath); if (System.IO.File.Exists(current)) { assembly = Assembly.LoadFrom(current); } else { throw new FileNotFoundException(assemblyPath); } } if (knownAssemblies.ContainsKey(assembly)) { if (Setup.Verbose) { Console.WriteLine("skipped " + assembly + " from " + assembly.Location); } return; } if (Setup.Verbose) { Console.WriteLine("loading " + assembly + " from " + assembly.Location); } knownAssemblies.Add(assembly, assembly); Registry.RegisterAssembly(assembly, true, classLoader); if (Setup.Verbose) { Console.WriteLine("loaded " + assembly + " from " + assembly.Location); } }
/// <summary> /// Tries to load a class from: the bootstrap loader, the system loader, /// the context loader (if one is present) and finally the loader specified. /// </summary> public Class tryToLoadClass(string @className, ClassLoader @fallback) { return default(Class); }
public static java.lang.Class forName0(string name, bool initialize, java.lang.ClassLoader loader, java.lang.Class caller) { #if FIRST_PASS return(null); #else //Console.WriteLine("forName: " + name + ", loader = " + loader); TypeWrapper tw = null; if (name.IndexOf(',') > 0) { // we essentially require full trust before allowing arbitrary types to be loaded, // hence we do the "createClassLoader" permission check java.lang.SecurityManager sm = java.lang.System.getSecurityManager(); if (sm != null) { sm.checkPermission(new java.lang.RuntimePermission("createClassLoader")); } Type type = Type.GetType(name); if (type != null) { tw = ClassLoaderWrapper.GetWrapperFromType(type); } if (tw == null) { java.lang.Throwable.suppressFillInStackTrace = true; throw new java.lang.ClassNotFoundException(name); } } else { try { ClassLoaderWrapper classLoaderWrapper = ClassLoaderWrapper.GetClassLoaderWrapper(loader); tw = classLoaderWrapper.LoadClassByDottedName(name); } catch (ClassNotFoundException x) { java.lang.Throwable.suppressFillInStackTrace = true; throw new java.lang.ClassNotFoundException(x.Message); } catch (ClassLoadingException x) { throw x.InnerException; } catch (RetargetableJavaException x) { throw x.ToJava(); } } java.security.ProtectionDomain pd; if (loader != null && caller != null && (pd = getProtectionDomain0(caller)) != null) { loader.checkPackageAccess(tw.ClassObject, pd); } if (initialize && !tw.IsArray) { try { tw.Finish(); } catch (RetargetableJavaException x) { throw x.ToJava(); } tw.RunClassInit(); } return(tw.ClassObject); #endif }
private static void BindJvm(RegistryRecord record, ClassLoader classLoader, JNIEnv env) { RegisterClass(record, classLoader, env); if (record.CLRProxy != null) { if (record.IsJVMClass || Bridge.Setup.BindCLRTypes) { RegisterStaticAndMethods(record, env); if (record.IsDelegate) { MethodInfo methodInfo = record.CLRInterface.GetMethod("Invoke"); ParameterInfo[] parameterInfo = methodInfo.GetParameters(); Type[] param=new Type[parameterInfo.Length]; for (int i = 0; i < param.Length; i++) { param[i] = parameterInfo[i].ParameterType; } record.JVMDelegateInvoke = record.CLRProxy.GetMethod("Invoke", param); } } if (initialized && Bridge.Setup.BindStatic) { RegisterTypeOf(record, env); } } if (initialized) { if (Bridge.Setup.BindNative && record.CLRWrapper != null) { RegisterNative(record.CLRWrapperInitMethod, env, record.JVMProxy, record.JVMInterface); } RegisterClassToMap(record); record.JVMBound = true; } }
public MySystemClassLoader(ClassLoader parent) : base(new AppDomainAssemblyClassLoader(typeof (MySystemClassLoader).Assembly)) { //empty (don Comment) }
public SystemClassLoader(ClassLoader parent) : base(new AppDomainAssemblyClassLoader(typeof(SystemClassLoader).Assembly)) { }
public static void LoadAndRegisterAssemblyFromClassLoader(File assemblyFile, ClassLoader classLoader) { string assemblyPath = new Uri(assemblyFile.getCanonicalFile().toURI().toString()).LocalPath; Assembly assembly; if (System.IO.File.Exists(assemblyPath)) { assembly = Assembly.LoadFrom(assemblyPath); } else { string current = Path.Combine(homeDir, assemblyPath); if (System.IO.File.Exists(current)) { assembly = Assembly.LoadFrom(current); } else { throw new FileNotFoundException(assemblyPath); } } RegisterAssembly(assembly, classLoader); }
private static void RegisterAssembly(Assembly assembly, ClassLoader classLoader) { if (knownAssemblies.ContainsKey(assembly)) { if (Setup.Verbose) { Console.WriteLine("skipped " + assembly + " from " + assembly.Location); } return; } if (Setup.Verbose) { Console.WriteLine("loading " + assembly + " from " + assembly.Location); } knownAssemblies.Add(assembly, assembly); Registry.RegisterAssembly(assembly, true, classLoader); if (Setup.Verbose) { Console.WriteLine("loaded " + assembly + " from " + assembly.Location); } }
/** * Standard procedure to compile resources: * 1. Get an AppDomain correspondint to the Classloader. * 2. Create an assembly in the given appdomain * 3. Create a type for each resource, given the className (resourceName), contents (pReader.getBytes(resourceName)), and the AppDomain. * 4. Write the compiled types to the store. */ public override CompilationResult compile( string[] pResourceNames, ResourceReader pReader, ResourceStore pStore, ClassLoader pClassLoader ) { int OFFSETCONSTANT = 8; Type[] types = new Type[pResourceNames.Length]; string[] contents = new string[pResourceNames.Length]; CodeSnippetCompileUnit[] units = new CodeSnippetCompileUnit[pResourceNames.Length]; for (int i = 0; i < types.Length; i++) { string resourceName = pResourceNames[i].Replace('.','/')+".java"; byte[] byteArray = pReader.getBytes(resourceName); string fileContents = this.StringFromBytes(byteArray); units[i] = new CodeSnippetCompileUnit(fileContents.Replace("cli.", "")); if (fileContents.Contains("public static void consequence")) { object[] info = this.GetLinePragmaInfo(fileContents,OFFSETCONSTANT); if(info != null) units[i].LinePragma = new CodeLinePragma(info[0] as string, (int)info[1]); } } CodeDomProvider provider = GetProvider(); CompilerParameters compilerParameters = new CompilerParameters(); compilerParameters.GenerateInMemory = true; compilerParameters.IncludeDebugInformation = true; // compilerParameters.OutputAssembly = pResourceNames[i].Substring(pResourceNames[i].LastIndexOf('.') + 1); int count = 0; foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (assembly.FullName.StartsWith("CompiledRules")) { try { File.Delete(assembly.Location); } catch (System.Exception e) { count++; } } else { compilerParameters.ReferencedAssemblies.Add(assembly.Location); } } compilerParameters.OutputAssembly = "CompiledRules" + count + ".dll"; CompilerResults results = provider.CompileAssemblyFromDom //(compilerParameters, contents); (compilerParameters, units); Collection problems = new ArrayList(); DotnetPackageCompilationData pcData = (DotnetPackageCompilationData) ((PackageStore)pStore).getPackageCompilationData(); MemoryStream stream = new MemoryStream(1024); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, results.CompiledAssembly); for (int i = 0; i < types.Length; i++) { string resourceName = pResourceNames[i]; pcData.write(resourceName, new object[]{results.CompiledAssembly, stream.GetBuffer()}); } CompilationProblem[] result = new CompilationProblem[problems.size()]; return new CompilationResult(result); }
/// <summary> /// Constructs a <code>DataFlavor</code> that represents a /// <code>MimeType</code>. /// </summary> public DataFlavor(string @mimeType, string @humanPresentableName, ClassLoader @classLoader) { }
public static void SetSystemClassLoader(ClassLoader classLoader) { Registry.systemClassLoader = classLoader; }
public DotnetPackageCompilationData(ClassLoader parentClassLoader) : base(parentClassLoader) { }
// one of the jobs of any class loader is to protect the system name space. // The normal ClassLoader heirarchy does address this by always delegating to the parent ClassLoader first, // thus ensuring that duplicate classes are not loaded // If you use custom ClassLoader, do not give the system one a chance to come into play. // http://blog.cyberborean.org/2007/07/04/custom-classloaders-the-black-art-of-java public InternalURLClassLoader(URL[] u, ClassLoader parent) : base(u, parent) { }
public static object defineClass0(java.lang.ClassLoader classLoader, string name, byte[] b, int off, int len) { return(Java_java_lang_ClassLoader.defineClass1(classLoader, name, b, off, len, null, null)); }
public static java.lang.Class defineClass(object thisUnsafe, string name, byte[] buf, int offset, int length, java.lang.ClassLoader cl, java.security.ProtectionDomain pd) { #if FIRST_PASS return(null); #else return(cl.defineClass(name, buf, offset, length, pd)); #endif }
/// <summary> /// Returns the <code>Class</code> object associated with the class or /// interface with the given string name, using the given class loader. /// </summary> public Class forName(string @name, bool @initialize, ClassLoader @loader) { return default(Class); }
///// <summary> ///// Constructs a new URLClassLoader for the specified URLs, parent ///// class loader, and URLStreamHandlerFactory. ///// </summary> //public URLClassLoader(URL[] @urls, ClassLoader @parent, URLStreamHandlerFactory @factory) //{ //} /// <summary> /// Constructs a new URLClassLoader for the given URLs. /// </summary> public URLClassLoader(URL[] @urls, ClassLoader @parent) { }
public static void RegisterAssembly(Assembly assembly, bool bindJVM, ClassLoader classLoader) { lock (typeof (Registry)) { JNIEnv env = JNIEnv.ThreadEnv; try { var types = assembly.GetTypes(); foreach (Type type in types) { RegisterType(type, bindJVM, classLoader, env); } } catch(ReflectionTypeLoadException ex) { if (Bridge.Setup.Debug) { Console.WriteLine(ex); Console.WriteLine(); foreach (var exception in ex.LoaderExceptions) { Console.WriteLine(exception); Console.WriteLine(); } } throw; } } }
/// <summary> /// Perform instantiation of the process's /// <see cref="Application">Application</see> /// object. The /// default implementation provides the normal system behavior. /// </summary> /// <param name="cl">The ClassLoader with which to instantiate the object.</param> /// <param name="className"> /// The name of the class implementing the Application /// object. /// </param> /// <param name="context">The context to initialize the application with</param> /// <returns>The newly instantiated Application object.</returns> /// <exception cref="java.lang.InstantiationException"></exception> /// <exception cref="System.MemberAccessException"></exception> /// <exception cref="System.TypeLoadException"></exception> public virtual Application newApplication (ClassLoader cl, string klass, Context context) { return newApplication (cl.loadClass (klass), context); }