Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-09-20 10:50:20 +0000
committerEike Stepper2013-09-20 10:50:20 +0000
commit6e4718788e24cefc9c06f0e73fba75858da6f2d0 (patch)
tree47bdd7fbd228b0d465499eac5e47122f06b7790d /plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util
parent3faadda34ad1992cd06a5c8b74ba3c1c01568299 (diff)
downloadcdo-6e4718788e24cefc9c06f0e73fba75858da6f2d0.tar.gz
cdo-6e4718788e24cefc9c06f0e73fba75858da6f2d0.tar.xz
cdo-6e4718788e24cefc9c06f0e73fba75858da6f2d0.zip
[417684] [Security] Provide a HomeFolderHandler
https://bugs.eclipse.org/bugs/show_bug.cgi?id=417684
Diffstat (limited to 'plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util')
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ArrayUtil.java77
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java50
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/IManagedContainer.java14
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/IManagedContainerFactory.java12
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ManagedContainer.java14
5 files changed, 157 insertions, 10 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ArrayUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ArrayUtil.java
new file mode 100644
index 0000000000..6d7dcaef0c
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ArrayUtil.java
@@ -0,0 +1,77 @@
+package org.eclipse.net4j.util;
+
+import java.lang.reflect.Array;
+
+/**
+ * Various static helper methods.
+ *
+ * @author Eike Stepper
+ * @since 3.4
+ */
+public final class ArrayUtil
+{
+ private ArrayUtil()
+ {
+ }
+
+ public static <T> T[] add(T[] array, T element)
+ {
+ int length = array.length;
+
+ @SuppressWarnings("unchecked")
+ T[] newArray = (T[])Array.newInstance(array.getClass().getComponentType(), length + 1);
+
+ System.arraycopy(array, 0, newArray, 0, length);
+ newArray[length] = element;
+ return newArray;
+ }
+
+ public static <T> T[] remove(T[] array, T element)
+ {
+ int length = array.length;
+ for (int i = 0; i < array.length; i++)
+ {
+ T t = array[i];
+ if (ObjectUtil.equals(t, element))
+ {
+ @SuppressWarnings("unchecked")
+ T[] newArray = (T[])Array.newInstance(array.getClass().getComponentType(), length - 1);
+
+ if (i != 0)
+ {
+ System.arraycopy(array, 0, newArray, 0, i);
+ }
+
+ int next = i + 1;
+ if (next <= length)
+ {
+ System.arraycopy(array, next, newArray, i, length - next);
+ }
+
+ return newArray;
+ }
+ }
+
+ return array;
+ }
+
+ public static String toString(Object[] array)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append('{');
+
+ for (int i = 0; i < array.length; i++)
+ {
+ Object element = array[i];
+ if (i != 0)
+ {
+ builder.append(", ");
+ }
+
+ builder.append(element);
+ }
+
+ builder.append('}');
+ return builder.toString();
+ }
+}
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 90202d5de6..eb31c81cc5 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
@@ -14,7 +14,9 @@ import org.eclipse.net4j.util.om.OMPlatform;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
/**
* Various static helper methods for dealing with strings.
@@ -73,6 +75,54 @@ public final class StringUtil
return text;
}
+ /**
+ * @since 3.4
+ */
+ public static List<String> split(String text, String separators, String brackets)
+ {
+ List<String> result = new ArrayList<String>();
+
+ StringBuilder builder = new StringBuilder();
+ int length = text.length();
+ int bracketLevel = 0;
+
+ for (int i = 0; i < length; i++)
+ {
+ char c = text.charAt(i);
+
+ if (bracketLevel == 0 && separators.indexOf(c) != -1)
+ {
+ result.add(builder.toString());
+ builder.setLength(0);
+ }
+ else
+ {
+ builder.append(c);
+ }
+
+ if (brackets != null)
+ {
+ int bracket = brackets.indexOf(c);
+ if (bracket != -1)
+ {
+ if ((bracket & 1) == 0)
+ {
+ // Opening bracket
+ ++bracketLevel;
+ }
+ else
+ {
+ // Closing bracket
+ --bracketLevel;
+ }
+ }
+ }
+ }
+
+ result.add(builder.toString());
+ return result;
+ }
+
public static String safe(String str)
{
if (str == null)
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/IManagedContainer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/IManagedContainer.java
index 25b0e138cb..6695c5b4e1 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/IManagedContainer.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/IManagedContainer.java
@@ -77,4 +77,18 @@ public interface IManagedContainer extends IContainer<Object>, ILifecycle
public void loadElements(InputStream stream) throws IOException, FactoryNotFoundException, ProductCreationException;
public void saveElements(OutputStream stream) throws IOException;
+
+ /**
+ * @author Eike Stepper
+ * @since 3.4
+ */
+ public interface ContainerAware
+ {
+ /**
+ * Assigns the container that I should use to get my dependencies.
+ *
+ * @param container the container in which I am created/registered
+ */
+ public void setManagedContainer(IManagedContainer container);
+ }
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/IManagedContainerFactory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/IManagedContainerFactory.java
index d97c681668..0cc4d6f8ac 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/IManagedContainerFactory.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/IManagedContainerFactory.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.net4j.util.container;
+import org.eclipse.net4j.util.container.IManagedContainer.ContainerAware;
import org.eclipse.net4j.util.factory.IFactory;
/**
@@ -17,19 +18,14 @@ import org.eclipse.net4j.util.factory.IFactory;
* awareness of the container that instantiated it, so that the
* factory may reach back into that container for dependencies.
*
+ * @author Christian W. Damus (CEA)
+ * @author Eike Stepper
* @since 3.3
*/
-public interface IManagedContainerFactory extends IFactory
+public interface IManagedContainerFactory extends IFactory, ContainerAware
{
/**
* Obtains the container that I should use to get my dependencies.
*/
public IManagedContainer getManagedContainer();
-
- /**
- * Assigns the container that I should use to get my dependencies.
- *
- * @param container the container in which I am created/registered
- */
- public void setManagedContainer(IManagedContainer container);
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ManagedContainer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ManagedContainer.java
index 8379cceb09..4ef445dabb 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ManagedContainer.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ManagedContainer.java
@@ -109,9 +109,9 @@ public class ManagedContainer extends Lifecycle implements IManagedContainer
private void updateFactory(Map.Entry<IFactoryKey, IFactory> entry, IManagedContainer container)
{
IFactory factory = entry.getValue();
- if (factory instanceof IManagedContainerFactory)
+ if (factory instanceof ContainerAware)
{
- IManagedContainerFactory f = (IManagedContainerFactory)factory;
+ ContainerAware f = (ContainerAware)factory;
f.setManagedContainer(container);
}
}
@@ -377,6 +377,11 @@ public class ManagedContainer extends Lifecycle implements IManagedContainer
if (oldElement != element)
{
+ if (element instanceof ContainerAware)
+ {
+ ((ContainerAware)element).setManagedContainer(this);
+ }
+
EventUtil.addUniqueListener(element, elementListener);
if (oldElement != null)
@@ -411,6 +416,11 @@ public class ManagedContainer extends Lifecycle implements IManagedContainer
{
EventUtil.removeListener(element, elementListener);
fireEvent(new SingleDeltaContainerEvent<Object>(this, element, IContainerDelta.Kind.REMOVED));
+
+ if (element instanceof ContainerAware)
+ {
+ ((ContainerAware)element).setManagedContainer(null);
+ }
}
return element;

Back to the top