1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package mnemosyne.util;
17
18 import java.io.File;
19 import java.lang.reflect.InvocationTargetException;
20 import java.lang.reflect.Method;
21
22 /***
23 * @version $Id: Util.java,v 1.1.1.1 2004/08/07 06:41:26 charlesblaxland Exp $
24 */
25 public class Util
26 {
27 public static final String CLONE_METHOD_NAME = "clone";
28
29 public static boolean ensureDirectoryExists(String directoryName)
30 {
31 boolean success = true;
32 File directory = new File(directoryName);
33 if (!directory.exists())
34 {
35 success = directory.mkdirs();
36 }
37 return success;
38 }
39
40 public static Object callCloneViaReflection(Object obj) throws CloneException
41 {
42 Object clone = null;
43 try
44 {
45 Method method = Object.class.getDeclaredMethod(CLONE_METHOD_NAME, null);
46 method.setAccessible(true);
47 clone = method.invoke(obj, null);
48 }
49 catch (NoSuchMethodException e)
50 {
51 throw new PersistenceRuntimeException(e);
52 }
53 catch (IllegalAccessException e)
54 {
55 throw new PersistenceRuntimeException(e);
56 }
57 catch (InvocationTargetException e)
58 {
59 throw new CloneException("Clone method raised exception: " + e.getMessage(), e);
60 }
61
62 return clone;
63 }
64 }