1 package org.andromda.cartridges.java;
2
3 import java.util.Date;
4 import org.apache.commons.lang.StringUtils;
5 import org.apache.commons.lang.time.FastDateFormat;
6
7
8
9
10
11
12 public class JavaUtils
13 {
14
15
16
17 public static final char NAMESPACE_DELIMITER = '.';
18
19
20
21
22
23
24
25 public static String reversePackage(String packageName)
26 {
27 return StringUtils.reverseDelimited(packageName, NAMESPACE_DELIMITER);
28 }
29
30 private static FastDateFormat df = FastDateFormat.getInstance("MM/dd/yyyy HH:mm:ssZ");
31
32
33
34
35
36
37
38 public static String getDate(String format)
39 {
40 if (df == null || !format.equals(df.getPattern()))
41 {
42 df = FastDateFormat.getInstance(format);
43 }
44 return df.format(new Date());
45 }
46
47
48
49
50
51
52 public static String getDate()
53 {
54 return df.format(new Date());
55 }
56
57
58
59
60
61
62 public static String getJDKVersion()
63 {
64
65 String version = "1.6";
66 final String classVersion = System.getProperty("java.class.version","44.0");
67 if ("50.0".compareTo(classVersion) > 0 && "49.0".compareTo(classVersion) <= 0)
68 {
69 version = "1.5";
70 }
71 else if ("52.0".compareTo(classVersion) > 0 && "51.0".compareTo(classVersion) <= 0)
72 {
73 version = "1.7";
74 }
75 else if ("49.0".compareTo(classVersion) > 0 && "48.0".compareTo(classVersion) <= 0)
76 {
77 version = "1.4";
78 }
79 else if ("48.0".compareTo(classVersion) > 0 && "47.0".compareTo(classVersion) <= 0)
80 {
81 version = "1.3";
82 }
83 else if ("47.0".compareTo(classVersion) > 0 && "46.0".compareTo(classVersion) <= 0)
84 {
85 version = "1.2";
86 }
87 else if ("46.0".compareTo(classVersion) > 0 && "45.0".compareTo(classVersion) <= 0)
88 {
89 version = "1.2";
90 }
91 return version;
92 }
93 }