summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-10-26 12:26:25 (EDT)
committerEike Stepper2006-10-26 12:26:25 (EDT)
commit35d15ecd3ecbaa6f5215745e006f39f6cd5a62aa (patch)
tree032003c8c40374d3b77a7fad8e128b486616090f
parentc93de0a2a0d0ea167a043993e8ae98f800a32710 (diff)
downloadcdo-35d15ecd3ecbaa6f5215745e006f39f6cd5a62aa.zip
cdo-35d15ecd3ecbaa6f5215745e006f39f6cd5a62aa.tar.gz
cdo-35d15ecd3ecbaa6f5215745e006f39f6cd5a62aa.tar.bz2
Added operations and maintenance (om) package
-rw-r--r--plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java12
-rw-r--r--plugins/org.eclipse.net4j/.options7
-rw-r--r--plugins/org.eclipse.net4j/META-INF/MANIFEST.MF5
-rw-r--r--plugins/org.eclipse.net4j/build.properties3
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMBundle.java283
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMPlatform.java132
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Activator.java41
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyBundle.java217
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyPlatform.java47
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Log.java76
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4j.java37
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMLoggerImpl.java107
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTracerImpl.java106
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiBundle.java49
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiPlatform.java68
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Trace.java71
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java37
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/AbstractCachingMap.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/map/AbstractCachingMap.java)2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/AbstractDelegatingMap.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/map/AbstractDelegatingMap.java)2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/AbstractLogger.java47
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/BundleDebugOptions.java81
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/BundleLogger.java78
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/IOUtil.java94
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java22
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/StringUtil.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/operation/AbstractTracer.java)23
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/ContextTracer.java72
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/EclipseLoggingBridge.java62
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMBundle.java119
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMLogHandler.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/operation/ITracer.java)16
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMLogger.java57
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMPlatform.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/operation/IDebugOptions.java)24
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTraceHandler.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/operation/ILogger.java)26
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTracer.java42
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OSGiLoggingBridge.java82
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/PrintStreamLogHandler.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/ConsoleLogger.java)32
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/PrintStreamTraceHandler.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/AbstractDebugOptions.java)32
37 files changed, 1695 insertions, 520 deletions
diff --git a/plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF
index ab86171..57b8abd 100644
--- a/plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF
@@ -5,7 +5,7 @@ Bundle-SymbolicName: org.eclipse.net4j.tests
Bundle-Version: 0.8.0.qualifier
Bundle-Activator: org.eclipse.net4j.tests.bundle.Activator
Bundle-Localization: plugin
-Import-Package: org.osgi.framework;version="1.3.0"
-Require-Bundle: org.eclipse.net4j,
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.net4j,
org.junit
Bundle-Vendor: %providerName
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
index 25ef15b..64d9e64 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
@@ -21,6 +21,9 @@ import org.eclipse.net4j.transport.util.BufferInputStream;
import org.eclipse.net4j.transport.util.BufferOutputStream;
import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.OSGiLoggingBridge;
+import org.eclipse.net4j.util.om.PrintStreamTraceHandler;
import org.eclipse.net4j.util.registry.HashMapRegistry;
import org.eclipse.net4j.util.registry.IRegistry;
@@ -52,6 +55,10 @@ public class SignalTest extends TestCase
protected void setUp() throws Exception
{
super.setUp();
+ // OMPlatform.INSTANCE.addLogHandler(EclipseLoggingBridge.INSTANCE);
+ OMPlatform.INSTANCE.addLogHandler(OSGiLoggingBridge.INSTANCE);
+ OMPlatform.INSTANCE.addTraceHandler(PrintStreamTraceHandler.CONSOLE);
+
AbstractLifecycle.DUMP_ON_ACTIVATE = true;
BufferImpl.TRACE = true;
BufferInputStream.TRACE = true;
@@ -70,7 +77,8 @@ public class SignalTest extends TestCase
assertTrue(selector.isActive());
acceptor = (TCPAcceptorImpl)Net4jFactory.createTCPAcceptor(bufferPool, selector);
- connector = (AbstractTCPConnector)Net4jFactory.createTCPConnector(bufferPool, selector, "localhost");
+ connector = (AbstractTCPConnector)Net4jFactory.createTCPConnector(bufferPool, selector,
+ "localhost");
}
@Override
@@ -124,7 +132,7 @@ public class SignalTest extends TestCase
System.out.println();
System.out.println();
- Thread.sleep(10);
+ Thread.sleep(100);
super.tearDown();
}
diff --git a/plugins/org.eclipse.net4j/.options b/plugins/org.eclipse.net4j/.options
index c5168cd..ab9973e 100644
--- a/plugins/org.eclipse.net4j/.options
+++ b/plugins/org.eclipse.net4j/.options
@@ -1,5 +1,4 @@
-org.eclipse.net4j/debug = false
+org.eclipse.net4j/debug = true
+org.eclipse.net4j/debug.connector = true
-org.eclipse.net4j/debug.connector = false
-org.eclipse.net4j/debug.connector.state = false
-org.eclipse.net4j/debug.connector.channels = false
+org.eclipse.net4j/perf = false
diff --git a/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
index 595f2d5..979bbb0 100644
--- a/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
@@ -14,8 +14,6 @@ Import-Package: org.eclipse.osgi.service.debug;version="1.0.0";resolution:=optio
Export-Package: org.eclipse.internal.net4j.transport;version="0.8.0",
org.eclipse.internal.net4j.transport.embedded;version="0.8.0",
org.eclipse.internal.net4j.transport.tcp;version="0.8.0",
- org.eclipse.internal.net4j.util.map;version="0.8.0",
- org.eclipse.internal.net4j.util.operation;version="0.8.0",
org.eclipse.net4j;version="0.8.0",
org.eclipse.net4j.message;version="0.8.0",
org.eclipse.net4j.remote;version="0.8.0",
@@ -26,6 +24,9 @@ Export-Package: org.eclipse.internal.net4j.transport;version="0.8.0",
org.eclipse.net4j.util;version="0.8.0",
org.eclipse.net4j.util.concurrent;version="0.8.0",
org.eclipse.net4j.util.lifecycle;version="0.8.0",
+ org.eclipse.net4j.util.om;version="0.8.0",
org.eclipse.net4j.util.registry;version="0.8.0",
org.eclipse.net4j.util.stream;version="0.8.0"
Eclipse-LazyStart: true
+Require-Bundle: org.eclipse.core.runtime;resolution:=optional,
+ org.eclipse.emf.common
diff --git a/plugins/org.eclipse.net4j/build.properties b/plugins/org.eclipse.net4j/build.properties
index aa1a008..e6abbde 100644
--- a/plugins/org.eclipse.net4j/build.properties
+++ b/plugins/org.eclipse.net4j/build.properties
@@ -2,4 +2,5 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
- plugin.properties
+ plugin.properties,\
+ .options
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMBundle.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMBundle.java
new file mode 100644
index 0000000..1d19658
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMBundle.java
@@ -0,0 +1,283 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.internal.net4j.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMLogger;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.OMTracer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class AbstractOMBundle implements OMBundle
+{
+ private AbstractOMPlatform platform;
+
+ private String bundleID;
+
+ private Class accessor;
+
+ private Object bundleContext;
+
+ private boolean debugging;
+
+ private boolean debuggingInitialized;
+
+ private Map<String, OMTracerImpl> tracers = new ConcurrentHashMap();
+
+ private OMLogger logger;
+
+ public ResourceBundle resourceBundle;
+
+ public ResourceBundle untranslatedResourceBundle;
+
+ public Map<String, String> strings = new HashMap();
+
+ public Map<String, String> untranslatedStrings = new HashMap();
+
+ public boolean shouldTranslate = true;
+
+ public AbstractOMBundle(AbstractOMPlatform 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;
+ }
+
+ public void setBundleContext(Object bundleContext)
+ {
+ this.bundleContext = bundleContext;
+ }
+
+ public boolean isDebugging()
+ {
+ if (!debuggingInitialized)
+ {
+ debugging = getDebugOption("debug", false);
+ 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 OMTracer tracer(String name)
+ {
+ OMTracer tracer = tracers.get(name);
+ if (tracer == null)
+ {
+ tracer = createTracer(name);
+ }
+
+ return tracer;
+ }
+
+ public OMLogger logger()
+ {
+ if (logger == null)
+ {
+ logger = createLogger();
+ }
+
+ return logger;
+ }
+
+ public InputStream getInputStream(String path) throws IOException
+ {
+ URL url = new URL(getBaseURL().toString() + ".options");
+ return url.openStream();
+ }
+
+ public boolean shouldTranslate()
+ {
+ return shouldTranslate;
+ }
+
+ public void setShouldTranslate(boolean shouldTranslate)
+ {
+ this.shouldTranslate = shouldTranslate;
+ }
+
+ public String getString(String key, boolean translate)
+ {
+ Map stringMap = translate ? strings : untranslatedStrings;
+ String result = (String)stringMap.get(key);
+ if (result == null)
+ {
+
+ ResourceBundle bundle = translate ? resourceBundle : untranslatedResourceBundle;
+ if (bundle == null)
+ {
+ String packageName = getClass().getName();
+ int index = packageName.lastIndexOf(".");
+ if (index != -1)
+ {
+ packageName = packageName.substring(0, index);
+ }
+ if (translate)
+ {
+ try
+ {
+ bundle = resourceBundle = ResourceBundle.getBundle(packageName + ".plugin");
+ }
+ 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.
+ try
+ {
+ InputStream inputStream = new URL(getBaseURL().toString() + "plugin.properties")
+ .openStream();
+ bundle = untranslatedResourceBundle = resourceBundle = new PropertyResourceBundle(
+ inputStream);
+ inputStream.close();
+ }
+ catch (IOException ioException)
+ {
+ }
+
+ if (resourceBundle == null)
+ {
+ throw exception;
+ }
+ }
+ }
+ else
+ {
+ String resourceName = getBaseURL().toString() + "plugin.properties";
+ try
+ {
+ InputStream inputStream = new URL(resourceName).openStream();
+ bundle = untranslatedResourceBundle = new PropertyResourceBundle(inputStream);
+ inputStream.close();
+ }
+ catch (IOException ioException)
+ {
+ throw new MissingResourceException("Missing properties: " + resourceName, getClass()
+ .getName(), "plugin.properties");
+ }
+ }
+ }
+
+ 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);
+ }
+
+ protected OMTracer createTracer(String name)
+ {
+ return new OMTracerImpl(this, name);
+ }
+
+ protected OMLogger createLogger()
+ {
+ return new OMLoggerImpl(this);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMPlatform.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMPlatform.java
new file mode 100644
index 0000000..06d73ea
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMPlatform.java
@@ -0,0 +1,132 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.internal.net4j.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMLogHandler;
+import org.eclipse.net4j.util.om.OMLogger;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.OMTraceHandler;
+import org.eclipse.net4j.util.om.OMTracer;
+import org.eclipse.net4j.util.om.OMLogger.Level;
+
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class AbstractOMPlatform implements OMPlatform
+{
+ static Object systemContext;
+
+ private Map<String, AbstractOMBundle> bundles = new ConcurrentHashMap();
+
+ private Queue<OMLogHandler> logHandlers = new ConcurrentLinkedQueue();
+
+ private Queue<OMTraceHandler> traceHandlers = new ConcurrentLinkedQueue();
+
+ protected AbstractOMPlatform()
+ {
+ }
+
+ public OMBundle bundle(String bundleID, Class accessor)
+ {
+ OMBundle bundle = bundles.get(bundleID);
+ if (bundle == null)
+ {
+ bundle = createBundle(bundleID, accessor);
+ }
+
+ return bundle;
+ }
+
+ public void addLogHandler(OMLogHandler logHandler)
+ {
+ if (!logHandlers.contains(logHandler))
+ {
+ logHandlers.add(logHandler);
+ }
+ }
+
+ public void removeLogHandler(OMLogHandler logHandler)
+ {
+ logHandlers.remove(logHandler);
+ }
+
+ public void addTraceHandler(OMTraceHandler traceHandler)
+ {
+ if (!traceHandlers.contains(traceHandler))
+ {
+ traceHandlers.add(traceHandler);
+ }
+ }
+
+ public void removeTraceHandler(OMTraceHandler traceHandler)
+ {
+ traceHandlers.remove(traceHandler);
+ }
+
+ protected void log(OMLogger logger, Level level, String msg, Throwable t)
+ {
+ for (OMLogHandler logHandler : logHandlers)
+ {
+ try
+ {
+ logHandler.logged(logger, level, msg, t);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ protected void trace(OMTracer tracer, Class context, String msg, Throwable t)
+ {
+ for (OMTraceHandler traceHandler : traceHandlers)
+ {
+ try
+ {
+ traceHandler.traced(tracer, context, msg, t);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ 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);
+
+ public static OMPlatform createPlatform()
+ {
+ try
+ {
+ if (systemContext != null)
+ {
+ return new OSGiPlatform(systemContext);
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+
+ return new LegacyPlatform();
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Activator.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Activator.java
index 3f20844..2221c10 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Activator.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Activator.java
@@ -10,9 +10,6 @@
**************************************************************************/
package org.eclipse.internal.net4j.bundle;
-import org.eclipse.internal.net4j.util.operation.BundleDebugOptions;
-import org.eclipse.internal.net4j.util.operation.BundleLogger;
-
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -21,45 +18,15 @@ import org.osgi.framework.BundleContext;
*/
public class Activator implements BundleActivator
{
- public static final String BUNDLE_ID = "org.eclipse.net4j";
-
- private BundleLogger logger;
-
- private BundleDebugOptions debugOptions;
-
public void start(BundleContext context) throws Exception
{
- try
- {
- Log.setLogger(logger = new BundleLogger(context));
- Trace.setDebugOptions(debugOptions = new BundleDebugOptions(context));
- }
- catch (RuntimeException ex)
- {
- ex.printStackTrace();
- }
+ AbstractOMPlatform.systemContext = context;
+ Net4j.BUNDLE.setBundleContext(context);
}
public void stop(BundleContext context) throws Exception
{
- try
- {
- Trace.unsetDebugOptions(debugOptions);
- debugOptions.dispose();
- }
- finally
- {
- debugOptions = null;
- }
-
- try
- {
- Log.unsetLogger(logger);
- logger.dispose();
- }
- finally
- {
- logger = null;
- }
+ Net4j.BUNDLE.setBundleContext(null);
+ AbstractOMPlatform.systemContext = null;
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyBundle.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyBundle.java
new file mode 100644
index 0000000..9ec1dc3
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyBundle.java
@@ -0,0 +1,217 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.internal.net4j.bundle;
+
+import org.eclipse.net4j.util.IOUtil;
+import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.StringUtil;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.MissingResourceException;
+import java.util.Properties;
+import java.util.Map.Entry;
+
+/**
+ * @author Eike Stepper
+ */
+public class LegacyBundle extends AbstractOMBundle
+{
+ private URL baseURL;
+
+ public LegacyBundle(AbstractOMPlatform platform, String bundleID, Class accessor)
+ {
+ super(platform, bundleID, accessor);
+
+ try
+ {
+ computeBaseURL(accessor);
+ loadOptions();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public URL getBaseURL()
+ {
+ return baseURL;
+ }
+
+ private void loadOptions()
+ {
+ InputStream inputStream = null;
+ Properties properties = new Properties();
+
+ try
+ {
+ final String prefix = getBundleID() + "/";
+ final int length = prefix.length();
+
+ inputStream = getInputStream(".options");
+ 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
+
+ String className = accessor.getName();
+ URL url = accessor.getResource(ReflectUtil.getSimpleName(accessor) + ".class");
+
+ int segmentsToTrim = 1 + StringUtil.occurrences(className, '.');
+ url = trimSegments(url, segmentsToTrim);
+
+ // 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.
+ InputStream inputStream = new URL(url.toString() + "plugin.properties").openStream();
+ inputStream.close();
+ 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))
+ {
+ 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();
+ inputStream.close();
+ baseURL = url;
+ }
+ catch (IOException exception)
+ {
+ }
+ }
+
+ // If we still don't have a good base URL, complain about it.
+ if (baseURL == null)
+ {
+ String resourceName = ReflectUtil.getPackageName(className).replace('.', '/')
+ + "/plugin.properties";
+ throw new MissingResourceException("Missing properties: " + resourceName, accessor.getName(),
+ "plugin.properties");
+ }
+ }
+
+ private static String lastSegment(URL url)
+ {
+ String path = url.getPath();
+ if (path.endsWith("/"))
+ {
+ 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("/"))
+ {
+ ++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 + "/");
+ }
+
+ /**
+ * TODO Make configurable
+ *
+ * @see org.eclipse.emf.common.util.URI#isArchiveScheme(String)
+ */
+ private static boolean isArchiveProtocol(String scheme)
+ {
+ return "jar".equalsIgnoreCase(scheme);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyPlatform.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyPlatform.java
new file mode 100644
index 0000000..396020e
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyPlatform.java
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.internal.net4j.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Eike Stepper
+ */
+public class LegacyPlatform extends AbstractOMPlatform
+{
+ private Map<String, String> debugOptions = new ConcurrentHashMap();
+
+ public LegacyPlatform()
+ {
+ }
+
+ @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);
+ }
+
+ @Override
+ protected void setDebugOption(String bundleID, String option, String value)
+ {
+ debugOptions.put(bundleID + "/" + option, value);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Log.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Log.java
deleted file mode 100644
index 7a08943..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Log.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
- * 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.internal.net4j.bundle;
-
-import org.eclipse.net4j.util.operation.ILogger;
-import org.eclipse.net4j.util.operation.ILogger.Level;
-
-import org.eclipse.internal.net4j.util.operation.ConsoleLogger;
-
-/**
- * @author Eike Stepper
- */
-public final class Log
-{
- private static ILogger logger;
-
- private Log()
- {
- };
-
- public static void log(Level level, Object plastic)
- {
- getLogger().log(level, plastic);
- }
-
- public static void error(Object plastic)
- {
- getLogger().error(plastic);
- }
-
- public static void warn(Object plastic)
- {
- getLogger().warn(plastic);
- }
-
- public static void info(Object plastic)
- {
- getLogger().info(plastic);
- }
-
- public static void debug(Object plastic)
- {
- getLogger().debug(plastic);
- }
-
- public static synchronized ILogger getLogger()
- {
- if (logger == null)
- {
- logger = new ConsoleLogger(Activator.BUNDLE_ID);
- }
-
- return logger;
- }
-
- public static void setLogger(ILogger logger)
- {
- Log.logger = logger;
- }
-
- public static void unsetLogger(ILogger logger)
- {
- if (Log.logger == logger)
- {
- Log.logger = null;
- }
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4j.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4j.java
new file mode 100644
index 0000000..d9ce3db
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4j.java
@@ -0,0 +1,37 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.internal.net4j.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMLogger;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.OMTracer;
+
+/**
+ * @author Eike Stepper
+ */
+public final class Net4j
+{
+ public static final OMBundle BUNDLE = OMPlatform.INSTANCE
+ .bundle("org.eclipse.net4j", Net4j.class);
+
+ public static final OMTracer DEBUG = BUNDLE.tracer("debug");
+
+ public static final OMTracer DEBUG_CONNECTOR = DEBUG.tracer("connector");
+
+ public static final OMTracer PERF = BUNDLE.tracer("perf");
+
+ public static final OMLogger LOG = BUNDLE.logger();
+
+ private Net4j()
+ {
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMLoggerImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMLoggerImpl.java
new file mode 100644
index 0000000..d705cdd
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMLoggerImpl.java
@@ -0,0 +1,107 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.internal.net4j.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMLogger;
+
+/**
+ * @author Eike Stepper
+ */
+public class OMLoggerImpl implements OMLogger
+{
+ private OMBundle bundle;
+
+ public OMLoggerImpl(OMBundle bundle)
+ {
+ this.bundle = bundle;
+ }
+
+ public OMBundle getBundle()
+ {
+ return bundle;
+ }
+
+ public void log(Level level, String msg, Throwable t)
+ {
+ ((AbstractOMPlatform)bundle.getPlatform()).log(this, level, msg, t);
+ }
+
+ public void error(String msg, Throwable t)
+ {
+ log(Level.ERROR, msg, t);
+ }
+
+ public void warn(String msg, Throwable t)
+ {
+ log(Level.WARN, msg, t);
+ }
+
+ public void info(String msg, Throwable t)
+ {
+ log(Level.INFO, msg, t);
+ }
+
+ public void debug(String msg, Throwable t)
+ {
+ log(Level.DEBUG, msg, t);
+ }
+
+ public void log(Level level, String msg)
+ {
+ log(level, msg, null);
+ }
+
+ public void error(String msg)
+ {
+ log(Level.ERROR, msg);
+ }
+
+ public void warn(String msg)
+ {
+ log(Level.WARN, msg);
+ }
+
+ public void info(String msg)
+ {
+ log(Level.INFO, msg);
+ }
+
+ public void debug(String msg)
+ {
+ log(Level.DEBUG, msg);
+ }
+
+ public void log(Level level, Throwable t)
+ {
+ log(level, t.getLocalizedMessage(), t);
+ }
+
+ public void error(Throwable t)
+ {
+ log(Level.ERROR, t);
+ }
+
+ public void warn(Throwable t)
+ {
+ log(Level.WARN, t);
+ }
+
+ public void info(Throwable t)
+ {
+ log(Level.INFO, t);
+ }
+
+ public void debug(Throwable t)
+ {
+ log(Level.DEBUG, t);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTracerImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTracerImpl.java
new file mode 100644
index 0000000..5b454d1
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTracerImpl.java
@@ -0,0 +1,106 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.internal.net4j.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMTracer;
+
+import java.text.MessageFormat;
+
+/**
+ * @author Eike Stepper
+ */
+public class OMTracerImpl implements OMTracer
+{
+ private OMBundle bundle;
+
+ private OMTracerImpl parent;
+
+ private String name;
+
+ private String fullName;
+
+ public OMTracerImpl(OMBundle bundle, String name)
+ {
+ this.bundle = bundle;
+ this.name = name;
+ fullName = name;
+ }
+
+ private OMTracerImpl(OMTracerImpl parent, String name)
+ {
+ this.bundle = (OMBundle)parent.getBundle();
+ this.parent = parent;
+ this.name = name;
+ fullName = parent.getFullName() + "." + name;
+ }
+
+ public OMBundle getBundle()
+ {
+ return bundle;
+ }
+
+ public OMTracer getParent()
+ {
+ return parent;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getFullName()
+ {
+ return fullName;
+ }
+
+ public boolean isEnabled()
+ {
+ return bundle.isDebugging() && bundle.getDebugOption(fullName, false);
+ }
+
+ public void setEnabled(boolean enabled)
+ {
+ bundle.setDebugOption(fullName, enabled);
+ }
+
+ public void trace(Class context, String pattern, Object... args)
+ {
+ trace(context, pattern, null, args);
+ }
+
+ public void trace(Class context, String pattern, Throwable t, Object... args)
+ {
+ String msg = MessageFormat.format(pattern, args);
+ trace(context, msg, t);
+ }
+
+ public void trace(Class context, String msg, Throwable t)
+ {
+ ((AbstractOMPlatform)bundle.getPlatform()).trace(this, context, msg, t);
+ }
+
+ public void trace(Class context, String msg)
+ {
+ trace(context, msg, (Throwable)null);
+ }
+
+ public void trace(Class context, Throwable t)
+ {
+ trace(context, t.getLocalizedMessage(), t);
+ }
+
+ public OMTracer tracer(String name)
+ {
+ return new OMTracerImpl(this, name);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiBundle.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiBundle.java
new file mode 100644
index 0000000..934a842
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiBundle.java
@@ -0,0 +1,49 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.internal.net4j.bundle;
+
+import org.eclipse.core.runtime.FileLocator;
+
+import org.osgi.framework.BundleContext;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * @author Eike Stepper
+ */
+public class OSGiBundle extends AbstractOMBundle
+{
+ public OSGiBundle(AbstractOMPlatform 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(".");
+ return FileLocator.resolve(entry);
+ }
+ catch (IOException ex)
+ {
+ ex.printStackTrace();
+ return null;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiPlatform.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiPlatform.java
new file mode 100644
index 0000000..1762caf
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiPlatform.java
@@ -0,0 +1,68 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.internal.net4j.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+
+import org.eclipse.osgi.service.debug.DebugOptions;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * @author Eike Stepper
+ */
+public class OSGiPlatform extends AbstractOMPlatform
+{
+ BundleContext systemContext;
+
+ public OSGiPlatform(Object systemContext)
+ {
+ this.systemContext = (BundleContext)systemContext;
+ }
+
+ @Override
+ protected OMBundle createBundle(String bundleID, Class accessor)
+ {
+ return new OSGiBundle(this, bundleID, accessor);
+ }
+
+ protected String getDebugOption(String bundleID, String option)
+ {
+ try
+ {
+ DebugOptions debugOptions = getDebugOptions();
+ return debugOptions.getOption(bundleID + "/" + option);
+ }
+ catch (Exception ex)
+ {
+ return null;
+ }
+ }
+
+ protected void setDebugOption(String bundleID, String option, String value)
+ {
+ try
+ {
+ DebugOptions debugOptions = getDebugOptions();
+ debugOptions.setOption(bundleID + "/" + option, value);
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+
+ 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/src/org/eclipse/internal/net4j/bundle/Trace.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Trace.java
deleted file mode 100644
index e5159c6..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Trace.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
- * 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.internal.net4j.bundle;
-
-import org.eclipse.net4j.util.operation.AbstractTracer;
-import org.eclipse.net4j.util.operation.IDebugOptions;
-import org.eclipse.net4j.util.operation.ITracer;
-
-/**
- * @author Eike Stepper
- */
-public final class Trace
-{
- public static final ITracer DEBUG = new Tracer("debug");
-
- public static final ITracer CONNECTOR = DEBUG.child("connector");
-
- public static final ITracer CONNECTOR_STATE = CONNECTOR.child("state");
-
- public static final ITracer CONNECTOR_CHANNELS = CONNECTOR.child("channels");
-
- private static IDebugOptions debugOptions;
-
- private Trace()
- {
- }
-
- public static void setDebugOptions(IDebugOptions debugOptions)
- {
- Trace.debugOptions = debugOptions;
- }
-
- public static void unsetDebugOptions(IDebugOptions options)
- {
- if (Trace.debugOptions == debugOptions)
- {
- Trace.debugOptions = null;
- }
- }
-
- private static class Tracer extends AbstractTracer
- {
- public Tracer(String tracerName)
- {
- super(tracerName);
- }
-
- public boolean isEnabled()
- {
- return debugOptions.isDebugging() && debugOptions.getBooleanOption(getTracerName(), false);
- }
-
- public void setEnabled(boolean enabled)
- {
- debugOptions.setOption(getTracerName(), Boolean.toString(enabled));
- }
-
- public ITracer child(String tracerName)
- {
- return new Tracer(getTracerName() + "." + tracerName);
- }
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java
index ac51654..ecbf7c2 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java
@@ -22,10 +22,10 @@ import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
import org.eclipse.net4j.util.lifecycle.LifecycleListener;
import org.eclipse.net4j.util.lifecycle.LifecycleNotifier;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.ContextTracer;
import org.eclipse.net4j.util.registry.IRegistry;
-import org.eclipse.internal.net4j.bundle.Log;
-import org.eclipse.internal.net4j.bundle.Trace;
+import org.eclipse.internal.net4j.bundle.Net4j;
import java.util.ArrayList;
import java.util.List;
@@ -41,6 +41,9 @@ import java.util.concurrent.TimeUnit;
public abstract class AbstractConnector extends AbstractLifecycle implements Connector,
BufferProvider
{
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_CONNECTOR,
+ AbstractConnector.class);
+
private static final ChannelImpl NULL_CHANNEL = new ChannelImpl(null)
{
@Override
@@ -192,10 +195,10 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
State oldState = getState();
if (newState != oldState)
{
- if (Trace.CONNECTOR_STATE.isEnabled())
+ if (TRACER.isEnabled())
{
- Trace.CONNECTOR_STATE.trace(AbstractConnector.class, "Setting state " + newState + " (was " //$NON-NLS-1$ //$NON-NLS-2$
- + oldState.toString().toLowerCase() + ")"); //$NON-NLS-1$
+ TRACER.trace("Setting state " + newState + " (was " + oldState.toString().toLowerCase() //$NON-NLS-1$ //$NON-NLS-2$
+ + ")"); //$NON-NLS-1$
}
state = newState;
@@ -271,9 +274,9 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
try
{
- if (Trace.CONNECTOR_STATE.isEnabled())
+ if (TRACER.isEnabled())
{
- Trace.CONNECTOR_STATE.trace(AbstractConnector.class, "Waiting for connection..."); //$NON-NLS-1$
+ TRACER.trace("Waiting for connection..."); //$NON-NLS-1$
}
return finishedNegotiating.await(timeout, TimeUnit.MILLISECONDS);
@@ -354,9 +357,9 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
{
ChannelImpl channel = new ChannelImpl(receiveExecutor);
Protocol protocol = createProtocol(protocolID, channel);
- if (Trace.CONNECTOR_CHANNELS.isEnabled())
+ if (TRACER.isEnabled())
{
- Trace.CONNECTOR_CHANNELS.trace(AbstractConnector.class, "Opening channel " + channelID //$NON-NLS-1$
+ TRACER.trace("Opening channel " + channelID //$NON-NLS-1$
+ (protocol == null ? " without protocol" : " with protocol " + protocolID)); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -382,9 +385,9 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
}
catch (IndexOutOfBoundsException ex)
{
- if (Trace.CONNECTOR_CHANNELS.isEnabled())
+ if (TRACER.isEnabled())
{
- Trace.CONNECTOR_CHANNELS.trace(AbstractConnector.class, "Invalid channelID " + channelID); //$NON-NLS-1$
+ TRACER.trace("Invalid channelID " + channelID); //$NON-NLS-1$
}
return null;
@@ -441,9 +444,9 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
{
channel.removeLifecycleListener(channelLifecycleListener);
int channelID = channel.getChannelID();
- if (Trace.CONNECTOR_CHANNELS.isEnabled())
+ if (TRACER.isEnabled())
{
- Trace.CONNECTOR_CHANNELS.trace(AbstractConnector.class, "Removing channel " + channelID); //$NON-NLS-1$
+ TRACER.trace("Removing channel " + channelID); //$NON-NLS-1$
}
channels.set(channelID, NULL_CHANNEL);
@@ -465,9 +468,9 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
ProtocolFactory factory = registry.lookup(protocolID);
if (factory == null)
{
- if (Trace.CONNECTOR_CHANNELS.isEnabled())
+ if (TRACER.isEnabled())
{
- Trace.CONNECTOR_CHANNELS.trace(AbstractConnector.class, "Unknown protocol " + protocolID); //$NON-NLS-1$
+ TRACER.trace("Unknown protocol " + protocolID); //$NON-NLS-1$
}
return null;
@@ -547,12 +550,12 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
if (protocolFactoryRegistry == null)
{
- Log.info("protocolFactoryRegistry == null"); //$NON-NLS-1$
+ Net4j.LOG.info("No protocol factory registry for " + this);
}
if (receiveExecutor == null)
{
- Log.info("receiveExecutor == null"); //$NON-NLS-1$
+ Net4j.LOG.info("No receive executor for " + this);
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/map/AbstractCachingMap.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/AbstractCachingMap.java
index 398eac0..bb69be2 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/map/AbstractCachingMap.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/AbstractCachingMap.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.internal.net4j.util.map;
+package org.eclipse.internal.net4j.util;
import java.util.AbstractMap;
import java.util.ArrayList;
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/map/AbstractDelegatingMap.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/AbstractDelegatingMap.java
index 9e04356..3b17776 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/map/AbstractDelegatingMap.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/AbstractDelegatingMap.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.internal.net4j.util.map;
+package org.eclipse.internal.net4j.util;
import java.util.Collection;
import java.util.Map;
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/AbstractLogger.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/AbstractLogger.java
deleted file mode 100644
index 39e866f..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/AbstractLogger.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
- * 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.internal.net4j.util.operation;
-
-import org.eclipse.net4j.util.operation.ILogger;
-
-/**
- * @author Eike Stepper
- */
-public abstract class AbstractLogger implements ILogger
-{
- public AbstractLogger()
- {
- }
-
- public void error(Object plastic)
- {
- log(Level.ERROR, plastic);
- }
-
- public void warn(Object plastic)
- {
- log(Level.WARN, plastic);
- }
-
- public void info(Object plastic)
- {
- log(Level.INFO, plastic);
- }
-
- public void debug(Object plastic)
- {
- log(Level.DEBUG, plastic);
- }
-
- public void dispose()
- {
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/BundleDebugOptions.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/BundleDebugOptions.java
deleted file mode 100644
index 4f910b8..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/BundleDebugOptions.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
- * 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.internal.net4j.util.operation;
-
-import org.eclipse.osgi.service.debug.DebugOptions;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * @author Eike Stepper
- */
-public class BundleDebugOptions extends AbstractDebugOptions
-{
- private String bundleName;
-
- private ServiceTracker debugTracker;
-
- public BundleDebugOptions(BundleContext context)
- {
- bundleName = context.getBundle().getSymbolicName();
- debugTracker = new ServiceTracker(context, DebugOptions.class.getName(), null);
- debugTracker.open();
- }
-
- @Override
- public void dispose()
- {
- debugTracker.close();
- debugTracker = null;
- }
-
- public String getOption(String option)
- {
- return getDebugService().getOption(getPrefixedOption(option));
- }
-
- public String getOption(String option, String defaultValue)
- {
- return getDebugService().getOption(getPrefixedOption(option), defaultValue);
- }
-
- public boolean getBooleanOption(String option, boolean defaultValue)
- {
- return getDebugService().getBooleanOption(getPrefixedOption(option), defaultValue);
- }
-
- public int getIntegerOption(String option, int defaultValue)
- {
- return getDebugService().getIntegerOption(getPrefixedOption(option), defaultValue);
- }
-
- public void setOption(String option, String value)
- {
- getDebugService().setOption(getPrefixedOption(option), value);
- }
-
- private DebugOptions getDebugService()
- {
- DebugOptions debugService = (DebugOptions)debugTracker.getService();
- if (debugService == null)
- {
- throw new IllegalStateException("debugService == null");
- }
-
- return debugService;
- }
-
- private String getPrefixedOption(String option)
- {
- return bundleName + "/" + option;
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/BundleLogger.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/BundleLogger.java
deleted file mode 100644
index 395b4a9..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/BundleLogger.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
- * 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.internal.net4j.util.operation;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogService;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * @author Eike Stepper
- */
-public class BundleLogger extends AbstractLogger
-{
- private String bundleName;
-
- private ServiceTracker logTracker;
-
- public BundleLogger(BundleContext context)
- {
- bundleName = context.getBundle().getSymbolicName();
- logTracker = new ServiceTracker(context, LogService.class.getName(), null);
- logTracker.open();
- }
-
- @Override
- public void dispose()
- {
- logTracker.close();
- logTracker = null;
- }
-
- public String getLoggerName()
- {
- return bundleName;
- }
-
- public void log(Level level, Object plastic)
- {
- LogService logService = (LogService)logTracker.getService();
- if (logService != null)
- {
- if (plastic instanceof Throwable)
- {
- Throwable t = (Throwable)plastic;
- logService.log(toOSGi(level), t.getLocalizedMessage(), t);
- }
- else
- {
- logService.log(toOSGi(level), plastic.toString());
- }
- }
- }
-
- private static int toOSGi(Level level)
- {
- switch (level)
- {
- case ERROR:
- return LogService.LOG_ERROR;
- case WARN:
- return LogService.LOG_WARNING;
- case INFO:
- return LogService.LOG_INFO;
- case DEBUG:
- return LogService.LOG_DEBUG;
- default:
- throw new IllegalArgumentException("Illegal log level: " + level);
- }
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/IOUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/IOUtil.java
new file mode 100644
index 0000000..064b786
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/IOUtil.java
@@ -0,0 +1,94 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.util;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * @author Eike Stepper
+ */
+public final class IOUtil
+{
+ private IOUtil()
+ {
+ }
+
+ public static Exception closeSilent(InputStream stream)
+ {
+ try
+ {
+ if (stream != null)
+ {
+ stream.close();
+ }
+
+ return null;
+ }
+ catch (Exception ex)
+ {
+ return ex;
+ }
+ }
+
+ public static Exception closeSilent(OutputStream stream)
+ {
+ try
+ {
+ if (stream != null)
+ {
+ stream.close();
+ }
+
+ return null;
+ }
+ catch (Exception ex)
+ {
+ return ex;
+ }
+ }
+
+ public static Exception closeSilent(Reader reader)
+ {
+ try
+ {
+ if (reader != null)
+ {
+ reader.close();
+ }
+
+ return null;
+ }
+ catch (Exception ex)
+ {
+ return ex;
+ }
+ }
+
+ public static Exception closeSilent(Writer writer)
+ {
+ try
+ {
+ if (writer != null)
+ {
+ writer.close();
+ }
+
+ return null;
+ }
+ catch (Exception ex)
+ {
+ return ex;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java
index 56085ba..7b06500 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java
@@ -68,9 +68,29 @@ public final class ReflectUtil
return id;
}
+ public static String getPackageName(Class<? extends Object> c)
+ {
+ return getPackageName(c.getName());
+ }
+
+ public static String getPackageName(String className)
+ {
+ int lastDot = className.lastIndexOf('.');
+ if (lastDot != -1)
+ {
+ className = className.substring(0, lastDot);
+ }
+
+ return className;
+ }
+
public static String getSimpleName(Class<? extends Object> c)
{
- String name = c.getName();
+ return getSimpleClassName(c.getName());
+ }
+
+ public static String getSimpleClassName(String name)
+ {
int lastDot = name.lastIndexOf('.');
if (lastDot != -1)
{
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/operation/AbstractTracer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/StringUtil.java
index 2ec5e6b..e8d0c1b 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/operation/AbstractTracer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/StringUtil.java
@@ -8,27 +8,26 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.util.operation;
+package org.eclipse.net4j.util;
/**
* @author Eike Stepper
*/
-public abstract class AbstractTracer implements ITracer
+public final class StringUtil
{
- private String tracerName;
-
- public AbstractTracer(String tracerName)
+ private StringUtil()
{
- this.tracerName = tracerName;
}
- public String getTracerName()
+ public static int occurrences(String str, char c)
{
- return tracerName;
- }
+ int count = 0;
+ for (int i = 0; (i = str.indexOf(c, i)) != -1; ++i)
+ {
+ ++count;
+ }
- public void trace(Class context, String msg)
- {
- System.out.println(context.getName() + ": " + msg);
+ return count;
}
+
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/ContextTracer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/ContextTracer.java
new file mode 100644
index 0000000..e0df7dc
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/ContextTracer.java
@@ -0,0 +1,72 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.util.om;
+
+/**
+ * @author Eike Stepper
+ */
+public class ContextTracer
+{
+ private OMTracer delegate;
+
+ private Class context;
+
+ public ContextTracer(OMTracer delegate, Class context)
+ {
+ this.delegate = delegate;
+ this.context = context;
+ }
+
+ public OMBundle getBundle()
+ {
+ return delegate.getBundle();
+ }
+
+ public String getFullName()
+ {
+ return delegate.getFullName();
+ }
+
+ public String getName()
+ {
+ return delegate.getName();
+ }
+
+ public OMTracer getParent()
+ {
+ return delegate.getParent();
+ }
+
+ public boolean isEnabled()
+ {
+ return delegate.isEnabled();
+ }
+
+ public void setEnabled(boolean enabled)
+ {
+ delegate.setEnabled(enabled);
+ }
+
+ public void trace(String msg, Throwable t)
+ {
+ delegate.trace(context, msg, t);
+ }
+
+ public void trace(String msg)
+ {
+ delegate.trace(context, msg);
+ }
+
+ public void trace(Throwable t)
+ {
+ delegate.trace(context, t);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/EclipseLoggingBridge.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/EclipseLoggingBridge.java
new file mode 100644
index 0000000..f9afc43
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/EclipseLoggingBridge.java
@@ -0,0 +1,62 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.util.om;
+
+import org.eclipse.net4j.util.om.OMLogger.Level;
+
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.internal.net4j.bundle.OSGiBundle;
+
+/**
+ * @author Eike Stepper
+ */
+public class EclipseLoggingBridge implements OMLogHandler
+{
+ public static final EclipseLoggingBridge INSTANCE = new EclipseLoggingBridge();
+
+ private EclipseLoggingBridge()
+ {
+ }
+
+ public void logged(OMLogger logger, Level level, String msg, Throwable t)
+ {
+ try
+ {
+ OSGiBundle bundle = ((OSGiBundle)logger.getBundle());
+ ILog log = Platform.getLog(bundle.getBundleContext().getBundle());
+ log.log(new Status(toEclipse(level), bundle.getBundleID(), IStatus.OK, msg, t));
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ private static int toEclipse(Level level)
+ {
+ switch (level)
+ {
+ case ERROR:
+ return IStatus.ERROR;
+ case WARN:
+ return IStatus.WARNING;
+ case INFO:
+ return IStatus.INFO;
+ case DEBUG:
+ return IStatus.OK;
+ default:
+ throw new IllegalArgumentException("Illegal log level: " + level);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMBundle.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMBundle.java
new file mode 100644
index 0000000..fda3f48
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMBundle.java
@@ -0,0 +1,119 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.util.om;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * @author Eike Stepper
+ */
+public interface OMBundle
+{
+ public OMPlatform getPlatform();
+
+ public String getBundleID();
+
+ public URL getBaseURL();
+
+ public void setBundleContext(Object bundleContext);
+
+ public OMTracer tracer(String name);
+
+ public OMLogger logger();
+
+ public boolean isDebugging();
+
+ public void setDebugging(boolean debugging);
+
+ public String getDebugOption(String option);
+
+ public void setDebugOption(String option, String value);
+
+ public String getDebugOption(String option, String defaultValue);
+
+ public boolean getDebugOption(String option, boolean defaultValue);
+
+ public void setDebugOption(String option, boolean value);
+
+ public int getDebugOption(String option, int defaultValue);
+
+ public void setDebugOption(String option, int value);
+
+ public InputStream getInputStream(String path) throws IOException;
+
+ /**
+ * Indicates whether strings should be translated by default.
+ *
+ * @return <code>true</code> if strings should be translated by default;
+ * <code>false</code> otherwise.
+ */
+ public boolean shouldTranslate();
+
+ /**
+ * Sets whether strings should be translated by default.
+ *
+ * @param shouldTranslate
+ * whether strings should be translated by default.
+ */
+ public void setShouldTranslate(boolean shouldTranslate);
+
+ /**
+ * Returns the string resource associated with the key.
+ *
+ * @param key
+ * the key of the string resource.
+ * @return the string resource associated with the key.
+ */
+ String getString(String key);
+
+ /**
+ * Returns the string resource associated with the key.
+ *
+ * @param key
+ * the key of the string resource.
+ * @param translate
+ * whether the result is to be translated to the current locale.
+ * @return the string resource associated with the key.
+ */
+ String getString(String key, boolean translate);
+
+ /**
+ * Returns a string resource associated with the key, and performs
+ * substitutions.
+ *
+ * @param key
+ * the key of the string.
+ * @param args
+ * the message substitutions.
+ * @return a string resource associated with the key.
+ * @see #getString(String)
+ * @see java.text.MessageFormat#format(String, Object...)
+ */
+ String getString(String key, Object... args);
+
+ /**
+ * Returns a string resource associated with the key, and performs
+ * substitutions.
+ *
+ * @param key
+ * the key of the string.
+ * @param translate
+ * whether the result is to be translated to the current locale.
+ * @param args
+ * the message substitutions.
+ * @return a string resource associated with the key.
+ * @see #getString(String)
+ * @see java.text.MessageFormat#format(String, Object[])
+ */
+ String getString(String key, boolean translate, Object... args);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/operation/ITracer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMLogHandler.java
index 1637413..6e2ef8a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/operation/ITracer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMLogHandler.java
@@ -8,20 +8,14 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.util.operation;
+package org.eclipse.net4j.util.om;
+
+import org.eclipse.net4j.util.om.OMLogger.Level;
/**
* @author Eike Stepper
*/
-public interface ITracer
+public interface OMLogHandler
{
- public String getTracerName();
-
- public boolean isEnabled();
-
- public void setEnabled(boolean enabled);
-
- public void trace(Class context, String msg);
-
- public ITracer child(String tracerName);
+ public void logged(OMLogger logger, Level level, String msg, Throwable t);
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMLogger.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMLogger.java
new file mode 100644
index 0000000..65a5d7d
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMLogger.java
@@ -0,0 +1,57 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.util.om;
+
+/**
+ * @author Eike Stepper
+ */
+public interface OMLogger
+{
+ public OMBundle getBundle();
+
+ public void log(Level level, String msg, Throwable t);
+
+ public void error(String msg, Throwable t);
+
+ public void warn(String msg, Throwable t);
+
+ public void info(String msg, Throwable t);
+
+ public void debug(String msg, Throwable t);
+
+ public void log(Level level, String msg);
+
+ public void error(String msg);
+
+ public void warn(String msg);
+
+ public void info(String msg);
+
+ public void debug(String msg);
+
+ public void log(Level level, Throwable t);
+
+ public void error(Throwable t);
+
+ public void warn(Throwable t);
+
+ public void info(Throwable t);
+
+ public void debug(Throwable t);
+
+ /**
+ * @author Eike Stepper
+ */
+ public enum Level
+ {
+ ERROR, WARN, INFO, DEBUG
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/operation/IDebugOptions.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMPlatform.java
index d42e2b2..87dda41 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/operation/IDebugOptions.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMPlatform.java
@@ -8,26 +8,24 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.util.operation;
+package org.eclipse.net4j.util.om;
+
+import org.eclipse.internal.net4j.bundle.AbstractOMPlatform;
/**
* @author Eike Stepper
*/
-public interface IDebugOptions
+public interface OMPlatform
{
- public boolean isDebugging();
-
- public void setDebugging(boolean debugging);
-
- public String getOption(String option);
+ public static final OMPlatform INSTANCE = AbstractOMPlatform.createPlatform();
- public String getOption(String option, String defaultValue);
+ public OMBundle bundle(String bundleID, Class accessor);
- public boolean getBooleanOption(String option, boolean defaultValue);
+ public void addLogHandler(OMLogHandler logHandler);
- public int getIntegerOption(String option, int defaultValue);
+ public void removeLogHandler(OMLogHandler logHandler);
- public void setOption(String option, String value);
+ public void addTraceHandler(OMTraceHandler traceHandler);
- public void dispose();
-}
+ public void removeTraceHandler(OMTraceHandler traceHandler);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/operation/ILogger.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTraceHandler.java
index 009c0d5..c5c5517 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/operation/ILogger.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTraceHandler.java
@@ -8,32 +8,12 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.util.operation;
+package org.eclipse.net4j.util.om;
/**
* @author Eike Stepper
*/
-public interface ILogger
+public interface OMTraceHandler
{
- public String getLoggerName();
-
- public void log(Level level, Object plastic);
-
- public void error(Object plastic);
-
- public void warn(Object plastic);
-
- public void info(Object plastic);
-
- public void debug(Object plastic);
-
- public void dispose();
-
- /**
- * @author Eike Stepper
- */
- public enum Level
- {
- ERROR, WARN, INFO, DEBUG
- }
+ public void traced(OMTracer tracer, Class context, String msg, Throwable t);
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTracer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTracer.java
new file mode 100644
index 0000000..800c8ad
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTracer.java
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.util.om;
+
+/**
+ * @author Eike Stepper
+ */
+public interface OMTracer
+{
+ public OMBundle getBundle();
+
+ public OMTracer getParent();
+
+ public String getName();
+
+ public String getFullName();
+
+ public boolean isEnabled();
+
+ public void setEnabled(boolean enabled);
+
+ public void trace(Class context, String pattern, Object... args);
+
+ public void trace(Class context, String pattern, Throwable t, Object... args);
+
+ public void trace(Class context, String msg, Throwable t);
+
+ public void trace(Class context, String msg);
+
+ public void trace(Class context, Throwable t);
+
+ public OMTracer tracer(String name);
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OSGiLoggingBridge.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OSGiLoggingBridge.java
new file mode 100644
index 0000000..bc6a4d5
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OSGiLoggingBridge.java
@@ -0,0 +1,82 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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.util.om;
+
+import org.eclipse.net4j.util.om.OMLogger.Level;
+
+import org.eclipse.internal.net4j.bundle.OSGiBundle;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+/**
+ * @author Eike Stepper
+ */
+public class OSGiLoggingBridge implements OMLogHandler
+{
+ public static final OSGiLoggingBridge INSTANCE = new OSGiLoggingBridge();
+
+ private OSGiLoggingBridge()
+ {
+ }
+
+ public void logged(OMLogger logger, Level level, String msg, Throwable t)
+ {
+ try
+ {
+ BundleContext bundleContext = ((OSGiBundle)logger.getBundle()).getBundleContext();
+ logged(bundleContext, level, msg, t);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void logged(BundleContext bundleContext, Level level, String msg, Throwable t)
+ throws Exception
+ {
+ LogService logService = getLogService(bundleContext);
+ logService.log(toOSGi(level), msg, t);
+ }
+
+ protected LogService getLogService(BundleContext bundleContext)
+ {
+ try
+ {
+ ServiceReference ref = bundleContext.getServiceReference(LogService.class.getName());
+ LogService logService = (LogService)bundleContext.getService(ref);
+ return logService;
+ }
+ catch (RuntimeException ex)
+ {
+ throw new IllegalStateException("Log service not found", ex);
+ }
+ }
+
+ private static int toOSGi(Level level)
+ {
+ switch (level)
+ {
+ case ERROR:
+ return LogService.LOG_ERROR;
+ case WARN:
+ return LogService.LOG_WARNING;
+ case INFO:
+ return LogService.LOG_INFO;
+ case DEBUG:
+ return LogService.LOG_DEBUG;
+ default:
+ throw new IllegalArgumentException("Illegal log level: " + level);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/ConsoleLogger.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/PrintStreamLogHandler.java
index d8c4211..ba2eba2 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/ConsoleLogger.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/PrintStreamLogHandler.java
@@ -8,52 +8,42 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.internal.net4j.util.operation;
+package org.eclipse.net4j.util.om;
+
+import org.eclipse.net4j.util.om.OMLogger.Level;
import java.io.PrintStream;
/**
* @author Eike Stepper
*/
-public class ConsoleLogger extends AbstractLogger
+public class PrintStreamLogHandler implements OMLogHandler
{
- private String loggerName;
+ public static final PrintStreamLogHandler CONSOLE = new PrintStreamLogHandler();
private PrintStream out;
private PrintStream err;
- public ConsoleLogger(String loggerName, PrintStream out, PrintStream err)
+ public PrintStreamLogHandler(PrintStream out, PrintStream err)
{
- this.loggerName = loggerName;
this.out = out;
this.err = err;
}
- public ConsoleLogger(String loggerName)
- {
- this(loggerName, System.out, System.err);
- }
-
- public String getLoggerName()
+ private PrintStreamLogHandler()
{
- return loggerName;
+ this(System.out, System.err);
}
- public void log(Level level, Object plastic)
+ public void logged(OMLogger logger, Level level, String msg, Throwable t)
{
PrintStream stream = level == Level.ERROR ? err : out;
- String prefix = toString(level) + " ";
- if (plastic instanceof Throwable)
+ stream.println((toString(level) + " ") + msg);
+ if (t != null)
{
- Throwable t = (Throwable)plastic;
- stream.println(prefix + t.getLocalizedMessage());
t.printStackTrace(stream);
}
- else
- {
- stream.println(prefix + plastic.toString());
- }
}
private static String toString(Level level)
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/AbstractDebugOptions.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/PrintStreamTraceHandler.java
index 1711586..fe2adee 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/operation/AbstractDebugOptions.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/PrintStreamTraceHandler.java
@@ -8,41 +8,35 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.internal.net4j.util.operation;
+package org.eclipse.net4j.util.om;
-import org.eclipse.net4j.util.operation.IDebugOptions;
+import java.io.PrintStream;
/**
* @author Eike Stepper
*/
-public abstract class AbstractDebugOptions implements IDebugOptions
+public class PrintStreamTraceHandler implements OMTraceHandler
{
- private boolean initialized;
+ public static final PrintStreamTraceHandler CONSOLE = new PrintStreamTraceHandler();
- private boolean debugging;
+ private PrintStream stream;
- public AbstractDebugOptions()
+ public PrintStreamTraceHandler(PrintStream stream)
{
+ this.stream = stream;
}
- public void dispose()
+ private PrintStreamTraceHandler()
{
+ this(System.out);
}
- public boolean isDebugging()
+ public void traced(OMTracer tracer, Class context, String msg, Throwable t)
{
- if (!initialized)
+ stream.println("[TRACE] " + msg);
+ if (t != null)
{
- debugging = getBooleanOption("debug", false);
- initialized = true;
+ t.printStackTrace(stream);
}
-
- return debugging;
- }
-
- public void setDebugging(boolean debugging)
- {
- this.debugging = debugging;
- initialized = true;
}
}