1 19 package gcc.rmi.iiop; 20 21 import gcc.*; 22 import gcc.util.*; 23 import java.util.HashMap; 24 import java.lang.reflect.*; 25 26 public class IDLEntityHelper implements ObjectHelper 27 { 28 private static Class[] EMPTY_CLASS_ARRAY = {}; 29 30 private static Object[] EMPTY_OBJECT_ARRAY = {}; 31 32 private static HashMap _helperMap = new HashMap(); 33 34 private Method _id; 35 36 private Method _type; 37 38 private Method _read; 39 40 private Method _write; 41 42 static IDLEntityHelper getInstance(Class theClass) 43 { 44 IDLEntityHelper helper = (IDLEntityHelper)_helperMap.get(theClass); 45 if (helper == null) 46 { 47 synchronized (_helperMap) 48 { 49 helper = (IDLEntityHelper)_helperMap.get(theClass); 50 if (helper == null) 51 { 52 helper = new IDLEntityHelper(theClass); 53 _helperMap.put(theClass, helper); 54 } 55 } 56 } 57 return helper; 58 } 59 60 private IDLEntityHelper(Class theClass) 61 { 62 try 63 { 64 Class helper = ThreadContext.loadClass(theClass.getName() + "Helper", theClass); 65 _id = helper.getDeclaredMethod("id", EMPTY_CLASS_ARRAY); 66 _type = helper.getDeclaredMethod("type", EMPTY_CLASS_ARRAY); 67 _read = helper.getDeclaredMethod("read", new Class[] { org.omg.CORBA.portable.InputStream.class }); 68 _write = helper.getDeclaredMethod("write", new Class[] { org.omg.CORBA.portable.OutputStream.class, theClass }); 69 } 70 catch (SystemException ex) 71 { 72 throw ex; 73 } 74 catch (Exception ex) 75 { 76 throw new SystemException(ex); 77 } 78 } 79 80 public String id() 81 { 82 try 83 { 84 return (String)_id.invoke(null, EMPTY_OBJECT_ARRAY); 85 } 86 catch (SystemException ex) 87 { 88 throw ex; 89 } 90 catch (Exception ex) 91 { 92 throw new SystemException(ex); 93 } 94 } 95 96 public org.omg.CORBA.TypeCode type() 97 { 98 try 99 { 100 return (org.omg.CORBA.TypeCode)_type.invoke(null, EMPTY_OBJECT_ARRAY); 101 } 102 catch (SystemException ex) 103 { 104 throw ex; 105 } 106 catch (Exception ex) 107 { 108 throw new SystemException(ex); 109 } 110 } 111 112 public Object read(ObjectInputStream input) 113 { 114 try 115 { 116 return _read.invoke(null, new Object[] { input._cdrInput }); 117 } 118 catch (SystemException ex) 119 { 120 throw ex; 121 } 122 catch (Exception ex) 123 { 124 throw new SystemException(ex); 125 } 126 } 127 128 public void write(ObjectOutputStream output, Object value) 129 { 130 try 131 { 132 _write.invoke(null, new Object[] { output._cdrOutput, value }); 133 } 134 catch (SystemException ex) 135 { 136 throw ex; 137 } 138 catch (Exception ex) 139 { 140 throw new SystemException(ex); 141 } 142 } 143 } 144 | Popular Tags |