diff options
author | Thomas Watson | 2010-02-13 03:59:57 +0000 |
---|---|---|
committer | Thomas Watson | 2010-02-13 03:59:57 +0000 |
commit | 1fac03c5368a21c96bfda9f288ac7033a85ff8ef (patch) | |
tree | 732da139bc6826adb9b186c1239a29fa46dad41e /bundles/org.eclipse.osgi | |
parent | d88f07cbd6f661cbb3802cd528fe2445f74d2194 (diff) | |
download | rt.equinox.framework-1fac03c5368a21c96bfda9f288ac7033a85ff8ef.tar.gz rt.equinox.framework-1fac03c5368a21c96bfda9f288ac7033a85ff8ef.tar.xz rt.equinox.framework-1fac03c5368a21c96bfda9f288ac7033a85ff8ef.zip |
Diffstat (limited to 'bundles/org.eclipse.osgi')
3 files changed, 114 insertions, 20 deletions
diff --git a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF index 887526b03..4a13ac327 100644 --- a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF @@ -6,7 +6,7 @@ Export-Package: org.eclipse.osgi.event;version="1.0", org.eclipse.osgi.framework.log;version="1.0", org.eclipse.osgi.launch; version="1.0", org.eclipse.osgi.service.datalocation;version="1.3", - org.eclipse.osgi.service.debug;version="1.1", + org.eclipse.osgi.service.debug;version="1.2", org.eclipse.osgi.service.environment;version="1.3", org.eclipse.osgi.service.localization;version="1.1", org.eclipse.osgi.service.pluginconversion;version="1.0", diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java index 5c0a137e5..020022dc8 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java @@ -14,6 +14,7 @@ import java.io.*; import java.net.MalformedURLException; import java.net.URL; import java.util.*; +import java.util.Map.Entry; import org.eclipse.osgi.framework.internal.core.FrameworkProperties; import org.eclipse.osgi.service.debug.*; import org.osgi.framework.*; @@ -188,6 +189,17 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom } } + public Map getOptions() { + Properties snapShot = new Properties(); + synchronized (lock) { + if (options != null) + snapShot.putAll(options); + else if (disabledOptions != null) + snapShot.putAll(disabledOptions); + } + return snapShot; + } + /* * (non-Javadoc) * @see org.eclipse.osgi.service.debug.DebugOptions#getAllOptions() @@ -220,19 +232,15 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom public void removeOption(String option) { if (option == null) return; - boolean fireChangedEvent = false; + String fireChangedEvent = null; synchronized (lock) { - if (options != null) { - fireChangedEvent = options.remove(option) != null; + if (options != null && options.remove(option) != null) { + fireChangedEvent = getSymbolicName(option); } } // Send the options change event outside the sync block - if (fireChangedEvent) { - int firstSlashIndex = option.indexOf("/"); //$NON-NLS-1$ - if (firstSlashIndex > 0) { - String symbolicName = option.substring(0, firstSlashIndex); - optionsChanged(symbolicName); - } + if (fireChangedEvent != null) { + optionsChanged(fireChangedEvent); } } @@ -241,7 +249,12 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom * @see org.eclipse.osgi.service.debug.DebugOptions#setOption(java.lang.String, java.lang.String) */ public void setOption(String option, String value) { - boolean fireChangedEvent = false; + + if (option == null || value == null) { + throw new IllegalArgumentException("The option and value must not be null."); //$NON-NLS-1$ + } + String fireChangedEvent = null; + value = value != null ? value.trim() : null; synchronized (lock) { if (options != null) { // get the current value @@ -249,26 +262,75 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom if (currentValue != null) { if (!currentValue.equals(value)) { - fireChangedEvent = true; + fireChangedEvent = getSymbolicName(option); } } else { if (value != null) { - fireChangedEvent = true; + fireChangedEvent = getSymbolicName(option); } } - if (fireChangedEvent) { - options.put(option, value.trim()); + if (fireChangedEvent != null) { + options.put(option, value); } } } // Send the options change event outside the sync block - if (fireChangedEvent) { - int firstSlashIndex = option.indexOf("/"); //$NON-NLS-1$ - if (firstSlashIndex > 0) { - String symbolicName = option.substring(0, firstSlashIndex); - optionsChanged(symbolicName); + if (fireChangedEvent != null) { + optionsChanged(fireChangedEvent); + } + } + + private String getSymbolicName(String option) { + int firstSlashIndex = option.indexOf("/"); //$NON-NLS-1$ + if (firstSlashIndex > 0) + return option.substring(0, firstSlashIndex); + return null; + } + + public void setOptions(Map ops) { + if (ops == null) + throw new IllegalArgumentException("The options must not be null."); //$NON-NLS-1$ + Properties newOptions = new Properties(); + for (Iterator entries = ops.entrySet().iterator(); entries.hasNext();) { + Entry entry = (Entry) entries.next(); + if (!(entry.getKey() instanceof String) || !(entry.getValue() instanceof String)) + throw new IllegalArgumentException("Option keys and values must be of type String: " + entry.getKey() + "=" + entry.getValue()); //$NON-NLS-1$ //$NON-NLS-2$ + newOptions.put(entry.getKey(), ((String) entry.getValue()).trim()); + } + Set fireChangesTo = null; + + synchronized (lock) { + if (options == null) { + disabledOptions = newOptions; + // no events to fire + return; + } + fireChangesTo = new HashSet(); + // first check for removals + for (Iterator keys = options.keySet().iterator(); keys.hasNext();) { + String key = (String) keys.next(); + if (!newOptions.containsKey(key)) { + String symbolicName = getSymbolicName(key); + if (symbolicName != null) + fireChangesTo.add(symbolicName); + } + } + // now check for changes to existing values + for (Iterator newEntries = newOptions.entrySet().iterator(); newEntries.hasNext();) { + Entry entry = (Entry) newEntries.next(); + String existingValue = (String) options.get(entry.getKey()); + if (!entry.getValue().equals(existingValue)) { + String symbolicName = getSymbolicName((String) entry.getKey()); + if (symbolicName != null) + fireChangesTo.add(symbolicName); + } } + // finally set the actual options + options = newOptions; } + if (fireChangesTo != null) + for (Iterator iChanges = fireChangesTo.iterator(); iChanges.hasNext();) + optionsChanged((String) iChanges.next()); } /* diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/debug/DebugOptions.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/debug/DebugOptions.java index 8611c310f..9e6b3bd2e 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/debug/DebugOptions.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/debug/DebugOptions.java @@ -11,6 +11,7 @@ package org.eclipse.osgi.service.debug; import java.io.File; +import java.util.Map; /** * Used to get debug options settings and creating a new {@link DebugTrace} instance for @@ -97,6 +98,19 @@ public interface DebugOptions { public abstract int getIntegerOption(String option, int defaultValue); /** + * Returns a snapshot of the current options. All + * keys and values are of type <code>String</code>. If no + * options are set then an empty map is returned. + * <p> + * If debug is not enabled then the snapshot of the current disabled + * values is returned. See {@link DebugOptions#setDebugEnabled(boolean)}. + * </p> + * @return a snapshot of the current options. + * @since 3.6 + */ + public Map /*<String, String>*/getOptions(); + + /** * Sets the identified option to the identified value. If debug is * not enabled then the specified option is not changed. * @param option the name of the option to set @@ -105,6 +119,24 @@ public interface DebugOptions { public abstract void setOption(String option, String value); /** + * Sets the current option key/value pairs to the specified options. + * The specified map replaces all keys and values of the current debug options. + * An <code>IllegalArgumentException</code> is thrown if any key or value + * in the specified map is not of type <code>String</code>. + * <p> + * If debug is not enabled then the specified options are saved as + * the disabled values and no notifications will be sent. + * See {@link DebugOptions#setDebugEnabled(boolean)}. + * If debug is enabled then notifications will be sent to the + * listeners which have options that have been changed, added or removed. + * </p> + + * @param options the new set of options + * @since 3.6 + */ + public abstract void setOptions(Map /*<String, String>*/options); + + /** * Removes the identified option. If debug is not enabled then * the specified option is not removed. * @param option the name of the option to remove |