/// <summary> /// Create information about a new .apk /// NOTE: This constructor is called with ActivityThread's lock held, /// so MUST NOT call back out to the activity manager. /// </summary> /// <remarks> /// Create information about a new .apk /// NOTE: This constructor is called with ActivityThread's lock held, /// so MUST NOT call back out to the activity manager. /// </remarks> public LoadedApk(android.app.ActivityThread activityThread, android.content.pm.ApplicationInfo aInfo, android.content.res.CompatibilityInfo compatInfo, android.app.ActivityThread mainThread, java.lang.ClassLoader baseLoader, bool securityViolation, bool includeCode ) { mActivityThread = activityThread; mApplicationInfo = aInfo; mPackageName = aInfo.packageName; mAppDir = aInfo.sourceDir; mResDir = aInfo.uid == android.os.Process.myUid() ? aInfo.sourceDir : aInfo.publicSourceDir; mSharedLibraries = aInfo.sharedLibraryFiles; mDataDir = aInfo.dataDir; mDataDirFile = mDataDir != null ? new java.io.File(mDataDir) : null; mLibDir = aInfo.nativeLibraryDir; mBaseClassLoader = baseLoader; mSecurityViolation = securityViolation; mIncludeCode = includeCode; mCompatibilityInfo.set(compatInfo); if (mAppDir == null) { if (android.app.ActivityThread.mSystemContext == null) { android.app.ActivityThread.mSystemContext = android.app.ContextImpl.createSystemContext (mainThread); android.app.ActivityThread.mSystemContext.getResources().updateConfiguration(mainThread .getConfiguration(), mainThread.getDisplayMetricsLocked(compatInfo, false), compatInfo ); } //Slog.i(TAG, "Created system resources " // + mSystemContext.getResources() + ": " // + mSystemContext.getResources().getConfiguration()); mClassLoader = android.app.ActivityThread.mSystemContext.getClassLoader(); mResources = android.app.ActivityThread.mSystemContext.getResources(); } }
private Driver ActivateJdbcDriver() { string driver = (string)_keyMapper["JdbcDriverClassName"]; if (driver == null) { driver = (string)_provider.ProviderInfo [ConfigurationConsts.JdbcDriverClassName]; } if (driver != null && driver.Length != 0) { try { java.lang.ClassLoader contextLoader = (java.lang.ClassLoader)AppDomain.CurrentDomain.GetData("GH_ContextClassLoader"); if (contextLoader != null) { return((Driver)contextLoader.loadClass(driver).newInstance()); } return((Driver)java.lang.Class.forName(driver).newInstance()); } catch (java.lang.ClassNotFoundException e) { throw new TypeLoadException(e.Message, e); } catch (java.lang.InstantiationException e) { throw new MemberAccessException(e.Message, e); } catch (java.lang.IllegalAccessException e) { throw new MissingMethodException(e.Message, e); } } return(null); }
internal ClassLoaderWrapper(CodeGenOptions codegenoptions, object javaClassLoader) { this.codegenoptions = codegenoptions; #if !STATIC_COMPILER && !FIRST_PASS && !STUB_GENERATOR this.javaClassLoader = (java.lang.ClassLoader)javaClassLoader; #endif }
private static TypeWrapper LoadTypeWrapper(string clazz, [email protected] callerId) { #if FIRST_PASS return(null); #else try { TypeWrapper context = TypeWrapper.FromClass(callerId.getCallerClass()); TypeWrapper wrapper = ClassLoaderWrapper.FromCallerID(callerId).LoadClassByDottedName(clazz); java.lang.ClassLoader loader = callerId.getCallerClassLoader(); if (loader != null) { loader.checkPackageAccess(wrapper.ClassObject, callerId.getCallerClass().pd); } if (!wrapper.IsAccessibleFrom(context)) { throw new java.lang.IllegalAccessError("Try to access class " + wrapper.Name + " from class " + context.Name); } wrapper.Finish(); return(wrapper); } catch (RetargetableJavaException x) { throw x.ToJava(); } #endif }
private static ClassLoaderWrapper GetGenericClassLoaderByKey(ClassLoaderWrapper[] key) { lock (wrapperLock) { if (genericClassLoaders == null) { genericClassLoaders = new List <GenericClassLoader>(); } foreach (GenericClassLoader loader in genericClassLoaders) { if (loader.Matches(key)) { return(loader); } } object javaClassLoader = null; #if !STATIC_COMPILER && !FIRST_PASS && !STUB_GENERATOR javaClassLoader = DoPrivileged(new AssemblyClassLoader.CreateAssemblyClassLoader(null)); #endif GenericClassLoader newLoader = new GenericClassLoader(key, javaClassLoader); SetWrapperForClassLoader(javaClassLoader, newLoader); genericClassLoaders.Add(newLoader); return(newLoader); } }
static TextReader GetJavaTextReader(string filename) { try { java.lang.ClassLoader cl = (java.lang.ClassLoader) AppDomain.CurrentDomain.GetData("GH_ContextClassLoader"); if (cl == null) { return(null); } string custom = String.Concat("browscap/", filename); java.io.InputStream inputStream = cl.getResourceAsStream(custom); if (inputStream == null) { inputStream = cl.getResourceAsStream(filename); } if (inputStream == null) { return(null); } return(new StreamReader(new System.Web.J2EE.J2EEUtils.InputStreamWrapper(inputStream))); } catch (Exception e) { return(null); } }
internal ClassLoader(java.lang.ClassLoader parentLoader, bool nullAllowed) { if (parentLoader == null && !nullAllowed) { throw new System.ArgumentNullException("Parent ClassLoader may not be null"); } parent = parentLoader; }
internal static object NewAnnotation(java.lang.ClassLoader classLoader, object definition) { #if FIRST_PASS return(null); #else return([email protected](classLoader, definition)); #endif }
internal static TypeWrapper LoadClassNoThrow(ClassLoaderWrapper classLoader, string name) { try { TypeWrapper wrapper = classLoader.LoadClassByDottedNameFast(name); if (wrapper == null) { string elementTypeName = name; if (elementTypeName.StartsWith("[")) { int skip = 1; while (elementTypeName[skip++] == '[') { ; } elementTypeName = elementTypeName.Substring(skip, elementTypeName.Length - skip - 1); } #if STATIC_COMPILER classLoader.IssueMessage(Message.ClassNotFound, elementTypeName); #else Tracer.Error(Tracer.ClassLoading, "Class not found: {0}", elementTypeName); #endif wrapper = new UnloadableTypeWrapper(name); } return(wrapper); } catch (RetargetableJavaException x) { // HACK keep the compiler from warning about unused local GC.KeepAlive(x); #if !STATIC_COMPILER && !FIRST_PASS && !STUB_GENERATOR && !NOEMIT if (Tracer.ClassLoading.TraceError) { java.lang.ClassLoader cl = (java.lang.ClassLoader)classLoader.GetJavaClassLoader(); if (cl != null) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); string sep = ""; while (cl != null) { sb.Append(sep).Append(cl); sep = " -> "; cl = cl.getParent(); } Tracer.Error(Tracer.ClassLoading, "ClassLoader chain: {0}", sb); } Exception m = ikvm.runtime.Util.mapException(x.ToJava()); Tracer.Error(Tracer.ClassLoading, m.ToString() + Environment.NewLine + m.StackTrace); } #endif // !STATIC_COMPILER && !FIRST_PASS && !STUB_GENERATOR return(new UnloadableTypeWrapper(name)); } }
public virtual void setContextClassLoader(java.lang.ClassLoader arg0) { global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv; if (!IsClrObject) { @__env.CallVoidMethod(this.JvmHandle, global::java.lang.Thread._setContextClassLoader13362, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)); } else { @__env.CallNonVirtualVoidMethod(this.JvmHandle, global::java.lang.Thread.staticClass, global::java.lang.Thread._setContextClassLoader13362, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)); } }
public bool LoadFromFile(string fileName) { this.fileName = fileName; Stream fs = null; if (fileName == null || !File.Exists(fileName)) { #if TARGET_J2EE if (fileName != null && fileName.EndsWith("machine.config")) { if (fileName.StartsWith("/")) { fileName = fileName.Substring(1); } java.lang.ClassLoader cl = (java.lang.ClassLoader)AppDomain.CurrentDomain.GetData("GH_ContextClassLoader"); if (cl == null) { return(false); } java.io.InputStream inputStream = cl.getResourceAsStream(fileName); fs = (Stream)IOUtils.getStream(inputStream); } else #endif return(false); } XmlTextReader reader = null; try { if (fs == null) { fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); } reader = new XmlTextReader(fs); InitRead(reader); ReadConfig(reader, false); } catch (ConfigurationException) { throw; } catch (Exception e) { throw new ConfigurationException("Error reading " + fileName, e); } finally { if (reader != null) { reader.Close(); } } return(true); }
public android.app.Application makeApplication(bool forceDefaultAppClass, android.app.Instrumentation instrumentation) { if (mApplication != null) { return(mApplication); } android.app.Application app = null; string appClass = mApplicationInfo.className; if (forceDefaultAppClass || (appClass == null)) { appClass = "android.app.Application"; } try { java.lang.ClassLoader cl = getClassLoader(); android.app.ContextImpl appContext = new android.app.ContextImpl(); appContext.init(this, null, mActivityThread); app = mActivityThread.mInstrumentation.newApplication(cl, appClass, appContext); appContext.setOuterContext(app); } catch (System.Exception e) { if (!mActivityThread.mInstrumentation.onException(app, e)) { throw new java.lang.RuntimeException("Unable to instantiate application " + appClass + ": " + e.ToString(), e); } } mActivityThread.mAllApplications.add(app); mApplication = app; if (instrumentation != null) { try { instrumentation.callApplicationOnCreate(app); } catch (System.Exception e) { if (!instrumentation.onException(app, e)) { throw new java.lang.RuntimeException("Unable to create application " + app.GetType ().FullName + ": " + e.ToString(), e); } } } return(app); }
/// <summary> /// Specify the dir containing your docx4j properties file /// </summary> /// <param name="dir"></param> public static void setDocx4jPropertiesDir(string dir) { ILog log = LogManager.GetCurrentClassLogger(); java.net.URL url = (new java.io.File(dir)).toURL(); //java.net.URL url = new java.net.URL("file:///C:/Users/jharrop/Documents/Visual%20Studio%202010/Projects/docx4j.NET/docx4j.NET/src/samples/resources/"); // also OK java.lang.ClassLoader contextCL = java.lang.Thread.currentThread().getContextClassLoader(); java.lang.ClassLoader urlCL = java.net.URLClassLoader.newInstance(new java.net.URL[] { url }, contextCL); java.lang.Thread.currentThread().setContextClassLoader(urlCL); // you can delete the below if the properties file is being found if (log.IsWarnEnabled && urlCL.getResource("docx4j.properties") == null) { log.Warn(url.toString() + " dir does not appear to contain docx4j.properties!"); } }
internal static object NewAnnotation(java.lang.ClassLoader classLoader, object definition) { #if !FIRST_PASS java.lang.annotation.Annotation ann = null; try { ann = (java.lang.annotation.Annotation)[email protected](classLoader, definition); } catch (java.lang.TypeNotPresentException) { } if (ann != null && sun.reflect.annotation.AnnotationType.getInstance(ann.annotationType()).retention() == java.lang.annotation.RetentionPolicy.RUNTIME) { return(ann); } #endif return(null); }
internal static object NewAnnotationElementValue(java.lang.ClassLoader classLoader, java.lang.Class expectedClass, object definition) { #if FIRST_PASS return(null); #else try { return([email protected](definition, expectedClass, classLoader)); } catch (java.lang.IllegalAccessException) { // TODO this shouldn't be here return(null); } #endif }
public virtual string GetStreamName(string configPath) { if (configPath == MachinePath) { if (map == null) { return(System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile); } else { return(map.MachineConfigFilename); } } else if (configPath == MachineWebPath) { string mdir; if (map == null) #if TARGET_J2EE { // check META-INF/web.config exists java.lang.ClassLoader cl = (java.lang.ClassLoader)AppDomain.CurrentDomain.GetData("GH_ContextClassLoader"); if (cl == null) { return(null); } java.io.InputStream wcs = cl.getResourceAsStream("META-INF/web.config"); if (wcs == null) { return(null); } wcs.close(); return("/META-INF/web.config"); } #else { mdir = Path.GetDirectoryName(System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile); } #endif else { mdir = Path.GetDirectoryName(map.MachineConfigFilename); } return(GetWebConfigFileName(mdir)); }
public void AddLoader(ClassLoader cl) { lock (lc) { if (cl != null) { if (lc.Contains(cl)) { return; } lc.Add(cl); bool added = false; if (cl is AppDomainAssemblyClassLoader) { AppDomainAssemblyClassLoaders.Add((AppDomainAssemblyClassLoader)cl); added = true; } if (cl is AssemblyClassLoader) { AssemblyClassLoaders.Add((AssemblyClassLoader)cl); added = true; } if (cl is ClassPathAssemblyClassLoader) { ClassPathAssemblyClassLoaders.Add((ClassPathAssemblyClassLoader)cl); added = true; } if (!added) { if (cl is MethodUtil) { MethodUtils.Add((MethodUtil)cl); added = true; } else if (cl is URLClassLoader) { URLClassLoaders.Add((URLClassLoader)cl); added = true; } } AddLoader(cl.getParent()); } } }
public static void DestroyRuntime(ServletContext context, IJDBCDriverDeregisterer evidence) { AppDomain servletDomain = (AppDomain)context.getAttribute(J2EEConsts.APP_DOMAIN); if (servletDomain == null) { return; } try { [email protected](servletDomain); Debug.WriteLine("Destroy of GhHttpServlet"); HttpRuntime.Close(); [email protected](evidence); context.removeAttribute(J2EEConsts.APP_DOMAIN); try { FactoryFinder.releaseFactories(); } catch (FacesException) { } java.lang.ClassLoader appClassLoader = vmw.common.TypeUtils.ToClass(evidence).getClassLoader(); IJDBCDriverDeregisterer dereg = evidence; java.util.Enumeration en = java.sql.DriverManager.getDrivers(); while (en.hasMoreElements()) { Object o = en.nextElement(); if (vmw.common.TypeUtils.ToClass(o).getClassLoader() == appClassLoader) { dereg.DeregisterDriver((java.sql.Driver)o); } } java.lang.Thread.currentThread().setContextClassLoader(null); } catch (Exception e) { Debug.WriteLine(String.Format("ERROR in Servlet Destroy {0},{1}", e.GetType(), e.Message)); Debug.WriteLine(e.StackTrace); } finally { [email protected](); } }
public void UnloadHandler(object sender, EventArgs e) { string shutUrl; switch (_policy) { case DerbyShutDownPolicy.Never: return; case DerbyShutDownPolicy.Database: shutUrl = GetConnectionProperty(_connectionString, "JdbcURL"); break; case DerbyShutDownPolicy.System: shutUrl = "JdbcURL=jdbc:derby:"; break; default: case DerbyShutDownPolicy.Default: java.lang.ClassLoader contextLoader = (java.lang.ClassLoader)AppDomain.CurrentDomain.GetData(J2EEConsts.CLASS_LOADER); java.lang.Class klass = contextLoader.loadClass("org.apache.derby.jdbc.EmbeddedDriver"); if (klass == null) { return; } shutUrl = (klass.getClassLoader() == contextLoader) ? "JdbcURL=jdbc:derby:" : GetConnectionProperty(_connectionString, "JdbcURL"); break; } const string shuttingConnection = "JdbcDriverClassName=org.apache.derby.jdbc.EmbeddedDriver;{0};shutdown=true"; if (!String.IsNullOrEmpty(shutUrl)) { try { new OleDbConnection(String.Format(shuttingConnection, shutUrl)).Open(); } catch (Exception ex) { Trace.Write(ex.ToString()); } } }
#pragma warning restore 414, 3021 private static void TestClassLoader() { //using java.lang; //IKVM.Internal.BootstrapClassLoader() ScriptingClassLoader cl = new ScriptingClassLoader(ClassLoader.getSystemClassLoader()); string s = "jpl.fli.term_t"; Class c; try { c = cl.loadClass(s); } catch (java.lang.ClassNotFoundException e) { } catch (java.security.PrivilegedActionException e) { } foreach (var s1 in new Type[] { 1.GetType(), true.GetType(), "".GetType(), typeof(void), 'a'.GetType(), typeof(Type[]), typeof(IComparable <Type>) }) { c = ikvm.runtime.Util.getFriendlyClassFromType(s1); if (c != null) { ConsoleTrace("class: " + c + " from type " + s1.FullName); continue; } ConsoleTrace("cant get " + s1.FullName); } foreach (var s1 in new jpl.JPL().GetType().Assembly.GetTypes()) { c = ikvm.runtime.Util.getFriendlyClassFromType(s1); if (c != null) { //ConsoleTrace("" + c); continue; } ConsoleTrace("cant get " + s1.FullName); } return; }
private static TypeWrapper LoadTypeWrapper(string clazz, [email protected] callerId) { #if FIRST_PASS return(null); #else try { TypeWrapper context = TypeWrapper.FromClass(callerId.getCallerClass()); #if WINRT RuntimeReflectionHelper.Instance.Mark(clazz); #endif System.Diagnostics.Debug.WriteLine("Trying to load " + clazz); TypeWrapper wrapper = null; try { wrapper = ClassLoaderWrapper.FromCallerID(callerId).LoadClassByDottedName(clazz); } catch (NotImplementedException nie) { #if WINRT RuntimeReflectionHelper.Instance.Mark(clazz); #endif System.Diagnostics.Debug.WriteLine("Not implemented " + clazz); throw nie; } java.lang.ClassLoader loader = callerId.getCallerClassLoader(); if (loader != null) { loader.checkPackageAccess(wrapper.ClassObject, callerId.getCallerClass().pd); } if (!wrapper.IsAccessibleFrom(context)) { throw new java.lang.IllegalAccessError("Try to access class " + wrapper.Name + " from class " + context.Name); } wrapper.Finish(); return(wrapper); } catch (RetargetableJavaException x) { throw x.ToJava(); } #endif }
/// <summary> /// Gets an embedded session using the given properties. /// </summary> /// <remarks> /// It is assumed (but not checked) that the given properties /// object requests a session with a res: protocol database /// instance; work is performed toward configuring and locking /// the ambient class loading environment to correctly handle /// searching the transitive closure of <c>ikvmres:</c> /// protocol resources reachable by compile-time reference, /// starting with the assemblies referenced on the call stack, /// as well as the entry level, calling and executing assemblies /// and their related satellite assemblies. /// </remarks> /// <param name="properties">The properties.</param> /// <returns>an embedded session</returns> internal static HsqlSession NewEmbeddedResSession( HsqlProperties properties) { StackTrace trace = new StackTrace(); java.util.Set set = new java.util.HashSet(); foreach (StackFrame frame in trace.GetFrames()) { set.add(frame.GetMethod().DeclaringType.Assembly.FullName); } List <Assembly> startingList = new List <Assembly>(); foreach (string name in set.toArray()) { try { startingList.Add(Assembly.Load(name)); } catch { } } startingList.Add(Assembly.GetExecutingAssembly()); startingList.Add(Assembly.GetCallingAssembly()); if (Assembly.GetEntryAssembly() != null) { startingList.Add(Assembly.GetEntryAssembly()); } java.lang.ClassLoader loader = IkvmResourceLoaderFactory.CreateLoader(startingList); lock (s_resLock) { org.hsqldb.lib.ResourceStreamProvider.setLoader(loader); return(HsqlSession.Factory.NewEmbeddedSession(properties)); } }
public LoadedApk(android.app.ActivityThread activityThread, string name, android.content.Context systemContext, android.content.pm.ApplicationInfo info, android.content.res.CompatibilityInfo compatInfo) { mActivityThread = activityThread; mApplicationInfo = info != null ? info : new android.content.pm.ApplicationInfo(); mApplicationInfo.packageName = name; mPackageName = name; mAppDir = null; mResDir = null; mSharedLibraries = null; mDataDir = null; mDataDirFile = null; mLibDir = null; mBaseClassLoader = null; mSecurityViolation = false; mIncludeCode = true; mClassLoader = systemContext.getClassLoader(); mResources = systemContext.getResources(); mCompatibilityInfo.set(compatInfo); }
// // InitClassLoaderFields // private void InitClassLoaderFields(java.lang.ClassLoader classLoaderObject) { if (_ClassesOffset == -1 || _DomainsOffset == -1) { var classLoaderClass = ((java.lang.Object)(object) classLoaderObject).getClass(); for (;;) { if (classLoaderClass == (java.lang.Class) typeof(java.lang.ClassLoader)) { break; } classLoaderClass = classLoaderClass.getSuperclass(); } _ClassesOffset = Util.JavaUnsafe.objectFieldOffset( classLoaderClass.getDeclaredField("classes")); _DomainsOffset = Util.JavaUnsafe.objectFieldOffset( classLoaderClass.getDeclaredField("domains")); } }
internal static TypeWrapper LoadClassNoThrow(ClassLoaderWrapper classLoader, string name) { try { TypeWrapper wrapper = classLoader.LoadClassByDottedNameFast(name); if (wrapper == null) { Tracer.Error(Tracer.ClassLoading, "Class not found: {0}", name); wrapper = new UnloadableTypeWrapper(name); } return(wrapper); } catch (RetargetableJavaException x) { // HACK keep the compiler from warning about unused local GC.KeepAlive(x); #if !STATIC_COMPILER && !FIRST_PASS && !STUB_GENERATOR if (Tracer.ClassLoading.TraceError) { java.lang.ClassLoader cl = (java.lang.ClassLoader)classLoader.GetJavaClassLoader(); if (cl != null) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); string sep = ""; while (cl != null) { sb.Append(sep).Append(cl); sep = " -> "; cl = cl.getParent(); } Tracer.Error(Tracer.ClassLoading, "ClassLoader chain: {0}", sb); } Exception m = ikvm.runtime.Util.mapException(x.ToJava()); Tracer.Error(Tracer.ClassLoading, m.ToString() + Environment.NewLine + m.StackTrace); } #endif // !STATIC_COMPILER && !FIRST_PASS && !STUB_GENERATOR return(new UnloadableTypeWrapper(name)); } }
public void AddLoader(ClassLoader cl) { lock (lc) { if (cl != null) { if (lc.Contains(cl)) return; lc.Add(cl); bool added = false; if (cl is AppDomainAssemblyClassLoader) { AppDomainAssemblyClassLoaders.Add((AppDomainAssemblyClassLoader)cl); added = true; } if (cl is AssemblyClassLoader) { AssemblyClassLoaders.Add((AssemblyClassLoader)cl); added = true; } if (cl is ClassPathAssemblyClassLoader) { ClassPathAssemblyClassLoaders.Add((ClassPathAssemblyClassLoader)cl); added = true; } if (!added) { if (cl is MethodUtil) { MethodUtils.Add((MethodUtil)cl); added = true; } else if (cl is URLClassLoader) { URLClassLoaders.Add((URLClassLoader)cl); added = true; } } AddLoader(cl.getParent()); } } }
public ScriptingClassLoader(ClassLoader cl) : base(new URL[0], cl) { AddLoader(cl); }
private void InitializeJavaClassLoader() { Assembly assembly = assemblyLoader.Assembly; { Type customClassLoaderClass = null; LoadCustomClassLoaderRedirects(); string assemblyName = assembly.FullName; foreach (KeyValuePair <string, string> kv in customClassLoaderRedirects) { string asm = kv.Key; // FXBUG // We only support matching on the assembly's simple name, // because there appears to be no viable alternative. // There is AssemblyName.ReferenceMatchesDefinition() // but it is completely broken. if (assemblyName.StartsWith(asm + ",")) { try { customClassLoaderClass = Type.GetType(kv.Value, true); } catch (Exception x) { Tracer.Error(Tracer.Runtime, "Unable to load custom class loader {0} specified in app.config for assembly {1}: {2}", kv.Value, assembly, x); } break; } } if (customClassLoaderClass == null) { object[] attribs = assembly.GetCustomAttributes(typeof(CustomAssemblyClassLoaderAttribute), false); if (attribs.Length == 1) { customClassLoaderClass = ((CustomAssemblyClassLoaderAttribute)attribs[0]).Type; } } if (customClassLoaderClass != null) { try { if (!customClassLoaderClass.IsPublic && !customClassLoaderClass.Assembly.Equals(assembly)) { throw new Exception("Type not accessible"); } ConstructorInfo customClassLoaderCtor = customClassLoaderClass.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(Assembly) }, null); if (customClassLoaderCtor == null) { throw new Exception("No constructor"); } if (!customClassLoaderCtor.IsPublic && !customClassLoaderClass.Assembly.Equals(assembly)) { customClassLoaderCtor = null; throw new Exception("Constructor not accessible"); } hasCustomClassLoader = true; // NOTE we're creating an uninitialized instance of the custom class loader here, so that getClassLoader will return the proper object // when it is called during the construction of the custom class loader later on. This still doesn't make it safe to use the custom // class loader before it is constructed, but at least the object instance is available and should anyone cache it, they will get the // right object to use later on. // Note that creating the unitialized instance will (unfortunately) trigger the static initializer. The static initializer can // trigger a call to getClassLoader(), which means we can end up here recursively. java.lang.ClassLoader newJavaClassLoader = (java.lang.ClassLoader)GetUninitializedObject(customClassLoaderClass); if (javaClassLoader == null) // check if we weren't invoked recursively and the nested invocation already did the work { javaClassLoader = newJavaClassLoader; SetWrapperForClassLoader(javaClassLoader, this); DoPrivileged(new CustomClassLoaderCtorCaller(customClassLoaderCtor, javaClassLoader, assembly)); Tracer.Info(Tracer.Runtime, "Created custom assembly class loader {0} for assembly {1}", customClassLoaderClass.FullName, assembly); } else { // we didn't initialize the object, so there is no need to finalize it GC.SuppressFinalize(newJavaClassLoader); } } catch (Exception x) { Tracer.Error(Tracer.Runtime, "Unable to create custom assembly class loader {0} for {1}: {2}", customClassLoaderClass.FullName, assembly, x); } } } if (javaClassLoader == null) { javaClassLoader = (java.lang.ClassLoader)DoPrivileged(new CreateAssemblyClassLoader(assembly)); SetWrapperForClassLoader(javaClassLoader, this); } }
public PrivilegedActionAnonymousInnerClassHelper2(java.beans.EventHandler handler, java.lang.ClassLoader loader, Type[] interfaces) { this.Handler = handler; this.Loader = loader; this.Interfaces = interfaces; }
public SystemClassLoader(java.lang.ClassLoader parent) : base(new AppDomainAssemblyClassLoader(typeof(SystemClassLoader).Assembly)) { }
/// <summary> /// Perform instantiation of the process's /// <see cref="Activity">Activity</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 Activity /// object. /// </param> /// <param name="intent"> /// The Intent object that specified the activity class being /// instantiated. /// </param> /// <returns>The newly instantiated Activity object.</returns> /// <exception cref="java.lang.InstantiationException"></exception> /// <exception cref="System.MemberAccessException"></exception> /// <exception cref="java.lang.ClassNotFoundException"></exception> public virtual android.app.Activity newActivity(java.lang.ClassLoader cl, string className, android.content.Intent intent) { return((android.app.Activity)System.Activator.CreateInstance(cl.loadClass(className ))); }