summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-15 06:06:40 (EDT)
committerEike Stepper2007-07-15 06:06:40 (EDT)
commitddf6f5e5f3e230d853deaf39086858286a0094e5 (patch)
tree2b9884784e47dddba27dadf2511171b9e2c7c6ed
parent457fe4ac62e5bf259b6642d47780c5b5232991f5 (diff)
downloadcdo-ddf6f5e5f3e230d853deaf39086858286a0094e5.zip
cdo-ddf6f5e5f3e230d853deaf39086858286a0094e5.tar.gz
cdo-ddf6f5e5f3e230d853deaf39086858286a0094e5.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.jms.server/src/org/eclipse/net4j/jms/internal/server/Server.java2
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/ArrayPreference.java96
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BytesPreference.java42
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java17
4 files changed, 155 insertions, 2 deletions
diff --git a/plugins/org.eclipse.net4j.jms.server/src/org/eclipse/net4j/jms/internal/server/Server.java b/plugins/org.eclipse.net4j.jms.server/src/org/eclipse/net4j/jms/internal/server/Server.java
index f0eeef5..950fb89 100644
--- a/plugins/org.eclipse.net4j.jms.server/src/org/eclipse/net4j/jms/internal/server/Server.java
+++ b/plugins/org.eclipse.net4j.jms.server/src/org/eclipse/net4j/jms/internal/server/Server.java
@@ -158,7 +158,7 @@ public class Server extends QueueWorker<MessageImpl> implements IServer
return null;
}
- messageIDs[i] = "ID:NET4J:" + HexUtil.formatLong(messageIDCounter.increment());
+ messageIDs[i] = "ID:NET4J:" + HexUtil.longToHex(messageIDCounter.increment());
message.setJMSMessageID(messageIDs[i]);
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/ArrayPreference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/ArrayPreference.java
new file mode 100644
index 0000000..7d4a75d
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/ArrayPreference.java
@@ -0,0 +1,96 @@
+/***************************************************************************
+ * 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.internal.util.om.pref;
+
+import org.eclipse.net4j.internal.util.bundle.OM;
+import org.eclipse.net4j.util.om.pref.OMPreference;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+
+/**
+ * @author Eike Stepper
+ */
+public final class ArrayPreference extends Preference<String[]> implements OMPreference<String[]>
+{
+ private static final String SEPARATOR = ",";
+
+ private static final String UTF_8 = "UTF-8";
+
+ public ArrayPreference(Preferences preferences, String name, String[] defaultValue)
+ {
+ super(preferences, name, defaultValue);
+ }
+
+ @Override
+ protected String getString()
+ {
+ String[] array = getValue();
+ if (array.length == 0)
+ {
+ return null;
+ }
+
+ StringBuilder builder = new StringBuilder();
+ for (String element : array)
+ {
+ if (builder.length() != 0)
+ {
+ builder.append(SEPARATOR);
+ builder.append(" ");
+ }
+
+ try
+ {
+ String encoded = URLEncoder.encode(element, UTF_8);
+ builder.append(encoded);
+ }
+ catch (UnsupportedEncodingException ex)
+ {
+ OM.LOG.error(ex);
+ return null;
+ }
+ }
+
+ return builder.toString();
+ }
+
+ @Override
+ protected String[] convert(String value)
+ {
+ String[] array = value.split(SEPARATOR);
+ if (array.length == 0)
+ {
+ return Preferences.DEFAULT_ARRAY;
+ }
+
+ for (int i = 0; i < array.length; i++)
+ {
+ try
+ {
+ array[i] = URLDecoder.decode(array[i].trim(), UTF_8);
+ }
+ catch (UnsupportedEncodingException ex)
+ {
+ OM.LOG.error(ex);
+ return null;
+ }
+ }
+
+ return array;
+ }
+
+ public Type getType()
+ {
+ return Type.ARRAY;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BytesPreference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BytesPreference.java
new file mode 100644
index 0000000..645e183
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/BytesPreference.java
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * 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.internal.util.om.pref;
+
+import org.eclipse.net4j.util.HexUtil;
+import org.eclipse.net4j.util.om.pref.OMPreference;
+
+/**
+ * @author Eike Stepper
+ */
+public final class BytesPreference extends Preference<byte[]> implements OMPreference<byte[]>
+{
+ public BytesPreference(Preferences preferences, String name, byte[] defaultValue)
+ {
+ super(preferences, name, defaultValue);
+ }
+
+ @Override
+ protected String getString()
+ {
+ return HexUtil.bytesToHex(getValue());
+ }
+
+ @Override
+ protected byte[] convert(String value)
+ {
+ return HexUtil.hexToBytes(value);
+ }
+
+ public Type getType()
+ {
+ return Type.BYTES;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java
index 030cfad..c5391f2 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java
@@ -43,6 +43,8 @@ public class Preferences extends Notifier implements OMPreferences
public static final String DEFAULT_STRING = "";
+ public static final String[] DEFAULT_ARRAY = {};
+
private AbstractBundle bundle;
private Map<String, Preference> prefs = new HashMap();
@@ -102,7 +104,10 @@ public class Preferences extends Notifier implements OMPreferences
{
String name = preference.getName();
String value = preference.getString();
- properties.put(name, value);
+ if (value != null)
+ {
+ properties.put(name, value);
+ }
}
}
@@ -164,6 +169,11 @@ public class Preferences extends Notifier implements OMPreferences
return init(new StringPreference(this, name, defaultValue));
}
+ public OMPreference<String[]> init(String name, String[] defaultValue)
+ {
+ return init(new ArrayPreference(this, name, defaultValue));
+ }
+
public OMPreference<Boolean> initBoolean(String name)
{
return init(name, DEFAULT_BOOLEAN);
@@ -194,6 +204,11 @@ public class Preferences extends Notifier implements OMPreferences
return init(name, DEFAULT_STRING);
}
+ public OMPreference<String[]> initArray(String name)
+ {
+ return init(name, DEFAULT_ARRAY);
+ }
+
public OMPreference<Boolean> getBoolean(String name)
{
return null;