summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Liebig2008-02-27 09:59:07 (EST)
committerStefan Liebig2008-02-27 09:59:07 (EST)
commitdbd2e1fe334173f807df73cdf1ea6897db7cbcbe (patch)
tree31f3c77b67cef4457d0dad3a00b78518512d6f4d
parent1451c9bc7adb8952895a4da12d42c8ba31bc7fd1 (diff)
downloadorg.eclipse.riena-dbd2e1fe334173f807df73cdf1ea6897db7cbcbe.zip
org.eclipse.riena-dbd2e1fe334173f807df73cdf1ea6897db7cbcbe.tar.gz
org.eclipse.riena-dbd2e1fe334173f807df73cdf1ea6897db7cbcbe.tar.bz2
useless
-rw-r--r--org.eclipse.riena.core/src/org/eclipse/riena/core/util/CloneHelper.java104
1 files changed, 0 insertions, 104 deletions
diff --git a/org.eclipse.riena.core/src/org/eclipse/riena/core/util/CloneHelper.java b/org.eclipse.riena.core/src/org/eclipse/riena/core/util/CloneHelper.java
deleted file mode 100644
index 973b232..0000000
--- a/org.eclipse.riena.core/src/org/eclipse/riena/core/util/CloneHelper.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 compeople AG and others.
- * 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:
- * compeople AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.riena.core.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.lang.reflect.Method;
-
-/**
- * This class offers methods for generic clone operations.
- *
- */
-public final class CloneHelper {
-
- /**
- * Private default constructor.
- */
- private CloneHelper() {
- super();
- }
-
- /**
- * try to (deep) clone the object passed.
- *
- * @param obj
- * the object to clone.
- * @return the cloned object.
- * @throws CloneNotSupportedException
- */
- public static Object cloneObject(Object obj) throws CloneNotSupportedException {
- Object clonedObject;
-
- if (obj instanceof java.lang.String) {
- clonedObject = obj; // Strings are immutable, so they can be shared.
- } else if (obj instanceof Serializable) {
- try { // serialize+deserialize the object to get a deep copy
- byte[] array = objectToByteArray(obj);
- clonedObject = byteArrayToObject(array);
- } catch (Throwable ex) {
- throw new CloneNotSupportedException();
- }
- } else if (obj instanceof Cloneable) {
- try {
- Method method = obj.getClass().getMethod("clone", new Class[0]);
- clonedObject = method.invoke(obj, new Object[0]);
- } catch (Throwable ex) {
- throw new CloneNotSupportedException();
- }
- } else {
- throw new CloneNotSupportedException();
- }
-
- return clonedObject;
- }
-
- /**
- * convert any serializable object to a byte array.
- *
- * @param obj
- * the object reference.
- * @return the result byte array.
- * @throws IOException
- * thrown in any case of errors.
- */
- private static byte[] objectToByteArray(Object obj) throws IOException {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(bos);
- oos.writeObject(obj);
- oos.flush();
- byte[] array = bos.toByteArray();
- bos.close();
- return array;
- }
-
- /**
- * convert a byte array which represents a serializable object to the object
- * itself.
- *
- * @param array
- * the byte array.
- * @return the object.
- * @throws ClassNotFoundException -
- * Classloader problem.
- * @throws IOException -
- * all other problems.
- */
- private static Object byteArrayToObject(byte[] array) throws IOException, ClassNotFoundException {
- ByteArrayInputStream bais = new ByteArrayInputStream(array);
- ObjectInputStream ois = new ObjectInputStream(bais);
- return ois.readObject();
- }
-} \ No newline at end of file