src/share/classes/java/util/prefs/Preferences.java

Print this page
rev 4802 : 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
Reviewed-by: alanb, dholmes, forax, sherman, smarks
Contributed-by: London Java Community and Michael Barker <mikeb01@gmail.com>


 396      *
 397      * @param c the class for whose package a system preference node is desired.
 398      * @return the system preference node associated with the package of which
 399      *         <tt>c</tt> is a member.
 400      * @throws NullPointerException if <tt>c</tt> is <tt>null</tt>.
 401      * @throws SecurityException if a security manager is present and
 402      *         it denies <tt>RuntimePermission("preferences")</tt>.
 403      * @see    RuntimePermission
 404      */
 405     public static Preferences systemNodeForPackage(Class<?> c) {
 406         return systemRoot().node(nodeName(c));
 407     }
 408 
 409     /**
 410      * Returns the absolute path name of the node corresponding to the package
 411      * of the specified object.
 412      *
 413      * @throws IllegalArgumentException if the package has node preferences
 414      *         node associated with it.
 415      */
 416     private static String nodeName(Class c) {
 417         if (c.isArray())
 418             throw new IllegalArgumentException(
 419                 "Arrays have no associated preferences node.");
 420         String className = c.getName();
 421         int pkgEndIndex = className.lastIndexOf('.');
 422         if (pkgEndIndex < 0)
 423             return "/<unnamed>";
 424         String packageName = className.substring(0, pkgEndIndex);
 425         return "/" + packageName.replace('.', '/');
 426     }
 427 
 428     /**
 429      * This permission object represents the permission required to get
 430      * access to the user or system root (which in turn allows for all
 431      * other operations).
 432      */
 433     private static Permission prefsPerm = new RuntimePermission("preferences");
 434 
 435     /**
 436      * Returns the root preference node for the calling user.




 396      *
 397      * @param c the class for whose package a system preference node is desired.
 398      * @return the system preference node associated with the package of which
 399      *         <tt>c</tt> is a member.
 400      * @throws NullPointerException if <tt>c</tt> is <tt>null</tt>.
 401      * @throws SecurityException if a security manager is present and
 402      *         it denies <tt>RuntimePermission("preferences")</tt>.
 403      * @see    RuntimePermission
 404      */
 405     public static Preferences systemNodeForPackage(Class<?> c) {
 406         return systemRoot().node(nodeName(c));
 407     }
 408 
 409     /**
 410      * Returns the absolute path name of the node corresponding to the package
 411      * of the specified object.
 412      *
 413      * @throws IllegalArgumentException if the package has node preferences
 414      *         node associated with it.
 415      */
 416     private static String nodeName(Class<?> c) {
 417         if (c.isArray())
 418             throw new IllegalArgumentException(
 419                 "Arrays have no associated preferences node.");
 420         String className = c.getName();
 421         int pkgEndIndex = className.lastIndexOf('.');
 422         if (pkgEndIndex < 0)
 423             return "/<unnamed>";
 424         String packageName = className.substring(0, pkgEndIndex);
 425         return "/" + packageName.replace('.', '/');
 426     }
 427 
 428     /**
 429      * This permission object represents the permission required to get
 430      * access to the user or system root (which in turn allows for all
 431      * other operations).
 432      */
 433     private static Permission prefsPerm = new RuntimePermission("preferences");
 434 
 435     /**
 436      * Returns the root preference node for the calling user.