1 16 package org.jmanage.core.util; 17 18 import org.apache.commons.beanutils.BeanUtils; 19 20 import java.io.File ; 21 import java.util.logging.Logger ; 22 import java.math.BigInteger ; 23 import java.math.BigDecimal ; 24 25 30 public class CoreUtils { 31 32 private static final Logger logger = Loggers.getLogger(CoreUtils.class); 33 34 public static String getRootDir(){ 35 return System.getProperty(SystemProperties.JMANAGE_ROOT); 36 } 37 38 public static String getConfigDir(){ 39 return getRootDir() + "/config"; 40 } 41 42 public static String getWebDir(){ 43 return getRootDir() + "/web"; 44 } 45 46 public static String getModuleDir(String moduleId){ 47 return getRootDir() + "/modules/" + moduleId; 48 } 49 50 public static String getApplicationDir(String appId){ 51 return getRootDir() + "/applications/" + appId; 52 } 53 54 public static String getLogDir(){ 55 return getRootDir() + "/logs"; 56 } 57 58 private static String dataDir = getRootDir() + "/data"; 59 60 static{ 61 File dataDirFile = new File (dataDir); 62 if(!dataDirFile.exists()){ 63 dataDirFile.mkdirs(); 64 } 65 } 66 public static String getDataDir() { 67 return dataDir; 68 } 69 70 public static void copyProperties(Object dest, Object source) { 71 try { 72 BeanUtils.copyProperties(dest, source); 73 } 74 catch(Exception ex) { 75 throw new RuntimeException (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 valueOf(String value, String dataType){ 85 if(dataType.equals("java.lang.Integer")|| dataType.equals("int")){ 86 return new Integer (value); 87 } 88 if(dataType.equals("java.lang.Double") || dataType.equals("double")){ 89 return new Double (value); 90 } 91 if(dataType.equals("java.lang.Long") || dataType.equals("long")){ 92 return new Long (value); 93 } 94 if(dataType.equals("java.lang.Float") || dataType.equals("float")){ 95 return new Double (value); 96 } 97 if(dataType.equals("java.lang.Short") || dataType.equals("short")){ 98 return new Short (value); 99 } 100 if(dataType.equals("java.lang.Byte") || dataType.equals("byte")){ 101 return new Byte (value); 102 } 103 if(dataType.equals("java.math.BigInteger")){ 104 return new BigInteger (value); 105 } 106 if(dataType.equals("java.math.BigDecimal")){ 107 return new BigDecimal (value); 108 } 109 return null; 110 } 111 } | Popular Tags |