コード例 #1
0
 /// <summary>
 /// This method is used to acquire the class of the specified name.
 /// Loading is performed by the thread context class loader as this
 /// will ensure that the class loading strategy can be changed as
 /// requirements dictate. Typically the thread context class loader
 /// can handle all serialization requirements.
 /// </summary>
 /// <param name="type">
 /// this is the name of the class that is to be loaded
 /// </param>
 /// <returns>
 /// this returns the class that has been loaded by this
 /// </returns>
 public Class Load(String type) {
    ClassLoader loader = ClassLoader;
    if(loader == null) {
       loader = CallerClassLoader;
    }
    return loader.loadClass(type);
 }
コード例 #2
0
ファイル: Registry.register.cs プロジェクト: cd37ycs/jni4net
        private static Class LoadClass(string name, JNIEnv env, ClassLoader classLoader)
        {
            Class  res;
            string rn = name.Replace('.', '/');

            res = env.FindClassNoThrow(rn);
            if (res == null)
            {
                if (classLoader == null)
                {
                    classLoader = systemClassLoader;
                }
                if (classLoader != null)
                {
                    try
                    {
                        res = classLoader.loadClass(name);
                    }
                    catch (Throwable th)
                    {
                        throw new JNIException("Can't load java class for " + name +
                                               ((classLoader == null) ? "" : " from classLoader " + classLoader), th);
                    }
                }
            }
            return(res);
        }
コード例 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") protected Class loadJobExecutorClass(ClassLoader processApplicationClassloader, String jobExecutorClassname)
        protected internal virtual Type loadJobExecutorClass(ClassLoader processApplicationClassloader, string jobExecutorClassname)
        {
            try
            {
                return((Type)processApplicationClassloader.loadClass(jobExecutorClassname));
            }
            catch (ClassNotFoundException e)
            {
                throw LOG.couldNotLoadJobExecutorClass(e);
            }
        }
コード例 #4
0
	  /// 
	  /// <param name="classLoader">
	  ///          the classloader to scan </param>
	  /// <param name="paResourceRootPath">
	  ///          see <seealso cref="ProcessArchiveXml.PROP_RESOURCE_ROOT_PATH"/> </param>
	  /// <param name="metaFileUrl">
	  ///          the URL to the META-INF/processes.xml file </param>
	  /// <param name="additionalResourceSuffixes">
	  ///          a list of additional suffixes for resources </param>
	  /// <returns> a Map of process definitions </returns>
	  public static IDictionary<string, sbyte[]> findResources(ClassLoader classLoader, string paResourceRootPath, URL metaFileUrl, string[] additionalResourceSuffixes)
	  {
		ProcessApplicationScanner scanner = null;

		try
		{
		  // check if we must use JBoss VFS
		  classLoader.loadClass("org.jboss.vfs.VFS");
		  scanner = new VfsProcessApplicationScanner();
		}
		catch (Exception)
		{
		  scanner = new ClassPathProcessApplicationScanner();
		}

		return scanner.findResources(classLoader, paResourceRootPath, metaFileUrl, additionalResourceSuffixes);

	  }
コード例 #5
0
        /// <summary>
        /// Create an ExpressionFactory instance.
        /// </summary>
        /// <param name="properties">
        ///            Properties passed to the constructor of the implementation. </param>
        /// <returns> an instance of ExpressionFactory </returns>
        /// <param name="className">
        ///            The name of the ExpressionFactory class. </param>
        /// <param name="classLoader">
        ///            The class loader to be used to load the class. </param>
        /// <returns> An instance of ExpressionFactory. </returns>
        /// <exception cref="ELException">
        ///             if the class could not be found or if it is not a subclass of ExpressionFactory
        ///             or if the class could not be instantiated. </exception>
        private static ExpressionFactory newInstance(Properties properties, string className, ClassLoader classLoader)
        {
            Type clazz = null;

            try
            {
                clazz = classLoader.loadClass(className.Trim());
                if (!clazz.IsAssignableFrom(typeof(ExpressionFactory)))
                {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                    throw new ELException("Invalid expression factory class: " + clazz.FullName);
                }
            }
            catch (ClassNotFoundException e)
            {
                throw new ELException("Could not find expression factory class", e);
            }
            try
            {
                if (properties != null)
                {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: Constructor<?> constructor = null;
                    System.Reflection.ConstructorInfo <object> constructor = null;
                    try
                    {
                        constructor = clazz.GetConstructor(typeof(Properties));
                    }
                    catch (Exception)
                    {
                        // do nothing
                    }
                    if (constructor != null)
                    {
                        return((ExpressionFactory)constructor.newInstance(properties));
                    }
                }
                return((ExpressionFactory)System.Activator.CreateInstance(clazz));
            }
            catch (Exception e)
            {
                throw new ELException("Could not create expression factory instance", e);
            }
        }
