Пример #1
0
    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");
        }
    }
Пример #2
0
        public static void lazyDefinePackages(global::java.lang.ClassLoader _this)
        {
#if !FIRST_PASS
            AssemblyClassLoader_             wrapper  = (AssemblyClassLoader_)ClassLoaderWrapper.GetClassLoaderWrapper(_this);
            global::java.net.URL             sealBase = GetCodeBase(wrapper.MainAssembly);
            global::java.util.jar.Manifest   manifest = GetManifest(_this);
            global::java.util.jar.Attributes attr     = null;
            if (manifest != null)
            {
                attr = manifest.getMainAttributes();
            }
            string[] packages = wrapper.GetPackages();
            for (int i = 0; i < packages.Length; i++)
            {
                string name = packages[i];
                if (_this.getPackage(name) == null)
                {
                    global::java.util.jar.Attributes entryAttr = null;
                    if (manifest != null)
                    {
                        entryAttr = manifest.getAttributes(name.Replace('.', '/') + '/');
                    }
                    _this.definePackage(name,
                                        GetAttributeValue(global::java.util.jar.Attributes.Name.SPECIFICATION_TITLE, entryAttr, attr),
                                        GetAttributeValue(global::java.util.jar.Attributes.Name.SPECIFICATION_VERSION, entryAttr, attr),
                                        GetAttributeValue(global::java.util.jar.Attributes.Name.SPECIFICATION_VENDOR, entryAttr, attr),
                                        GetAttributeValue(global::java.util.jar.Attributes.Name.IMPLEMENTATION_TITLE, entryAttr, attr),
                                        GetAttributeValue(global::java.util.jar.Attributes.Name.IMPLEMENTATION_VERSION, entryAttr, attr),
                                        GetAttributeValue(global::java.util.jar.Attributes.Name.IMPLEMENTATION_VENDOR, entryAttr, attr),
                                        "true".Equals(GetAttributeValue(global::java.util.jar.Attributes.Name.SEALED, entryAttr, attr), StringComparison.OrdinalIgnoreCase) ? sealBase : null);
                }
            }
#endif
        }
Пример #3
0
 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
 }
Пример #4
0
        public static int GetGenericClassLoaderId(object classLoader)
        {
#if FIRST_PASS
            return(0);
#else
            return(ClassLoaderWrapper.GetGenericClassLoaderId(ClassLoaderWrapper.GetClassLoaderWrapper(classLoader)));
#endif
        }
Пример #5
0
        public static string GetGenericClassLoaderName(object classLoader)
        {
#if FIRST_PASS
            return(null);
#else
            return(((GenericClassLoader)ClassLoaderWrapper.GetClassLoaderWrapper(classLoader)).GetName());
#endif
        }
Пример #6
0
        public static global::java.net.URL findResource(global::java.lang.ClassLoader _this, string name)
        {
#if !FIRST_PASS
            AssemblyClassLoader_ wrapper = (AssemblyClassLoader_)ClassLoaderWrapper.GetClassLoaderWrapper(_this);
            foreach (global::java.net.URL url in wrapper.FindResources(name))
            {
                return(url);
            }
#endif
            return(null);
        }
Пример #7
0
    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);
    }
Пример #8
0
    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);
    }
Пример #9
0
 public static global::java.lang.Class LoadClass(object classLoader, Assembly assembly, string name)
 {
     try
     {
         TypeWrapper tw = null;
         if (classLoader == null)
         {
             tw = ClassLoaderWrapper.GetBootstrapClassLoader().LoadClassByDottedName(name);
         }
         else if (assembly != null)
         {
             AssemblyClassLoader_ acl = global::IKVM.Internal.AssemblyClassLoader.FromAssembly(assembly);
             tw = acl.GetLoadedClass(name);
             if (tw == null)
             {
                 tw = acl.LoadGenericClass(name);
             }
             if (tw == null)
             {
                 tw = acl.LoadReferenced(name);
             }
             if (tw == null)
             {
                 throw new ClassNotFoundException(name);
             }
         }
         else
         {
             // this must be a GenericClassLoader
             tw = ((GenericClassLoader)ClassLoaderWrapper.GetClassLoaderWrapper(classLoader)).LoadClassByDottedName(name);
         }
         Tracer.Info(Tracer.ClassLoading, "Loaded class \"{0}\" from {1}", name, classLoader == null ? "boot class loader" : classLoader);
         return(tw.ClassObject);
     }
     catch (RetargetableJavaException x)
     {
         Tracer.Info(Tracer.ClassLoading, "Failed to load class \"{0}\" from {1}", name, classLoader == null ? "boot class loader" : classLoader);
         throw x.ToJava();
     }
 }
