1 11 package org.eclipse.core.internal.preferences; 12 13 import org.eclipse.core.runtime.IPath; 14 import org.eclipse.core.runtime.preferences.IEclipsePreferences; 15 import org.osgi.service.prefs.BackingStoreException; 16 import org.osgi.service.prefs.Preferences; 17 18 21 public class RootPreferences extends EclipsePreferences { 22 23 26 public RootPreferences() { 27 super(null, ""); } 29 30 33 public void flush() throws BackingStoreException { 34 BackingStoreException exception = null; 36 String [] names = childrenNames(); 37 for (int i = 0; i < names.length; i++) { 38 try { 39 node(names[i]).flush(); 40 } catch (BackingStoreException e) { 41 if (exception == null) 44 exception = e; 45 } 46 } 47 if (exception != null) 48 throw exception; 49 } 50 51 54 protected synchronized IEclipsePreferences getChild(String key, Object context) { 55 Object value = null; 56 IEclipsePreferences child = null; 57 if (children != null) 58 value = children.get(key); 59 if (value != null) { 60 if (value instanceof IEclipsePreferences) 61 return (IEclipsePreferences) value; 62 child = PreferencesService.getDefault().createNode(key); 64 addChild(key, child); 65 } 66 return child; 67 } 68 69 72 protected synchronized IEclipsePreferences[] getChildren() { 73 String [] childNames = childrenNames(); 75 IEclipsePreferences[] childNodes = new IEclipsePreferences[childNames.length]; 76 for (int i = 0; i < childNames.length; i++) 77 childNodes[i] = getChild(childNames[i], null); 78 return childNodes; 79 } 80 81 84 public Preferences node(String path) { 85 return getNode(path, true); } 87 88 public Preferences getNode(String path, boolean create) { 89 if (path.length() == 0 || (path.length() == 1 && path.charAt(0) == IPath.SEPARATOR)) 90 return this; 91 int startIndex = path.charAt(0) == IPath.SEPARATOR ? 1 : 0; 92 int endIndex = path.indexOf(IPath.SEPARATOR, startIndex + 1); 93 String scope = path.substring(startIndex, endIndex == -1 ? path.length() : endIndex); 94 IEclipsePreferences child; 95 if (create) { 96 child = getChild(scope, null); 97 if (child == null) { 98 child = new EclipsePreferences(this, scope); 99 addChild(scope, child); 100 } 101 } else { 102 child = getChild(scope, null, false); 103 if (child == null) 104 return null; 105 } 106 return child.node(endIndex == -1 ? "" : path.substring(endIndex + 1)); } 108 109 112 public void sync() throws BackingStoreException { 113 BackingStoreException exception = null; 115 String [] names = childrenNames(); 116 for (int i = 0; i < names.length; i++) { 117 try { 118 node(names[i]).sync(); 119 } catch (BackingStoreException e) { 120 if (exception == null) 123 exception = e; 124 } 125 } 126 if (exception != null) 127 throw exception; 128 } 129 } 130 | Popular Tags |