1 45 package org.openejb.alt.assembler.classic; 46 47 import java.util.ArrayList ; 48 import java.util.Arrays ; 49 import java.util.HashMap ; 50 import java.util.Iterator ; 51 import java.util.Properties ; 52 53 import javax.resource.spi.ConnectionManager ; 54 import javax.resource.spi.ManagedConnectionFactory ; 55 import javax.transaction.TransactionManager ; 56 57 import org.openejb.EnvProps; 58 import org.openejb.OpenEJBException; 59 import org.openejb.core.ConnectorReference; 60 import org.openejb.core.DeploymentInfo; 61 import org.openejb.spi.SecurityService; 62 import org.openejb.util.OpenEJBErrorHandler; 63 import org.openejb.util.SafeToolkit; 64 91 public class Assembler extends AssemblerTool implements org.openejb.spi.Assembler{ 92 private org.openejb.core.ContainerSystem containerSystem; 93 private TransactionManager transactionManager; 94 private org.openejb.spi.SecurityService securityService; 95 private HashMap remoteJndiContexts = null; 96 97 public org.openejb.spi.ContainerSystem getContainerSystem(){ 98 return containerSystem; 99 } 100 public TransactionManager getTransactionManager(){ 101 return transactionManager; 102 } 103 public SecurityService getSecurityService(){ 104 return securityService; 105 } 106 107 protected SafeToolkit toolkit = SafeToolkit.getToolkit("Assembler"); 108 protected OpenEjbConfiguration config; 109 110 111 114 private String INVALID_CONNECTION_MANAGER_ERROR = "Invalid connection manager specified for connector identity = "; 115 116 119 120 public Assembler(){ 121 } 122 123 public void init(Properties props) throws OpenEJBException{ 124 this.props = props; 125 126 127 String className = props.getProperty(EnvProps.CONFIGURATION_FACTORY); 128 if ( className == null ) className = props.getProperty("openejb.configurator","org.openejb.alt.config.ConfigurationFactory"); 129 130 OpenEjbConfigurationFactory configFactory = (OpenEjbConfigurationFactory)toolkit.newInstance(className); 131 configFactory.init(props); 132 config = configFactory.getOpenEjbConfiguration(); 133 134 135 136 137 Properties systemProperties = System.getProperties(); 138 synchronized(systemProperties){ 139 String str = systemProperties.getProperty(javax.naming.Context.URL_PKG_PREFIXES); 140 String naming = "org.openejb.core.ivm.naming"; 141 if (str == null) { 142 str = naming; 143 } else if (str.indexOf(naming) == -1) { 144 str = naming + ":" + str; 145 } 146 systemProperties.setProperty(javax.naming.Context.URL_PKG_PREFIXES, str); 147 } 148 149 } 150 151 public void build() throws OpenEJBException{ 152 try{ 153 containerSystem = buildContainerSystem(config); 154 }catch(OpenEJBException ae){ 155 158 throw ae; 159 }catch(Exception e){ 160 165 OpenEJBErrorHandler.handleUnknownError(e, "Assembler"); 166 throw new OpenEJBException(e); 167 } 168 } 169 170 176 204 public org.openejb.core.ContainerSystem buildContainerSystem(OpenEjbConfiguration configInfo)throws Exception { 205 206 214 215 this.applyProxyFactory(configInfo.facilities.intraVmServer); 216 217 218 219 ContainerSystemInfo containerSystemInfo = configInfo.containerSystem; 220 221 222 223 org.openejb.core.ContainerSystem containerSystem = new org.openejb.core.ContainerSystem(); 224 225 226 227 assembleContainers(containerSystem,containerSystemInfo); 228 229 230 231 232 securityService = assembleSecurityService(configInfo.facilities.securityService); 233 containerSystem.getJNDIContext().bind("java:openejb/SecurityService",securityService); 234 235 236 237 238 239 AssemblerTool.RoleMapping roleMapping = new AssemblerTool.RoleMapping(configInfo.facilities.securityService.roleMappings); 241 org.openejb.DeploymentInfo [] deployments = containerSystem.deployments(); 242 for(int i = 0; i < deployments.length; i++){ 243 applyMethodPermissions((org.openejb.core.DeploymentInfo)deployments[i], containerSystemInfo.methodPermissions, roleMapping); 244 applyTransactionAttributes((org.openejb.core.DeploymentInfo)deployments[i],containerSystemInfo.methodTransactions); 245 } 246 247 ArrayList list = new ArrayList (); 248 if(containerSystemInfo.entityContainers!=null)list.addAll(Arrays.asList(containerSystemInfo.entityContainers)); 249 if(containerSystemInfo.statefulContainers!=null)list.addAll(Arrays.asList(containerSystemInfo.statefulContainers)); 250 if(containerSystemInfo.statelessContainers!=null)list.addAll(Arrays.asList(containerSystemInfo.statelessContainers)); 251 Iterator iterator = list.iterator(); 252 while(iterator.hasNext()){ 253 ContainerInfo container = (ContainerInfo)iterator.next(); 254 for(int z = 0; z < container.ejbeans.length; z++){ 255 DeploymentInfo deployment= (org.openejb.core.DeploymentInfo)containerSystem.getDeploymentInfo(container.ejbeans[z].ejbDeploymentId); 256 applySecurityRoleReference(deployment, container.ejbeans[z], roleMapping); 257 } 258 } 259 260 if(configInfo.facilities.remoteJndiContexts!=null){ 261 for(int i = 0; i < configInfo.facilities.remoteJndiContexts.length; i++){ 262 javax.naming.InitialContext cntx = assembleRemoteJndiContext(configInfo.facilities.remoteJndiContexts[i]); 263 containerSystem.getJNDIContext().bind("java:openejb/remote_jndi_contexts/"+configInfo.facilities.remoteJndiContexts[i].jndiContextId, cntx); 264 } 265 266 } 267 268 269 270 transactionManager = assembleTransactionManager(configInfo.facilities.transactionService); 271 containerSystem.getJNDIContext().bind("java:openejb/TransactionManager",transactionManager); 272 273 274 275 276 HashMap connectionManagerMap = new HashMap (); 277 if (configInfo.facilities.connectionManagers != null) { 279 for(int i = 0; i < configInfo.facilities.connectionManagers.length;i++){ 280 ConnectionManagerInfo cmInfo = configInfo.facilities.connectionManagers[i]; 281 ConnectionManager connectionManager = assembleConnectionManager(cmInfo); 282 connectionManagerMap.put(cmInfo.connectionManagerId,connectionManager); 283 } 284 } 285 if (configInfo.facilities.connectors != null) { 287 for(int i = 0; i < configInfo.facilities.connectors.length; i++){ 288 ConnectorInfo conInfo = configInfo.facilities.connectors[i]; 289 290 ConnectionManager connectionManager = (ConnectionManager )connectionManagerMap.get(conInfo.connectionManagerId); 291 if(connectionManager == null) 292 throw new RuntimeException (INVALID_CONNECTION_MANAGER_ERROR + conInfo.connectorId); 293 294 ManagedConnectionFactory managedConnectionFactory = assembleManagedConnectionFactory(conInfo.managedConnectionFactory); 295 296 ConnectorReference reference = new ConnectorReference(connectionManager, managedConnectionFactory); 297 298 containerSystem.getJNDIContext().bind("java:openejb/connector/"+conInfo.connectorId, reference); 299 } 300 } 301 302 return containerSystem; 303 } 304 } 305 | Popular Tags |