1 21 22 package org.opensubsystems.core.logic; 23 24 import java.rmi.RemoteException ; 25 import java.util.HashMap ; 26 import java.util.Map ; 27 import java.util.logging.Logger ; 28 29 import org.opensubsystems.core.error.OSSException; 30 import org.opensubsystems.core.error.OSSInternalErrorException; 31 import org.opensubsystems.core.util.ClassFactory; 32 import org.opensubsystems.core.util.GlobalConstants; 33 import org.opensubsystems.core.util.J2EEUtils; 34 import org.opensubsystems.core.util.Log; 35 36 48 public class ControllerManager 49 { 50 52 55 private static final String IMPL_LOCK = "IMPL_LOCK"; 56 57 59 62 protected ClassFactory m_controllerClassFactory; 63 64 68 private Map m_mpControllerCache; 69 70 72 75 private static Logger s_logger = Log.getInstance(ControllerManager.class); 76 77 80 private static ControllerManager s_defaultInstance; 81 82 84 87 public ControllerManager( 88 ) 89 { 90 m_controllerClassFactory = new ControllerClassFactory(); 91 m_mpControllerCache = new HashMap (); 92 } 93 94 96 106 public static Object getInstance( 107 Class controller 108 ) throws OSSException 109 { 110 return getManagerInstance().getControllerInstance(controller); 111 } 112 113 121 public static ControllerManager getManagerInstance( 122 ) throws OSSException 123 { 124 if (s_defaultInstance == null) 125 { 126 synchronized (IMPL_LOCK) 129 { 130 Class defaultControllerManager = ControllerManager.class; 131 132 if (J2EEUtils.getJ2EEServerType() != J2EEUtils.J2EE_SERVER_NO) 136 { 137 defaultControllerManager = J2EEControllerManager.class; 138 } 139 140 setManagerInstance((ControllerManager) 141 ClassFactory.getInstance().createInstance( 142 defaultControllerManager, defaultControllerManager)); 143 } 144 } 145 146 return s_defaultInstance; 147 } 148 149 156 public static void setManagerInstance( 157 ControllerManager defaultInstance 158 ) 159 { 160 if (GlobalConstants.ERROR_CHECKING) 161 { 162 assert defaultInstance != null : "Default instance cannot be null"; 163 } 164 165 synchronized (IMPL_LOCK) 166 { 167 s_defaultInstance = defaultInstance; 168 s_logger.fine("Default controller manager is " 169 + s_defaultInstance.getClass().getName()); 170 } 171 } 172 173 185 public Object getControllerInstance( 186 Class controller 187 ) throws OSSException 188 { 189 Object control; 190 191 control = m_mpControllerCache.get(controller.getName()); 192 if (control == null) 193 { 194 synchronized (m_mpControllerCache) 195 { 196 control = m_controllerClassFactory.createInstance(controller); 197 m_mpControllerCache.put(controller.getName(), control); 201 try 203 { 204 ((StatelessController)control).constructor(); 205 } 206 catch (RemoteException rExc) 207 { 208 throw new OSSInternalErrorException("Remote error occured", rExc); 212 } 213 } 214 } 215 216 return control; 217 } 218 } 219 | Popular Tags |