1 19 package gcc.rmi.iiop.compiler; 20 21 import gcc.*; 22 import gcc.rmi.iiop.*; 23 import gcc.rmi.iiop.compiler.StubClass; 24 import gcc.rmi.iiop.compiler.StubCompiler; 25 import gcc.util.*; 26 import java.util.*; 27 28 public class StubFactory 29 { 30 protected static StubFactory _sf; 31 32 protected StubFactory() 33 { 34 } 35 36 public static StubFactory getInstance() 37 { 38 if (_sf == null) 39 { 40 synchronized( StubFactory.class ) 41 { 42 if (_sf == null) 43 { 44 _sf = new StubFactory(); 45 _sf.init(); 46 } 47 } 48 } 49 50 return _sf; 51 } 52 53 55 private static HashMap _stubClassMap; 56 57 59 protected void init() 60 { 61 _stubClassMap = new HashMap(); 62 } 63 64 protected Class loadStub(Class remoteInterface) 65 { 66 System.out.println( "StubFactory.loadStub(): remoteInterface: " + remoteInterface ); 67 String className = remoteInterface.getName(); 68 String stubClassName = JavaClass.addPackageSuffix(className, "iiop_stubs"); 69 System.out.println( "StubFactory.loadStub(): stubClassName: " + stubClassName ); 70 71 Class sc = null; 72 try 76 { 77 sc = Class.forName( stubClassName + "_Stub" ); 78 } 79 catch (ClassNotFoundException e) 80 { 81 e.printStackTrace(); 82 } 83 84 85 if (sc == null) 86 { 87 91 StubCompiler stubCompiler = new StubCompiler( remoteInterface ); 92 System.out.println( "StubFactory.loadStub(): stubCompiler: " + stubCompiler ); 93 sc = stubCompiler.getStubClass(); 94 System.out.println( "StubFactory.loadStub(): sc: " + sc ); 95 } 96 97 110 111 return sc; 112 } 113 114 116 public ObjectRef getStub(Class remoteInterface) 117 { 118 System.out.println( "StubFactory.getStub(): remoteInterface: " + remoteInterface ); 119 try 120 { 121 Class sc = (Class)_stubClassMap.get(remoteInterface); 122 System.out.println( "StubFactory.getStub(): sc: " + sc ); 123 if (sc == null) 124 { 125 synchronized (_stubClassMap) 126 { 127 sc = (Class)_stubClassMap.get(remoteInterface); 128 if (sc == null) 129 { 130 sc = loadStub(remoteInterface); 131 System.out.println( "StubFactory.getStub(): sc: " + sc ); 132 _stubClassMap.put(remoteInterface, sc); 133 } 134 } 135 } 136 137 if (sc == null) 138 { 139 throw new SystemException( "Error: Unable to load stub for remote interface: " + remoteInterface ); 140 } 141 142 java.lang.Object sobj = sc.newInstance(); 143 144 if (! (sobj instanceof ObjectRef) ) 145 { 146 throw new SystemException( "Error: Stub for remote interface: '" + remoteInterface + "' is not a valid ObjectRef." ); 147 } 148 149 return (ObjectRef)sobj; 150 } 152 catch (Exception ex) 153 { 154 throw new SystemException(ex); 155 } 156 } 157 158 public Object getStub(String remoteInterface) 159 { 160 return getStub(ThreadContext.loadClass(remoteInterface)); 161 } 162 } 163 | Popular Tags |