1 11 package org.eclipse.core.internal.preferences; 12 13 import java.net.URL ; 14 import java.util.HashSet ; 15 import java.util.Set ; 16 import org.eclipse.core.runtime.IPath; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.core.runtime.preferences.IEclipsePreferences; 19 20 23 public class ConfigurationPreferences extends EclipsePreferences { 24 25 private int segmentCount; 27 private String qualifier; 28 private IPath location; 29 private IEclipsePreferences loadLevel; 30 private static Set loadedNodes = new HashSet (); 32 private static boolean initialized = false; 33 private static IPath baseLocation; 34 35 static { 36 URL url = PreferencesOSGiUtils.getDefault().getConfigurationLocation().getURL(); 37 if (url != null) 38 baseLocation = new Path(url.getFile()); 39 } 40 41 44 public ConfigurationPreferences() { 45 this(null, null); 46 } 47 48 private ConfigurationPreferences(EclipsePreferences parent, String name) { 49 super(parent, name); 50 51 initializeChildren(); 52 53 String path = absolutePath(); 55 segmentCount = getSegmentCount(path); 56 if (segmentCount < 2) 57 return; 58 59 qualifier = getSegment(path, 1); 61 62 if (qualifier == null) 64 return; 65 if (baseLocation != null) 66 location = computeLocation(baseLocation, qualifier); 67 } 68 69 protected IPath getLocation() { 70 return location; 71 } 72 73 protected boolean isAlreadyLoaded(IEclipsePreferences node) { 74 return loadedNodes.contains(node.name()); 75 } 76 77 protected void loaded() { 78 loadedNodes.add(name()); 79 } 80 81 84 protected IEclipsePreferences getLoadLevel() { 85 if (loadLevel == null) { 86 if (qualifier == null) 87 return null; 88 IEclipsePreferences node = this; 92 for (int i = 2; i < segmentCount; i++) 93 node = (EclipsePreferences) node.parent(); 94 loadLevel = node; 95 } 96 return loadLevel; 97 } 98 99 protected void initializeChildren() { 100 if (initialized || parent == null) 101 return; 102 try { 103 synchronized (this) { 104 if (baseLocation == null) 105 return; 106 String [] names = computeChildren(baseLocation); 107 for (int i = 0; i < names.length; i++) 108 addChild(names[i], null); 109 } 110 } finally { 111 initialized = true; 112 } 113 } 114 115 protected EclipsePreferences internalCreate(EclipsePreferences nodeParent, String nodeName, Object context) { 116 return new ConfigurationPreferences(nodeParent, nodeName); 117 } 118 } 119 | Popular Tags |