Пример #10
0
        public static void lazyDefinePackages(global::java.lang.ClassLoader _this)
        {
#if !FIRST_PASS
            AssemblyClassLoader_ wrapper  = (AssemblyClassLoader_)ClassLoaderWrapper.GetClassLoaderWrapper(_this);
            global::java.net.URL sealBase = GetCodeBase(wrapper.MainAssembly);
            foreach (KeyValuePair <string, string[]> packages in wrapper.GetPackageInfo())
            {
                global::java.util.jar.Manifest   manifest = null;
                global::java.util.jar.Attributes attr     = null;
                if (packages.Key != null)
                {
                    global::java.util.jar.JarFile jarFile = new global::java.util.jar.JarFile(VirtualFileSystem.GetAssemblyResourcesPath(wrapper.MainAssembly) + packages.Key);
                    manifest = jarFile.getManifest();
                }
                if (manifest != null)
                {
                    attr = manifest.getMainAttributes();
                }
                foreach (string name in packages.Value)
                {
                    if (_this.getPackage(name) == null)
                    {
                        global::java.util.jar.Attributes entryAttr = null;
                        if (manifest != null)
                        {
                            entryAttr = manifest.getAttributes(name.Replace('.', '/') + '/');
                        }
                        _this.definePackage(name,
                                            GetAttributeValue(global::java.util.jar.Attributes.Name.SPECIFICATION_TITLE, entryAttr, attr),
                                            GetAttributeValue(global::java.util.jar.Attributes.Name.SPECIFICATION_VERSION, entryAttr, attr),
                                            GetAttributeValue(global::java.util.jar.Attributes.Name.SPECIFICATION_VENDOR, entryAttr, attr),
                                            GetAttributeValue(global::java.util.jar.Attributes.Name.IMPLEMENTATION_TITLE, entryAttr, attr),
                                            GetAttributeValue(global::java.util.jar.Attributes.Name.IMPLEMENTATION_VERSION, entryAttr, attr),
                                            GetAttributeValue(global::java.util.jar.Attributes.Name.IMPLEMENTATION_VENDOR, entryAttr, attr),
                                            "true".Equals(GetAttributeValue(global::java.util.jar.Attributes.Name.SEALED, entryAttr, attr), StringComparison.OrdinalIgnoreCase) ? sealBase : null);
                    }
                }
            }
#endif
        }
Пример #11
0
        public static global::java.lang.Class loadClass(global::java.lang.ClassLoader _this, string name, bool resolve)
        {
#if FIRST_PASS
            return(null);
#else
            try
            {
                if (!global::java.lang.ClassLoader.checkName(name))
                {
                    throw new ClassNotFoundException(name);
                }
                AssemblyClassLoader_ wrapper = (AssemblyClassLoader_)ClassLoaderWrapper.GetClassLoaderWrapper(_this);
                TypeWrapper          tw      = wrapper.LoadClass(name);
                if (tw == null)
                {
                    Tracer.Info(Tracer.ClassLoading, "Failed to load class \"{0}\" from {1}", name, _this);
                    global::java.lang.Throwable.suppressFillInStackTrace = true;
                    throw new global::java.lang.ClassNotFoundException(name);
                }
                Tracer.Info(Tracer.ClassLoading, "Loaded class \"{0}\" from {1}", name, _this);
                return(tw.ClassObject);
            }
            catch (ClassNotFoundException x)
            {
                Tracer.Info(Tracer.ClassLoading, "Failed to load class \"{0}\" from {1}", name, _this);
                throw new global::java.lang.ClassNotFoundException(x.Message);
            }
            catch (ClassLoadingException x)
            {
                Tracer.Info(Tracer.ClassLoading, "Failed to load class \"{0}\" from {1}", name, _this);
                throw x.InnerException;
            }
            catch (RetargetableJavaException x)
            {
                Tracer.Info(Tracer.ClassLoading, "Failed to load class \"{0}\" from {1}", name, _this);
                throw x.ToJava();
            }
#endif
        }
Пример #12
0
 public static global::java.net.URL findResource(global::java.lang.ClassLoader _this, string name)
 {
     return(((GenericClassLoaderWrapper)ClassLoaderWrapper.GetClassLoaderWrapper(_this)).FindResource(name));
 }
Пример #13
0
 public static global::java.util.Enumeration getResources(global::java.lang.ClassLoader _this, string name)
 {
     return(((GenericClassLoaderWrapper)ClassLoaderWrapper.GetClassLoaderWrapper(_this)).GetResources(name));
 }
Пример #14
0
 public static string toString(global::java.lang.ClassLoader _this)
 {
     return(((GenericClassLoaderWrapper)ClassLoaderWrapper.GetClassLoaderWrapper(_this)).GetName());
 }
Пример #15
0
 public static string toString(global::java.lang.ClassLoader _this)
 {
     return(((AssemblyClassLoader_)ClassLoaderWrapper.GetClassLoaderWrapper(_this)).MainAssembly.FullName);
 }
Пример #16
0
        public static global::java.util.Enumeration findResources(global::java.lang.ClassLoader _this, string name)
        {
#if FIRST_PASS
            return(null);
#else
            return(new global::ikvm.runtime.EnumerationWrapper(((AssemblyClassLoader_)ClassLoaderWrapper.GetClassLoaderWrapper(_this)).FindResources(name)));
#endif
        }
Пример #17
0
    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
    }