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