private Class findClass_catch(string name) { var f = Resolve(name); var c = default(Class); //if (name == "com.amazonaws.AmazonWebServiceRequest") if (f == null) { throw new InvalidOperationException(); } //var x = @"C:\util\aws-android-sdk-0.2.0\lib\aws-android-sdk-0.2.0-core.jar"; var x = f.FullName; //Console.WriteLine("will look into: " + x); try { var url = new jvm::java.io.File(x).toURL(); this.addURL(url); } catch (jvm::csharp.ThrowableException cc) { Console.WriteLine("InternalURLClassLoader.findClass_catch error, x: " + x + "; " + cc); throw new InvalidOperationException(); } c = __findClass(name, x); return(c); }
public void LoadFile(string path) { InternalEntries = null; var jar = new FileInfo(path); this.FileName = jar; #region clazzLoader this.clazzLoader = default(InternalURLClassLoader); try { //var filePath = "jar:file://" + jar.FullName + "!/"; // http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html // file:///C:/util/aws-android-sdk-0.2.0/lib/aws-android-sdk-0.2.0-ec2.jar // error @URLClassLoader: java.net.MalformedURLException: unknown protocol: c var url = new jvm::java.io.File(jar.FullName).toURL(); // http://www.javakb.com/Uwe/Forum.aspx/java-programmer/34778/URLClassLoader-ClassNotFoundException // http://www.chinaup.org/docs/reference/java/net/URLClassLoader.html // http://www.docjar.com/html/api/sun/applet/AppletClassLoader.java.html // http://www.docjar.com/html/api/java/net/URLClassLoader.java.html // http://www.docjar.com/html/api/java/security/SecureClassLoader.java.html clazzLoader = new InternalURLClassLoader(new URL[] { url }, null); } catch (jvm::csharp.ThrowableException ex) { Console.WriteLine("error @URLClassLoader: " + ex); throw new InvalidOperationException(); } #endregion //clazzLoader.CacheClassBytes(jar); #region Resolve clazzLoader.Resolve = name => { var f = default(FileInfo); if (this.JavaArchiveResolve != null) { f = this.JavaArchiveResolve(name); //clazzLoader.CacheClassBytes(f); } return f; }; #endregion #region GetDynamicEnumerator this.GetDynamicEnumerator = () => { var zip = default(ZipInputStream); try { zip = new ZipInputStream(new jvm::java.io.FileInputStream(jar.FullName)); } catch { Console.WriteLine("error @ ZipInputStream"); throw new InvalidOperationException(); } return (GetNextEntry) delegate { if (zip == null) return null; var e = default(ZipEntry); try { e = zip.getNextEntry(); } catch { } if (e == null) return null; var n = new Entry { Name = e.getName() }; if (clazzLoader != null) if (n.Name.EndsWith(".class")) { var TypeFullName = n.Name.Substring(0, n.Name.Length - ".class".Length).Replace("/", "."); var NestedTypeName = TypeFullName.SkipUntilLastOrEmpty("$"); var NestedTypeNameStartsWithNumber = NestedTypeName.StartsWithNumber(); if (NestedTypeNameStartsWithNumber) { // we should skip nested types with only numbers // as we might not be able to load them } else { n.TypeFullName = TypeFullName; Console.WriteLine("JavaArchiveReflector.Loadfile.InternalGetType almost set for " + n.TypeFullName); n.InternalGetType = delegate { Console.WriteLine("JavaArchiveReflector.Loadfile.InternalGetType - " + n.TypeFullName); var c = default(jvm::java.lang.Class); try { //Console.WriteLine(".deprecated loadClass: " + n.TypeFullName); c = clazzLoader.loadClass(n.TypeFullName); } catch (jvm::csharp.ThrowableException cc) { Console.WriteLine("** JavaArchiveReflector.Loadfile - error loadClass: " + n.TypeFullName + "; " + cc); //throw new InvalidOperationException(); } // what if we need javax.jms.MessageListener ? if (c == null) { return null; } // cant be more explicit:P return jvm::ScriptCoreLibJava.Extensions.BCLImplementationExtensions.ToType(c); }; } } return n; }; }; #endregion }
private Class findClass_catch(string name) { var f = Resolve(name); var c = default(Class); //if (name == "com.amazonaws.AmazonWebServiceRequest") if (f == null) throw new InvalidOperationException(); //var x = @"C:\util\aws-android-sdk-0.2.0\lib\aws-android-sdk-0.2.0-core.jar"; var x = f.FullName; //Console.WriteLine("will look into: " + x); try { var url = new jvm::java.io.File(x).toURL(); this.addURL(url); } catch (jvm::csharp.ThrowableException cc) { Console.WriteLine("InternalURLClassLoader.findClass_catch error, x: " + x + "; " + cc); throw new InvalidOperationException(); } c = __findClass(name, x); return c; }
public void LoadFile(string path) { InternalEntries = null; var jar = new FileInfo(path); this.FileName = jar; #region clazzLoader this.clazzLoader = default(InternalURLClassLoader); try { //var filePath = "jar:file://" + jar.FullName + "!/"; // http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html // file:///C:/util/aws-android-sdk-0.2.0/lib/aws-android-sdk-0.2.0-ec2.jar // error @URLClassLoader: java.net.MalformedURLException: unknown protocol: c var url = new jvm::java.io.File(jar.FullName).toURL(); // http://www.javakb.com/Uwe/Forum.aspx/java-programmer/34778/URLClassLoader-ClassNotFoundException // http://www.chinaup.org/docs/reference/java/net/URLClassLoader.html // http://www.docjar.com/html/api/sun/applet/AppletClassLoader.java.html // http://www.docjar.com/html/api/java/net/URLClassLoader.java.html // http://www.docjar.com/html/api/java/security/SecureClassLoader.java.html clazzLoader = new InternalURLClassLoader(new URL[] { url }, null); } catch (jvm::csharp.ThrowableException ex) { Console.WriteLine("error @URLClassLoader: " + ex); throw new InvalidOperationException(); } #endregion //clazzLoader.CacheClassBytes(jar); #region Resolve clazzLoader.Resolve = name => { var f = default(FileInfo); if (this.JavaArchiveResolve != null) { f = this.JavaArchiveResolve(name); //clazzLoader.CacheClassBytes(f); } return(f); }; #endregion #region GetDynamicEnumerator this.GetDynamicEnumerator = () => { var zip = default(ZipInputStream); try { zip = new ZipInputStream(new jvm::java.io.FileInputStream(jar.FullName)); } catch { Console.WriteLine("error @ ZipInputStream"); throw new InvalidOperationException(); } return((GetNextEntry) delegate { if (zip == null) { return null; } var e = default(ZipEntry); try { e = zip.getNextEntry(); } catch { } if (e == null) { return null; } var n = new Entry { Name = e.getName() }; if (clazzLoader != null) { if (n.Name.EndsWith(".class")) { var TypeFullName = n.Name.Substring(0, n.Name.Length - ".class".Length).Replace("/", "."); var NestedTypeName = TypeFullName.SkipUntilLastOrEmpty("$"); var NestedTypeNameStartsWithNumber = NestedTypeName.StartsWithNumber(); if (NestedTypeNameStartsWithNumber) { // we should skip nested types with only numbers // as we might not be able to load them } else { n.TypeFullName = TypeFullName; Console.WriteLine("JavaArchiveReflector.Loadfile.InternalGetType almost set for " + n.TypeFullName); n.InternalGetType = delegate { Console.WriteLine("JavaArchiveReflector.Loadfile.InternalGetType - " + n.TypeFullName); var c = default(jvm::java.lang.Class); try { //Console.WriteLine(".deprecated loadClass: " + n.TypeFullName); c = clazzLoader.loadClass(n.TypeFullName); } catch (jvm::csharp.ThrowableException cc) { Console.WriteLine("** JavaArchiveReflector.Loadfile - error loadClass: " + n.TypeFullName + "; " + cc); //throw new InvalidOperationException(); } // what if we need javax.jms.MessageListener ? if (c == null) { return null; } // cant be more explicit:P return jvm::ScriptCoreLibJava.Extensions.BCLImplementationExtensions.ToType(c); }; } } } return n; }); }; #endregion }