Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util')
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java912
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java760
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java210
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginElementProcessorList.java506
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/PluginFactoryRegistry.java254
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java686
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyPlatform.java116
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java232
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiPlatform.java218
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/ArrayPreference.java190
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BooleanPreference.java78
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BytesPreference.java82
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/DoublePreference.java78
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/FloatPreference.java78
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/IntegerPreference.java78
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/LongPreference.java78
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preference.java242
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java594
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/PreferencesChangeEvent.java114
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/StringPreference.java78
20 files changed, 2792 insertions, 2792 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
index d997a4969c..adfd4f55c1 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
@@ -1,456 +1,456 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.bundle;
-
-import org.eclipse.net4j.internal.util.om.pref.Preferences;
-import org.eclipse.net4j.util.ReflectUtil;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.om.OMBundle;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.log.Logger;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.trace.OMTracer;
-import org.eclipse.net4j.util.om.trace.Tracer;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.text.MessageFormat;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.Properties;
-import java.util.PropertyResourceBundle;
-import java.util.ResourceBundle;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * @author Eike Stepper
- */
-public abstract class AbstractBundle implements OMBundle, OMBundle.DebugSupport, OMBundle.TranslationSupport
-{
- private static final String CLASS_EXTENSION = ".class";
-
- private AbstractPlatform platform;
-
- private String bundleID;
-
- private Class<?> accessor;
-
- private Object bundleContext;
-
- private boolean debugging;
-
- private boolean debuggingInitialized;
-
- private Map<String, Tracer> tracers = new ConcurrentHashMap<String, Tracer>(0);
-
- private OMLogger logger;
-
- private Preferences preferences;
-
- private ResourceBundle resourceBundle;
-
- private ResourceBundle untranslatedResourceBundle;
-
- private Map<String, String> strings = new HashMap<String, String>(0);
-
- private Map<String, String> untranslatedStrings = new HashMap<String, String>(0);
-
- private boolean shouldTranslate = true;
-
- public AbstractBundle(AbstractPlatform platform, String bundleID, Class<?> accessor)
- {
- this.platform = platform;
- this.bundleID = bundleID;
- this.accessor = accessor;
- }
-
- public OMPlatform getPlatform()
- {
- return platform;
- }
-
- public String getBundleID()
- {
- return bundleID;
- }
-
- public Class<?> getAccessor()
- {
- return accessor;
- }
-
- public Object getBundleContext()
- {
- return bundleContext;
- }
-
- @Deprecated
- public void setBundleContext(Object bundleContext)
- {
- this.bundleContext = bundleContext;
- }
-
- public DebugSupport getDebugSupport()
- {
- return this;
- }
-
- public TranslationSupport getTranslationSupport()
- {
- return this;
- }
-
- public boolean isDebugging()
- {
- if (!platform.isDebugging())
- {
- return false;
- }
-
- if (!debuggingInitialized)
- {
- debugging = getDebugOption("debug", false); //$NON-NLS-1$
- debuggingInitialized = true;
- }
-
- return debugging;
- }
-
- public void setDebugging(boolean debugging)
- {
- this.debugging = debugging;
- }
-
- public String getDebugOption(String option, String defaultValue)
- {
- String value = getDebugOption(option);
- return value == null ? defaultValue : value;
- }
-
- public boolean getDebugOption(String option, boolean defaultValue)
- {
- String value = getDebugOption(option);
- return value == null ? defaultValue : Boolean.parseBoolean(value);
- }
-
- public void setDebugOption(String option, boolean value)
- {
- setDebugOption(option, Boolean.toString(value));
- }
-
- public int getDebugOption(String option, int defaultValue)
- {
- try
- {
- String value = getDebugOption(option);
- return value == null ? defaultValue : Integer.parseInt(value);
- }
- catch (NumberFormatException e)
- {
- return defaultValue;
- }
- }
-
- public void setDebugOption(String option, int value)
- {
- setDebugOption(option, Integer.toString(value));
- }
-
- public String getDebugOption(String option)
- {
- return platform.getDebugOption(bundleID, option);
- }
-
- public void setDebugOption(String option, String value)
- {
- platform.setDebugOption(bundleID, option, value);
- }
-
- public synchronized OMTracer tracer(String name)
- {
- OMTracer tracer = tracers.get(name);
- if (tracer == null)
- {
- tracer = createTracer(name);
- }
-
- return tracer;
- }
-
- public synchronized OMLogger logger()
- {
- if (logger == null)
- {
- logger = createLogger();
- }
-
- return logger;
- }
-
- public File getConfigFile()
- {
- return platform.getConfigFile(getConfigFileName());
- }
-
- public Properties getConfigProperties()
- {
- return platform.getConfigProperties(getConfigFileName());
- }
-
- public synchronized Preferences preferences()
- {
- if (preferences == null)
- {
- preferences = new Preferences(this);
- }
-
- return preferences;
- }
-
- public InputStream getInputStream(String path) throws IOException
- {
- String base = getBaseURL().toString();
- if (!base.endsWith("/")) //$NON-NLS-1$
- {
- base += "/"; //$NON-NLS-1$
- }
-
- if (path.startsWith("/")) //$NON-NLS-1$
- {
- path = path.substring(1);
- }
-
- URL url = new URL(base + path);
- return url.openStream();
- }
-
- public boolean shouldTranslate()
- {
- return shouldTranslate;
- }
-
- public void setShouldTranslate(boolean shouldTranslate)
- {
- this.shouldTranslate = shouldTranslate;
- }
-
- public String getString(String key, boolean translate)
- {
- Map<String, String> stringMap = translate ? strings : untranslatedStrings;
- String result = stringMap.get(key);
- if (result == null)
- {
- ResourceBundle bundle = translate ? resourceBundle : untranslatedResourceBundle;
- if (bundle == null)
- {
- String packageName = ReflectUtil.getPackageName(accessor);
- if (translate)
- {
- try
- {
- bundle = resourceBundle = ResourceBundle.getBundle(packageName + ".plugin"); //$NON-NLS-1$
- }
- catch (MissingResourceException exception)
- {
- // If the bundle can't be found the normal way, try to find it as
- // the base URL. If that also doesn't work, rethrow the original
- // exception.
- InputStream inputStream = null;
- try
- {
- inputStream = getInputStream("plugin.properties"); //$NON-NLS-1$
- bundle = new PropertyResourceBundle(inputStream);
- untranslatedResourceBundle = resourceBundle = bundle;
- inputStream.close();
- }
- catch (IOException ignore)
- {
- }
- finally
- {
- IOUtil.closeSilent(inputStream);
- }
-
- if (resourceBundle == null)
- {
- throw exception;
- }
- }
- }
- else
- {
- InputStream inputStream = null;
-
- try
- {
- inputStream = getInputStream("plugin.properties"); //$NON-NLS-1$
- bundle = untranslatedResourceBundle = new PropertyResourceBundle(inputStream);
- inputStream.close();
- }
- catch (IOException ioException)
- {
- throw new MissingResourceException("Missing resource: plugin.properties", accessor //$NON-NLS-1$
- .getName(), key);
- }
- finally
- {
- IOUtil.closeSilent(inputStream);
- }
- }
- }
-
- result = bundle.getString(key);
- stringMap.put(key, result);
- }
-
- return result;
- }
-
- public String getString(String key)
- {
- return getString(key, shouldTranslate());
- }
-
- public String getString(String key, Object... args)
- {
- return getString(key, shouldTranslate(), args);
- }
-
- public String getString(String key, boolean translate, Object... args)
- {
- return MessageFormat.format(getString(key, translate), args);
- }
-
- @Override
- public String toString()
- {
- return bundleID;
- }
-
- public void start() throws Exception
- {
- invokeMethod("start"); //$NON-NLS-1$
- }
-
- public void stop() throws Exception
- {
- try
- {
- if (preferences != null)
- {
- preferences.save();
- }
- }
- catch (RuntimeException ex)
- {
- OM.LOG.error(ex);
- }
-
- invokeMethod("stop"); //$NON-NLS-1$
- }
-
- protected OMTracer createTracer(String name)
- {
- return new Tracer(this, name);
- }
-
- protected OMLogger createLogger()
- {
- return new Logger(this);
- }
-
- protected String getConfigFileName()
- {
- return bundleID + ".properties"; //$NON-NLS-1$
- }
-
- protected final Class<?> getClassFromBundle(String path)
- {
- if (path.endsWith(CLASS_EXTENSION))
- {
- int start = path.startsWith("/") ? 1 : 0;
- int end = path.length() - CLASS_EXTENSION.length();
- String className = path.substring(start, end).replace('/', '.');
-
- for (;;)
- {
- try
- {
- ClassLoader classLoader = getAccessor().getClassLoader();
- Class<?> c = classLoader.loadClass(className);
- if (c != null)
- {
- return c;
- }
- }
- catch (NoClassDefFoundError ex)
- {
- //$FALL-THROUGH$
- }
- catch (ClassNotFoundException ex)
- {
- //$FALL-THROUGH$
- }
-
- int dot = className.indexOf('.');
- if (dot == -1)
- {
- break;
- }
-
- className = className.substring(dot + 1);
- }
- }
-
- return null;
- }
-
- private void invokeMethod(String name) throws Exception
- {
- try
- {
- Method method = accessor.getDeclaredMethod(name, ReflectUtil.NO_PARAMETERS);
- if (!method.isAccessible())
- {
- method.setAccessible(true);
- }
-
- method.invoke(null, ReflectUtil.NO_ARGUMENTS);
- }
- catch (NoSuchMethodException ignore)
- {
- }
- catch (IllegalAccessException ignore)
- {
- }
- catch (InvocationTargetException ex)
- {
- Throwable targetException = ex.getTargetException();
- if (targetException instanceof Exception)
- {
- throw (Exception)targetException;
- }
- else if (targetException instanceof Error)
- {
- throw (Error)targetException;
- }
- else
- {
- OM.LOG.error(targetException);
- }
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.bundle;
+
+import org.eclipse.net4j.internal.util.om.pref.Preferences;
+import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.log.Logger;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.trace.OMTracer;
+import org.eclipse.net4j.util.om.trace.Tracer;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.Properties;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class AbstractBundle implements OMBundle, OMBundle.DebugSupport, OMBundle.TranslationSupport
+{
+ private static final String CLASS_EXTENSION = ".class";
+
+ private AbstractPlatform platform;
+
+ private String bundleID;
+
+ private Class<?> accessor;
+
+ private Object bundleContext;
+
+ private boolean debugging;
+
+ private boolean debuggingInitialized;
+
+ private Map<String, Tracer> tracers = new ConcurrentHashMap<String, Tracer>(0);
+
+ private OMLogger logger;
+
+ private Preferences preferences;
+
+ private ResourceBundle resourceBundle;
+
+ private ResourceBundle untranslatedResourceBundle;
+
+ private Map<String, String> strings = new HashMap<String, String>(0);
+
+ private Map<String, String> untranslatedStrings = new HashMap<String, String>(0);
+
+ private boolean shouldTranslate = true;
+
+ public AbstractBundle(AbstractPlatform platform, String bundleID, Class<?> accessor)
+ {
+ this.platform = platform;
+ this.bundleID = bundleID;
+ this.accessor = accessor;
+ }
+
+ public OMPlatform getPlatform()
+ {
+ return platform;
+ }
+
+ public String getBundleID()
+ {
+ return bundleID;
+ }
+
+ public Class<?> getAccessor()
+ {
+ return accessor;
+ }
+
+ public Object getBundleContext()
+ {
+ return bundleContext;
+ }
+
+ @Deprecated
+ public void setBundleContext(Object bundleContext)
+ {
+ this.bundleContext = bundleContext;
+ }
+
+ public DebugSupport getDebugSupport()
+ {
+ return this;
+ }
+
+ public TranslationSupport getTranslationSupport()
+ {
+ return this;
+ }
+
+ public boolean isDebugging()
+ {
+ if (!platform.isDebugging())
+ {
+ return false;
+ }
+
+ if (!debuggingInitialized)
+ {
+ debugging = getDebugOption("debug", false); //$NON-NLS-1$
+ debuggingInitialized = true;
+ }
+
+ return debugging;
+ }
+
+ public void setDebugging(boolean debugging)
+ {
+ this.debugging = debugging;
+ }
+
+ public String getDebugOption(String option, String defaultValue)
+ {
+ String value = getDebugOption(option);
+ return value == null ? defaultValue : value;
+ }
+
+ public boolean getDebugOption(String option, boolean defaultValue)
+ {
+ String value = getDebugOption(option);
+ return value == null ? defaultValue : Boolean.parseBoolean(value);
+ }
+
+ public void setDebugOption(String option, boolean value)
+ {
+ setDebugOption(option, Boolean.toString(value));
+ }
+
+ public int getDebugOption(String option, int defaultValue)
+ {
+ try
+ {
+ String value = getDebugOption(option);
+ return value == null ? defaultValue : Integer.parseInt(value);
+ }
+ catch (NumberFormatException e)
+ {
+ return defaultValue;
+ }
+ }
+
+ public void setDebugOption(String option, int value)
+ {
+ setDebugOption(option, Integer.toString(value));
+ }
+
+ public String getDebugOption(String option)
+ {
+ return platform.getDebugOption(bundleID, option);
+ }
+
+ public void setDebugOption(String option, String value)
+ {
+ platform.setDebugOption(bundleID, option, value);
+ }
+
+ public synchronized OMTracer tracer(String name)
+ {
+ OMTracer tracer = tracers.get(name);
+ if (tracer == null)
+ {
+ tracer = createTracer(name);
+ }
+
+ return tracer;
+ }
+
+ public synchronized OMLogger logger()
+ {
+ if (logger == null)
+ {
+ logger = createLogger();
+ }
+
+ return logger;
+ }
+
+ public File getConfigFile()
+ {
+ return platform.getConfigFile(getConfigFileName());
+ }
+
+ public Properties getConfigProperties()
+ {
+ return platform.getConfigProperties(getConfigFileName());
+ }
+
+ public synchronized Preferences preferences()
+ {
+ if (preferences == null)
+ {
+ preferences = new Preferences(this);
+ }
+
+ return preferences;
+ }
+
+ public InputStream getInputStream(String path) throws IOException
+ {
+ String base = getBaseURL().toString();
+ if (!base.endsWith("/")) //$NON-NLS-1$
+ {
+ base += "/"; //$NON-NLS-1$
+ }
+
+ if (path.startsWith("/")) //$NON-NLS-1$
+ {
+ path = path.substring(1);
+ }
+
+ URL url = new URL(base + path);
+ return url.openStream();
+ }
+
+ public boolean shouldTranslate()
+ {
+ return shouldTranslate;
+ }
+
+ public void setShouldTranslate(boolean shouldTranslate)
+ {
+ this.shouldTranslate = shouldTranslate;
+ }
+
+ public String getString(String key, boolean translate)
+ {
+ Map<String, String> stringMap = translate ? strings : untranslatedStrings;
+ String result = stringMap.get(key);
+ if (result == null)
+ {
+ ResourceBundle bundle = translate ? resourceBundle : untranslatedResourceBundle;
+ if (bundle == null)
+ {
+ String packageName = ReflectUtil.getPackageName(accessor);
+ if (translate)
+ {
+ try
+ {
+ bundle = resourceBundle = ResourceBundle.getBundle(packageName + ".plugin"); //$NON-NLS-1$
+ }
+ catch (MissingResourceException exception)
+ {
+ // If the bundle can't be found the normal way, try to find it as
+ // the base URL. If that also doesn't work, rethrow the original
+ // exception.
+ InputStream inputStream = null;
+ try
+ {
+ inputStream = getInputStream("plugin.properties"); //$NON-NLS-1$
+ bundle = new PropertyResourceBundle(inputStream);
+ untranslatedResourceBundle = resourceBundle = bundle;
+ inputStream.close();
+ }
+ catch (IOException ignore)
+ {
+ }
+ finally
+ {
+ IOUtil.closeSilent(inputStream);
+ }
+
+ if (resourceBundle == null)
+ {
+ throw exception;
+ }
+ }
+ }
+ else
+ {
+ InputStream inputStream = null;
+
+ try
+ {
+ inputStream = getInputStream("plugin.properties"); //$NON-NLS-1$
+ bundle = untranslatedResourceBundle = new PropertyResourceBundle(inputStream);
+ inputStream.close();
+ }
+ catch (IOException ioException)
+ {
+ throw new MissingResourceException("Missing resource: plugin.properties", accessor //$NON-NLS-1$
+ .getName(), key);
+ }
+ finally
+ {
+ IOUtil.closeSilent(inputStream);
+ }
+ }
+ }
+
+ result = bundle.getString(key);
+ stringMap.put(key, result);
+ }
+
+ return result;
+ }
+
+ public String getString(String key)
+ {
+ return getString(key, shouldTranslate());
+ }
+
+ public String getString(String key, Object... args)
+ {
+ return getString(key, shouldTranslate(), args);
+ }
+
+ public String getString(String key, boolean translate, Object... args)
+ {
+ return MessageFormat.format(getString(key, translate), args);
+ }
+
+ @Override
+ public String toString()
+ {
+ return bundleID;
+ }
+
+ public void start() throws Exception
+ {
+ invokeMethod("start"); //$NON-NLS-1$
+ }
+
+ public void stop() throws Exception
+ {
+ try
+ {
+ if (preferences != null)
+ {
+ preferences.save();
+ }
+ }
+ catch (RuntimeException ex)
+ {
+ OM.LOG.error(ex);
+ }
+
+ invokeMethod("stop"); //$NON-NLS-1$
+ }
+
+ protected OMTracer createTracer(String name)
+ {
+ return new Tracer(this, name);
+ }
+
+ protected OMLogger createLogger()
+ {
+ return new Logger(this);
+ }
+
+ protected String getConfigFileName()
+ {
+ return bundleID + ".properties"; //$NON-NLS-1$
+ }
+
+ protected final Class<?> getClassFromBundle(String path)
+ {
+ if (path.endsWith(CLASS_EXTENSION))
+ {
+ int start = path.startsWith("/") ? 1 : 0;
+ int end = path.length() - CLASS_EXTENSION.length();
+ String className = path.substring(start, end).replace('/', '.');
+
+ for (;;)
+ {
+ try
+ {
+ ClassLoader classLoader = getAccessor().getClassLoader();
+ Class<?> c = classLoader.loadClass(className);
+ if (c != null)
+ {
+ return c;
+ }
+ }
+ catch (NoClassDefFoundError ex)
+ {
+ //$FALL-THROUGH$
+ }
+ catch (ClassNotFoundException ex)
+ {
+ //$FALL-THROUGH$
+ }
+
+ int dot = className.indexOf('.');
+ if (dot == -1)
+ {
+ break;
+ }
+
+ className = className.substring(dot + 1);
+ }
+ }
+
+ return null;
+ }
+
+ private void invokeMethod(String name) throws Exception
+ {
+ try
+ {
+ Method method = accessor.getDeclaredMethod(name, ReflectUtil.NO_PARAMETERS);
+ if (!method.isAccessible())
+ {
+ method.setAccessible(true);
+ }
+
+ method.invoke(null, ReflectUtil.NO_ARGUMENTS);
+ }
+ catch (NoSuchMethodException ignore)
+ {
+ }
+ catch (IllegalAccessException ignore)
+ {
+ }
+ catch (InvocationTargetException ex)
+ {
+ Throwable targetException = ex.getTargetException();
+ if (targetException instanceof Exception)
+ {
+ throw (Exception)targetException;
+ }
+ else if (targetException instanceof Error)
+ {
+ throw (Error)targetException;
+ }
+ else
+ {
+ OM.LOG.error(targetException);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java
index 7d0aef5db7..dd5f24bd8e 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java
@@ -1,380 +1,380 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.bundle;
-
-import org.eclipse.net4j.internal.util.om.LegacyPlatform;
-import org.eclipse.net4j.internal.util.om.OSGiPlatform;
-import org.eclipse.net4j.util.collection.ConcurrentArray;
-import org.eclipse.net4j.util.io.IORuntimeException;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.om.OMBundle;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.log.OMLogFilter;
-import org.eclipse.net4j.util.om.log.OMLogHandler;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.log.OMLogger.Level;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.om.trace.OMTraceHandler;
-import org.eclipse.net4j.util.om.trace.OMTraceHandlerEvent;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.URI;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * @author Eike Stepper
- */
-public abstract class AbstractPlatform implements OMPlatform
-{
- public static final String SYSTEM_PROPERTY_OSGI_STATE = "osgi.instance.area"; //$NON-NLS-1$
-
- public static final String SYSTEM_PROPERTY_NET4J_STATE = "net4j.state"; //$NON-NLS-1$
-
- public static final String SYSTEM_PROPERTY_NET4J_CONFIG = "net4j.config"; //$NON-NLS-1$
-
- static Object systemContext;
-
- private static ContextTracer __TRACER__;
-
- private Map<String, AbstractBundle> bundles = new ConcurrentHashMap<String, AbstractBundle>(0);
-
- private ConcurrentArray<OMLogFilter> logFilters = new ConcurrentArray.Unique<OMLogFilter>()
- {
- @Override
- protected OMLogFilter[] newArray(int length)
- {
- return new OMLogFilter[length];
- }
- };
-
- private ConcurrentArray<OMLogHandler> logHandlers = new ConcurrentArray.Unique<OMLogHandler>()
- {
- @Override
- protected OMLogHandler[] newArray(int length)
- {
- return new OMLogHandler[length];
- }
- };
-
- private ConcurrentArray<OMTraceHandler> traceHandlers = new ConcurrentArray.Unique<OMTraceHandler>()
- {
- @Override
- protected OMTraceHandler[] newArray(int length)
- {
- return new OMTraceHandler[length];
- }
- };
-
- private boolean debugging;
-
- protected AbstractPlatform()
- {
- debugging = Boolean.parseBoolean(getProperty("debug", "false")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public synchronized OMBundle bundle(String bundleID, Class<?> accessor)
- {
- OMBundle bundle = bundles.get(bundleID);
- if (bundle == null)
- {
- bundle = createBundle(bundleID, accessor);
- }
-
- return bundle;
- }
-
- public void addLogFilter(OMLogFilter logFilter)
- {
- logFilters.add(logFilter);
- }
-
- public void removeLogFilter(OMLogFilter logFilter)
- {
- logFilters.remove(logFilter);
- }
-
- public void addLogHandler(OMLogHandler logHandler)
- {
- logHandlers.add(logHandler);
- }
-
- public void removeLogHandler(OMLogHandler logHandler)
- {
- logHandlers.remove(logHandler);
- }
-
- public void addTraceHandler(OMTraceHandler traceHandler)
- {
- traceHandlers.add(traceHandler);
- }
-
- public void removeTraceHandler(OMTraceHandler traceHandler)
- {
- traceHandlers.remove(traceHandler);
- }
-
- public boolean isExtensionRegistryAvailable()
- {
- try
- {
- return internalExtensionRegistryAvailable();
- }
- catch (Throwable ex)
- {
- return false;
- }
- }
-
- public boolean isDebugging()
- {
- return debugging;
- }
-
- public void setDebugging(boolean debugging)
- {
- this.debugging = debugging;
- }
-
- public File getStateFolder()
- {
- String state = getProperty(SYSTEM_PROPERTY_NET4J_STATE);
- if (state == null)
- {
- state = getProperty(SYSTEM_PROPERTY_OSGI_STATE);
- if (state == null)
- {
- state = "state"; //$NON-NLS-1$
- }
- else
- {
- try
- {
- URI uri = new URI(state);
- state = new File(new File(uri), ".metadata").getAbsolutePath(); //$NON-NLS-1$;
- }
- catch (Exception ex)
- {
- OM.LOG.error("Property " + SYSTEM_PROPERTY_OSGI_STATE + " is not a proper file URI: " + state); //$NON-NLS-1$ //$NON-NLS-2$
- state = "state"; //$NON-NLS-1$
- }
- }
- }
-
- File stateFolder = new File(state);
- if (!stateFolder.exists())
- {
- if (!stateFolder.mkdirs())
- {
- throw new IORuntimeException("State folder " + stateFolder.getAbsolutePath() + " could not be created"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- if (!stateFolder.isDirectory())
- {
- throw new IORuntimeException("State folder " + stateFolder.getAbsolutePath() + " is not a directoy"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- return stateFolder;
- }
-
- public File getConfigFolder()
- {
- String config = getProperty(SYSTEM_PROPERTY_NET4J_CONFIG, "config"); //$NON-NLS-1$
- File configFolder = new File(config);
- if (!configFolder.exists())
- {
- if (!configFolder.mkdirs())
- {
- OM.LOG.error("Config folder " + configFolder.getAbsolutePath() + " could not be created"); //$NON-NLS-1$ //$NON-NLS-2$
- return null;
- }
- }
-
- if (!configFolder.isDirectory())
- {
- OM.LOG.error("Config folder " + configFolder.getAbsolutePath() + " is not a directoy"); //$NON-NLS-1$ //$NON-NLS-2$
- return null;
- }
-
- return configFolder;
- }
-
- public File getConfigFile(String name)
- {
- File configFolder = getConfigFolder();
- if (configFolder == null)
- {
- return null;
- }
-
- return new File(configFolder, name);
- }
-
- public Properties getConfigProperties(String name)
- {
- File configFile = getConfigFile(name);
- if (configFile == null)
- {
- return null;
- }
-
- FileInputStream fis = null;
- try
- {
- fis = new FileInputStream(configFile);
- Properties properties = new Properties();
- properties.load(fis);
- return properties;
- }
- catch (IOException ex)
- {
- OM.LOG.error("Config file " + configFile.getAbsolutePath() + " could not be read"); //$NON-NLS-1$ //$NON-NLS-2$
- return null;
- }
- finally
- {
- IOUtil.closeSilent(fis);
- }
- }
-
- public void log(OMLogger logger, Level level, String msg, Throwable t)
- {
- if (!logFilters.isEmpty())
- {
- for (OMLogFilter logFilter : logFilters.get())
- {
- try
- {
- if (logFilter.filter(logger, level, msg, t))
- {
- if (TRACER().isEnabled())
- {
- TRACER().format("Filtered log event: logger={0}, level={1}, msg={2}\n{3}", logger, level, msg, t);
- }
-
- return;
- }
- }
- catch (Exception ex)
- {
- if (TRACER().isEnabled())
- {
- TRACER().trace(ex);
- }
- }
- }
- }
-
- if (!logHandlers.isEmpty())
- {
- for (OMLogHandler logHandler : logHandlers.get())
- {
- try
- {
- logHandler.logged(logger, level, msg, t);
- }
- catch (Exception ex)
- {
- if (TRACER().isEnabled())
- {
- TRACER().trace(ex);
- }
- }
- }
- }
- }
-
- public void trace(OMTraceHandlerEvent event)
- {
- if (!traceHandlers.isEmpty())
- {
- for (OMTraceHandler traceHandler : traceHandlers.get())
- {
- try
- {
- traceHandler.traced(event);
- }
- catch (Exception ex)
- {
- if (TRACER().isEnabled())
- {
- TRACER().trace(ex);
- }
- }
- }
- }
- }
-
- protected Map<String, AbstractBundle> getBundles()
- {
- return bundles;
- }
-
- public String getProperty(String key)
- {
- return System.getProperty(key);
- }
-
- public String getProperty(String key, String defaultValue)
- {
- return System.getProperty(key, defaultValue);
- }
-
- protected abstract OMBundle createBundle(String bundleID, Class<?> accessor);
-
- protected abstract String getDebugOption(String bundleID, String option);
-
- protected abstract void setDebugOption(String bundleID, String option, String value);
-
- /**
- * TODO Make configurable via system property
- */
- public static synchronized OMPlatform createPlatform()
- {
- try
- {
- if (systemContext != null)
- {
- return new OSGiPlatform(systemContext);
- }
-
- return new LegacyPlatform();
- }
- catch (Exception ex)
- {
- if (TRACER().isEnabled())
- {
- TRACER().trace(ex);
- }
- }
-
- return null;
- }
-
- private static ContextTracer TRACER()
- {
- if (__TRACER__ == null)
- {
- __TRACER__ = new ContextTracer(OM.DEBUG_OM, AbstractPlatform.class);
- }
-
- return __TRACER__;
- }
-
- private static boolean internalExtensionRegistryAvailable() throws Throwable
- {
- return org.eclipse.core.runtime.Platform.getExtensionRegistry() != null;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.bundle;
+
+import org.eclipse.net4j.internal.util.om.LegacyPlatform;
+import org.eclipse.net4j.internal.util.om.OSGiPlatform;
+import org.eclipse.net4j.util.collection.ConcurrentArray;
+import org.eclipse.net4j.util.io.IORuntimeException;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.log.OMLogFilter;
+import org.eclipse.net4j.util.om.log.OMLogHandler;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.log.OMLogger.Level;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.om.trace.OMTraceHandler;
+import org.eclipse.net4j.util.om.trace.OMTraceHandlerEvent;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class AbstractPlatform implements OMPlatform
+{
+ public static final String SYSTEM_PROPERTY_OSGI_STATE = "osgi.instance.area"; //$NON-NLS-1$
+
+ public static final String SYSTEM_PROPERTY_NET4J_STATE = "net4j.state"; //$NON-NLS-1$
+
+ public static final String SYSTEM_PROPERTY_NET4J_CONFIG = "net4j.config"; //$NON-NLS-1$
+
+ static Object systemContext;
+
+ private static ContextTracer __TRACER__;
+
+ private Map<String, AbstractBundle> bundles = new ConcurrentHashMap<String, AbstractBundle>(0);
+
+ private ConcurrentArray<OMLogFilter> logFilters = new ConcurrentArray.Unique<OMLogFilter>()
+ {
+ @Override
+ protected OMLogFilter[] newArray(int length)
+ {
+ return new OMLogFilter[length];
+ }
+ };
+
+ private ConcurrentArray<OMLogHandler> logHandlers = new ConcurrentArray.Unique<OMLogHandler>()
+ {
+ @Override
+ protected OMLogHandler[] newArray(int length)
+ {
+ return new OMLogHandler[length];
+ }
+ };
+
+ private ConcurrentArray<OMTraceHandler> traceHandlers = new ConcurrentArray.Unique<OMTraceHandler>()
+ {
+ @Override
+ protected OMTraceHandler[] newArray(int length)
+ {
+ return new OMTraceHandler[length];
+ }
+ };
+
+ private boolean debugging;
+
+ protected AbstractPlatform()
+ {
+ debugging = Boolean.parseBoolean(getProperty("debug", "false")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public synchronized OMBundle bundle(String bundleID, Class<?> accessor)
+ {
+ OMBundle bundle = bundles.get(bundleID);
+ if (bundle == null)
+ {
+ bundle = createBundle(bundleID, accessor);
+ }
+
+ return bundle;
+ }
+
+ public void addLogFilter(OMLogFilter logFilter)
+ {
+ logFilters.add(logFilter);
+ }
+
+ public void removeLogFilter(OMLogFilter logFilter)
+ {
+ logFilters.remove(logFilter);
+ }
+
+ public void addLogHandler(OMLogHandler logHandler)
+ {
+ logHandlers.add(logHandler);
+ }
+
+ public void removeLogHandler(OMLogHandler logHandler)
+ {
+ logHandlers.remove(logHandler);
+ }
+
+ public void addTraceHandler(OMTraceHandler traceHandler)
+ {
+ traceHandlers.add(traceHandler);
+ }
+
+ public void removeTraceHandler(OMTraceHandler traceHandler)
+ {
+ traceHandlers.remove(traceHandler);
+ }
+
+ public boolean isExtensionRegistryAvailable()
+ {
+ try
+ {
+ return internalExtensionRegistryAvailable();
+ }
+ catch (Throwable ex)
+ {
+ return false;
+ }
+ }
+
+ public boolean isDebugging()
+ {
+ return debugging;
+ }
+
+ public void setDebugging(boolean debugging)
+ {
+ this.debugging = debugging;
+ }
+
+ public File getStateFolder()
+ {
+ String state = getProperty(SYSTEM_PROPERTY_NET4J_STATE);
+ if (state == null)
+ {
+ state = getProperty(SYSTEM_PROPERTY_OSGI_STATE);
+ if (state == null)
+ {
+ state = "state"; //$NON-NLS-1$
+ }
+ else
+ {
+ try
+ {
+ URI uri = new URI(state);
+ state = new File(new File(uri), ".metadata").getAbsolutePath(); //$NON-NLS-1$;
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error("Property " + SYSTEM_PROPERTY_OSGI_STATE + " is not a proper file URI: " + state); //$NON-NLS-1$ //$NON-NLS-2$
+ state = "state"; //$NON-NLS-1$
+ }
+ }
+ }
+
+ File stateFolder = new File(state);
+ if (!stateFolder.exists())
+ {
+ if (!stateFolder.mkdirs())
+ {
+ throw new IORuntimeException("State folder " + stateFolder.getAbsolutePath() + " could not be created"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ if (!stateFolder.isDirectory())
+ {
+ throw new IORuntimeException("State folder " + stateFolder.getAbsolutePath() + " is not a directoy"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ return stateFolder;
+ }
+
+ public File getConfigFolder()
+ {
+ String config = getProperty(SYSTEM_PROPERTY_NET4J_CONFIG, "config"); //$NON-NLS-1$
+ File configFolder = new File(config);
+ if (!configFolder.exists())
+ {
+ if (!configFolder.mkdirs())
+ {
+ OM.LOG.error("Config folder " + configFolder.getAbsolutePath() + " could not be created"); //$NON-NLS-1$ //$NON-NLS-2$
+ return null;
+ }
+ }
+
+ if (!configFolder.isDirectory())
+ {
+ OM.LOG.error("Config folder " + configFolder.getAbsolutePath() + " is not a directoy"); //$NON-NLS-1$ //$NON-NLS-2$
+ return null;
+ }
+
+ return configFolder;
+ }
+
+ public File getConfigFile(String name)
+ {
+ File configFolder = getConfigFolder();
+ if (configFolder == null)
+ {
+ return null;
+ }
+
+ return new File(configFolder, name);
+ }
+
+ public Properties getConfigProperties(String name)
+ {
+ File configFile = getConfigFile(name);
+ if (configFile == null)
+ {
+ return null;
+ }
+
+ FileInputStream fis = null;
+ try
+ {
+ fis = new FileInputStream(configFile);
+ Properties properties = new Properties();
+ properties.load(fis);
+ return properties;
+ }
+ catch (IOException ex)
+ {
+ OM.LOG.error("Config file " + configFile.getAbsolutePath() + " could not be read"); //$NON-NLS-1$ //$NON-NLS-2$
+ return null;
+ }
+ finally
+ {
+ IOUtil.closeSilent(fis);
+ }
+ }
+
+ public void log(OMLogger logger, Level level, String msg, Throwable t)
+ {
+ if (!logFilters.isEmpty())
+ {
+ for (OMLogFilter logFilter : logFilters.get())
+ {
+ try
+ {
+ if (logFilter.filter(logger, level, msg, t))
+ {
+ if (TRACER().isEnabled())
+ {
+ TRACER().format("Filtered log event: logger={0}, level={1}, msg={2}\n{3}", logger, level, msg, t);
+ }
+
+ return;
+ }
+ }
+ catch (Exception ex)
+ {
+ if (TRACER().isEnabled())
+ {
+ TRACER().trace(ex);
+ }
+ }
+ }
+ }
+
+ if (!logHandlers.isEmpty())
+ {
+ for (OMLogHandler logHandler : logHandlers.get())
+ {
+ try
+ {
+ logHandler.logged(logger, level, msg, t);
+ }
+ catch (Exception ex)
+ {
+ if (TRACER().isEnabled())
+ {
+ TRACER().trace(ex);
+ }
+ }
+ }
+ }
+ }
+
+ public void trace(OMTraceHandlerEvent event)
+ {
+ if (!traceHandlers.isEmpty())
+ {
+ for (OMTraceHandler traceHandler : traceHandlers.get())
+ {
+ try
+ {
+ traceHandler.traced(event);
+ }
+ catch (Exception ex)
+ {
+ if (TRACER().isEnabled())
+ {
+ TRACER().trace(ex);
+ }
+ }
+ }
+ }
+ }
+
+ protected Map<String, AbstractBundle> getBundles()
+ {
+ return bundles;
+ }
+
+ public String getProperty(String key)
+ {
+ return System.getProperty(key);
+ }
+
+ public String getProperty(String key, String defaultValue)
+ {
+ return System.getProperty(key, defaultValue);
+ }
+
+ protected abstract OMBundle createBundle(String bundleID, Class<?> accessor);
+
+ protected abstract String getDebugOption(String bundleID, String option);
+
+ protected abstract void setDebugOption(String bundleID, String option, String value);
+
+ /**
+ * TODO Make configurable via system property
+ */
+ public static synchronized OMPlatform createPlatform()
+ {
+ try
+ {
+ if (systemContext != null)
+ {
+ return new OSGiPlatform(systemContext);
+ }
+
+ return new LegacyPlatform();
+ }
+ catch (Exception ex)
+ {
+ if (TRACER().isEnabled())
+ {
+ TRACER().trace(ex);
+ }
+ }
+
+ return null;
+ }
+
+ private static ContextTracer TRACER()
+ {
+ if (__TRACER__ == null)
+ {
+ __TRACER__ = new ContextTracer(OM.DEBUG_OM, AbstractPlatform.class);
+ }
+
+ return __TRACER__;
+ }
+
+ private static boolean internalExtensionRegistryAvailable() throws Throwable
+ {
+ return org.eclipse.core.runtime.Platform.getExtensionRegistry() != null;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java
index d9cb9960d5..7e50f80d26 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java
@@ -1,105 +1,105 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.bundle;
-
-import org.eclipse.net4j.internal.util.container.PluginContainer;
-import org.eclipse.net4j.internal.util.om.OSGiBundle;
-import org.eclipse.net4j.util.container.IPluginContainer;
-import org.eclipse.net4j.util.om.OMBundle;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.OSGiActivator;
-import org.eclipse.net4j.util.om.log.EclipseLoggingBridge;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.log.PrintLogHandler;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.om.trace.OMTracer;
-import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-/**
- * The <em>Operations & Maintenance</em> class of this bundle.
- *
- * @author Eike Stepper
- */
-public abstract class OM
-{
- public static final String BUNDLE_ID = "org.eclipse.net4j.util"; //$NON-NLS-1$
-
- public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
-
- public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_LIFECYCLE = DEBUG.tracer("lifecycle"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_LIFECYCLE_DUMP = DEBUG_LIFECYCLE.tracer("dump"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_CONCURRENCY = DEBUG.tracer("concurrency"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_REGISTRY = DEBUG.tracer("registry"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_OM = DEBUG.tracer("om"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_MONITOR = DEBUG_OM.tracer("monitor"); //$NON-NLS-1$
-
- public static final OMLogger LOG = BUNDLE.logger();
-
- public static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_OM, OM.class);
-
- /**
- * @author Eike Stepper
- */
- public static final class Activator implements BundleActivator
- {
- public void start(BundleContext context) throws Exception
- {
- AbstractPlatform.systemContext = context;
- setBundleContext(context);
- ((OSGiBundle)OM.BUNDLE).start();
-
- // TODO Make configurable
- PrintTraceHandler.CONSOLE.setPattern("{6} [{0}] {5}"); //$NON-NLS-1$
- AbstractPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
- AbstractPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
-
- try
- {
- AbstractPlatform.INSTANCE.addLogHandler(EclipseLoggingBridge.INSTANCE);
- }
- catch (Throwable ignore)
- {
- }
-
- OSGiActivator.traceStart(context);
- IPluginContainer container = IPluginContainer.INSTANCE;
- if (TRACER.isEnabled())
- {
- TRACER.format("Plugin container created: {0}", container); //$NON-NLS-1$
- }
- }
-
- public void stop(BundleContext context) throws Exception
- {
- OSGiActivator.traceStop(context);
- ((OSGiBundle)OM.BUNDLE).stop();
- PluginContainer.dispose();
- setBundleContext(null);
- AbstractPlatform.systemContext = null;
- }
-
- @SuppressWarnings("deprecation")
- private void setBundleContext(BundleContext context)
- {
- OM.BUNDLE.setBundleContext(context);
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.bundle;
+
+import org.eclipse.net4j.internal.util.container.PluginContainer;
+import org.eclipse.net4j.internal.util.om.OSGiBundle;
+import org.eclipse.net4j.util.container.IPluginContainer;
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.OSGiActivator;
+import org.eclipse.net4j.util.om.log.EclipseLoggingBridge;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.log.PrintLogHandler;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.om.trace.OMTracer;
+import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The <em>Operations & Maintenance</em> class of this bundle.
+ *
+ * @author Eike Stepper
+ */
+public abstract class OM
+{
+ public static final String BUNDLE_ID = "org.eclipse.net4j.util"; //$NON-NLS-1$
+
+ public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
+
+ public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_LIFECYCLE = DEBUG.tracer("lifecycle"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_LIFECYCLE_DUMP = DEBUG_LIFECYCLE.tracer("dump"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_CONCURRENCY = DEBUG.tracer("concurrency"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_REGISTRY = DEBUG.tracer("registry"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_OM = DEBUG.tracer("om"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_MONITOR = DEBUG_OM.tracer("monitor"); //$NON-NLS-1$
+
+ public static final OMLogger LOG = BUNDLE.logger();
+
+ public static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_OM, OM.class);
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class Activator implements BundleActivator
+ {
+ public void start(BundleContext context) throws Exception
+ {
+ AbstractPlatform.systemContext = context;
+ setBundleContext(context);
+ ((OSGiBundle)OM.BUNDLE).start();
+
+ // TODO Make configurable
+ PrintTraceHandler.CONSOLE.setPattern("{6} [{0}] {5}"); //$NON-NLS-1$
+ AbstractPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
+ AbstractPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
+
+ try
+ {
+ AbstractPlatform.INSTANCE.addLogHandler(EclipseLoggingBridge.INSTANCE);
+ }
+ catch (Throwable ignore)
+ {
+ }
+
+ OSGiActivator.traceStart(context);
+ IPluginContainer container = IPluginContainer.INSTANCE;
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Plugin container created: {0}", container); //$NON-NLS-1$
+ }
+ }
+
+ public void stop(BundleContext context) throws Exception
+ {
+ OSGiActivator.traceStop(context);
+ ((OSGiBundle)OM.BUNDLE).stop();
+ PluginContainer.dispose();
+ setBundleContext(null);
+ AbstractPlatform.systemContext = null;
+ }
+
+ @SuppressWarnings("deprecation")
+ private void setBundleContext(BundleContext context)
+ {
+ OM.BUNDLE.setBundleContext(context);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginElementProcessorList.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginElementProcessorList.java
index 8fa5704f59..1c1e5349d8 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginElementProcessorList.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginElementProcessorList.java
@@ -1,253 +1,253 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.container;
-
-import org.eclipse.net4j.internal.util.bundle.OM;
-import org.eclipse.net4j.util.container.IElementProcessor;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-
-import org.eclipse.core.runtime.CoreException;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * @author Eike Stepper
- */
-public class PluginElementProcessorList extends Lifecycle implements List<IElementProcessor>
-{
- private static final String ATTR_CLASS = "class"; //$NON-NLS-1$
-
- public static final String NAMESPACE = OM.BUNDLE_ID;
-
- public static final String EXT_POINT = "elementProcessors"; //$NON-NLS-1$
-
- private List<IElementProcessor> processors = new ArrayList<IElementProcessor>();
-
- private Object extensionRegistryListener;
-
- public PluginElementProcessorList()
- {
- }
-
- public boolean add(IElementProcessor o)
- {
- return processors.add(o);
- }
-
- public void add(int index, IElementProcessor element)
- {
- processors.add(index, element);
- }
-
- public boolean addAll(Collection<? extends IElementProcessor> c)
- {
- return processors.addAll(c);
- }
-
- public boolean addAll(int index, Collection<? extends IElementProcessor> c)
- {
- return processors.addAll(index, c);
- }
-
- public void clear()
- {
- processors.clear();
- }
-
- public boolean contains(Object o)
- {
- return processors.contains(o);
- }
-
- public boolean containsAll(Collection<?> c)
- {
- return processors.containsAll(c);
- }
-
- @Override
- public boolean equals(Object o)
- {
- return processors.equals(o);
- }
-
- public IElementProcessor get(int index)
- {
- return processors.get(index);
- }
-
- @Override
- public int hashCode()
- {
- return processors.hashCode();
- }
-
- public int indexOf(Object o)
- {
- return processors.indexOf(o);
- }
-
- public boolean isEmpty()
- {
- return processors.isEmpty();
- }
-
- public Iterator<IElementProcessor> iterator()
- {
- return processors.iterator();
- }
-
- public int lastIndexOf(Object o)
- {
- return processors.lastIndexOf(o);
- }
-
- public ListIterator<IElementProcessor> listIterator()
- {
- return processors.listIterator();
- }
-
- public ListIterator<IElementProcessor> listIterator(int index)
- {
- return processors.listIterator(index);
- }
-
- public IElementProcessor remove(int index)
- {
- return processors.remove(index);
- }
-
- public boolean remove(Object o)
- {
- return processors.remove(o);
- }
-
- public boolean removeAll(Collection<?> c)
- {
- return processors.removeAll(c);
- }
-
- public boolean retainAll(Collection<?> c)
- {
- return processors.retainAll(c);
- }
-
- public IElementProcessor set(int index, IElementProcessor element)
- {
- return processors.set(index, element);
- }
-
- public int size()
- {
- return processors.size();
- }
-
- public List<IElementProcessor> subList(int fromIndex, int toIndex)
- {
- return processors.subList(fromIndex, toIndex);
- }
-
- public Object[] toArray()
- {
- return processors.toArray();
- }
-
- public <T> T[] toArray(T[] a)
- {
- return processors.toArray(a);
- }
-
- @Override
- public String toString()
- {
- return processors.toString();
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- try
- {
- doActivateOSGi();
- }
- catch (Throwable t)
- {
- OM.LOG.warn(t);
- }
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- try
- {
- doDeactivateOSGi();
- }
- catch (Throwable t)
- {
- OM.LOG.warn(t);
- }
-
- processors.clear();
- super.doDeactivate();
- }
-
- private void doActivateOSGi() throws CoreException
- {
- org.eclipse.core.runtime.IExtensionRegistry extensionRegistry = org.eclipse.core.runtime.Platform
- .getExtensionRegistry();
- if (extensionRegistry == null)
- {
- return;
- }
-
- org.eclipse.core.runtime.IConfigurationElement[] elements = extensionRegistry.getConfigurationElementsFor(
- NAMESPACE, EXT_POINT);
- for (org.eclipse.core.runtime.IConfigurationElement element : elements)
- {
- IElementProcessor processor = (IElementProcessor)element.createExecutableExtension(ATTR_CLASS);
- processors.add(processor);
- }
-
- org.eclipse.core.runtime.IRegistryChangeListener listener = new org.eclipse.core.runtime.IRegistryChangeListener()
- {
- public void registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent event)
- {
- org.eclipse.core.runtime.IExtensionDelta[] deltas = event.getExtensionDeltas(NAMESPACE, EXT_POINT);
- for (org.eclipse.core.runtime.IExtensionDelta delta : deltas)
- {
- // TODO Handle ExtensionDelta
- OM.LOG.warn("ExtensionDelta not handled: " + delta); //$NON-NLS-1$
- }
- }
- };
-
- extensionRegistry.addRegistryChangeListener(listener, NAMESPACE);
- extensionRegistryListener = listener;
- }
-
- private void doDeactivateOSGi()
- {
- org.eclipse.core.runtime.IExtensionRegistry extensionRegistry = org.eclipse.core.runtime.Platform
- .getExtensionRegistry();
- if (extensionRegistry == null)
- {
- return;
- }
-
- extensionRegistry
- .removeRegistryChangeListener((org.eclipse.core.runtime.IRegistryChangeListener)extensionRegistryListener);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.container;
+
+import org.eclipse.net4j.internal.util.bundle.OM;
+import org.eclipse.net4j.util.container.IElementProcessor;
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+
+import org.eclipse.core.runtime.CoreException;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * @author Eike Stepper
+ */
+public class PluginElementProcessorList extends Lifecycle implements List<IElementProcessor>
+{
+ private static final String ATTR_CLASS = "class"; //$NON-NLS-1$
+
+ public static final String NAMESPACE = OM.BUNDLE_ID;
+
+ public static final String EXT_POINT = "elementProcessors"; //$NON-NLS-1$
+
+ private List<IElementProcessor> processors = new ArrayList<IElementProcessor>();
+
+ private Object extensionRegistryListener;
+
+ public PluginElementProcessorList()
+ {
+ }
+
+ public boolean add(IElementProcessor o)
+ {
+ return processors.add(o);
+ }
+
+ public void add(int index, IElementProcessor element)
+ {
+ processors.add(index, element);
+ }
+
+ public boolean addAll(Collection<? extends IElementProcessor> c)
+ {
+ return processors.addAll(c);
+ }
+
+ public boolean addAll(int index, Collection<? extends IElementProcessor> c)
+ {
+ return processors.addAll(index, c);
+ }
+
+ public void clear()
+ {
+ processors.clear();
+ }
+
+ public boolean contains(Object o)
+ {
+ return processors.contains(o);
+ }
+
+ public boolean containsAll(Collection<?> c)
+ {
+ return processors.containsAll(c);
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ return processors.equals(o);
+ }
+
+ public IElementProcessor get(int index)
+ {
+ return processors.get(index);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return processors.hashCode();
+ }
+
+ public int indexOf(Object o)
+ {
+ return processors.indexOf(o);
+ }
+
+ public boolean isEmpty()
+ {
+ return processors.isEmpty();
+ }
+
+ public Iterator<IElementProcessor> iterator()
+ {
+ return processors.iterator();
+ }
+
+ public int lastIndexOf(Object o)
+ {
+ return processors.lastIndexOf(o);
+ }
+
+ public ListIterator<IElementProcessor> listIterator()
+ {
+ return processors.listIterator();
+ }
+
+ public ListIterator<IElementProcessor> listIterator(int index)
+ {
+ return processors.listIterator(index);
+ }
+
+ public IElementProcessor remove(int index)
+ {
+ return processors.remove(index);
+ }
+
+ public boolean remove(Object o)
+ {
+ return processors.remove(o);
+ }
+
+ public boolean removeAll(Collection<?> c)
+ {
+ return processors.removeAll(c);
+ }
+
+ public boolean retainAll(Collection<?> c)
+ {
+ return processors.retainAll(c);
+ }
+
+ public IElementProcessor set(int index, IElementProcessor element)
+ {
+ return processors.set(index, element);
+ }
+
+ public int size()
+ {
+ return processors.size();
+ }
+
+ public List<IElementProcessor> subList(int fromIndex, int toIndex)
+ {
+ return processors.subList(fromIndex, toIndex);
+ }
+
+ public Object[] toArray()
+ {
+ return processors.toArray();
+ }
+
+ public <T> T[] toArray(T[] a)
+ {
+ return processors.toArray(a);
+ }
+
+ @Override
+ public String toString()
+ {
+ return processors.toString();
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ super.doActivate();
+ try
+ {
+ doActivateOSGi();
+ }
+ catch (Throwable t)
+ {
+ OM.LOG.warn(t);
+ }
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ try
+ {
+ doDeactivateOSGi();
+ }
+ catch (Throwable t)
+ {
+ OM.LOG.warn(t);
+ }
+
+ processors.clear();
+ super.doDeactivate();
+ }
+
+ private void doActivateOSGi() throws CoreException
+ {
+ org.eclipse.core.runtime.IExtensionRegistry extensionRegistry = org.eclipse.core.runtime.Platform
+ .getExtensionRegistry();
+ if (extensionRegistry == null)
+ {
+ return;
+ }
+
+ org.eclipse.core.runtime.IConfigurationElement[] elements = extensionRegistry.getConfigurationElementsFor(
+ NAMESPACE, EXT_POINT);
+ for (org.eclipse.core.runtime.IConfigurationElement element : elements)
+ {
+ IElementProcessor processor = (IElementProcessor)element.createExecutableExtension(ATTR_CLASS);
+ processors.add(processor);
+ }
+
+ org.eclipse.core.runtime.IRegistryChangeListener listener = new org.eclipse.core.runtime.IRegistryChangeListener()
+ {
+ public void registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent event)
+ {
+ org.eclipse.core.runtime.IExtensionDelta[] deltas = event.getExtensionDeltas(NAMESPACE, EXT_POINT);
+ for (org.eclipse.core.runtime.IExtensionDelta delta : deltas)
+ {
+ // TODO Handle ExtensionDelta
+ OM.LOG.warn("ExtensionDelta not handled: " + delta); //$NON-NLS-1$
+ }
+ }
+ };
+
+ extensionRegistry.addRegistryChangeListener(listener, NAMESPACE);
+ extensionRegistryListener = listener;
+ }
+
+ private void doDeactivateOSGi()
+ {
+ org.eclipse.core.runtime.IExtensionRegistry extensionRegistry = org.eclipse.core.runtime.Platform
+ .getExtensionRegistry();
+ if (extensionRegistry == null)
+ {
+ return;
+ }
+
+ extensionRegistry
+ .removeRegistryChangeListener((org.eclipse.core.runtime.IRegistryChangeListener)extensionRegistryListener);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/PluginFactoryRegistry.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/PluginFactoryRegistry.java
index 04f569d54e..19491cd3e0 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/PluginFactoryRegistry.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/PluginFactoryRegistry.java
@@ -1,127 +1,127 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.factory;
-
-import org.eclipse.net4j.internal.util.bundle.OM;
-import org.eclipse.net4j.util.factory.FactoryDescriptor;
-import org.eclipse.net4j.util.factory.IFactory;
-import org.eclipse.net4j.util.factory.IFactoryKey;
-import org.eclipse.net4j.util.registry.HashMapRegistry;
-
-/**
- * @author Eike Stepper
- */
-public class PluginFactoryRegistry extends HashMapRegistry<IFactoryKey, IFactory>
-{
- public static final String NAMESPACE = OM.BUNDLE_ID;
-
- public static final String EXT_POINT = "factories"; //$NON-NLS-1$
-
- private Object extensionRegistryListener;
-
- public PluginFactoryRegistry()
- {
- }
-
- @Override
- public IFactory get(Object key)
- {
- IFactory factory = super.get(key);
- if (factory instanceof FactoryDescriptor)
- {
- FactoryDescriptor descriptor = (FactoryDescriptor)factory;
- factory = descriptor.createFactory();
- }
-
- return factory;
- }
-
- public void registerFactory(FactoryDescriptor factory)
- {
- put(factory.getKey(), factory);
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- try
- {
- doActivateOSGi();
- }
- catch (Throwable t)
- {
- OM.LOG.warn(t);
- }
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- try
- {
- doDeactivateOSGi();
- }
- catch (Throwable t)
- {
- OM.LOG.warn(t);
- }
-
- clear();
- super.doDeactivate();
- }
-
- private void doActivateOSGi()
- {
- org.eclipse.core.runtime.IExtensionRegistry extensionRegistry = org.eclipse.core.runtime.Platform
- .getExtensionRegistry();
- if (extensionRegistry == null)
- {
- return;
- }
-
- org.eclipse.core.runtime.IConfigurationElement[] elements = extensionRegistry.getConfigurationElementsFor(
- NAMESPACE, EXT_POINT);
- for (org.eclipse.core.runtime.IConfigurationElement element : elements)
- {
- registerFactory(new FactoryDescriptor(element));
- }
-
- org.eclipse.core.runtime.IRegistryChangeListener listener = new org.eclipse.core.runtime.IRegistryChangeListener()
- {
- public void registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent event)
- {
- org.eclipse.core.runtime.IExtensionDelta[] deltas = event.getExtensionDeltas(NAMESPACE, EXT_POINT);
- for (org.eclipse.core.runtime.IExtensionDelta delta : deltas)
- {
- // TODO Handle ExtensionDelta
- OM.LOG.warn("ExtensionDelta not handled: " + delta); //$NON-NLS-1$
- }
- }
- };
-
- extensionRegistry.addRegistryChangeListener(listener, NAMESPACE);
- extensionRegistryListener = listener;
- }
-
- private void doDeactivateOSGi()
- {
- org.eclipse.core.runtime.IExtensionRegistry extensionRegistry = org.eclipse.core.runtime.Platform
- .getExtensionRegistry();
- if (extensionRegistry == null)
- {
- return;
- }
-
- extensionRegistry
- .removeRegistryChangeListener((org.eclipse.core.runtime.IRegistryChangeListener)extensionRegistryListener);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.factory;
+
+import org.eclipse.net4j.internal.util.bundle.OM;
+import org.eclipse.net4j.util.factory.FactoryDescriptor;
+import org.eclipse.net4j.util.factory.IFactory;
+import org.eclipse.net4j.util.factory.IFactoryKey;
+import org.eclipse.net4j.util.registry.HashMapRegistry;
+
+/**
+ * @author Eike Stepper
+ */
+public class PluginFactoryRegistry extends HashMapRegistry<IFactoryKey, IFactory>
+{
+ public static final String NAMESPACE = OM.BUNDLE_ID;
+
+ public static final String EXT_POINT = "factories"; //$NON-NLS-1$
+
+ private Object extensionRegistryListener;
+
+ public PluginFactoryRegistry()
+ {
+ }
+
+ @Override
+ public IFactory get(Object key)
+ {
+ IFactory factory = super.get(key);
+ if (factory instanceof FactoryDescriptor)
+ {
+ FactoryDescriptor descriptor = (FactoryDescriptor)factory;
+ factory = descriptor.createFactory();
+ }
+
+ return factory;
+ }
+
+ public void registerFactory(FactoryDescriptor factory)
+ {
+ put(factory.getKey(), factory);
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ super.doActivate();
+ try
+ {
+ doActivateOSGi();
+ }
+ catch (Throwable t)
+ {
+ OM.LOG.warn(t);
+ }
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ try
+ {
+ doDeactivateOSGi();
+ }
+ catch (Throwable t)
+ {
+ OM.LOG.warn(t);
+ }
+
+ clear();
+ super.doDeactivate();
+ }
+
+ private void doActivateOSGi()
+ {
+ org.eclipse.core.runtime.IExtensionRegistry extensionRegistry = org.eclipse.core.runtime.Platform
+ .getExtensionRegistry();
+ if (extensionRegistry == null)
+ {
+ return;
+ }
+
+ org.eclipse.core.runtime.IConfigurationElement[] elements = extensionRegistry.getConfigurationElementsFor(
+ NAMESPACE, EXT_POINT);
+ for (org.eclipse.core.runtime.IConfigurationElement element : elements)
+ {
+ registerFactory(new FactoryDescriptor(element));
+ }
+
+ org.eclipse.core.runtime.IRegistryChangeListener listener = new org.eclipse.core.runtime.IRegistryChangeListener()
+ {
+ public void registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent event)
+ {
+ org.eclipse.core.runtime.IExtensionDelta[] deltas = event.getExtensionDeltas(NAMESPACE, EXT_POINT);
+ for (org.eclipse.core.runtime.IExtensionDelta delta : deltas)
+ {
+ // TODO Handle ExtensionDelta
+ OM.LOG.warn("ExtensionDelta not handled: " + delta); //$NON-NLS-1$
+ }
+ }
+ };
+
+ extensionRegistry.addRegistryChangeListener(listener, NAMESPACE);
+ extensionRegistryListener = listener;
+ }
+
+ private void doDeactivateOSGi()
+ {
+ org.eclipse.core.runtime.IExtensionRegistry extensionRegistry = org.eclipse.core.runtime.Platform
+ .getExtensionRegistry();
+ if (extensionRegistry == null)
+ {
+ return;
+ }
+
+ extensionRegistry
+ .removeRegistryChangeListener((org.eclipse.core.runtime.IRegistryChangeListener)extensionRegistryListener);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java
index 2cfb67bb15..4905a122a6 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java
@@ -1,343 +1,343 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om;
-
-import org.eclipse.net4j.internal.util.bundle.AbstractBundle;
-import org.eclipse.net4j.internal.util.bundle.AbstractPlatform;
-import org.eclipse.net4j.util.ReflectUtil;
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.io.IOUtil;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.MissingResourceException;
-import java.util.Properties;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-/**
- * @author Eike Stepper
- */
-public class LegacyBundle extends AbstractBundle
-{
- private URL baseURL;
-
- public LegacyBundle(AbstractPlatform platform, String bundleID, Class<?> accessor)
- {
- super(platform, bundleID, accessor);
-
- try
- {
- computeBaseURL(accessor);
- if (baseURL == null)
- {
- throw new IllegalStateException("No base URL");
- }
-
- loadOptions();
- }
- catch (Exception ex)
- {
- IOUtil.print(ex);
- }
- }
-
- public String getStateLocation()
- {
- return new File(getPlatform().getStateFolder(), ".plugins/" + getBundleID()).getAbsolutePath(); //$NON-NLS-1$
- }
-
- public URL getBaseURL()
- {
- return baseURL;
- }
-
- public Iterator<Class<?>> getClasses()
- {
- List<Class<?>> result = new ArrayList<Class<?>>();
-
- if (isArchiveProtocol(baseURL.getProtocol()))
- {
- JarFile jarFile = null;
-
- try
- {
- jarFile = new JarFile(baseURL.getFile());
-
- Enumeration<JarEntry> entries = jarFile.entries();
- while (entries.hasMoreElements())
- {
- JarEntry jarEntry = entries.nextElement();
- if (!jarEntry.isDirectory())
- {
- Class<?> c = getClassFromBundle(jarEntry.getName());
- if (c != null)
- {
- result.add(c);
- }
- }
- }
- }
- catch (IOException ex)
- {
- throw WrappedException.wrap(ex);
- }
- finally
- {
- if (jarFile != null)
- {
- try
- {
- jarFile.close();
- }
- catch (IOException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
- }
- }
- else
- {
- try
- {
- URL url = getClassesURL(getAccessor());
- File folder = new File(url.getFile());
- collectFileClasses(folder, null, result);
- }
- catch (MalformedURLException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- return result.iterator();
- }
-
- private void collectFileClasses(File folder, String path, List<Class<?>> result)
- {
- File file = folder;
- if (path == null)
- {
- path = "";
- }
- else
- {
- file = new File(folder, path);
- }
-
- if (file.isDirectory())
- {
- for (String child : file.list())
- {
- collectFileClasses(folder, path + "/" + child, result);
- }
- }
- else
- {
- Class<?> c = getClassFromBundle(path);
- if (c != null)
- {
- result.add(c);
- }
- }
- }
-
- private void loadOptions()
- {
- InputStream inputStream = null;
- Properties properties = new Properties();
-
- try
- {
- final String prefix = getBundleID() + "/"; //$NON-NLS-1$
- final int length = prefix.length();
-
- inputStream = getInputStream(".options"); //$NON-NLS-1$
- properties.load(inputStream);
-
- for (Entry<Object, Object> entry : properties.entrySet())
- {
- try
- {
- String key = (String)entry.getKey();
- if (key.startsWith(prefix))
- {
- String value = (String)entry.getValue();
- setDebugOption(key.substring(length), value);
- }
- }
- catch (RuntimeException ignore)
- {
- }
- }
- }
- catch (IOException ignore)
- {
- }
- finally
- {
- IOUtil.closeSilent(inputStream);
- }
- }
-
- private void computeBaseURL(Class<?> accessor) throws MalformedURLException
- {
- // Determine the URL for the class itself. The URL will be of one of the
- // following forms, so there are a few good places to consider looking for
- // the plugin.properties.
- //
- // For a plugin.xml with runtime="common.jar":
- // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/common.jar!/org/eclipse/common/
- // CommonPlugin.class
- //
- // For a plugin.xml with runtime="runtime/common.jar":
- // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/runtime/common.jar!/org/eclipse/common
- // /CommonPlugin.class
- //
- // For a plugin.xml with runtime="." where the plugin is jarred:
- // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common.jar!/org/eclipse/common/CommonPlugin.
- // class
- //
- // For a plugin.xml with runtime="." where the plugin is not jarred.
- // file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/org/eclipse/emf/common/CommonPlugin.class
- //
- // Running in PDE with bin on classpath:
- // file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/bin/org/eclipse/emf/common/CommonPlugin.
- // class
-
- URL url = getClassesURL(accessor);
-
- // For an archive URI, check for the plugin.properties in the archive.
- if (isArchiveProtocol(url.getProtocol()))
- {
- try
- {
- // If we can open an input stream, then the plugin.properties is there,
- // and we have a good base URL.
- URL u = new URL(url.toString() + "plugin.properties");
- InputStream inputStream = null;
-
- try
- {
- inputStream = u.openStream();
- }
- finally
- {
- IOUtil.close(inputStream);
- }
-
- baseURL = url;
- }
- catch (IOException exception)
- {
- // If the plugin.properties isn't within the root of the archive, create
- // a new URI for the folder location of the archive, so we can look in
- // the folder that contains it.
- url = trimSegments(new URL(url.getFile()), 1);
- }
- }
-
- // If we didn't find the plugin.properties in the usual place nor in the
- // archive...
- if (baseURL == null)
- {
- // Trim off the "bin" or "runtime" segment.
- String lastSegment = lastSegment(url);
- if ("bin".equals(lastSegment) || "runtime".equals(lastSegment)) //$NON-NLS-1$ //$NON-NLS-2$
- {
- url = trimSegments(url, 1);
- }
-
- try
- {
- // If we can open an input stream, then the plugin.properties is in the
- // folder, and we have a good base URL.
- InputStream inputStream = new URL(url.toString() + "plugin.properties").openStream(); //$NON-NLS-1$
- inputStream.close();
- baseURL = url;
- }
- catch (IOException exception)
- {
- }
- }
-
- // If we still don't have a good base URL, complain about it.
- if (baseURL == null)
- {
- throw new MissingResourceException("Missing properties: " + accessor.getName(), accessor.getName(), //$NON-NLS-1$
- "plugin.properties"); //$NON-NLS-1$
- }
- }
-
- private static URL getClassesURL(Class<?> accessor) throws MalformedURLException
- {
- String className = accessor.getName();
- URL url = accessor.getResource(ReflectUtil.getSimpleName(accessor) + ".class"); //$NON-NLS-1$
-
- int segmentsToTrim = 1 + StringUtil.occurrences(className, '.');
- return trimSegments(url, segmentsToTrim);
- }
-
- private static String lastSegment(URL url)
- {
- String path = url.getPath();
- if (path.endsWith("/")) //$NON-NLS-1$
- {
- path = path.substring(0, path.length() - 1);
- }
-
- int pos = path.lastIndexOf('/');
- return pos == -1 ? path : path.substring(pos + 1);
- }
-
- private static URL trimSegments(URL url, int count) throws MalformedURLException
- {
- String path = url.getPath();
- if (path.endsWith("/")) //$NON-NLS-1$
- {
- ++count;
- }
-
- for (int i = 0; i < count; i++)
- {
- int pos = path.lastIndexOf('/');
- if (pos == -1)
- {
- break;
- }
-
- // TODO Optimize
- path = path.substring(0, pos);
- }
-
- return new URL(url.getProtocol() + ":" + path + "/"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * TODO Make configurable
- *
- * @see org.eclipse.emf.common.util.URI#isArchiveScheme(String)
- */
- private static boolean isArchiveProtocol(String scheme)
- {
- return "jar".equalsIgnoreCase(scheme); //$NON-NLS-1$
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om;
+
+import org.eclipse.net4j.internal.util.bundle.AbstractBundle;
+import org.eclipse.net4j.internal.util.bundle.AbstractPlatform;
+import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.io.IOUtil;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.MissingResourceException;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * @author Eike Stepper
+ */
+public class LegacyBundle extends AbstractBundle
+{
+ private URL baseURL;
+
+ public LegacyBundle(AbstractPlatform platform, String bundleID, Class<?> accessor)
+ {
+ super(platform, bundleID, accessor);
+
+ try
+ {
+ computeBaseURL(accessor);
+ if (baseURL == null)
+ {
+ throw new IllegalStateException("No base URL");
+ }
+
+ loadOptions();
+ }
+ catch (Exception ex)
+ {
+ IOUtil.print(ex);
+ }
+ }
+
+ public String getStateLocation()
+ {
+ return new File(getPlatform().getStateFolder(), ".plugins/" + getBundleID()).getAbsolutePath(); //$NON-NLS-1$
+ }
+
+ public URL getBaseURL()
+ {
+ return baseURL;
+ }
+
+ public Iterator<Class<?>> getClasses()
+ {
+ List<Class<?>> result = new ArrayList<Class<?>>();
+
+ if (isArchiveProtocol(baseURL.getProtocol()))
+ {
+ JarFile jarFile = null;
+
+ try
+ {
+ jarFile = new JarFile(baseURL.getFile());
+
+ Enumeration<JarEntry> entries = jarFile.entries();
+ while (entries.hasMoreElements())
+ {
+ JarEntry jarEntry = entries.nextElement();
+ if (!jarEntry.isDirectory())
+ {
+ Class<?> c = getClassFromBundle(jarEntry.getName());
+ if (c != null)
+ {
+ result.add(c);
+ }
+ }
+ }
+ }
+ catch (IOException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ finally
+ {
+ if (jarFile != null)
+ {
+ try
+ {
+ jarFile.close();
+ }
+ catch (IOException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+ }
+ }
+ else
+ {
+ try
+ {
+ URL url = getClassesURL(getAccessor());
+ File folder = new File(url.getFile());
+ collectFileClasses(folder, null, result);
+ }
+ catch (MalformedURLException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ return result.iterator();
+ }
+
+ private void collectFileClasses(File folder, String path, List<Class<?>> result)
+ {
+ File file = folder;
+ if (path == null)
+ {
+ path = "";
+ }
+ else
+ {
+ file = new File(folder, path);
+ }
+
+ if (file.isDirectory())
+ {
+ for (String child : file.list())
+ {
+ collectFileClasses(folder, path + "/" + child, result);
+ }
+ }
+ else
+ {
+ Class<?> c = getClassFromBundle(path);
+ if (c != null)
+ {
+ result.add(c);
+ }
+ }
+ }
+
+ private void loadOptions()
+ {
+ InputStream inputStream = null;
+ Properties properties = new Properties();
+
+ try
+ {
+ final String prefix = getBundleID() + "/"; //$NON-NLS-1$
+ final int length = prefix.length();
+
+ inputStream = getInputStream(".options"); //$NON-NLS-1$
+ properties.load(inputStream);
+
+ for (Entry<Object, Object> entry : properties.entrySet())
+ {
+ try
+ {
+ String key = (String)entry.getKey();
+ if (key.startsWith(prefix))
+ {
+ String value = (String)entry.getValue();
+ setDebugOption(key.substring(length), value);
+ }
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ }
+ catch (IOException ignore)
+ {
+ }
+ finally
+ {
+ IOUtil.closeSilent(inputStream);
+ }
+ }
+
+ private void computeBaseURL(Class<?> accessor) throws MalformedURLException
+ {
+ // Determine the URL for the class itself. The URL will be of one of the
+ // following forms, so there are a few good places to consider looking for
+ // the plugin.properties.
+ //
+ // For a plugin.xml with runtime="common.jar":
+ // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/common.jar!/org/eclipse/common/
+ // CommonPlugin.class
+ //
+ // For a plugin.xml with runtime="runtime/common.jar":
+ // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/runtime/common.jar!/org/eclipse/common
+ // /CommonPlugin.class
+ //
+ // For a plugin.xml with runtime="." where the plugin is jarred:
+ // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common.jar!/org/eclipse/common/CommonPlugin.
+ // class
+ //
+ // For a plugin.xml with runtime="." where the plugin is not jarred.
+ // file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/org/eclipse/emf/common/CommonPlugin.class
+ //
+ // Running in PDE with bin on classpath:
+ // file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/bin/org/eclipse/emf/common/CommonPlugin.
+ // class
+
+ URL url = getClassesURL(accessor);
+
+ // For an archive URI, check for the plugin.properties in the archive.
+ if (isArchiveProtocol(url.getProtocol()))
+ {
+ try
+ {
+ // If we can open an input stream, then the plugin.properties is there,
+ // and we have a good base URL.
+ URL u = new URL(url.toString() + "plugin.properties");
+ InputStream inputStream = null;
+
+ try
+ {
+ inputStream = u.openStream();
+ }
+ finally
+ {
+ IOUtil.close(inputStream);
+ }
+
+ baseURL = url;
+ }
+ catch (IOException exception)
+ {
+ // If the plugin.properties isn't within the root of the archive, create
+ // a new URI for the folder location of the archive, so we can look in
+ // the folder that contains it.
+ url = trimSegments(new URL(url.getFile()), 1);
+ }
+ }
+
+ // If we didn't find the plugin.properties in the usual place nor in the
+ // archive...
+ if (baseURL == null)
+ {
+ // Trim off the "bin" or "runtime" segment.
+ String lastSegment = lastSegment(url);
+ if ("bin".equals(lastSegment) || "runtime".equals(lastSegment)) //$NON-NLS-1$ //$NON-NLS-2$
+ {
+ url = trimSegments(url, 1);
+ }
+
+ try
+ {
+ // If we can open an input stream, then the plugin.properties is in the
+ // folder, and we have a good base URL.
+ InputStream inputStream = new URL(url.toString() + "plugin.properties").openStream(); //$NON-NLS-1$
+ inputStream.close();
+ baseURL = url;
+ }
+ catch (IOException exception)
+ {
+ }
+ }
+
+ // If we still don't have a good base URL, complain about it.
+ if (baseURL == null)
+ {
+ throw new MissingResourceException("Missing properties: " + accessor.getName(), accessor.getName(), //$NON-NLS-1$
+ "plugin.properties"); //$NON-NLS-1$
+ }
+ }
+
+ private static URL getClassesURL(Class<?> accessor) throws MalformedURLException
+ {
+ String className = accessor.getName();
+ URL url = accessor.getResource(ReflectUtil.getSimpleName(accessor) + ".class"); //$NON-NLS-1$
+
+ int segmentsToTrim = 1 + StringUtil.occurrences(className, '.');
+ return trimSegments(url, segmentsToTrim);
+ }
+
+ private static String lastSegment(URL url)
+ {
+ String path = url.getPath();
+ if (path.endsWith("/")) //$NON-NLS-1$
+ {
+ path = path.substring(0, path.length() - 1);
+ }
+
+ int pos = path.lastIndexOf('/');
+ return pos == -1 ? path : path.substring(pos + 1);
+ }
+
+ private static URL trimSegments(URL url, int count) throws MalformedURLException
+ {
+ String path = url.getPath();
+ if (path.endsWith("/")) //$NON-NLS-1$
+ {
+ ++count;
+ }
+
+ for (int i = 0; i < count; i++)
+ {
+ int pos = path.lastIndexOf('/');
+ if (pos == -1)
+ {
+ break;
+ }
+
+ // TODO Optimize
+ path = path.substring(0, pos);
+ }
+
+ return new URL(url.getProtocol() + ":" + path + "/"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * TODO Make configurable
+ *
+ * @see org.eclipse.emf.common.util.URI#isArchiveScheme(String)
+ */
+ private static boolean isArchiveProtocol(String scheme)
+ {
+ return "jar".equalsIgnoreCase(scheme); //$NON-NLS-1$
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyPlatform.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyPlatform.java
index f5df96131d..c16e7dcdd5 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyPlatform.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyPlatform.java
@@ -1,58 +1,58 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om;
-
-import org.eclipse.net4j.internal.util.bundle.AbstractPlatform;
-import org.eclipse.net4j.util.om.LegacyUtil;
-import org.eclipse.net4j.util.om.OMBundle;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * @author Eike Stepper
- */
-public class LegacyPlatform extends AbstractPlatform
-{
- private Map<String, String> debugOptions = new ConcurrentHashMap<String, String>(0);
-
- public LegacyPlatform()
- {
- }
-
- public boolean isOSGiRunning()
- {
- return false;
- }
-
- @Override
- protected OMBundle createBundle(String bundleID, Class<?> accessor)
- {
- return new LegacyBundle(this, bundleID, accessor);
- }
-
- @Override
- protected String getDebugOption(String bundleID, String option)
- {
- return debugOptions.get(bundleID + "/" + option); //$NON-NLS-1$
- }
-
- @Override
- protected void setDebugOption(String bundleID, String option, String value)
- {
- debugOptions.put(bundleID + "/" + option, value); //$NON-NLS-1$
- }
-
- public String[] getCommandLineArgs()
- {
- return LegacyUtil.getCommandLineArgs();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om;
+
+import org.eclipse.net4j.internal.util.bundle.AbstractPlatform;
+import org.eclipse.net4j.util.om.LegacyUtil;
+import org.eclipse.net4j.util.om.OMBundle;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Eike Stepper
+ */
+public class LegacyPlatform extends AbstractPlatform
+{
+ private Map<String, String> debugOptions = new ConcurrentHashMap<String, String>(0);
+
+ public LegacyPlatform()
+ {
+ }
+
+ public boolean isOSGiRunning()
+ {
+ return false;
+ }
+
+ @Override
+ protected OMBundle createBundle(String bundleID, Class<?> accessor)
+ {
+ return new LegacyBundle(this, bundleID, accessor);
+ }
+
+ @Override
+ protected String getDebugOption(String bundleID, String option)
+ {
+ return debugOptions.get(bundleID + "/" + option); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setDebugOption(String bundleID, String option, String value)
+ {
+ debugOptions.put(bundleID + "/" + option, value); //$NON-NLS-1$
+ }
+
+ public String[] getCommandLineArgs()
+ {
+ return LegacyUtil.getCommandLineArgs();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java
index ed6d5bd4d1..29887d84ae 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java
@@ -1,116 +1,116 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om;
-
-import org.eclipse.net4j.internal.util.bundle.AbstractBundle;
-import org.eclipse.net4j.internal.util.bundle.AbstractPlatform;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.collection.AbstractIterator;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Queue;
-
-/**
- * @author Eike Stepper
- */
-public class OSGiBundle extends AbstractBundle
-{
- public OSGiBundle(AbstractPlatform platform, String bundleID, Class<?> accessor)
- {
- super(platform, bundleID, accessor);
- }
-
- @Override
- public BundleContext getBundleContext()
- {
- return (BundleContext)super.getBundleContext();
- }
-
- public URL getBaseURL()
- {
- try
- {
- URL entry = getBundleContext().getBundle().getEntry("/"); //$NON-NLS-1$
- URL baseURL = FileLocator.resolve(entry);
- String str = baseURL.toExternalForm();
- if (str.endsWith("/./")) //$NON-NLS-1$
- {
- baseURL = new URL(str.substring(0, str.length() - 2));
- }
-
- return baseURL;
- }
- catch (IOException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- public Iterator<Class<?>> getClasses()
- {
- final Queue<String> folders = new LinkedList<String>();
- folders.offer("/");
-
- return new AbstractIterator<Class<?>>()
- {
- private Enumeration<String> entryPaths;
-
- @Override
- protected Object computeNextElement()
- {
- for (;;)
- {
- while (entryPaths != null && entryPaths.hasMoreElements())
- {
- String entryPath = entryPaths.nextElement();
- if (entryPath.endsWith("/"))
- {
- folders.offer(entryPath);
- }
- else
- {
- Class<?> c = getClassFromBundle(entryPath);
- if (c != null)
- {
- return c;
- }
- }
- }
-
- String folder = folders.poll();
- if (folder == null)
- {
- return END_OF_DATA;
- }
-
- Bundle bundle = getBundleContext().getBundle();
- entryPaths = bundle.getEntryPaths(folder);
- }
- }
- };
- }
-
- public String getStateLocation()
- {
- Bundle bundle = getBundleContext().getBundle();
- return Platform.getStateLocation(bundle).toString();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om;
+
+import org.eclipse.net4j.internal.util.bundle.AbstractBundle;
+import org.eclipse.net4j.internal.util.bundle.AbstractPlatform;
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.collection.AbstractIterator;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Queue;
+
+/**
+ * @author Eike Stepper
+ */
+public class OSGiBundle extends AbstractBundle
+{
+ public OSGiBundle(AbstractPlatform platform, String bundleID, Class<?> accessor)
+ {
+ super(platform, bundleID, accessor);
+ }
+
+ @Override
+ public BundleContext getBundleContext()
+ {
+ return (BundleContext)super.getBundleContext();
+ }
+
+ public URL getBaseURL()
+ {
+ try
+ {
+ URL entry = getBundleContext().getBundle().getEntry("/"); //$NON-NLS-1$
+ URL baseURL = FileLocator.resolve(entry);
+ String str = baseURL.toExternalForm();
+ if (str.endsWith("/./")) //$NON-NLS-1$
+ {
+ baseURL = new URL(str.substring(0, str.length() - 2));
+ }
+
+ return baseURL;
+ }
+ catch (IOException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ public Iterator<Class<?>> getClasses()
+ {
+ final Queue<String> folders = new LinkedList<String>();
+ folders.offer("/");
+
+ return new AbstractIterator<Class<?>>()
+ {
+ private Enumeration<String> entryPaths;
+
+ @Override
+ protected Object computeNextElement()
+ {
+ for (;;)
+ {
+ while (entryPaths != null && entryPaths.hasMoreElements())
+ {
+ String entryPath = entryPaths.nextElement();
+ if (entryPath.endsWith("/"))
+ {
+ folders.offer(entryPath);
+ }
+ else
+ {
+ Class<?> c = getClassFromBundle(entryPath);
+ if (c != null)
+ {
+ return c;
+ }
+ }
+ }
+
+ String folder = folders.poll();
+ if (folder == null)
+ {
+ return END_OF_DATA;
+ }
+
+ Bundle bundle = getBundleContext().getBundle();
+ entryPaths = bundle.getEntryPaths(folder);
+ }
+ }
+ };
+ }
+
+ public String getStateLocation()
+ {
+ Bundle bundle = getBundleContext().getBundle();
+ return Platform.getStateLocation(bundle).toString();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiPlatform.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiPlatform.java
index e32483f1c9..fa52602b4c 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiPlatform.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiPlatform.java
@@ -1,109 +1,109 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om;
-
-import org.eclipse.net4j.internal.util.bundle.AbstractPlatform;
-import org.eclipse.net4j.util.om.OMBundle;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.osgi.service.debug.DebugOptions;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-
-/**
- * @author Eike Stepper
- */
-public class OSGiPlatform extends AbstractPlatform
-{
- BundleContext systemContext;
-
- public OSGiPlatform(Object systemContext)
- {
- this.systemContext = (BundleContext)systemContext;
-
- try
- {
- setDebugging(Platform.inDebugMode());
- }
- catch (Throwable ignore)
- {
- }
- }
-
- public boolean isOSGiRunning()
- {
- return true;
- }
-
- @Override
- public String getProperty(String key)
- {
- return systemContext != null ? systemContext.getProperty(key) : null;
- }
-
- @Override
- public String getProperty(String key, String defaultValue)
- {
- String property = getProperty(key);
- return property != null ? property : defaultValue;
- }
-
- public String[] getCommandLineArgs()
- {
- return Platform.getCommandLineArgs();
- }
-
- public void setCommandLineArgs(String[] args)
- {
- throw new UnsupportedOperationException("Set command line arguements inside the OSGi enviorment is not needed.");
- }
-
- @Override
- protected OMBundle createBundle(String bundleID, Class<?> accessor)
- {
- return new OSGiBundle(this, bundleID, accessor);
- }
-
- @Override
- protected String getDebugOption(String bundleID, String option)
- {
- try
- {
- DebugOptions debugOptions = getDebugOptions();
- return debugOptions.getOption(bundleID + "/" + option); //$NON-NLS-1$
- }
- catch (RuntimeException ex)
- {
- return null;
- }
- }
-
- @Override
- protected void setDebugOption(String bundleID, String option, String value)
- {
- try
- {
- DebugOptions debugOptions = getDebugOptions();
- debugOptions.setOption(bundleID + "/" + option, value); //$NON-NLS-1$
- }
- catch (RuntimeException ex)
- {
- }
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- protected DebugOptions getDebugOptions() throws NoClassDefFoundError, NullPointerException
- {
- ServiceReference ref = systemContext.getServiceReference(DebugOptions.class.getName());
- return (DebugOptions)systemContext.getService(ref);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om;
+
+import org.eclipse.net4j.internal.util.bundle.AbstractPlatform;
+import org.eclipse.net4j.util.om.OMBundle;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.osgi.service.debug.DebugOptions;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * @author Eike Stepper
+ */
+public class OSGiPlatform extends AbstractPlatform
+{
+ BundleContext systemContext;
+
+ public OSGiPlatform(Object systemContext)
+ {
+ this.systemContext = (BundleContext)systemContext;
+
+ try
+ {
+ setDebugging(Platform.inDebugMode());
+ }
+ catch (Throwable ignore)
+ {
+ }
+ }
+
+ public boolean isOSGiRunning()
+ {
+ return true;
+ }
+
+ @Override
+ public String getProperty(String key)
+ {
+ return systemContext != null ? systemContext.getProperty(key) : null;
+ }
+
+ @Override
+ public String getProperty(String key, String defaultValue)
+ {
+ String property = getProperty(key);
+ return property != null ? property : defaultValue;
+ }
+
+ public String[] getCommandLineArgs()
+ {
+ return Platform.getCommandLineArgs();
+ }
+
+ public void setCommandLineArgs(String[] args)
+ {
+ throw new UnsupportedOperationException("Set command line arguements inside the OSGi enviorment is not needed.");
+ }
+
+ @Override
+ protected OMBundle createBundle(String bundleID, Class<?> accessor)
+ {
+ return new OSGiBundle(this, bundleID, accessor);
+ }
+
+ @Override
+ protected String getDebugOption(String bundleID, String option)
+ {
+ try
+ {
+ DebugOptions debugOptions = getDebugOptions();
+ return debugOptions.getOption(bundleID + "/" + option); //$NON-NLS-1$
+ }
+ catch (RuntimeException ex)
+ {
+ return null;
+ }
+ }
+
+ @Override
+ protected void setDebugOption(String bundleID, String option, String value)
+ {
+ try
+ {
+ DebugOptions debugOptions = getDebugOptions();
+ debugOptions.setOption(bundleID + "/" + option, value); //$NON-NLS-1$
+ }
+ catch (RuntimeException ex)
+ {
+ }
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ protected DebugOptions getDebugOptions() throws NoClassDefFoundError, NullPointerException
+ {
+ ServiceReference ref = systemContext.getServiceReference(DebugOptions.class.getName());
+ return (DebugOptions)systemContext.getService(ref);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/ArrayPreference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/ArrayPreference.java
index cf413fb9a6..46475d7bd5 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/ArrayPreference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/ArrayPreference.java
@@ -1,95 +1,95 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om.pref;
-
-import org.eclipse.net4j.internal.util.bundle.OM;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-
-/**
- * @author Eike Stepper
- */
-public final class ArrayPreference extends Preference<String[]>
-{
- private static final String SEPARATOR = ","; //$NON-NLS-1$
-
- private static final String UTF_8 = "UTF-8"; //$NON-NLS-1$
-
- public ArrayPreference(Preferences preferences, String name, String[] defaultValue)
- {
- super(preferences, name, defaultValue);
- }
-
- @Override
- protected String getString()
- {
- String[] array = getValue();
- if (array == null || array.length == 0)
- {
- return null;
- }
-
- StringBuilder builder = new StringBuilder();
- for (String element : array)
- {
- if (builder.length() != 0)
- {
- builder.append(SEPARATOR);
- builder.append(" "); //$NON-NLS-1$
- }
-
- try
- {
- String encoded = URLEncoder.encode(element, UTF_8);
- builder.append(encoded);
- }
- catch (UnsupportedEncodingException ex)
- {
- OM.LOG.error(ex);
- return null;
- }
- }
-
- return builder.toString();
- }
-
- @Override
- protected String[] convert(String value)
- {
- String[] array = value.split(SEPARATOR);
- if (array == null || array.length == 0)
- {
- return Preferences.DEFAULT_ARRAY;
- }
-
- for (int i = 0; i < array.length; i++)
- {
- try
- {
- array[i] = URLDecoder.decode(array[i].trim(), UTF_8);
- }
- catch (UnsupportedEncodingException ex)
- {
- OM.LOG.error(ex);
- return null;
- }
- }
-
- return array;
- }
-
- public Type getType()
- {
- return Type.ARRAY;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om.pref;
+
+import org.eclipse.net4j.internal.util.bundle.OM;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+
+/**
+ * @author Eike Stepper
+ */
+public final class ArrayPreference extends Preference<String[]>
+{
+ private static final String SEPARATOR = ","; //$NON-NLS-1$
+
+ private static final String UTF_8 = "UTF-8"; //$NON-NLS-1$
+
+ public ArrayPreference(Preferences preferences, String name, String[] defaultValue)
+ {
+ super(preferences, name, defaultValue);
+ }
+
+ @Override
+ protected String getString()
+ {
+ String[] array = getValue();
+ if (array == null || array.length == 0)
+ {
+ return null;
+ }
+
+ StringBuilder builder = new StringBuilder();
+ for (String element : array)
+ {
+ if (builder.length() != 0)
+ {
+ builder.append(SEPARATOR);
+ builder.append(" "); //$NON-NLS-1$
+ }
+
+ try
+ {
+ String encoded = URLEncoder.encode(element, UTF_8);
+ builder.append(encoded);
+ }
+ catch (UnsupportedEncodingException ex)
+ {
+ OM.LOG.error(ex);
+ return null;
+ }
+ }
+
+ return builder.toString();
+ }
+
+ @Override
+ protected String[] convert(String value)
+ {
+ String[] array = value.split(SEPARATOR);
+ if (array == null || array.length == 0)
+ {
+ return Preferences.DEFAULT_ARRAY;
+ }
+
+ for (int i = 0; i < array.length; i++)
+ {
+ try
+ {
+ array[i] = URLDecoder.decode(array[i].trim(), UTF_8);
+ }
+ catch (UnsupportedEncodingException ex)
+ {
+ OM.LOG.error(ex);
+ return null;
+ }
+ }
+
+ return array;
+ }
+
+ public Type getType()
+ {
+ return Type.ARRAY;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BooleanPreference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BooleanPreference.java
index 1167003eab..e02336314a 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BooleanPreference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BooleanPreference.java
@@ -1,39 +1,39 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om.pref;
-
-/**
- * @author Eike Stepper
- */
-public final class BooleanPreference extends Preference<Boolean>
-{
- public BooleanPreference(Preferences preferences, String name, Boolean defaultValue)
- {
- super(preferences, name, defaultValue);
- }
-
- @Override
- protected String getString()
- {
- return Boolean.toString(getValue());
- }
-
- @Override
- protected Boolean convert(String value)
- {
- return Boolean.parseBoolean(value);
- }
-
- public Type getType()
- {
- return Type.BOOLEAN;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om.pref;
+
+/**
+ * @author Eike Stepper
+ */
+public final class BooleanPreference extends Preference<Boolean>
+{
+ public BooleanPreference(Preferences preferences, String name, Boolean defaultValue)
+ {
+ super(preferences, name, defaultValue);
+ }
+
+ @Override
+ protected String getString()
+ {
+ return Boolean.toString(getValue());
+ }
+
+ @Override
+ protected Boolean convert(String value)
+ {
+ return Boolean.parseBoolean(value);
+ }
+
+ public Type getType()
+ {
+ return Type.BOOLEAN;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BytesPreference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BytesPreference.java
index bec70ea622..5ccdb748ef 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BytesPreference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BytesPreference.java
@@ -1,41 +1,41 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om.pref;
-
-import org.eclipse.net4j.util.HexUtil;
-
-/**
- * @author Eike Stepper
- */
-public final class BytesPreference extends Preference<byte[]>
-{
- public BytesPreference(Preferences preferences, String name, byte[] defaultValue)
- {
- super(preferences, name, defaultValue);
- }
-
- @Override
- protected String getString()
- {
- return HexUtil.bytesToHex(getValue());
- }
-
- @Override
- protected byte[] convert(String value)
- {
- return HexUtil.hexToBytes(value);
- }
-
- public Type getType()
- {
- return Type.BYTES;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om.pref;
+
+import org.eclipse.net4j.util.HexUtil;
+
+/**
+ * @author Eike Stepper
+ */
+public final class BytesPreference extends Preference<byte[]>
+{
+ public BytesPreference(Preferences preferences, String name, byte[] defaultValue)
+ {
+ super(preferences, name, defaultValue);
+ }
+
+ @Override
+ protected String getString()
+ {
+ return HexUtil.bytesToHex(getValue());
+ }
+
+ @Override
+ protected byte[] convert(String value)
+ {
+ return HexUtil.hexToBytes(value);
+ }
+
+ public Type getType()
+ {
+ return Type.BYTES;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/DoublePreference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/DoublePreference.java
index e3d9617f70..3872c09cbb 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/DoublePreference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/DoublePreference.java
@@ -1,39 +1,39 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om.pref;
-
-/**
- * @author Eike Stepper
- */
-public final class DoublePreference extends Preference<Double>
-{
- public DoublePreference(Preferences preferences, String name, Double defaultValue)
- {
- super(preferences, name, defaultValue);
- }
-
- @Override
- protected String getString()
- {
- return Double.toString(getValue());
- }
-
- @Override
- protected Double convert(String value)
- {
- return Double.parseDouble(value);
- }
-
- public Type getType()
- {
- return Type.DOUBLE;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om.pref;
+
+/**
+ * @author Eike Stepper
+ */
+public final class DoublePreference extends Preference<Double>
+{
+ public DoublePreference(Preferences preferences, String name, Double defaultValue)
+ {
+ super(preferences, name, defaultValue);
+ }
+
+ @Override
+ protected String getString()
+ {
+ return Double.toString(getValue());
+ }
+
+ @Override
+ protected Double convert(String value)
+ {
+ return Double.parseDouble(value);
+ }
+
+ public Type getType()
+ {
+ return Type.DOUBLE;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/FloatPreference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/FloatPreference.java
index ae5b951b62..3dd19e31fe 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/FloatPreference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/FloatPreference.java
@@ -1,39 +1,39 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om.pref;
-
-/**
- * @author Eike Stepper
- */
-public final class FloatPreference extends Preference<Float>
-{
- public FloatPreference(Preferences preferences, String name, Float defaultValue)
- {
- super(preferences, name, defaultValue);
- }
-
- @Override
- protected String getString()
- {
- return Float.toString(getValue());
- }
-
- @Override
- protected Float convert(String value)
- {
- return Float.parseFloat(value);
- }
-
- public Type getType()
- {
- return Type.FLOAT;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om.pref;
+
+/**
+ * @author Eike Stepper
+ */
+public final class FloatPreference extends Preference<Float>
+{
+ public FloatPreference(Preferences preferences, String name, Float defaultValue)
+ {
+ super(preferences, name, defaultValue);
+ }
+
+ @Override
+ protected String getString()
+ {
+ return Float.toString(getValue());
+ }
+
+ @Override
+ protected Float convert(String value)
+ {
+ return Float.parseFloat(value);
+ }
+
+ public Type getType()
+ {
+ return Type.FLOAT;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/IntegerPreference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/IntegerPreference.java
index bd5fe357ef..45838472ef 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/IntegerPreference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/IntegerPreference.java
@@ -1,39 +1,39 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om.pref;
-
-/**
- * @author Eike Stepper
- */
-public final class IntegerPreference extends Preference<Integer>
-{
- public IntegerPreference(Preferences preferences, String name, Integer defaultValue)
- {
- super(preferences, name, defaultValue);
- }
-
- @Override
- protected String getString()
- {
- return Integer.toString(getValue());
- }
-
- @Override
- protected Integer convert(String value)
- {
- return Integer.parseInt(value);
- }
-
- public Type getType()
- {
- return Type.INTEGER;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om.pref;
+
+/**
+ * @author Eike Stepper
+ */
+public final class IntegerPreference extends Preference<Integer>
+{
+ public IntegerPreference(Preferences preferences, String name, Integer defaultValue)
+ {
+ super(preferences, name, defaultValue);
+ }
+
+ @Override
+ protected String getString()
+ {
+ return Integer.toString(getValue());
+ }
+
+ @Override
+ protected Integer convert(String value)
+ {
+ return Integer.parseInt(value);
+ }
+
+ public Type getType()
+ {
+ return Type.INTEGER;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/LongPreference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/LongPreference.java
index 6607f71f4b..9c0aca0927 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/LongPreference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/LongPreference.java
@@ -1,39 +1,39 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om.pref;
-
-/**
- * @author Eike Stepper
- */
-public final class LongPreference extends Preference<Long>
-{
- public LongPreference(Preferences preferences, String name, Long defaultValue)
- {
- super(preferences, name, defaultValue);
- }
-
- @Override
- protected String getString()
- {
- return Long.toString(getValue());
- }
-
- @Override
- protected Long convert(String value)
- {
- return Long.parseLong(value);
- }
-
- public Type getType()
- {
- return Type.LONG;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om.pref;
+
+/**
+ * @author Eike Stepper
+ */
+public final class LongPreference extends Preference<Long>
+{
+ public LongPreference(Preferences preferences, String name, Long defaultValue)
+ {
+ super(preferences, name, defaultValue);
+ }
+
+ @Override
+ protected String getString()
+ {
+ return Long.toString(getValue());
+ }
+
+ @Override
+ protected Long convert(String value)
+ {
+ return Long.parseLong(value);
+ }
+
+ public Type getType()
+ {
+ return Type.LONG;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preference.java
index 1c7edf0d14..9220d6d23c 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preference.java
@@ -1,121 +1,121 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om.pref;
-
-import org.eclipse.net4j.util.ObjectUtil;
-import org.eclipse.net4j.util.om.pref.OMPreference;
-
-/**
- * @author Eike Stepper
- */
-public abstract class Preference<T> implements OMPreference<T>
-{
- private Preferences preferences;
-
- private String name;
-
- private T defaultValue;
-
- private T value;
-
- public Preference(Preferences preferences, String name, T defaultValue)
- {
- if (defaultValue == null)
- {
- throw new IllegalArgumentException("defaultValue == null"); //$NON-NLS-1$
- }
-
- this.preferences = preferences;
- this.name = name;
- this.defaultValue = defaultValue;
- }
-
- public Preferences getPreferences()
- {
- return preferences;
- }
-
- public String getName()
- {
- return name;
- }
-
- public T getDefaultValue()
- {
- return defaultValue;
- }
-
- public T getValue()
- {
- load();
- return value;
- }
-
- public T setValue(T value)
- {
- if (value == null)
- {
- throw new IllegalArgumentException("value == null"); //$NON-NLS-1$
- }
-
- load();
- T oldValue = this.value;
- if (!equals(oldValue, value))
- {
- if (equals(defaultValue, value))
- {
- value = defaultValue;
- }
-
- this.value = value;
- preferences.fireChangeEvent(this, oldValue, value);
- return oldValue;
- }
-
- return null;
- }
-
- public boolean isSet()
- {
- return !equals(defaultValue, value);
- }
-
- public T unSet()
- {
- return setValue(defaultValue);
- }
-
- protected boolean equals(T v1, T v2)
- {
- return ObjectUtil.equals(v1, v2);
- }
-
- protected void init(String value)
- {
- if (value == null)
- {
- this.value = defaultValue;
- }
- else
- {
- this.value = convert(value);
- }
- }
-
- protected abstract T convert(String value);
-
- protected abstract String getString();
-
- private void load()
- {
- preferences.load();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om.pref;
+
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.om.pref.OMPreference;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class Preference<T> implements OMPreference<T>
+{
+ private Preferences preferences;
+
+ private String name;
+
+ private T defaultValue;
+
+ private T value;
+
+ public Preference(Preferences preferences, String name, T defaultValue)
+ {
+ if (defaultValue == null)
+ {
+ throw new IllegalArgumentException("defaultValue == null"); //$NON-NLS-1$
+ }
+
+ this.preferences = preferences;
+ this.name = name;
+ this.defaultValue = defaultValue;
+ }
+
+ public Preferences getPreferences()
+ {
+ return preferences;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public T getDefaultValue()
+ {
+ return defaultValue;
+ }
+
+ public T getValue()
+ {
+ load();
+ return value;
+ }
+
+ public T setValue(T value)
+ {
+ if (value == null)
+ {
+ throw new IllegalArgumentException("value == null"); //$NON-NLS-1$
+ }
+
+ load();
+ T oldValue = this.value;
+ if (!equals(oldValue, value))
+ {
+ if (equals(defaultValue, value))
+ {
+ value = defaultValue;
+ }
+
+ this.value = value;
+ preferences.fireChangeEvent(this, oldValue, value);
+ return oldValue;
+ }
+
+ return null;
+ }
+
+ public boolean isSet()
+ {
+ return !equals(defaultValue, value);
+ }
+
+ public T unSet()
+ {
+ return setValue(defaultValue);
+ }
+
+ protected boolean equals(T v1, T v2)
+ {
+ return ObjectUtil.equals(v1, v2);
+ }
+
+ protected void init(String value)
+ {
+ if (value == null)
+ {
+ this.value = defaultValue;
+ }
+ else
+ {
+ this.value = convert(value);
+ }
+ }
+
+ protected abstract T convert(String value);
+
+ protected abstract String getString();
+
+ private void load()
+ {
+ preferences.load();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java
index 18f650667b..65f0249fa6 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java
@@ -1,297 +1,297 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om.pref;
-
-import org.eclipse.net4j.internal.util.bundle.AbstractBundle;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.event.Notifier;
-import org.eclipse.net4j.util.io.IORunnable;
-import org.eclipse.net4j.util.io.IORuntimeException;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.om.pref.OMPreference;
-import org.eclipse.net4j.util.om.pref.OMPreferences;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * @author Eike Stepper
- */
-public class Preferences extends Notifier implements OMPreferences
-{
- private AbstractBundle bundle;
-
- private Map<String, Preference<?>> prefs = new HashMap<String, Preference<?>>();
-
- private boolean loaded;
-
- private boolean dirty;
-
- public Preferences(AbstractBundle bundle)
- {
- this.bundle = bundle;
- }
-
- public AbstractBundle getBundle()
- {
- return bundle;
- }
-
- public synchronized void load()
- {
- if (!loaded)
- {
- loaded = true;
- final Properties properties = new Properties();
-
- File file = getFile();
- if (file.exists())
- {
- IOUtil.safeInput(file, new IORunnable<FileInputStream>()
- {
- public void run(FileInputStream io) throws IOException
- {
- properties.load(io);
- }
- });
- }
-
- for (Preference<?> preference : prefs.values())
- {
- String name = preference.getName();
- String value = properties.getProperty(name);
- preference.init(value);
- }
- }
- }
-
- public synchronized void save()
- {
- if (dirty)
- {
- final Properties properties = new Properties();
- for (Preference<?> preference : prefs.values())
- {
- if (preference.isSet())
- {
- String name = preference.getName();
- String value = preference.getString();
- if (value != null)
- {
- properties.put(name, value);
- }
- }
- }
-
- File file = getFile();
- if (properties.isEmpty())
- {
- if (file.exists())
- {
- file.delete();
- }
- }
- else
- {
- IOUtil.safeOutput(file, new IORunnable<FileOutputStream>()
- {
- public void run(FileOutputStream io) throws IOException
- {
- properties.store(io, "Preferences of " + bundle.getBundleID()); //$NON-NLS-1$
- }
- });
- }
-
- dirty = false;
- }
- }
-
- public boolean isDirty()
- {
- return dirty;
- }
-
- public OMPreference<Boolean> init(String name, boolean defaultValue)
- {
- return init(new BooleanPreference(this, name, defaultValue));
- }
-
- public OMPreference<Integer> init(String name, int defaultValue)
- {
- return init(new IntegerPreference(this, name, defaultValue));
- }
-
- public OMPreference<Long> init(String name, long defaultValue)
- {
- return init(new LongPreference(this, name, defaultValue));
- }
-
- public OMPreference<Float> init(String name, float defaultValue)
- {
- return init(new FloatPreference(this, name, defaultValue));
- }
-
- public OMPreference<Double> init(String name, double defaultValue)
- {
- return init(new DoublePreference(this, name, defaultValue));
- }
-
- public OMPreference<String> init(String name, String defaultValue)
- {
- return init(new StringPreference(this, name, defaultValue));
- }
-
- public OMPreference<String[]> init(String name, String[] defaultValue)
- {
- return init(new ArrayPreference(this, name, defaultValue));
- }
-
- public OMPreference<byte[]> init(String name, byte[] defaultValue)
- {
- return init(new BytesPreference(this, name, defaultValue));
- }
-
- public OMPreference<Boolean> initBoolean(String name)
- {
- return init(name, DEFAULT_BOOLEAN);
- }
-
- public OMPreference<Integer> initInteger(String name)
- {
- return init(name, DEFAULT_INTEGER);
- }
-
- public OMPreference<Long> initLong(String name)
- {
- return init(name, DEFAULT_LONG);
- }
-
- public OMPreference<Float> initFloat(String name)
- {
- return init(name, DEFAULT_FLOAT);
- }
-
- public OMPreference<Double> initDouble(String name)
- {
- return init(name, DEFAULT_DOUBLE);
- }
-
- public OMPreference<String> initString(String name)
- {
- return init(name, DEFAULT_STRING);
- }
-
- public OMPreference<String[]> initArray(String name)
- {
- return init(name, DEFAULT_ARRAY);
- }
-
- public OMPreference<byte[]> initBytes(String name)
- {
- return init(name, DEFAULT_BYTES);
- }
-
- public boolean contains(String name)
- {
- return prefs.containsKey(name);
- }
-
- public OMPreference<?> get(String name)
- {
- return prefs.get(name);
- }
-
- @SuppressWarnings("unchecked")
- public OMPreference<Boolean> getBoolean(String name)
- {
- return (OMPreference<Boolean>)get(name);
- }
-
- @SuppressWarnings("unchecked")
- public OMPreference<Integer> getInteger(String name)
- {
- return (OMPreference<Integer>)get(name);
- }
-
- @SuppressWarnings("unchecked")
- public OMPreference<Long> getLong(String name)
- {
- return (OMPreference<Long>)get(name);
- }
-
- @SuppressWarnings("unchecked")
- public OMPreference<Float> getFloat(String name)
- {
- return (OMPreference<Float>)get(name);
- }
-
- @SuppressWarnings("unchecked")
- public OMPreference<Double> getDouble(String name)
- {
- return (OMPreference<Double>)get(name);
- }
-
- @SuppressWarnings("unchecked")
- public OMPreference<String> getString(String name)
- {
- return (OMPreference<String>)get(name);
- }
-
- @SuppressWarnings("unchecked")
- public OMPreference<String[]> getArray(String name)
- {
- return (OMPreference<String[]>)get(name);
- }
-
- @SuppressWarnings("unchecked")
- public OMPreference<byte[]> getBytes(String name)
- {
- return (OMPreference<byte[]>)get(name);
- }
-
- public <T> void fireChangeEvent(Preference<T> preference, T oldValue, T newValue)
- {
- dirty = true;
- IListener[] listeners = getListeners();
- if (listeners != null)
- {
- fireEvent(new PreferencesChangeEvent<T>(preference, oldValue, newValue), listeners);
- }
- }
-
- private <T> OMPreference<T> init(Preference<T> preference)
- {
- String name = preference.getName();
- if (prefs.containsKey(name))
- {
- throw new IllegalArgumentException("Duplicate name: " + name); //$NON-NLS-1$
- }
-
- prefs.put(name, preference);
- return preference;
- }
-
- private File getFile()
- {
- File file = new File(bundle.getStateLocation(), ".prefs"); //$NON-NLS-1$
- if (file.exists() && !file.isFile())
- {
- throw new IORuntimeException("Not a file: " + file.getAbsolutePath()); //$NON-NLS-1$
- }
-
- return file;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om.pref;
+
+import org.eclipse.net4j.internal.util.bundle.AbstractBundle;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.event.Notifier;
+import org.eclipse.net4j.util.io.IORunnable;
+import org.eclipse.net4j.util.io.IORuntimeException;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.om.pref.OMPreference;
+import org.eclipse.net4j.util.om.pref.OMPreferences;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * @author Eike Stepper
+ */
+public class Preferences extends Notifier implements OMPreferences
+{
+ private AbstractBundle bundle;
+
+ private Map<String, Preference<?>> prefs = new HashMap<String, Preference<?>>();
+
+ private boolean loaded;
+
+ private boolean dirty;
+
+ public Preferences(AbstractBundle bundle)
+ {
+ this.bundle = bundle;
+ }
+
+ public AbstractBundle getBundle()
+ {
+ return bundle;
+ }
+
+ public synchronized void load()
+ {
+ if (!loaded)
+ {
+ loaded = true;
+ final Properties properties = new Properties();
+
+ File file = getFile();
+ if (file.exists())
+ {
+ IOUtil.safeInput(file, new IORunnable<FileInputStream>()
+ {
+ public void run(FileInputStream io) throws IOException
+ {
+ properties.load(io);
+ }
+ });
+ }
+
+ for (Preference<?> preference : prefs.values())
+ {
+ String name = preference.getName();
+ String value = properties.getProperty(name);
+ preference.init(value);
+ }
+ }
+ }
+
+ public synchronized void save()
+ {
+ if (dirty)
+ {
+ final Properties properties = new Properties();
+ for (Preference<?> preference : prefs.values())
+ {
+ if (preference.isSet())
+ {
+ String name = preference.getName();
+ String value = preference.getString();
+ if (value != null)
+ {
+ properties.put(name, value);
+ }
+ }
+ }
+
+ File file = getFile();
+ if (properties.isEmpty())
+ {
+ if (file.exists())
+ {
+ file.delete();
+ }
+ }
+ else
+ {
+ IOUtil.safeOutput(file, new IORunnable<FileOutputStream>()
+ {
+ public void run(FileOutputStream io) throws IOException
+ {
+ properties.store(io, "Preferences of " + bundle.getBundleID()); //$NON-NLS-1$
+ }
+ });
+ }
+
+ dirty = false;
+ }
+ }
+
+ public boolean isDirty()
+ {
+ return dirty;
+ }
+
+ public OMPreference<Boolean> init(String name, boolean defaultValue)
+ {
+ return init(new BooleanPreference(this, name, defaultValue));
+ }
+
+ public OMPreference<Integer> init(String name, int defaultValue)
+ {
+ return init(new IntegerPreference(this, name, defaultValue));
+ }
+
+ public OMPreference<Long> init(String name, long defaultValue)
+ {
+ return init(new LongPreference(this, name, defaultValue));
+ }
+
+ public OMPreference<Float> init(String name, float defaultValue)
+ {
+ return init(new FloatPreference(this, name, defaultValue));
+ }
+
+ public OMPreference<Double> init(String name, double defaultValue)
+ {
+ return init(new DoublePreference(this, name, defaultValue));
+ }
+
+ public OMPreference<String> init(String name, String defaultValue)
+ {
+ return init(new StringPreference(this, name, defaultValue));
+ }
+
+ public OMPreference<String[]> init(String name, String[] defaultValue)
+ {
+ return init(new ArrayPreference(this, name, defaultValue));
+ }
+
+ public OMPreference<byte[]> init(String name, byte[] defaultValue)
+ {
+ return init(new BytesPreference(this, name, defaultValue));
+ }
+
+ public OMPreference<Boolean> initBoolean(String name)
+ {
+ return init(name, DEFAULT_BOOLEAN);
+ }
+
+ public OMPreference<Integer> initInteger(String name)
+ {
+ return init(name, DEFAULT_INTEGER);
+ }
+
+ public OMPreference<Long> initLong(String name)
+ {
+ return init(name, DEFAULT_LONG);
+ }
+
+ public OMPreference<Float> initFloat(String name)
+ {
+ return init(name, DEFAULT_FLOAT);
+ }
+
+ public OMPreference<Double> initDouble(String name)
+ {
+ return init(name, DEFAULT_DOUBLE);
+ }
+
+ public OMPreference<String> initString(String name)
+ {
+ return init(name, DEFAULT_STRING);
+ }
+
+ public OMPreference<String[]> initArray(String name)
+ {
+ return init(name, DEFAULT_ARRAY);
+ }
+
+ public OMPreference<byte[]> initBytes(String name)
+ {
+ return init(name, DEFAULT_BYTES);
+ }
+
+ public boolean contains(String name)
+ {
+ return prefs.containsKey(name);
+ }
+
+ public OMPreference<?> get(String name)
+ {
+ return prefs.get(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public OMPreference<Boolean> getBoolean(String name)
+ {
+ return (OMPreference<Boolean>)get(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public OMPreference<Integer> getInteger(String name)
+ {
+ return (OMPreference<Integer>)get(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public OMPreference<Long> getLong(String name)
+ {
+ return (OMPreference<Long>)get(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public OMPreference<Float> getFloat(String name)
+ {
+ return (OMPreference<Float>)get(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public OMPreference<Double> getDouble(String name)
+ {
+ return (OMPreference<Double>)get(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public OMPreference<String> getString(String name)
+ {
+ return (OMPreference<String>)get(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public OMPreference<String[]> getArray(String name)
+ {
+ return (OMPreference<String[]>)get(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public OMPreference<byte[]> getBytes(String name)
+ {
+ return (OMPreference<byte[]>)get(name);
+ }
+
+ public <T> void fireChangeEvent(Preference<T> preference, T oldValue, T newValue)
+ {
+ dirty = true;
+ IListener[] listeners = getListeners();
+ if (listeners != null)
+ {
+ fireEvent(new PreferencesChangeEvent<T>(preference, oldValue, newValue), listeners);
+ }
+ }
+
+ private <T> OMPreference<T> init(Preference<T> preference)
+ {
+ String name = preference.getName();
+ if (prefs.containsKey(name))
+ {
+ throw new IllegalArgumentException("Duplicate name: " + name); //$NON-NLS-1$
+ }
+
+ prefs.put(name, preference);
+ return preference;
+ }
+
+ private File getFile()
+ {
+ File file = new File(bundle.getStateLocation(), ".prefs"); //$NON-NLS-1$
+ if (file.exists() && !file.isFile())
+ {
+ throw new IORuntimeException("Not a file: " + file.getAbsolutePath()); //$NON-NLS-1$
+ }
+
+ return file;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/PreferencesChangeEvent.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/PreferencesChangeEvent.java
index ff56a8291d..98ae17b5ba 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/PreferencesChangeEvent.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/PreferencesChangeEvent.java
@@ -1,57 +1,57 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om.pref;
-
-import org.eclipse.net4j.util.event.Event;
-import org.eclipse.net4j.util.om.pref.OMPreferencesChangeEvent;
-
-/**
- * @author Eike Stepper
- */
-public final class PreferencesChangeEvent<T> extends Event implements OMPreferencesChangeEvent<T>
-{
- private static final long serialVersionUID = 1L;
-
- private Preference<T> preference;
-
- private T oldValue;
-
- private T newValue;
-
- public PreferencesChangeEvent(Preference<T> preference, T oldValue, T newValue)
- {
- super(preference.getPreferences());
- this.preference = preference;
- this.oldValue = oldValue;
- this.newValue = newValue;
- }
-
- @Override
- public Preferences getSource()
- {
- return (Preferences)super.getSource();
- }
-
- public Preference<T> getPreference()
- {
- return preference;
- }
-
- public T getOldValue()
- {
- return oldValue;
- }
-
- public T getNewValue()
- {
- return newValue;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om.pref;
+
+import org.eclipse.net4j.util.event.Event;
+import org.eclipse.net4j.util.om.pref.OMPreferencesChangeEvent;
+
+/**
+ * @author Eike Stepper
+ */
+public final class PreferencesChangeEvent<T> extends Event implements OMPreferencesChangeEvent<T>
+{
+ private static final long serialVersionUID = 1L;
+
+ private Preference<T> preference;
+
+ private T oldValue;
+
+ private T newValue;
+
+ public PreferencesChangeEvent(Preference<T> preference, T oldValue, T newValue)
+ {
+ super(preference.getPreferences());
+ this.preference = preference;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+
+ @Override
+ public Preferences getSource()
+ {
+ return (Preferences)super.getSource();
+ }
+
+ public Preference<T> getPreference()
+ {
+ return preference;
+ }
+
+ public T getOldValue()
+ {
+ return oldValue;
+ }
+
+ public T getNewValue()
+ {
+ return newValue;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/StringPreference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/StringPreference.java
index 8038862b37..40240985df 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/StringPreference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/StringPreference.java
@@ -1,39 +1,39 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.internal.util.om.pref;
-
-/**
- * @author Eike Stepper
- */
-public final class StringPreference extends Preference<String>
-{
- public StringPreference(Preferences preferences, String name, String defaultValue)
- {
- super(preferences, name, defaultValue);
- }
-
- @Override
- protected String getString()
- {
- return getValue();
- }
-
- @Override
- protected String convert(String value)
- {
- return value;
- }
-
- public Type getType()
- {
- return Type.STRING;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.internal.util.om.pref;
+
+/**
+ * @author Eike Stepper
+ */
+public final class StringPreference extends Preference<String>
+{
+ public StringPreference(Preferences preferences, String name, String defaultValue)
+ {
+ super(preferences, name, defaultValue);
+ }
+
+ @Override
+ protected String getString()
+ {
+ return getValue();
+ }
+
+ @Override
+ protected String convert(String value)
+ {
+ return value;
+ }
+
+ public Type getType()
+ {
+ return Type.STRING;
+ }
+}

Back to the top