diff options
5 files changed, 74 insertions, 304 deletions
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 deleted file mode 100644 index 6273879672..0000000000 --- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Activator.java +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004-2007 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.log.EclipseLoggingBridge; -import org.eclipse.net4j.util.om.log.PrintLogHandler; -import org.eclipse.net4j.util.om.trace.PrintTraceHandler; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -/** - * @author Eike Stepper - */ -public class Activator implements BundleActivator -{ - public void start(BundleContext context) throws Exception - { - AbstractOMPlatform.systemContext = context; - - PrintTraceHandler.CONSOLE.setPattern("{6} [{0}] {5}"); - AbstractOMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE); - AbstractOMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE); - - try - { - AbstractOMPlatform.INSTANCE.addLogHandler(EclipseLoggingBridge.INSTANCE); - } - catch (Exception ignore) - { - } - - Net4j.BUNDLE.setBundleContext(context); - } - - public void stop(BundleContext context) throws Exception - { - Net4j.BUNDLE.setBundleContext(null); - AbstractOMPlatform.systemContext = null; - } -} 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 index 5d42179d68..85e18742a3 100644 --- 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 @@ -14,6 +14,13 @@ 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 org.eclipse.net4j.util.om.log.EclipseLoggingBridge; +import org.eclipse.net4j.util.om.log.PrintLogHandler; +import org.eclipse.net4j.util.om.trace.ContextTracer; +import org.eclipse.net4j.util.om.trace.PrintTraceHandler; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; /** * @author Eike Stepper @@ -54,7 +61,70 @@ public final class Net4j public static final OMLogger LOG = BUNDLE.logger(); + private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_OM, Net4j.class); + private Net4j() { } + + /** + * @author Eike Stepper + */ + public static final class Activator implements BundleActivator + { + public void start(BundleContext context) throws Exception + { + AbstractOMPlatform.systemContext = context; + Net4j.BUNDLE.setBundleContext(context); + + PrintTraceHandler.CONSOLE.setPattern("{6} [{0}] {5}"); + AbstractOMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE); + AbstractOMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE); + + try + { + AbstractOMPlatform.INSTANCE.addLogHandler(EclipseLoggingBridge.INSTANCE); + } + catch (Exception ignore) + { + } + + traceStart(context); + } + + public void stop(BundleContext context) throws Exception + { + traceStop(context); + Net4j.BUNDLE.setBundleContext(null); + AbstractOMPlatform.systemContext = null; + } + + public static void traceStart(BundleContext context) + { + try + { + if (TRACER.isEnabled()) + { + TRACER.format("Starting bundle {0}", context.getBundle().getSymbolicName()); + } + } + catch (Exception ignore) + { + } + } + + public static void traceStop(BundleContext context) + { + try + { + if (TRACER.isEnabled()) + { + TRACER.format("Stopping bundle {0}", context.getBundle().getSymbolicName()); + } + } + catch (Exception ignore) + { + } + } + } } diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/om/OSGiActivator.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/om/OSGiActivator.java index 39d568eb86..72045e8d1b 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/om/OSGiActivator.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/om/OSGiActivator.java @@ -12,6 +12,8 @@ package org.eclipse.internal.net4j.util.om; import org.eclipse.net4j.util.om.OMBundle; +import org.eclipse.internal.net4j.bundle.Net4j; + import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -29,6 +31,7 @@ public abstract class OSGiActivator implements BundleActivator try { getOMBundle().setBundleContext(context); + Net4j.Activator.traceStart(context); start(); } catch (Exception ex) @@ -42,6 +45,7 @@ public abstract class OSGiActivator implements BundleActivator { try { + Net4j.Activator.traceStop(context); stop(); getOMBundle().setBundleContext(null); } diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/FileStore.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/FileStore.java deleted file mode 100644 index f6458698d3..0000000000 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/FileStore.java +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004-2007 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.store; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.MessageFormat; - -/** - * @author Eike Stepper - */ -public abstract class FileStore<CONTENT> extends Store<CONTENT> -{ - private File file; - - public FileStore(File file) - { - this.file = file; - } - - public File getFile() - { - return file; - } - - @Override - protected InputStream getInputStream() throws IOException - { - return new FileInputStream(file); - } - - @Override - protected OutputStream getOutputStream() throws IOException - { - return new FileOutputStream(file); - } - - @Override - public String toString() - { - return MessageFormat.format("FileStore[{0}]", file.getAbsolutePath()); - } -} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/Store.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/Store.java deleted file mode 100644 index bd686491a5..0000000000 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/Store.java +++ /dev/null @@ -1,200 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004-2007 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.store; - -import org.eclipse.net4j.util.IOUtil; -import org.eclipse.net4j.util.lifecycle.LifecycleImpl; -import org.eclipse.net4j.util.om.trace.ContextTracer; - -import org.eclipse.internal.net4j.bundle.Net4j; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStream; - -/** - * @author Eike Stepper - */ -public abstract class Store<CONTENT> extends LifecycleImpl -{ - private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG, Store.class); - - private CONTENT content; - - private boolean dirty; - - public Store() - { - } - - public CONTENT getContent() - { - return content; - } - - public boolean isDirty() - { - return dirty; - } - - public void setDirty() - { - dirty = true; - } - - @Override - protected void onActivate() throws Exception - { - super.onActivate(); - loadContent(); - } - - @Override - protected void onDeactivate() throws Exception - { - if (dirty) - { - saveContent(); - dirty = false; - } - - super.onDeactivate(); - } - - private void loadContent() throws Exception - { - ObjectInputStream ois = null; - if (TRACER.isEnabled()) - { - TRACER.trace("Loading content"); - } - - try - { - ois = new StoreInputStream(getInputStream()); - content = (CONTENT)ois.readObject(); - } - catch (Exception ex) - { - if (TRACER.isEnabled()) - { - TRACER.trace("Initializing content"); - } - - content = getInitialContent(); - - if (!(ex instanceof FileNotFoundException)) - { - throw ex; - } - } - finally - { - IOUtil.closeSilent(ois); - } - } - - private void saveContent() - { - ObjectOutputStream oos = null; - if (TRACER.isEnabled()) - { - TRACER.trace("Saving content"); - } - - try - { - oos = new StoreOutputStream(getOutputStream()); - oos.writeObject(content); - } - catch (Exception ex) - { - Net4j.LOG.error(ex); - } - finally - { - IOUtil.closeSilent(oos); - } - } - - protected String formatForTracing(Object obj) - { - if (obj instanceof String) - { - return (String)obj; - } - - return null; - } - - protected abstract CONTENT getInitialContent(); - - protected abstract InputStream getInputStream() throws IOException; - - protected abstract OutputStream getOutputStream() throws IOException; - - /** - * @author Eike Stepper - */ - private final class StoreInputStream extends ObjectInputStream - { - private StoreInputStream(InputStream in) throws IOException - { - super(in); - enableResolveObject(true); - } - - @Override - protected Object resolveObject(Object obj) throws IOException - { - if (TRACER.isEnabled() && obj instanceof String) - { - String str = formatForTracing(obj); - if (str != null) - { - TRACER.trace("Loaded " + obj); - } - } - - return super.resolveObject(obj); - } - } - - /** - * @author Eike Stepper - */ - private final class StoreOutputStream extends ObjectOutputStream - { - private StoreOutputStream(OutputStream out) throws IOException - { - super(out); - enableReplaceObject(true); - } - - @Override - protected Object replaceObject(Object obj) throws IOException - { - if (TRACER.isEnabled()) - { - String str = formatForTracing(obj); - if (str != null) - { - TRACER.trace("Saved " + obj); - } - } - - return super.replaceObject(obj); - } - } -}
\ No newline at end of file |