Пример #1
0
        /// <summary>
        /// Find a package by name in the callers {@code ClassLoader} instance.
        /// The callers {@code ClassLoader} instance is used to find the package
        /// instance corresponding to the named class. If the callers
        /// {@code ClassLoader} instance is null then the set of packages loaded
        /// by the system {@code ClassLoader} instance is searched to find the
        /// named package. <para>
        ///
        /// Packages have attributes for versions and specifications only if the class
        /// loader created the package instance with the appropriate attributes. Typically,
        /// those attributes are defined in the manifests that accompany the classes.
        ///
        /// </para>
        /// </summary>
        /// <param name="name"> a package name, for example, java.lang. </param>
        /// <returns> the package of the requested name. It may be null if no package
        ///          information is available from the archive or codebase. </returns>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @CallerSensitive public static Package getPackage(String name)
        public static Package GetPackage(String name)
        {
            ClassLoader l = ClassLoader.GetClassLoader(Reflection.CallerClass);

            if (l != reflect.AnnotatedElement_Fields.Null)
            {
                return(l.GetPackage(name));
            }
            else
            {
                return(GetSystemPackage(name));
            }
        }
Пример #2
0
        /// <summary>
        /// Get the package for the specified class.
        /// The class's class loader is used to find the package instance
        /// corresponding to the specified class. If the class loader
        /// is the bootstrap class loader, which may be represented by
        /// {@code null} in some implementations, then the set of packages
        /// loaded by the bootstrap class loader is searched to find the package.
        /// <para>
        /// Packages have attributes for versions and specifications only
        /// if the class loader created the package
        /// instance with the appropriate attributes. Typically those
        /// attributes are defined in the manifests that accompany
        /// the classes.
        ///
        /// </para>
        /// </summary>
        /// <param name="c"> the class to get the package of. </param>
        /// <returns> the package of the class. It may be null if no package
        ///          information is available from the archive or codebase.   </returns>
        internal static Package GetPackage(Class c)
        {
            String name = c.Name;
            int    i    = name.LastIndexOf('.');

            if (i != -1)
            {
                name = name.Substring(0, i);
                ClassLoader cl = c.ClassLoader;
                if (cl != reflect.AnnotatedElement_Fields.Null)
                {
                    return(cl.GetPackage(name));
                }
                else
                {
                    return(GetSystemPackage(name));
                }
            }
            else
            {
                return(reflect.AnnotatedElement_Fields.Null);
            }
        }