コード例 #6
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private org.neo4j.helpers.collection.Visitable<DbStructureVisitor> compileVisitable(final String className, String inputSource)
        private Visitable <DbStructureVisitor> CompileVisitable(string className, string inputSource)
        {
            return(Compile(className, inputSource, (success, manager, diagnostics) =>
            {
                AssertSuccessfullyCompiled(success, diagnostics, className);
                object instance;
                try
                {
                    ClassLoader classLoader = manager.getClassLoader(null);
                    Type clazz = classLoader.loadClass(className);
                    instance = clazz.getDeclaredField("INSTANCE").get(null);
                }
                catch (Exception e) when(e is IllegalAccessException || e is ClassNotFoundException || e is NoSuchFieldException)
                {
                    throw new AssertionError("Failed to instantiate compiled class", e);
                }
                return (Visitable <DbStructureVisitor>)instance;
            }));
        }
コード例 #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected Class fetchNextOrNull() throws java.io.IOException
            protected internal override Type fetchNextOrNull()
            {
                try
                {
                    while (true)
                    {
                        ZipEntry nextEntry = _zip.NextEntry;
                        if (nextEntry == null)
                        {
                            _zip.close();
                            return(null);
                        }

                        string name = nextEntry.Name;
                        if (name.EndsWith(".class", StringComparison.Ordinal))
                        {
                            string className = name.Substring(0, name.Length - ".class".Length).Replace('/', '.');

                            try
                            {
                                Type aClass = _loader.loadClass(className);
                                // We do getDeclaredMethods to trigger NoClassDefErrors, which loadClass above does
                                // not do.
                                // This way, even if some of the classes in a jar cannot be loaded, we still check
                                // the others.
                                aClass.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
                                return(aClass);
                            }
                            catch (Exception e) when(e is UnsatisfiedLinkError || e is NoClassDefFoundError || e is Exception)
                            {
                                _outerInstance.log.warn("Failed to load `%s` from plugin jar `%s`: %s", className, _jar.File, e.Message);
                            }
                        }
                    }
                }
                catch (Exception e) when(e is IOException || e is Exception)
                {
                    _zip.close();
                    throw e;
                }
            }
コード例 #8
0
ファイル: AudioDeviceFactory.cs プロジェクト: rejc2/utils
        //UPGRADE_ISSUE: Class 'java.lang.ClassLoader' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javalangClassLoader"'
        /// <summary> Creates an instance of an AudioDevice implementation.
        /// </summary>
        /// <param name="loader	The"><code>ClassLoader</code> to use to
        /// load the named class, or null to use the
        /// system class loader.
        /// </param>
        /// <param name="name		The">name of the class to load.
        /// </param>
        /// <returns>			A newly-created instance of the audio device class.
        ///
        /// </returns>
        protected internal virtual AudioDevice instantiate(ClassLoader loader, System.String name)
        {
            AudioDevice dev = null;

            System.Type cls = null;
            if (loader == null)
            {
                //UPGRADE_TODO: Format of parameters of method 'java.lang.Class.forName' are different in the equivalent in .NET. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1092"'
                cls = System.Type.GetType(name);
            }
            else
            {
                //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.loadClass' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javalangClassLoader"'
                cls = loader.loadClass(name);
            }

            System.Object o = SupportClass.CreateNewInstance(cls);
            dev = (AudioDevice)o;

            return(dev);
        }
