%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
mnemosyne.util.Util |
|
|
1 | /* |
|
2 | * Copyright 2004 Charles Blaxland |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
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 | 0 | public class Util |
26 | { |
|
27 | public static final String CLONE_METHOD_NAME = "clone"; |
|
28 | ||
29 | public static boolean ensureDirectoryExists(String directoryName) |
|
30 | { |
|
31 | 32 | boolean success = true; |
32 | 32 | File directory = new File(directoryName); |
33 | 32 | if (!directory.exists()) |
34 | { |
|
35 | 25 | success = directory.mkdirs(); |
36 | } |
|
37 | 32 | return success; |
38 | } |
|
39 | ||
40 | public static Object callCloneViaReflection(Object obj) throws CloneException |
|
41 | { |
|
42 | 5 | Object clone = null; |
43 | try |
|
44 | { |
|
45 | 6 | Method method = Object.class.getDeclaredMethod(CLONE_METHOD_NAME, null); |
46 | 5 | method.setAccessible(true); |
47 | 5 | clone = method.invoke(obj, null); |
48 | 5 | } |
49 | catch (NoSuchMethodException e) |
|
50 | { |
|
51 | 0 | throw new PersistenceRuntimeException(e); |
52 | } |
|
53 | catch (IllegalAccessException e) |
|
54 | { |
|
55 | 0 | throw new PersistenceRuntimeException(e); |
56 | } |
|
57 | catch (InvocationTargetException e) |
|
58 | { |
|
59 | 0 | throw new CloneException("Clone method raised exception: " + e.getMessage(), e); |
60 | } |
|
61 | ||
62 | 5 | return clone; |
63 | } |
|
64 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |