下面列出了怎么用java.util.prefs.AbstractPreferences的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
protected AbstractPreferences childSpi(String name) {
if (prefs == null) {
prefs = new HashMap<String, AbstractPreferences>(3);
}
AbstractPreferences p = prefs.get(name);
if (p == null) {
// root.cacheMisses++;
Preferences r = delegate.node(name);
p = new CachingPreferences(this, name, r);
// ((CachingPreferences)p).root = this.root;
prefs.put(name, p);
// } else {
// root.cacheHits++;
}
return p;
}
@Override
protected AbstractPreferences childSpi(String name) {
String escapedName = escape(name);
NodeList nl = node.getElementsByTagName("node");
for (int i = 0; i < nl.getLength(); i++) {
Node n = nl.item(i);
if (n instanceof Element && escapedName.equals(((Element) n).getAttribute("name"))) {
return new XMLHintPreferences(driver, this, name, (Element) n, node, true);
}
}
Element nue = node.getOwnerDocument().createElement("node");
nue.setAttribute("name", escapedName);
return new XMLHintPreferences(driver, this, name, nue, node, false);
}
/**
* http://stackoverflow.com/a/24249709
*/
@NotNull
@Override
protected AbstractPreferences childSpi(@NotNull String name) {
AbstractPreferences childPreferenceNode = (AbstractPreferences) children.get(name);
boolean isChildRemoved = false;
if (childPreferenceNode != null) {
try {
isChildRemoved = getIsRemoved(childPreferenceNode);
} catch (ReflectiveOperationException e) {
Log.error( e.getMessage() );
}
}
if (childPreferenceNode == null || isChildRemoved) {
final AbstractPreferences castedPreferences = new MarginallyCleverPreferences(this, name);
childPreferenceNode = castedPreferences;
children.put(name, childPreferenceNode);
}
return childPreferenceNode;
}
/**
* http://stackoverflow.com/a/24249709
*
* @param name
* @return
*/
@NotNull
@Override
protected AbstractPreferences childSpi(@NotNull String name) {
AbstractPreferences childPreferenceNode = (AbstractPreferences) children.get(name);
boolean isChildRemoved = false;
if (childPreferenceNode != null) {
try {
isChildRemoved = getIsRemoved(childPreferenceNode);
} catch (ReflectiveOperationException e) {
Log.error( e.getMessage() );
}
}
if (childPreferenceNode == null || isChildRemoved) {
final AbstractPreferences castedPreferences = new MarginallyCleverPreferences(this, name);
childPreferenceNode = castedPreferences;
children.put(name, childPreferenceNode);
}
return childPreferenceNode;
}
@Override
protected AbstractPreferences childSpi(String name) {
AbstractPreferences child = children.get(name);
if (child == null) {
child = new MockPreferences(this, name);
children.put(name, child);
}
return child;
}
@Override
protected AbstractPreferences childSpi(String name) {
AbstractPreferences child = children.get(name);
if (child == null) {
child = new MockPreferences(this, name);
children.put(name, child);
}
return child;
}
@Override
protected AbstractPreferences childSpi(String name) {
Preferences storedNode = stored != null ? stored.node(name) : null;
if (storedNode != null) {
return new InheritedPreferences(null, storedNode);
} else {
return null;
}
}
protected AbstractPreferences childSpi(String name) {
ModifiedPreferences result = subNodes.get(name);
if (result == null) {
subNodes.put(name, result = new ModifiedPreferences(this, name));
}
return result;
}
@Override
protected AbstractPreferences childSpi(String name) {
synchronized (AuxiliaryConfigBasedPreferencesProvider.this) {
String nuePath = path + "/" + name;
if (!getChildrenNames().contains(name)) {
AuxiliaryConfigBasedPreferencesProvider.this.createdNodes.add(nuePath);
}
return new AuxiliaryConfigBasedPreferences(this, name, nuePath);
}
}
@Override
protected AbstractPreferences getChild(final String nodeName) throws BackingStoreException {
try {
return ProjectManager.mutex(false, project).readAccess(new ExceptionAction<AbstractPreferences>() {
public AbstractPreferences run() throws BackingStoreException {
return AuxiliaryConfigBasedPreferences.super.getChild(nodeName);
}
});
} catch (MutexException ex) {
throw (BackingStoreException) ex.getException();
}
}
@Override
protected AbstractPreferences childSpi(String name) {
Preferences storedNode = stored != null ? stored.node(name) : null;
if (storedNode != null) {
return new InheritedPreferences(null, storedNode);
} else {
return null;
}
}
public Preferences getPreferences() {
synchronized (this) {
Preferences prefs = useProject ? projectPrefs : globalPrefs;
// to support tests that don't use editor.mimelookup.impl
return prefs == null ? AbstractPreferences.systemRoot() : prefs;
}
}
@Override
protected AbstractPreferences childSpi(String name) {
// Preferences [] nueDelegates = new Preferences[delegates.length];
// for(int i = 0; i < delegates.length; i++) {
// nueDelegates[i] = delegates[i].node(name);
// }
// return new ProxyPreferences(name, this, nueDelegates);
throw new UnsupportedOperationException("Not supported yet."); //NOI18N
}
private void firePrefChange(String key, String newValue) {
try {
Method m = AbstractPreferences.class.getDeclaredMethod("enqueuePreferenceChangeEvent", String.class, String.class); //NOI18N
m.setAccessible(true);
m.invoke(this, key, newValue);
} catch (Exception e) {
LOG.log(Level.WARNING, null, e);
}
}
@Override
protected AbstractPreferences childSpi(String name) {
AbstractPreferences child = children.get(name);
if (child == null) {
child = new MockPreferences(this, name);
children.put(name, child);
}
return child;
}
protected AbstractPreferences childSpi(String name) {
synchronized(mounts) {
Preferences mount = mounts.get(name);
if(mount != null) {
return new MountedPreferences(this, mount, name);
}
if(target != null) {
return new MountedPreferences(this, target.node(name), name);
} else {
MountedPreferences m = new MountedPreferences(this, null, name);
mount(m, name);
return m;
}
}
}
protected AbstractPreferences childSpi(String name) {
synchronized(children) {
OSGiPreferences child = children.get(name);
if(child == null) {
org.osgi.service.prefs.Preferences node =
prefsService.getUserPreferences(name);
child = new OSGiPreferences(this, node, name);
children.put(name, child);
}
return child;
}
}
/**
* FIXME - Pure hack to get around erasure.
*
* @return true if removed
* @throws ReflectiveOperationException
*/
private boolean getIsRemoved(AbstractPreferences abstractPreference) throws ReflectiveOperationException {
Log.message( abstractPreference.toString() );
final Method declaredMethod = AbstractPreferences.class.getDeclaredMethod("isRemoved");
declaredMethod.setAccessible(true);
Object isRemoved = declaredMethod.invoke(abstractPreference, new Object[]{null});
return (boolean) isRemoved;
}
/**
* FIXME - Pure hack to get around erasure.
*
* @param abstractPreference
* @return
* @throws ReflectiveOperationException
*/
private boolean getIsRemoved(AbstractPreferences abstractPreference) throws ReflectiveOperationException {
Log.message( abstractPreference.toString() );
final Method declaredMethod = AbstractPreferences.class.getDeclaredMethod("isRemoved");
declaredMethod.setAccessible(true);
Object isRemoved = declaredMethod.invoke(abstractPreference, new Object[]{null});
return (boolean) isRemoved;
}
protected AbstractPreferences childSpi( final String name ) {
if ( name == null || name.length() == 0 ) {
throw new IllegalArgumentException();
}
return new BinaryPreferences( this, name );
}
protected MockPreferences(AbstractPreferences parent, String name) {
super(parent, name);
}
protected MockPreferences(AbstractPreferences parent, String name) {
super(parent, name);
}
protected AbstractPreferences childSpi(String name) {
return new TempPreferences(this, name);
}
@Override
protected AbstractPreferences childSpi(String name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override protected AbstractPreferences childSpi(String name) {
throw new UnsupportedOperationException("Not supported yet.");
}
protected AbstractPreferences childSpi(String name) {
return new TempPreferences(this, name);
}
@Override
protected AbstractPreferences childSpi(String name) {
throw new UnsupportedOperationException("Not supported yet.");
}
protected AbstractPreferences childSpi(String name) {
throw new UnsupportedOperationException("Not supported yet.");
}
protected AbstractPreferences childSpi(String name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected AbstractPreferences childSpi(String name) {
return new UserPreferences(this, name);
}