コード例 #9
0
        public static List <Class> loadClasses(this ClassLoader classLoader, List <string> classesToLoad)
        {
            var classes = new List <Class>();

            foreach (var classToLoad in classesToLoad)
            {
                try
                {
                    var loadedClass = classLoader.loadClass(classToLoad);
                    if (loadedClass.notNull())
                    {
                        classes.add(loadedClass);
                    }
                    "Loaded class: {0}".info(classToLoad);
                }
                catch (System.Exception ex)
                {
                    "[ClassLoader] loading class {0} threw: {1}".error(classToLoad, ex.Message);
                }
            }
            return(classes);
        }
コード例 #10
0
        private static Class LoadClass(string name, JNIEnv env, bool throwNoFound)
        {
            Class  res;
            string rn = name.Replace('.', '/');

            res = env.FindClassNoThrow(rn);
            if (res == null && systemClassLoader != null)
            {
                try
                {
                    res = systemClassLoader.loadClass(name);
                }
                catch (Throwable th)
                {
                }
            }
            if (res == null && throwNoFound)
            {
                throw new JNIException("Can't find java class for " + name);
            }
            return(res);
        }
コード例 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") protected <T> Class loadClass(String className, ClassLoader customClassloader, Class<T> clazz)
        protected internal virtual Type loadClass <T>(string className, ClassLoader customClassloader, Type clazz)
        {
            clazz = typeof(T);
            try
            {
                if (customClassloader != null)
                {
                    return((Type)customClassloader.loadClass(className));
                }
                else
                {
                    return((Type)ReflectUtil.loadClass(className));
                }
            }
            catch (ClassNotFoundException e)
            {
                throw LOG.camnnotLoadConfigurationClass(className, e);
            }
            catch (System.InvalidCastException e)
            {
                throw LOG.configurationClassHasWrongType(className, clazz, e);
            }
        }
コード例 #12
0
ファイル: Repository.cs プロジェクト: hc4/jni4net
        private static Class loadClass(string clazzName, bool logDetails)
        {
            Class clazz = JNIEnv.ThreadEnv.FindClassNoThrow(clazzName);

            if (clazz == null && systemClassLoader != null)
            {
                try
                {
                    string replace = clazzName.Replace('/', '.');
                    clazz = systemClassLoader.loadClass(replace);
                }
                catch (Throwable ex)
                {
                    Console.Error.WriteLine("Can't load class " + clazzName);
                    if (config.Verbose)
                    {
                        Console.Error.WriteLine(ex.ToString());
                    }
                    clazz = null;
                }
            }
            return(clazz);
        }
コード例 #13
0
        //UPGRADE_ISSUE: Class 'java.lang.ClassLoader' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javalangClassLoader"'
        /// <summary> Creates an instance of an AudioDevice implementation. 
        /// </summary>
        /// <param name="loader	The"><code>ClassLoader</code> to use to
        /// load the named class, or null to use the
        /// system class loader.
        /// </param>
        /// <param name="name		The">name of the class to load.
        /// </param>
        /// <returns>			A newly-created instance of the audio device class.
        /// 
        /// </returns>
        protected internal virtual AudioDevice instantiate(ClassLoader loader, System.String name)
        {
            AudioDevice dev = null;

            System.Type cls = null;
            if (loader == null)
            {
                //UPGRADE_TODO: Format of parameters of method 'java.lang.Class.forName' are different in the equivalent in .NET. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1092"'
                cls = System.Type.GetType(name);
            }
            else
            {
                //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.loadClass' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javalangClassLoader"'
                cls = loader.loadClass(name);
            }

            System.Object o = SupportClass.CreateNewInstance(cls);
            dev = (AudioDevice) o;

            return dev;
        }
コード例 #14
0
 /// <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));
 }