1 18 package org.apache.geronimo.interop.util; 19 20 import java.util.HashMap ; 21 22 23 public abstract class JavaType { 24 private static HashMap _wrapper = new HashMap (); 25 26 static { 27 _wrapper.put("boolean", "java.lang.Boolean"); 28 _wrapper.put("byte", "java.lang.Byte"); 29 _wrapper.put("char", "java.lang.Character"); 30 _wrapper.put("double", "java.lang.Double"); 31 _wrapper.put("float", "java.lang.Float"); 32 _wrapper.put("int", "java.lang.Integer"); 33 _wrapper.put("long", "java.lang.Long"); 34 _wrapper.put("short", "java.lang.Short"); 35 } 36 37 41 public static String getName(Class t) { 42 if (t.isArray()) { 43 return getName(t.getComponentType()) + "[]"; 44 } else { 45 return t.getName().replace('$', '.'); 46 } 47 } 48 49 public static String wrapper(String type) { 50 return (String ) _wrapper.get(type); 51 } 52 53 public static String wrapper(Class type) { 54 return wrapper(getName(type)); 55 } 56 57 public static String wrap(String type, String name) { 58 String w = wrapper(type); 59 return w != null ? ("new " + w + "(" + name + ")") : name; 60 } 61 62 public static String wrap(Class type, String name) { 63 return wrap(getName(type), name); 64 } 65 66 public static String unwrap(String type, String name) { 67 String w = wrapper(type); 68 return w != null ? ("((" + w + ")" + name + ")." + type + "Value()") : name; 69 } 70 71 public static String unwrap(Class type, String name) { 72 return unwrap(getName(type), name); 73 } 74 75 public static String unwrapObject(Class type, Object expression) { 76 return unwrapObject(getName(type), expression); 77 } 78 79 public static String unwrapObject(String type, Object expression) { 80 String w = wrapper(type); 81 if (w == null) { 82 if (type.equals("java.lang.Object")) { 83 return expression.toString(); 84 } else { 85 return "(" + type + ")" + expression; 86 } 87 } else { 88 return "((" + w + ")" + expression + ")." + type + "Value()"; 89 } 90 } 91 } 92 | Popular Tags |