summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-06-10 22:55:03 (EDT)
committerEike Stepper2007-06-10 22:55:03 (EDT)
commit73e915caf1e13c427ebccc62050457a3af6fac21 (patch)
tree07a8fbda5f907dda24d0b7e553632a092fb008af
parent4281be22cc7da65d17334c15069af33b7c7ebc4d (diff)
downloadcdo-73e915caf1e13c427ebccc62050457a3af6fac21.zip
cdo-73e915caf1e13c427ebccc62050457a3af6fac21.tar.gz
cdo-73e915caf1e13c427ebccc62050457a3af6fac21.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/CDO UI.launch40
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractOMBundle.java12
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractOMPlatform.java72
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ReflectUtil.java144
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java46
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java6
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java9
7 files changed, 309 insertions, 20 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/CDO UI.launch b/plugins/org.eclipse.emf.cdo.ui/CDO UI.launch
index 8dc2071..0d1ef17 100644
--- a/plugins/org.eclipse.emf.cdo.ui/CDO UI.launch
+++ b/plugins/org.eclipse.emf.cdo.ui/CDO UI.launch
@@ -1,28 +1,30 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.pde.ui.RuntimeWorkbench">
-<stringAttribute key="product" value="org.eclipse.sdk.ide"/>
-<booleanAttribute key="usefeatures" value="false"/>
-<stringAttribute key="bootstrap" value=""/>
-<booleanAttribute key="useProduct" value="true"/>
-<booleanAttribute key="tracing" value="true"/>
-<stringAttribute key="selected_target_plugins" value="com.ibm.icu,com.ibm.icu.source,com.jcraft.jsch,javax.servlet,javax.servlet.jsp,org.apache.ant,org.apache.commons.el,org.apache.commons.logging,org.apache.jasper,org.apache.lucene,org.apache.lucene.analysis,org.eclipse.ant.core,org.eclipse.ant.ui,org.eclipse.compare,org.eclipse.core.boot,org.eclipse.core.commands,org.eclipse.core.contenttype,org.eclipse.core.databinding,org.eclipse.core.databinding.beans,org.eclipse.core.expressions,org.eclipse.core.filebuffers,org.eclipse.core.filesystem,org.eclipse.core.filesystem.win32.x86,org.eclipse.core.jobs,org.eclipse.core.net,org.eclipse.core.resources,org.eclipse.core.resources.compatibility,org.eclipse.core.resources.win32,org.eclipse.core.runtime,org.eclipse.core.runtime.compatibility,org.eclipse.core.runtime.compatibility.auth,org.eclipse.core.runtime.compatibility.registry,org.eclipse.core.variables,org.eclipse.cvs,org.eclipse.cvs.source,org.eclipse.debug.core,org.eclipse.debug.ui,org.eclipse.emf,org.eclipse.emf.ant,org.eclipse.emf.cheatsheets,org.eclipse.emf.codegen,org.eclipse.emf.codegen.ecore,org.eclipse.emf.codegen.ecore.ui,org.eclipse.emf.codegen.ui,org.eclipse.emf.common,org.eclipse.emf.common.ui,org.eclipse.emf.commonj.sdo,org.eclipse.emf.converter,org.eclipse.emf.doc,org.eclipse.emf.ecore,org.eclipse.emf.ecore.change,org.eclipse.emf.ecore.change.edit,org.eclipse.emf.ecore.edit,org.eclipse.emf.ecore.editor,org.eclipse.emf.ecore.sdo,org.eclipse.emf.ecore.sdo.doc,org.eclipse.emf.ecore.sdo.edit,org.eclipse.emf.ecore.sdo.editor,org.eclipse.emf.ecore.sdo.source,org.eclipse.emf.ecore.xmi,org.eclipse.emf.edit,org.eclipse.emf.edit.ui,org.eclipse.emf.exporter,org.eclipse.emf.importer,org.eclipse.emf.importer.ecore,org.eclipse.emf.importer.java,org.eclipse.emf.importer.rose,org.eclipse.emf.mapping,org.eclipse.emf.mapping.ecore2ecore,org.eclipse.emf.mapping.ecore2ecore.editor,org.eclipse.emf.mapping.ecore2xml,org.eclipse.emf.mapping.ecore2xml.ui,org.eclipse.emf.mapping.ui,org.eclipse.emf.mapping.xsd2ecore,org.eclipse.emf.mapping.xsd2ecore.editor,org.eclipse.emf.source,org.eclipse.equinox.app,org.eclipse.equinox.common,org.eclipse.equinox.http.jetty,org.eclipse.equinox.http.servlet,org.eclipse.equinox.jsp.jasper,org.eclipse.equinox.jsp.jasper.registry,org.eclipse.equinox.launcher,org.eclipse.equinox.launcher.win32.win32.x86,org.eclipse.equinox.preferences,org.eclipse.equinox.registry,org.eclipse.help,org.eclipse.help.appserver,org.eclipse.help.base,org.eclipse.help.ui,org.eclipse.help.webapp,org.eclipse.jdt,org.eclipse.jdt.apt.core,org.eclipse.jdt.apt.ui,org.eclipse.jdt.core,org.eclipse.jdt.core.manipulation,org.eclipse.jdt.debug,org.eclipse.jdt.debug.ui,org.eclipse.jdt.doc.isv,org.eclipse.jdt.doc.user,org.eclipse.jdt.junit,org.eclipse.jdt.junit.runtime,org.eclipse.jdt.junit4.runtime,org.eclipse.jdt.launching,org.eclipse.jdt.source,org.eclipse.jdt.ui,org.eclipse.jface,org.eclipse.jface.databinding,org.eclipse.jface.text,org.eclipse.jsch.core,org.eclipse.ltk.core.refactoring,org.eclipse.ltk.ui.refactoring,org.eclipse.osgi,org.eclipse.osgi.services,org.eclipse.osgi.util,org.eclipse.pde,org.eclipse.pde.build,org.eclipse.pde.core,org.eclipse.pde.doc.user,org.eclipse.pde.junit.runtime,org.eclipse.pde.runtime,org.eclipse.pde.source,org.eclipse.pde.ui,org.eclipse.pde.ui.templates,org.eclipse.platform,org.eclipse.platform.doc.isv,org.eclipse.platform.source,org.eclipse.platform.source.win32.win32.x86,org.eclipse.rcp,org.eclipse.rcp.source,org.eclipse.rcp.source.win32.win32.x86,org.eclipse.sdk,org.eclipse.search,org.eclipse.swt,org.eclipse.swt.win32.win32.x86,org.eclipse.team.core,org.eclipse.team.cvs.core,org.eclipse.team.cvs.ssh,org.eclipse.team.cvs.ssh2,org.eclipse.team.cvs.ui,org.eclipse.team.ui,org.eclipse.text,org.eclipse.tomcat,org.eclipse.ui,org.eclipse.ui.browser,org.eclipse.ui.cheatsheets,org.eclipse.ui.console,org.eclipse.ui.editors,org.eclipse.ui.externaltools,org.eclipse.ui.forms,org.eclipse.ui.ide,org.eclipse.ui.ide.application,org.eclipse.ui.intro,org.eclipse.ui.intro.universal,org.eclipse.ui.navigator,org.eclipse.ui.navigator.resources,org.eclipse.ui.presentations.r21,org.eclipse.ui.views,org.eclipse.ui.views.properties.tabbed,org.eclipse.ui.win32,org.eclipse.ui.workbench,org.eclipse.ui.workbench.compatibility,org.eclipse.ui.workbench.texteditor,org.eclipse.update.configurator,org.eclipse.update.core,org.eclipse.update.core.win32,org.eclipse.update.scheduler,org.eclipse.update.ui,org.eclipse.xsd,org.eclipse.xsd.cheatsheets,org.eclipse.xsd.doc,org.eclipse.xsd.ecore.exporter,org.eclipse.xsd.ecore.importer,org.eclipse.xsd.edit,org.eclipse.xsd.editor,org.eclipse.xsd.source,org.junit,org.junit4,org.mortbay.jetty"/>
-<booleanAttribute key="automaticValidate" value="true"/>
-<stringAttribute key="selectedPlugin" value="org.eclipse.emf.cdo.ui"/>
+<booleanAttribute key="askclear" value="true"/>
<booleanAttribute key="automaticAdd" value="false"/>
+<booleanAttribute key="automaticValidate" value="false"/>
+<stringAttribute key="bootstrap" value=""/>
<stringAttribute key="checked" value="org.eclipse.emf.cdo,org.eclipse.emf.cdo.protocol,org.eclipse.emf.cdo.server,org.eclipse.emf.cdo.ui,org.eclipse.net4j,org.eclipse.net4j.jvm,org.eclipse.net4j.tcp,org.eclipse.net4j.ui"/>
-<stringAttribute key="selected_workspace_plugins" value="org.eclipse.emf.cdo.server,org.eclipse.emf.cdo.protocol,org.eclipse.emf.cdo.tests.model1.editor,org.eclipse.emf.cdo.tests.model1.edit,org.eclipse.emf.cdo.ui,org.eclipse.emf.cdo.tests.model1,org.eclipse.net4j,org.eclipse.net4j.tcp,org.eclipse.net4j.ui,org.eclipse.emf.cdo"/>
-<stringAttribute key="location" value="${workspace_loc}/../cdo.ui"/>
-<stringAttribute key="configLocation" value=""/>
+<booleanAttribute key="clearConfig" value="false"/>
<booleanAttribute key="clearws" value="false"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-nosplash"/>
-<stringAttribute key="pde.version" value="3.3"/>
-<stringAttribute key="templateConfig" value="${target_home}\configuration\config.ini"/>
+<booleanAttribute key="clearwslog" value="false"/>
+<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/CDO UI"/>
<booleanAttribute key="default" value="false"/>
-<booleanAttribute key="clearConfig" value="false"/>
+<booleanAttribute key="includeOptional" value="true"/>
+<stringAttribute key="location" value="${workspace_loc}/../cdo.ui"/>
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-nosplash"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
-<booleanAttribute key="useDefaultConfigArea" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dosgi.console"/>
+<stringAttribute key="pde.version" value="3.3"/>
+<stringAttribute key="product" value="org.eclipse.sdk.ide"/>
+<stringAttribute key="selectedPlugin" value="org.eclipse.emf.cdo.ui"/>
+<stringAttribute key="selected_target_plugins" value="com.ibm.icu,com.jcraft.jsch,javax.servlet,javax.servlet.jsp,org.apache.ant,org.apache.commons.el,org.apache.commons.logging,org.apache.jasper,org.apache.lucene,org.apache.lucene.analysis,org.eclipse.ant.core,org.eclipse.ant.ui,org.eclipse.compare,org.eclipse.core.boot,org.eclipse.core.commands,org.eclipse.core.contenttype,org.eclipse.core.databinding,org.eclipse.core.databinding.beans,org.eclipse.core.expressions,org.eclipse.core.filebuffers,org.eclipse.core.filesystem,org.eclipse.core.filesystem.win32.x86,org.eclipse.core.jobs,org.eclipse.core.net,org.eclipse.core.resources,org.eclipse.core.resources.compatibility,org.eclipse.core.resources.win32,org.eclipse.core.runtime,org.eclipse.core.runtime.compatibility,org.eclipse.core.runtime.compatibility.auth,org.eclipse.core.runtime.compatibility.registry,org.eclipse.core.variables,org.eclipse.cvs,org.eclipse.cvs.source,org.eclipse.debug.core,org.eclipse.debug.ui,org.eclipse.emf,org.eclipse.emf.ant,org.eclipse.emf.cheatsheets,org.eclipse.emf.codegen,org.eclipse.emf.codegen.ecore,org.eclipse.emf.codegen.ecore.ui,org.eclipse.emf.codegen.ui,org.eclipse.emf.common,org.eclipse.emf.common.ui,org.eclipse.emf.commonj.sdo,org.eclipse.emf.converter,org.eclipse.emf.doc,org.eclipse.emf.ecore,org.eclipse.emf.ecore.change,org.eclipse.emf.ecore.change.edit,org.eclipse.emf.ecore.edit,org.eclipse.emf.ecore.editor,org.eclipse.emf.ecore.sdo,org.eclipse.emf.ecore.sdo.doc,org.eclipse.emf.ecore.sdo.edit,org.eclipse.emf.ecore.sdo.editor,org.eclipse.emf.ecore.sdo.source,org.eclipse.emf.ecore.xmi,org.eclipse.emf.edit,org.eclipse.emf.edit.ui,org.eclipse.emf.exporter,org.eclipse.emf.importer,org.eclipse.emf.importer.ecore,org.eclipse.emf.importer.java,org.eclipse.emf.importer.rose,org.eclipse.emf.mapping,org.eclipse.emf.mapping.ecore2ecore,org.eclipse.emf.mapping.ecore2ecore.editor,org.eclipse.emf.mapping.ecore2xml,org.eclipse.emf.mapping.ecore2xml.ui,org.eclipse.emf.mapping.ui,org.eclipse.emf.mapping.xsd2ecore,org.eclipse.emf.mapping.xsd2ecore.editor,org.eclipse.emf.source,org.eclipse.equinox.app,org.eclipse.equinox.common,org.eclipse.equinox.http.jetty,org.eclipse.equinox.http.registry,org.eclipse.equinox.http.servlet,org.eclipse.equinox.jsp.jasper,org.eclipse.equinox.jsp.jasper.registry,org.eclipse.equinox.launcher,org.eclipse.equinox.launcher.win32.win32.x86,org.eclipse.equinox.preferences,org.eclipse.equinox.registry,org.eclipse.help,org.eclipse.help.appserver,org.eclipse.help.base,org.eclipse.help.ui,org.eclipse.help.webapp,org.eclipse.jdt,org.eclipse.jdt.apt.core,org.eclipse.jdt.apt.ui,org.eclipse.jdt.compiler.apt,org.eclipse.jdt.compiler.tool,org.eclipse.jdt.core,org.eclipse.jdt.core.manipulation,org.eclipse.jdt.debug,org.eclipse.jdt.debug.ui,org.eclipse.jdt.doc.isv,org.eclipse.jdt.doc.user,org.eclipse.jdt.junit,org.eclipse.jdt.junit.runtime,org.eclipse.jdt.junit4.runtime,org.eclipse.jdt.launching,org.eclipse.jdt.source,org.eclipse.jdt.ui,org.eclipse.jface,org.eclipse.jface.databinding,org.eclipse.jface.text,org.eclipse.jsch.core,org.eclipse.ltk.core.refactoring,org.eclipse.ltk.ui.refactoring,org.eclipse.osgi,org.eclipse.osgi.services,org.eclipse.osgi.util,org.eclipse.pde,org.eclipse.pde.build,org.eclipse.pde.core,org.eclipse.pde.doc.user,org.eclipse.pde.junit.runtime,org.eclipse.pde.runtime,org.eclipse.pde.source,org.eclipse.pde.ui,org.eclipse.pde.ui.templates,org.eclipse.platform,org.eclipse.platform.doc.isv,org.eclipse.platform.source,org.eclipse.platform.source.win32.win32.x86,org.eclipse.rcp,org.eclipse.rcp.source,org.eclipse.rcp.source.win32.win32.x86,org.eclipse.sdk,org.eclipse.search,org.eclipse.swt,org.eclipse.swt.win32.win32.x86,org.eclipse.team.core,org.eclipse.team.cvs.core,org.eclipse.team.cvs.ssh,org.eclipse.team.cvs.ssh2,org.eclipse.team.cvs.ui,org.eclipse.team.ui,org.eclipse.text,org.eclipse.tomcat,org.eclipse.ui,org.eclipse.ui.browser,org.eclipse.ui.cheatsheets,org.eclipse.ui.console,org.eclipse.ui.editors,org.eclipse.ui.externaltools,org.eclipse.ui.forms,org.eclipse.ui.ide,org.eclipse.ui.ide.application,org.eclipse.ui.intro,org.eclipse.ui.intro.universal,org.eclipse.ui.navigator,org.eclipse.ui.navigator.resources,org.eclipse.ui.presentations.r21,org.eclipse.ui.views,org.eclipse.ui.views.properties.tabbed,org.eclipse.ui.win32,org.eclipse.ui.workbench,org.eclipse.ui.workbench.compatibility,org.eclipse.ui.workbench.texteditor,org.eclipse.update.configurator,org.eclipse.update.core,org.eclipse.update.core.win32,org.eclipse.update.scheduler,org.eclipse.update.ui,org.eclipse.xsd,org.eclipse.xsd.cheatsheets,org.eclipse.xsd.doc,org.eclipse.xsd.ecore.exporter,org.eclipse.xsd.ecore.importer,org.eclipse.xsd.edit,org.eclipse.xsd.editor,org.eclipse.xsd.source,org.junit,org.junit4,org.mortbay.jetty"/>
+<stringAttribute key="selected_workspace_plugins" value="org.eclipse.emf.cdo.server,org.eclipse.emf.cdo.protocol,org.eclipse.emf.cdo.tests.model1.editor,org.eclipse.emf.cdo.tests.model1.edit,org.eclipse.net4j.util,org.eclipse.emf.cdo.ui,org.eclipse.emf.cdo.tests.model1,org.eclipse.net4j,org.eclipse.net4j.tcp,org.eclipse.net4j.ui,org.eclipse.emf.cdo"/>
+<stringAttribute key="templateConfig" value="${target_home}\configuration\config.ini"/>
+<booleanAttribute key="tracing" value="true"/>
<booleanAttribute key="useDefaultConfig" value="true"/>
-<booleanAttribute key="askclear" value="true"/>
-<booleanAttribute key="includeOptional" value="true"/>
+<booleanAttribute key="useDefaultConfigArea" value="true"/>
+<booleanAttribute key="useProduct" value="true"/>
+<booleanAttribute key="usefeatures" value="false"/>
</launchConfiguration>
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractOMBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractOMBundle.java
index c365e9e..89e228b 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractOMBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractOMBundle.java
@@ -17,6 +17,7 @@ import org.eclipse.net4j.util.om.OMLogger;
import org.eclipse.net4j.util.om.OMPlatform;
import org.eclipse.net4j.util.om.OMTracer;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -24,6 +25,7 @@ import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.MissingResourceException;
+import java.util.Properties;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.concurrent.ConcurrentHashMap;
@@ -178,6 +180,16 @@ public abstract class AbstractOMBundle implements OMBundle
return logger;
}
+ public File getConfigFile()
+ {
+ return platform.getConfigFile(bundleID);
+ }
+
+ public Properties getConfigProperties()
+ {
+ return platform.getConfigProperties(bundleID);
+ }
+
public InputStream getInputStream(String path) throws IOException
{
URL url = new URL(getBaseURL().toString() + ".options"); //$NON-NLS-1$
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractOMPlatform.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractOMPlatform.java
index b485ae8..e0048f1 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractOMPlatform.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractOMPlatform.java
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.net4j.internal.util.bundle;
+import org.eclipse.net4j.util.IOUtil;
import org.eclipse.net4j.util.om.OMBundle;
import org.eclipse.net4j.util.om.OMLogHandler;
import org.eclipse.net4j.util.om.OMLogger;
@@ -19,7 +20,11 @@ import org.eclipse.net4j.util.om.OMLogger.Level;
import org.eclipse.net4j.util.om.OMTraceHandler.Event;
import org.eclipse.net4j.util.om.trace.ContextTracer;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
import java.util.Map;
+import java.util.Properties;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -29,6 +34,8 @@ import java.util.concurrent.ConcurrentLinkedQueue;
*/
public abstract class AbstractOMPlatform implements OMPlatform
{
+ public static final String SYSTEM_PROPERTY_NET4J_CONFIG = "net4j.config"; //$NON-NLS-1$
+
static Object systemContext;
private static ContextTracer __TRACER__;
@@ -93,6 +100,71 @@ public abstract class AbstractOMPlatform implements OMPlatform
this.debugging = debugging;
}
+ public File getConfigFolder()
+ {
+ String config = System.getProperty(SYSTEM_PROPERTY_NET4J_CONFIG);
+ if (config == null)
+ {
+ return null;
+ }
+
+ File configFolder = new File(config);
+ if (!configFolder.exists())
+ {
+ if (!configFolder.mkdirs())
+ {
+ OM.LOG.error("Config folder " + config + " could not be created");
+ return null;
+ }
+ }
+
+ if (!configFolder.isDirectory())
+ {
+ OM.LOG.error("Config folder " + config + " is not a directoy");
+ return null;
+ }
+
+ return configFolder;
+ }
+
+ public File getConfigFile(String name)
+ {
+ File configFolder = getConfigFolder();
+ if (configFolder == null)
+ {
+ return null;
+ }
+
+ return new File(configFolder, name);
+ }
+
+ public Properties getConfigProperties(String name)
+ {
+ File configFile = getConfigFile(name);
+ if (configFile == null)
+ {
+ return null;
+ }
+
+ FileInputStream fis = null;
+ try
+ {
+ fis = new FileInputStream(configFile);
+ Properties properties = new Properties();
+ properties.load(fis);
+ return properties;
+ }
+ catch (IOException ex)
+ {
+ OM.LOG.error("Config file " + configFile.getAbsolutePath() + " could not be read");
+ return null;
+ }
+ finally
+ {
+ IOUtil.closeSilent(fis);
+ }
+ }
+
protected void log(OMLogger logger, Level level, String msg, Throwable t)
{
for (OMLogHandler logHandler : logHandlers)
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ReflectUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ReflectUtil.java
index c888b61..20efea2 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ReflectUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ReflectUtil.java
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.net4j.util;
+import org.eclipse.net4j.internal.util.bundle.OM;
import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
import java.io.PrintStream;
@@ -18,17 +19,22 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
+import java.util.Map.Entry;
/**
* @author Eike Stepper
*/
public final class ReflectUtil
{
+ private static final String NAMESPACE_SEPARATOR = ".";
+
public static final Class<Object> ROOT_CLASS = Object.class;
public static final Class[] NO_PARAMETERS = null;
@@ -196,6 +202,142 @@ public final class ReflectUtil
}
}
+ public static Object instantiate(Map<Object, Object> properties, String namespace, String classKey,
+ ClassLoader classLoader) throws ClassNotFoundException, InstantiationException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException
+ {
+ if (namespace != null)
+ {
+ if (namespace.length() == 0)
+ {
+ namespace = null;
+ }
+ else if (!namespace.endsWith(NAMESPACE_SEPARATOR))
+ {
+ namespace += NAMESPACE_SEPARATOR;
+ }
+ }
+
+ String className = null;
+ Map<String, Object> values = new HashMap();
+ for (Entry<Object, Object> entry : properties.entrySet())
+ {
+ if (entry.getKey() instanceof String)
+ {
+ String key = (String)entry.getKey();
+ if (namespace != null)
+ {
+ if (key.startsWith(namespace))
+ {
+ key = key.substring(namespace.length());
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ if (classKey.equals(key))
+ {
+ Object classValue = entry.getValue();
+ if (classValue instanceof String)
+ {
+ className = (String)classValue;
+ }
+ else
+ {
+ OM.LOG.warn("Value of classKey " + classKey + " is not a String");
+ }
+ }
+ else
+ {
+ values.put(key, entry.getValue());
+ }
+ }
+ }
+
+ if (className == null)
+ {
+ throw new IllegalArgumentException("Properties do not contain a valid class name for key " + classKey);
+ }
+
+ Class<?> c = classLoader.loadClass(className);
+ Object instance = c.newInstance();
+ Method[] methods = c.getMethods();
+ for (Method method : methods)
+ {
+ if (isSetter(method))
+ {
+ String name = StringUtil.uncap(method.getName().substring(3));
+ Object value = values.get(name);
+ if (value != null)
+ {
+ Class<?> type = method.getParameterTypes()[0];
+ if (!type.isAssignableFrom(value.getClass()))
+ {
+ if (value instanceof String)
+ {
+ String str = (String)value;
+ value = null;
+ if (type.isAssignableFrom(Boolean.class))
+ {
+ value = Boolean.parseBoolean(str);
+ }
+ else if (type.isAssignableFrom(Byte.class))
+ {
+ value = Byte.parseByte(str);
+ }
+ else if (type.isAssignableFrom(Short.class))
+ {
+ value = Short.parseShort(str);
+ }
+ else if (type.isAssignableFrom(Integer.class))
+ {
+ value = Integer.parseInt(str);
+ }
+ else if (type.isAssignableFrom(Long.class))
+ {
+ value = Long.parseLong(str);
+ }
+ else if (type.isAssignableFrom(Float.class))
+ {
+ value = Float.parseFloat(str);
+ }
+ else if (type.isAssignableFrom(Double.class))
+ {
+ value = Double.parseDouble(str);
+ }
+ }
+ else
+ {
+ value = null;
+ }
+ }
+
+ if (value == null)
+ {
+ throw new IllegalArgumentException("Value of property " + name + " can not be assigned to type "
+ + type.getName());
+ }
+
+ method.invoke(instance, value);
+ }
+ }
+ }
+
+ return instance;
+ }
+
+ public static boolean isSetter(Method method)
+ {
+ return method.getParameterTypes().length == 1 && isSetterName(method.getName());
+ }
+
+ public static boolean isSetterName(String name)
+ {
+ return name.startsWith("set") && name.length() > 3 && Character.isUpperCase(name.charAt(3));
+ }
+
public static String toString(Object object)
{
return toString(object, " "); //$NON-NLS-1$
@@ -221,7 +363,7 @@ public final class ReflectUtil
// Recurse
toString(segment.getSuperclass(), object, prefix, builder);
- String segmentPrefix = segment == object.getClass() ? "" : getSimpleName(segment) + "."; //$NON-NLS-1$ //$NON-NLS-2$
+ String segmentPrefix = segment == object.getClass() ? "" : getSimpleName(segment) + NAMESPACE_SEPARATOR; //$NON-NLS-1$ //$NON-NLS-2$
Field[] fields = segment.getDeclaredFields();
for (Field field : fields)
{
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java
index 34199b7..917a820 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java
@@ -46,6 +46,52 @@ public final class StringUtil
return s1.compareTo(s2);
}
+ public static String cap(String str)
+ {
+ if (str == null || str.length() == 0)
+ {
+ return str;
+ }
+
+ char first = str.charAt(0);
+ if (Character.isUpperCase(first))
+ {
+ return str;
+ }
+
+ if (str.length() == 1)
+ {
+ return str.toUpperCase();
+ }
+
+ StringBuilder builder = new StringBuilder(str);
+ builder.setCharAt(0, Character.toUpperCase(first));
+ return builder.toString();
+ }
+
+ public static String uncap(String str)
+ {
+ if (str == null || str.length() == 0)
+ {
+ return str;
+ }
+
+ char first = str.charAt(0);
+ if (Character.isLowerCase(first))
+ {
+ return str;
+ }
+
+ if (str.length() == 1)
+ {
+ return str.toLowerCase();
+ }
+
+ StringBuilder builder = new StringBuilder(str);
+ builder.setCharAt(0, Character.toLowerCase(first));
+ return builder.toString();
+ }
+
public static int occurrences(String str, char c)
{
int count = 0;
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java
index 367d762..12501ba 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java
@@ -10,9 +10,11 @@
**************************************************************************/
package org.eclipse.net4j.util.om;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.Properties;
/**
* @author Eike Stepper
@@ -49,6 +51,10 @@ public interface OMBundle
public void setDebugOption(String option, int value);
+ public File getConfigFile();
+
+ public Properties getConfigProperties();
+
public String getStateLocation();
public InputStream getInputStream(String path) throws IOException;
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java
index 9fe07b6..021e96f 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java
@@ -12,6 +12,9 @@ package org.eclipse.net4j.util.om;
import org.eclipse.net4j.internal.util.bundle.AbstractOMPlatform;
+import java.io.File;
+import java.util.Properties;
+
/**
* @author Eike Stepper
*/
@@ -33,4 +36,10 @@ public interface OMPlatform
public void addTraceHandler(OMTraceHandler traceHandler);
public void removeTraceHandler(OMTraceHandler traceHandler);
+
+ public File getConfigFolder();
+
+ public File getConfigFile(String name);
+
+ public Properties getConfigProperties(String name);
} \ No newline at end of file