Lines 64-81
Link Here
|
64 |
* Returns user preference node . {@link Preferences#absolutePath} of such |
64 |
* Returns user preference node . {@link Preferences#absolutePath} of such |
65 |
* a node depends whether class provided as a parameter was loaded as a part of any module |
65 |
* a node depends whether class provided as a parameter was loaded as a part of any module |
66 |
* or not. If so, then absolute path corresponds to slashified code name base of module. |
66 |
* or not. If so, then absolute path corresponds to slashified code name base of module. |
67 |
* If not, then absolute path corresponds to class's package. |
67 |
* If not, then absolute path corresponds to class's package. Equals to <code>Preferences.forModule(Preferences.root(), cls)</code> |
68 |
* |
68 |
* |
69 |
* @param cls the class for which a user preference node is desired. |
69 |
* @param cls the class for which a user preference node is desired. |
70 |
* @return the user preference node |
70 |
* @return the user preference node |
71 |
*/ |
71 |
*/ |
72 |
public static Preferences forModule(Class cls) { |
72 |
public static Preferences forModule(Class cls) { |
|
|
73 |
return forModule(root(), cls); |
74 |
} |
75 |
|
76 |
/** |
77 |
* Returns user preference node . {@link Preferences#absolutePath} of such |
78 |
* a node depends whether class provided as a parameter was loaded as a part of any module |
79 |
* or not. If so, then absolute path corresponds to slashified code name base of module. |
80 |
* If not, then absolute path corresponds to class's package. |
81 |
* |
82 |
* @param root the reference point, base Preferences node. |
83 |
* @param cls the class for which a user preference node is desired. |
84 |
* @return the user preference node |
85 |
* @since 8.27 |
86 |
*/ |
87 |
public static Preferences forModule(Preferences root, Class cls) { |
73 |
if (PREFS_IMPL == null) { |
88 |
if (PREFS_IMPL == null) { |
74 |
PREFS_IMPL = getPreferencesProvider(); |
89 |
PREFS_IMPL = getPreferencesProvider(); |
75 |
} |
90 |
} |
76 |
return PREFS_IMPL.preferencesForModule(cls); |
91 |
return PREFS_IMPL.preferencesForModule(root, cls); |
77 |
} |
92 |
} |
78 |
|
93 |
|
|
|
94 |
|
79 |
/** |
95 |
/** |
80 |
* Returns the root preference node. |
96 |
* Returns the root preference node. |
81 |
* |
97 |
* |
Lines 92-104
Link Here
|
92 |
Provider retval = Lookup.getDefault().lookup(Provider.class); |
108 |
Provider retval = Lookup.getDefault().lookup(Provider.class); |
93 |
if (retval == null) { |
109 |
if (retval == null) { |
94 |
retval = new Provider() { |
110 |
retval = new Provider() { |
95 |
public Preferences preferencesForModule(Class cls) { |
111 |
|
96 |
return Preferences.userNodeForPackage(cls); |
112 |
@Override |
|
|
113 |
public Preferences preferencesForModule(Preferences root, Class cls) { |
114 |
return root.node(nodeName(cls)); |
97 |
} |
115 |
} |
98 |
|
116 |
|
|
|
117 |
@Override |
99 |
public Preferences preferencesRoot() { |
118 |
public Preferences preferencesRoot() { |
100 |
return Preferences.userRoot(); |
119 |
return Preferences.userRoot(); |
101 |
} |
120 |
} |
|
|
121 |
private String nodeName(Class c) { |
122 |
if (c.isArray()) { |
123 |
throw new IllegalArgumentException( |
124 |
"Arrays have no associated preferences node."); |
125 |
} |
126 |
String className = c.getName(); |
127 |
int pkgEndIndex = className.lastIndexOf('.'); |
128 |
if (pkgEndIndex < 0) { |
129 |
return "/<unnamed>"; |
130 |
} |
131 |
String packageName = className.substring(0, pkgEndIndex); |
132 |
return "/" + packageName.replace('.', '/'); |
133 |
} |
102 |
}; |
134 |
}; |
103 |
// Avoided warning in case it is set |
135 |
// Avoided warning in case it is set |
104 |
//(e.g. from NbTestCase - org.netbeans.junit.internal.MemoryPreferencesFactory). |
136 |
//(e.g. from NbTestCase - org.netbeans.junit.internal.MemoryPreferencesFactory). |
Lines 127-133
Link Here
|
127 |
* @param cls the class for which a user preference node is desired. |
159 |
* @param cls the class for which a user preference node is desired. |
128 |
* @return the user preference node |
160 |
* @return the user preference node |
129 |
*/ |
161 |
*/ |
130 |
Preferences preferencesForModule(Class cls); |
162 |
Preferences preferencesForModule(Preferences root, Class cls); |
131 |
/** |
163 |
/** |
132 |
* Returns the root preference node. |
164 |
* Returns the root preference node. |
133 |
* |
165 |
* |