KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > util > CoreUtils


1 /**
2  * Copyright 2004-2005 jManage.org
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 org.jmanage.core.util;
17
18 import org.apache.commons.beanutils.BeanUtils;
19
20 import java.io.File JavaDoc;
21 import java.util.logging.Logger JavaDoc;
22 import java.math.BigInteger JavaDoc;
23 import java.math.BigDecimal JavaDoc;
24
25 /**
26  *
27  * date: Jun 22, 2004
28  * @author Rakesh Kalra
29  */

30 public class CoreUtils {
31
32     private static final Logger JavaDoc logger = Loggers.getLogger(CoreUtils.class);
33
34     public static String JavaDoc getRootDir(){
35         return System.getProperty(SystemProperties.JMANAGE_ROOT);
36     }
37
38     public static String JavaDoc getConfigDir(){
39         return getRootDir() + "/config";
40     }
41
42     public static String JavaDoc getWebDir(){
43         return getRootDir() + "/web";
44     }
45
46     public static String JavaDoc getModuleDir(String JavaDoc moduleId){
47         return getRootDir() + "/modules/" + moduleId;
48     }
49
50     public static String JavaDoc getApplicationDir(String JavaDoc appId){
51         return getRootDir() + "/applications/" + appId;
52     }
53
54     public static String JavaDoc getLogDir(){
55         return getRootDir() + "/logs";
56     }
57
58     private static String JavaDoc dataDir = getRootDir() + "/data";
59
60     static{
61         File JavaDoc dataDirFile = new File JavaDoc(dataDir);
62         if(!dataDirFile.exists()){
63              dataDirFile.mkdirs();
64         }
65     }
66     public static String JavaDoc getDataDir() {
67         return dataDir;
68     }
69
70     public static void copyProperties(Object JavaDoc dest, Object JavaDoc source) {
71         try {
72             BeanUtils.copyProperties(dest, source);
73         }
74         catch(Exception JavaDoc ex) {
75             throw new RuntimeException JavaDoc(ex);
76         }
77     }
78
79     public static void exitSystem(){
80         logger.severe("Shutting down application");
81         System.exit(1);
82     }
83
84     public static Number JavaDoc valueOf(String JavaDoc value, String JavaDoc dataType){
85         if(dataType.equals("java.lang.Integer")|| dataType.equals("int")){
86             return new Integer JavaDoc(value);
87         }
88         if(dataType.equals("java.lang.Double") || dataType.equals("double")){
89             return new Double JavaDoc(value);
90         }
91         if(dataType.equals("java.lang.Long") || dataType.equals("long")){
92             return new Long JavaDoc(value);
93         }
94         if(dataType.equals("java.lang.Float") || dataType.equals("float")){
95             return new Double JavaDoc(value);
96         }
97         if(dataType.equals("java.lang.Short") || dataType.equals("short")){
98             return new Short JavaDoc(value);
99         }
100         if(dataType.equals("java.lang.Byte") || dataType.equals("byte")){
101             return new Byte JavaDoc(value);
102         }
103         if(dataType.equals("java.math.BigInteger")){
104             return new BigInteger JavaDoc(value);
105         }
106         if(dataType.equals("java.math.BigDecimal")){
107             return new BigDecimal JavaDoc(value);
108         }
109         return null;
110     }
111 }
Popular Tags