1 18 package org.apache.geronimo.interop.rmi.iiop.compiler; 19 20 import java.util.HashMap ; 21 22 import org.apache.geronimo.interop.SystemException; 23 import org.apache.geronimo.interop.rmi.iiop.ObjectRef; 24 import org.apache.geronimo.interop.util.JavaClass; 25 import org.apache.geronimo.interop.util.ThreadContext; 26 27 public class StubFactory { 28 protected static StubFactory sf; 29 30 protected StubFactory() { 31 } 32 33 public static StubFactory getInstance() { 34 if (sf == null) { 35 synchronized (StubFactory.class) { 36 if (sf == null) { 37 sf = new StubFactory(); 38 sf.init(); 39 } 40 } 41 } 42 43 return sf; 44 } 45 46 private static HashMap stubClassMap; 47 48 protected void init() { 49 stubClassMap = new HashMap (); 50 } 51 52 protected Class loadStub(Class remoteInterface) { 53 System.out.println("StubFactory.loadStub(): remoteInterface: " + remoteInterface); 54 String className = remoteInterface.getName(); 55 String stubClassName = JavaClass.addPackageSuffix(className, "iiop_stubs"); 56 System.out.println("StubFactory.loadStub(): stubClassName: " + stubClassName); 57 58 Class sc = null; 59 try { 63 sc = Class.forName(stubClassName + "_Stub"); 64 } catch (ClassNotFoundException e) { 65 e.printStackTrace(); 66 } 67 68 69 if (sc == null) { 70 74 System.out.println("StubFactory.loadStub(): sc: " + sc); 78 } 79 80 93 94 return sc; 95 } 96 97 public ObjectRef getStub(Class remoteInterface) { 98 System.out.println("StubFactory.getStub(): remoteInterface: " + remoteInterface); 99 try { 100 Class sc = (Class ) stubClassMap.get(remoteInterface); 101 System.out.println("StubFactory.getStub(): sc: " + sc); 102 if (sc == null) { 103 synchronized (stubClassMap) { 104 sc = (Class ) stubClassMap.get(remoteInterface); 105 if (sc == null) { 106 sc = loadStub(remoteInterface); 107 System.out.println("StubFactory.getStub(): sc: " + sc); 108 stubClassMap.put(remoteInterface, sc); 109 } 110 } 111 } 112 113 if (sc == null) { 114 throw new SystemException("Error: Unable to load stub for remote interface: " + remoteInterface); 115 } 116 117 java.lang.Object sobj = sc.newInstance(); 118 119 if (!(sobj instanceof ObjectRef)) { 120 throw new SystemException("Error: Stub for remote interface: '" + remoteInterface + "' is not a valid ObjectRef."); 121 } 122 123 return (ObjectRef) sobj; 124 } catch (Exception ex) { 126 throw new SystemException(ex); 127 } 128 } 129 130 public Object getStub(String remoteInterface) { 131 return getStub(ThreadContext.loadClass(remoteInterface)); 132 } 133 } 134 | Popular Tags |