1 18 package org.apache.geronimo.interop.util; 19 20 import java.io.File ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.apache.geronimo.interop.properties.StringProperty; 25 import org.apache.geronimo.interop.properties.SystemProperties; 26 27 28 public abstract class JavaClass { 29 30 public static final StringProperty classDirProperty = 31 new StringProperty(SystemProperties.class, "org.apache.geronimo.interop.classDir") 32 .defaultValue(FileUtil.pretty(SystemProperties.getHome() + "/genfiles/java/classes")); 33 34 public static final StringProperty classPathProperty = 35 new StringProperty(SystemProperties.class, "org.apache.geronimo.interop.classPath") 36 .defaultValue(FileUtil.pretty(SystemProperties.getHome() + "/genfiles/java/classes")); 37 38 public static final StringProperty sourceDirProperty = 39 new StringProperty(SystemProperties.class, "org.apache.geronimo.interop.sourceDir") 40 .defaultValue(FileUtil.pretty(SystemProperties.getHome() + "/genfiles/java/src")); 41 42 public static final StringProperty sourcePathProperty = 43 new StringProperty(SystemProperties.class, "org.apache.geronimo.interop.sourcePath") 44 .defaultValue(FileUtil.pretty(SystemProperties.getHome() + "/src/java") 45 + File.pathSeparator 46 + FileUtil.pretty(SystemProperties.getHome() + "/genfiles/java/src")); 47 48 private static String _classDir = classDirProperty.getString(); 49 private static List _classPath = ListUtil.getPathList(classPathProperty.getString()); 50 private static String _sourceDir = sourceDirProperty.getString(); 51 private static List _sourcePath = ListUtil.getPathList(sourcePathProperty.getString()); 52 53 public static String addPackageSuffix(String className, String suffix) { 54 String jp = getPackagePrefix(className); 55 if (jp.length() == 0) { 56 jp = suffix; 57 } else { 58 jp += "." + suffix; 59 } 60 return jp + "." + getNameSuffix(className); 61 } 62 63 public static String getClassDir() { 64 return _classDir; 65 } 66 67 public static List getClassPath() { 68 return _classPath; 69 } 70 71 public static File getClassFile(Class theClass) { 72 return getClassFile(theClass.getName()); 73 } 74 75 public static File getClassFile(String className) { 76 for (Iterator i = _classPath.iterator(); i.hasNext();) { 77 String dir = (String ) i.next(); 78 String fileName = FileUtil.pretty(dir + "/" + className.replace('.', '/') + ".class"); 79 File classFile = new File (fileName); 80 if (classFile.exists()) { 81 return classFile; 82 } 83 } 84 return null; 85 } 86 87 public static String getName(String packagePrefix, String nameSuffix) { 88 if (packagePrefix == null || packagePrefix.length() == 0) { 89 return nameSuffix; 90 } else { 91 return packagePrefix + "." + nameSuffix; 92 } 93 } 94 95 public static String getNamePrefix(String className) { 96 return StringUtil.beforeLast(".", className); 97 } 98 99 public static String getNameSuffix(String className) { 100 return StringUtil.afterLast(".", className); 101 } 102 103 public static String getPackagePrefix(String className) { 104 return getNamePrefix(className); 105 } 106 107 110 public static String getSignature(Class clazz) { 111 String type = null; 112 if (clazz.isArray()) { 113 Class cl = clazz; 114 int dimensions = 0; 115 while (cl.isArray()) { 116 dimensions++; 117 cl = cl.getComponentType(); 118 } 119 StringBuffer sb = new StringBuffer (); 120 for (int i = 0; i < dimensions; i++) { 121 sb.append("["); 122 } 123 sb.append(getSignature(cl)); 124 type = sb.toString(); 125 } else if (clazz.isPrimitive()) { 126 if (clazz == Integer.TYPE) { 127 type = "I"; 128 } else if (clazz == Byte.TYPE) { 129 type = "B"; 130 } else if (clazz == Long.TYPE) { 131 type = "J"; 132 } else if (clazz == Float.TYPE) { 133 type = "F"; 134 } else if (clazz == Double.TYPE) { 135 type = "D"; 136 } else if (clazz == Short.TYPE) { 137 type = "S"; 138 } else if (clazz == Character.TYPE) { 139 type = "C"; 140 } else if (clazz == Boolean.TYPE) { 141 type = "Z"; 142 } else if (clazz == Void.TYPE) { 143 type = "V"; 144 } 145 146 } else { 147 type = "L" + clazz.getName().replace('.', '/') + ";"; 148 } 149 return type; 150 } 151 152 public static String getSourceDir() { 153 return _sourceDir; 154 } 155 156 public static File getSourceFile(Class theClass) { 157 return getSourceFile(theClass.getName()); 158 } 159 160 public static File getSourceFile(String className) { 161 for (Iterator i = _sourcePath.iterator(); ;) { 162 String dir; 163 if (i.hasNext()) { 164 dir = (String ) i.next(); 165 } else { 166 dir = _sourceDir; 167 } 168 String fileName = FileUtil.pretty(dir + "/" + className.replace('.', '/') + ".java"); 169 File sourceFile = new File (fileName); 170 if (sourceFile.exists()) { 171 return sourceFile; 172 } 173 if (dir == _sourceDir) { 174 break; 175 } 176 } 177 return null; 178 } 179 180 public static List getSourcePath() { 181 return _sourcePath; 182 } 183 } 184 | Popular Tags |