Inheritance: java.security.SecureClassLoader
示例#1
0
		public void Invoke(params string[] args)
		{
			try
			{
				// http://bigjavablog.blogspot.com/2008/08/load-jar-files-and-java-classes.html

				if (Method != null)
				{
					var main_args = new string[0];

					this.Method.invoke(null, new object[] { main_args });
				}
				else
				{
					/* We need and URL to load the jar file. */
					URL u = new File(this.AssemblyPath).toURL();
					/* Load jar file using URLClassLoader. */
					URLClassLoader cl = new URLClassLoader(new URL[] { u });

					if (NativeAssemblyPath != null)
					{
						var nc = cl.loadClass("jni.CPtrLibrary");
						var ncf = nc.getField("LibraryPath");

						ncf.set(null, NativeAssemblyPath);
					}

					var c = cl.loadClass(this.TypeName);

					foreach (var m in c.getMethods())
					{
						if (m.getDeclaringClass() == c)
						{
							if (m.getName() == "main")
							{
								this.Method = m;

								var main_args = new string[0];

								this.Method.invoke(null, new object[] { main_args });
							}
						}
					}
				}

			}
			catch (csharp.ThrowableException ex)
			{
				var exo = (object)ex;

				Console.WriteLine("error!");
				Console.WriteLine(ex.Message + " - " + ex.ToString());

				ErrorHandler(exo);

			}
		}
示例#2
0
        /// <summary>
        /// Creates a new instance of URLClassLoader for the specified
        /// URLs and default parent class loader. If a security manager is
        /// installed, the {@code loadClass} method of the URLClassLoader
        /// returned by this method will invoke the
        /// {@code SecurityManager.checkPackageAccess} before
        /// loading the class.
        /// </summary>
        /// <param name="urls"> the URLs to search for classes and resources </param>
        /// <exception cref="NullPointerException"> if {@code urls} is {@code null}. </exception>
        /// <returns> the resulting class loader </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
//ORIGINAL LINE: public static URLClassLoader newInstance(final URL[] urls)
        public static URLClassLoader NewInstance(URL[] urls)
        {
            // Save the caller's context
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.security.AccessControlContext acc = java.security.AccessController.getContext();
            AccessControlContext acc = AccessController.Context;
            // Need a privileged block to create the class loader
            URLClassLoader ucl = AccessController.doPrivileged(new PrivilegedActionAnonymousInnerClassHelper5(urls, acc));

            return(ucl);
        }
 public static void removeCodeBase(URL codeBase, URLClassLoader urlClassLoader)
 {
   ArrayList arrayList = new ArrayList();
   URL[] urLs = urlClassLoader.getURLs();
   for (int index = 0; index < urLs.Length; ++index)
   {
     if (!urLs[index].sameFile(codeBase))
       ((List) arrayList).add((object) urLs[index]);
   }
   ResourceBundleWrapper.noCodeBaseClassLoader = URLClassLoader.newInstance((URL[]) ((List) arrayList).toArray((object[]) new URL[0]));
 }
示例#4
0
 public PrivilegedActionAnonymousInnerClassHelper3(URLClassLoader outerInstance, java.lang.SecurityManager sm, Permission fp)
 {
     this.OuterInstance = outerInstance;
     this.Sm            = sm;
     this.Fp            = fp;
 }
示例#5
0
 public IteratorAnonymousInnerClassHelper(URLClassLoader outerInstance, IEnumerator <URL> e)
 {
     this.OuterInstance = outerInstance;
     this.e             = e;
     url = null;
 }
示例#6
0
 public PrivilegedActionAnonymousInnerClassHelper(URLClassLoader outerInstance, string name)
 {
     this.OuterInstance = outerInstance;
     this.Name          = name;
 }
示例#7
0
 public virtual URLClassPath GetURLClassPath(URLClassLoader u)
 {
     return(u.Ucp);
 }
示例#8
0
        public void StartJavaServer()
        {
            Console.WriteLine("Starting server");

            URL url = new URL("file:VehicleSystemServer.jar");
            URLClassLoader loader = new URLClassLoader(new[] {url});
            try
            {
                Class cl = Class.forName("VehicleSystemServer", true, loader);
                object obj = cl.newInstance();
                _server = (VehicleSystemServer) obj;

                String userName = Globals.GCM_SENDER_ID + "@gcm.googleapis.com";
                String password = Globals.GCM_SERVER_KEY;

                _server.connect(userName, password);

                MessageListener listener = new MessageListener(this);

                _server.addListener(listener);

                _server.testListener();

                Console.WriteLine("Server started successfully");
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in starting server");
                Console.WriteLine(e.Message);
            }
        }
        public JavaArchiveReflector(FileInfo jar)
        {
            this.FileName = jar;

            var clazzLoader = default(URLClassLoader);

            try
            {
                var filePath = "jar:file://" + jar.FullName + "!/";
                var url = new java.io.File(filePath).toURL();


                clazzLoader = new URLClassLoader(new URL[] { url });
            }
            catch
            {
            }



            this.GetDynamicEnumerator = () =>
            {

                var zip = default(ZipInputStream);

                try
                {
                    zip = new ZipInputStream(new FileInputStream(jar.FullName));
                }
                catch
                {
                }

                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"))
                            {

                                n.TypeFullName = n.Name.Substring(0, n.Name.Length - ".class".Length).Replace("/", ".");


                                n.InternalGetType = delegate
                                {

                                    var c = default(java.lang.Class);

                                    try
                                    {
                                        c = clazzLoader.loadClass(n.TypeFullName.Replace(".", "/"));
                                    }
                                    catch (csharp.ThrowableException cc)
                                    {
                                        System.Console.WriteLine("error: " + cc);
                                    }

                                    return c.ToType();
                                };
                            }

                        return n;
                    };
            };
        }