Factor out appInfo.containerIds as we now have appInfo.containers
[tomee.git] / container / openejb-core / src / main / java / org / apache / openejb / config / AppInfoBuilder.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.openejb.config;
19
20 import org.apache.openejb.ClassLoaderUtil;
21 import org.apache.openejb.OpenEJBException;
22 import org.apache.openejb.OpenEJBRuntimeException;
23 import org.apache.openejb.assembler.classic.AppInfo;
24 import org.apache.openejb.assembler.classic.ClassListInfo;
25 import org.apache.openejb.assembler.classic.ClientInfo;
26 import org.apache.openejb.assembler.classic.ConnectorInfo;
27 import org.apache.openejb.assembler.classic.ContainerInfo;
28 import org.apache.openejb.assembler.classic.EjbJarInfo;
29 import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
30 import org.apache.openejb.assembler.classic.EntityManagerFactoryCallable;
31 import org.apache.openejb.assembler.classic.FilterInfo;
32 import org.apache.openejb.assembler.classic.HandlerChainInfo;
33 import org.apache.openejb.assembler.classic.IdPropertiesInfo;
34 import org.apache.openejb.assembler.classic.JndiEncInfo;
35 import org.apache.openejb.assembler.classic.ListenerInfo;
36 import org.apache.openejb.assembler.classic.MdbContainerInfo;
37 import org.apache.openejb.assembler.classic.MessageDrivenBeanInfo;
38 import org.apache.openejb.assembler.classic.ParamValueInfo;
39 import org.apache.openejb.assembler.classic.PersistenceUnitInfo;
40 import org.apache.openejb.assembler.classic.PortInfo;
41 import org.apache.openejb.assembler.classic.ResourceInfo;
42 import org.apache.openejb.assembler.classic.ServiceInfo;
43 import org.apache.openejb.assembler.classic.ServletInfo;
44 import org.apache.openejb.assembler.classic.ValidatorBuilder;
45 import org.apache.openejb.assembler.classic.WebAppInfo;
46 import org.apache.openejb.config.event.BeforeAppInfoBuilderEvent;
47 import org.apache.openejb.config.sys.Container;
48 import org.apache.openejb.config.sys.Resource;
49 import org.apache.openejb.config.sys.Service;
50 import org.apache.openejb.config.sys.ServiceProvider;
51 import org.apache.openejb.jee.AdminObject;
52 import org.apache.openejb.jee.ApplicationClient;
53 import org.apache.openejb.jee.ConfigProperty;
54 import org.apache.openejb.jee.ConnectionDefinition;
55 import org.apache.openejb.jee.Connector;
56 import org.apache.openejb.jee.EnterpriseBean;
57 import org.apache.openejb.jee.Filter;
58 import org.apache.openejb.jee.InboundResourceadapter;
59 import org.apache.openejb.jee.Listener;
60 import org.apache.openejb.jee.MessageListener;
61 import org.apache.openejb.jee.OutboundResourceAdapter;
62 import org.apache.openejb.jee.ParamValue;
63 import org.apache.openejb.jee.PortComponent;
64 import org.apache.openejb.jee.ResourceAdapter;
65 import org.apache.openejb.jee.ServiceImplBean;
66 import org.apache.openejb.jee.Servlet;
67 import org.apache.openejb.jee.SessionConfig;
68 import org.apache.openejb.jee.TransactionSupportType;
69 import org.apache.openejb.jee.WebApp;
70 import org.apache.openejb.jee.WebserviceDescription;
71 import org.apache.openejb.jee.Webservices;
72 import org.apache.openejb.jee.jpa.EntityMappings;
73 import org.apache.openejb.jee.jpa.JpaJaxbUtil;
74 import org.apache.openejb.jee.jpa.unit.Persistence;
75 import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
76 import org.apache.openejb.jee.oejb3.EjbDeployment;
77 import org.apache.openejb.jee.oejb3.OpenejbJar;
78 import org.apache.openejb.jee.oejb3.PojoDeployment;
79 import org.apache.openejb.jpa.integration.MakeTxLookup;
80 import org.apache.openejb.loader.SystemInstance;
81 import org.apache.openejb.persistence.PersistenceBootstrap;
82 import org.apache.openejb.util.CircularReferencesException;
83 import org.apache.openejb.util.JavaSecurityManagers;
84 import org.apache.openejb.util.LogCategory;
85 import org.apache.openejb.util.Logger;
86 import org.apache.openejb.util.Messages;
87 import org.apache.openejb.util.References;
88
89 import java.io.File;
90 import java.io.IOException;
91 import java.net.URL;
92 import java.util.ArrayList;
93 import java.util.Collection;
94 import java.util.HashMap;
95 import java.util.HashSet;
96 import java.util.LinkedHashSet;
97 import java.util.List;
98 import java.util.Map;
99 import java.util.Properties;
100 import java.util.Set;
101 import javax.xml.bind.JAXBException;
102
103 import static java.util.Arrays.asList;
104 import static java.util.Collections.singletonList;
105 import static org.apache.openejb.util.URLs.toFile;
106
107 /**
108 * @version $Rev$ $Date$
109 */
110 class AppInfoBuilder {
111
112 private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, "org.apache.openejb.util.resources");
113
114 private static final boolean USE_EAR_AS_CONTEXT_ROOT_BASE = SystemInstance.get().getOptions().get("openejb.ear.use-as-webcontext-base", false);
115
116 private final ConfigurationFactory configFactory;
117
118 private final EjbJarInfoBuilder ejbJarInfoBuilder = new EjbJarInfoBuilder();
119
120 public AppInfoBuilder(final ConfigurationFactory configFactory) {
121 this.configFactory = configFactory;
122 }
123
124 public AppInfo build(final AppModule appModule) throws OpenEJBException {
125 // send an event so that it becomes pretty easy at this step to dynamically change the module description
126 // before going into the info tree. Pretty easy to hack on portability issues.
127 SystemInstance.get().fireEvent(new BeforeAppInfoBuilderEvent(appModule));
128
129 final AppInfo appInfo = new AppInfo();
130 appInfo.appId = appModule.getModuleId();
131 appInfo.path = appModule.getJarLocation();
132 appInfo.standaloneModule = appModule.isStandaloneModule() || appModule.isWebapp();
133 appInfo.delegateFirst = appModule.isDelegateFirst();
134 appInfo.watchedResources.addAll(appModule.getWatchedResources());
135 appInfo.mbeans.addAll(appModule.getAdditionalLibMbeans());
136 appInfo.jaxRsProviders.addAll(appModule.getJaxRsProviders());
137 appInfo.properties.putAll(appModule.getProperties());
138
139 if (appInfo.appId == null) {
140 throw new IllegalArgumentException("AppInfo.appId cannot be null");
141 }
142 if (appInfo.path == null) {
143 appInfo.path = appInfo.appId;
144 }
145
146 this.buildPojoConfiguration(appModule, appInfo);
147
148 this.buildAppResources(appModule, appInfo);
149 this.buildAppContainers(appModule, appInfo);
150 this.buildAppServices(appModule, appInfo);
151
152 //
153 // J2EE Connectors
154 //
155 this.buildConnectorModules(appModule, appInfo);
156
157 //
158 // Persistence Units
159 //
160 this.buildPersistenceModules(appModule, appInfo);
161
162
163 final List<String> containerIds = this.configFactory.getContainerIds();
164 for (final ConnectorInfo connectorInfo : appInfo.connectors) {
165 for (final MdbContainerInfo containerInfo : connectorInfo.inbound) {
166 containerIds.add(containerInfo.id);
167 }
168 }
169
170 for (final ContainerInfo containerInfo : appInfo.containers) {
171 containerIds.add(containerInfo.id);
172 }
173
174 //
175 // EJB Jars
176 //
177 final Map<EjbModule, EjbJarInfo> ejbJarInfos = new HashMap<EjbModule, EjbJarInfo>();
178 for (final EjbModule ejbModule : appModule.getEjbModules()) {
179 try {
180 final EjbJarInfo ejbJarInfo = this.ejbJarInfoBuilder.buildInfo(ejbModule);
181 ejbJarInfo.mbeans = ejbModule.getMbeans();
182
183 final Map<String, EjbDeployment> deploymentsByEjbName = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
184
185 for (final EnterpriseBeanInfo bean : ejbJarInfo.enterpriseBeans) {
186 final EjbDeployment d = deploymentsByEjbName.get(bean.ejbName);
187 if (d.getContainerId() != null && !containerIds.contains(d.getContainerId())) {
188 for (final ContainerInfo containerInfo : appInfo.containers) {
189 if (containerInfo.id.endsWith("/" + d.getContainerId())) {
190 d.setContainerId(containerInfo.id);
191 break;
192 }
193 }
194 }
195
196 /*
197 * JRG - there's probably a better way of handling this, but this code handles the case when:
198 *
199 * A connector with two or more inbound adapter is registered, causing two containers named with the format:
200 * <moduleId>-<message listener interface>
201 *
202 * This code adjusts the container id for the associated MDBs by sticking the message listener interface on the end.
203 *
204 */
205 if (bean instanceof MessageDrivenBeanInfo && !containerIds.contains(d.getContainerId()) && !skipMdb(bean)) {
206 final MessageDrivenBeanInfo mdb = (MessageDrivenBeanInfo) bean;
207 final String newContainerId = d.getContainerId() + "-" + mdb.mdbInterface;
208 if (containerIds.contains(newContainerId)) {
209 d.setContainerId(newContainerId);
210 }
211 }
212
213 if (!containerIds.contains(d.getContainerId()) && !skipMdb(bean)) {
214 final String msg = new Messages("org.apache.openejb.util.resources").format("config.noContainerFound", d.getContainerId(), d.getEjbName());
215 logger.fatal(msg);
216 throw new OpenEJBException(msg);
217 }
218
219 bean.containerId = d.getContainerId();
220 }
221
222
223 for (final PojoDeployment pojoDeployment : ejbModule.getOpenejbJar().getPojoDeployment()) {
224 final IdPropertiesInfo info = new IdPropertiesInfo();
225 info.id = pojoDeployment.getClassName();
226 info.properties.putAll(pojoDeployment.getProperties());
227 ejbJarInfo.pojoConfigurations.add(info);
228 }
229
230 ejbJarInfo.validationInfo = ValidatorBuilder.getInfo(ejbModule.getValidationConfig());
231 ejbJarInfo.portInfos.addAll(this.configureWebservices(ejbModule.getWebservices()));
232 ejbJarInfo.uniqueId = ejbModule.getUniqueId();
233 ejbJarInfo.webapp = ejbModule.isWebapp();
234 this.configureWebserviceSecurity(ejbJarInfo, ejbModule);
235
236 ejbJarInfos.put(ejbModule, ejbJarInfo);
237
238 appInfo.ejbJars.add(ejbJarInfo);
239
240
241 } catch (final OpenEJBException e) {
242 ConfigUtils.logger.warning("conf.0004", ejbModule.getJarLocation(), e.getMessage());
243 throw e;
244 }
245 }
246 // Create the JNDI info builder
247 final JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(appInfo);
248 if (appModule.getApplication() != null) {
249 //TODO figure out how to prevent adding stuff to the module and comp contexts from the application
250 //or maybe validate the xml so this won't happen.
251 jndiEncInfoBuilder.build(appModule.getApplication(), appInfo.appId, null, appModule.getModuleUri(), new JndiEncInfo(), new JndiEncInfo());
252 }
253
254 final List<EnterpriseBeanInfo> beans = new ArrayList<EnterpriseBeanInfo>();
255 // Build the JNDI tree for each ejb
256 for (final EjbModule ejbModule : appModule.getEjbModules()) {
257
258 final EjbJarInfo ejbJar = ejbJarInfos.get(ejbModule);
259
260 final Map<String, EnterpriseBean> beanData = ejbModule.getEjbJar().getEnterpriseBeansByEjbName();
261
262 for (final EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
263 beans.add(beanInfo);
264
265 // Get the ejb-jar.xml object
266 final EnterpriseBean enterpriseBean = beanData.get(beanInfo.ejbName);
267
268 // Build the JNDI info tree for the EJB
269 jndiEncInfoBuilder.build(enterpriseBean, beanInfo.ejbName, ejbJar.moduleName, ejbModule.getModuleUri(), ejbJar.moduleJndiEnc, beanInfo.jndiEnc);
270
271
272 jndiEncInfoBuilder.buildDependsOnRefs(enterpriseBean, beanInfo, ejbJar.moduleName);
273 }
274 }
275
276 // Check for circular references in Singleton @DependsOn
277 try {
278 References.sort(beans, new References.Visitor<EnterpriseBeanInfo>() {
279 @Override
280 public String getName(final EnterpriseBeanInfo bean) {
281 return bean.ejbDeploymentId;
282 }
283
284 @Override
285 public Set<String> getReferences(final EnterpriseBeanInfo bean) {
286 return new LinkedHashSet<String>(bean.dependsOn);
287 }
288 });
289 } catch (final CircularReferencesException e) {
290 // List<List> circuits = e.getCircuits();
291 // TODO Seems we lost circular reference detection, or we do it elsewhere and don't need it here
292 }
293
294 //
295 // Application Clients
296 //
297 this.buildClientModules(appModule, appInfo, jndiEncInfoBuilder);
298
299 //
300 // Webapps
301 //
302 this.buildWebModules(appModule, jndiEncInfoBuilder, appInfo);
303
304
305 //
306 // Final AppInfo creation
307 //
308 final List<URL> additionalLibraries = appModule.getAdditionalLibraries();
309 for (final URL url : additionalLibraries) {
310 final File file = toFile(url);
311 try {
312 appInfo.libs.add(file.getCanonicalPath());
313 } catch (final IOException e) {
314 throw new OpenEJBException("Invalid application lib path " + file.getAbsolutePath());
315 }
316 }
317
318 if (appModule.getCmpMappings() != null) {
319 try {
320 appInfo.cmpMappingsXml = JpaJaxbUtil.marshal(EntityMappings.class, appModule.getCmpMappings());
321 } catch (final JAXBException e) {
322 throw new OpenEJBException("Unable to marshal cmp entity mappings", e);
323 }
324 }
325
326 final ReportValidationResults reportValidationResults = new ReportValidationResults();
327 reportValidationResults.deploy(appModule);
328
329 logger.info("config.appLoaded", appInfo.path);
330
331 appInfo.webAppAlone = appModule.isWebapp();
332
333 return appInfo;
334
335 }
336
337 private void buildPojoConfiguration(final AppModule appModule, final AppInfo appInfo) {
338 for (final Map.Entry<String, PojoConfiguration> config : appModule.getPojoConfigurations().entrySet()) {
339 final IdPropertiesInfo info = new IdPropertiesInfo();
340 info.id = config.getKey();
341 info.properties.putAll(config.getValue().getProperties());
342 appInfo.pojoConfigurations.add(info);
343 }
344 }
345
346 private void buildAppServices(final AppModule appModule, final AppInfo appInfo) throws OpenEJBException {
347 final Collection<Service> services = appModule.getServices();
348 for (final Service service : services) {
349 final ServiceInfo info = this.configFactory.configureService(service, ServiceInfo.class);
350 appInfo.services.add(info);
351 }
352 }
353
354 private void buildAppResources(final AppModule module, final AppInfo info) {
355 for (final Resource def : module.getResources()) {
356 // the resource is already deployed
357 // however we keep its id to be able to undeployed it later
358 // note: if ApplicationWide property was specified
359 // we want this application be managed only by the container
360 // once deployed = not undeployed with the app
361 // so we skip the undeployement skipping the id
362 if (!def.getProperties().containsKey("ApplicationWide")) {
363 info.resourceIds.add(def.getId());
364 info.resourceAliases.addAll(def.getAliases());
365 }
366 }
367
368 // for (final Container def : module.getContainers()) {
369 // if (!def.getProperties().containsKey("ApplicationWide")) {
370 // info.containerIds.add(def.getId());
371 // }
372 // }
373 }
374
375 private void buildAppContainers(final AppModule module, final AppInfo info) throws OpenEJBException {
376 final List<ContainerInfo> containerInfos = getContainerInfos(module);
377 if (containerInfos == null) { return; }
378
379 info.containers.addAll(containerInfos);
380 }
381
382 private List<ContainerInfo> getContainerInfos(AppModule module) throws OpenEJBException {
383 return ContainerUtils.getContainerInfos(module, configFactory);
384 }
385
386 private void buildClientModules(final AppModule appModule, final AppInfo appInfo, final JndiEncInfoBuilder jndiEncInfoBuilder) throws OpenEJBException {
387 for (final ClientModule clientModule : appModule.getClientModules()) {
388 final ApplicationClient applicationClient = clientModule.getApplicationClient();
389 final ClientInfo clientInfo = new ClientInfo();
390 clientInfo.description = applicationClient.getDescription();
391 clientInfo.displayName = applicationClient.getDisplayName();
392 clientInfo.path = clientModule.getJarLocation();
393 clientInfo.mainClass = clientModule.getMainClass();
394 clientInfo.localClients.addAll(clientModule.getLocalClients());
395 clientInfo.remoteClients.addAll(clientModule.getRemoteClients());
396 clientInfo.callbackHandler = applicationClient.getCallbackHandler();
397 clientInfo.moduleId = getClientModuleId(clientModule);
398 clientInfo.watchedResources.addAll(clientModule.getWatchedResources());
399 clientInfo.validationInfo = ValidatorBuilder.getInfo(clientModule.getValidationConfig());
400 clientInfo.uniqueId = clientModule.getUniqueId();
401
402 jndiEncInfoBuilder.build(applicationClient, clientModule.getJarLocation(), clientInfo.moduleId, clientModule.getModuleUri(), clientInfo.jndiEnc, clientInfo.jndiEnc);
403 appInfo.clients.add(clientInfo);
404 }
405 }
406
407 private void buildWebModules(final AppModule appModule, final JndiEncInfoBuilder jndiEncInfoBuilder, final AppInfo appInfo) throws OpenEJBException {
408 for (final WebModule webModule : appModule.getWebModules()) {
409 final WebApp webApp = webModule.getWebApp();
410 final WebAppInfo webAppInfo = new WebAppInfo();
411 webAppInfo.description = webApp.getDescription();
412 webAppInfo.displayName = webApp.getDisplayName();
413 webAppInfo.path = webModule.getJarLocation();
414 webAppInfo.moduleId = webModule.getModuleId();
415 webAppInfo.watchedResources.addAll(webModule.getWatchedResources());
416 webAppInfo.validationInfo = ValidatorBuilder.getInfo(webModule.getValidationConfig());
417 webAppInfo.uniqueId = webModule.getUniqueId();
418 webAppInfo.restApplications.addAll(webModule.getRestApplications());
419 webAppInfo.restClass.addAll(webModule.getRestClasses());
420 webAppInfo.ejbWebServices.addAll(webModule.getEjbWebServices());
421 webAppInfo.ejbRestServices.addAll(webModule.getEjbRestServices());
422 webAppInfo.jaxRsProviders.addAll(webModule.getJaxrsProviders());
423
424 for (final Map.Entry<String, Set<String>> entry : webModule.getWebAnnotatedClasses().entrySet()) {
425 final ClassListInfo info = new ClassListInfo();
426 info.name = entry.getKey();
427 info.list.addAll(entry.getValue());
428 webAppInfo.webAnnotatedClasses.add(info);
429 }
430
431 for (final Map.Entry<String, Set<String>> entry : webModule.getJsfAnnotatedClasses().entrySet()) {
432 final ClassListInfo info = new ClassListInfo();
433 info.name = entry.getKey();
434 info.list.addAll(entry.getValue());
435 webAppInfo.jsfAnnotatedClasses.add(info);
436 }
437
438 webAppInfo.host = webModule.getHost();
439
440 if (!webModule.isStandaloneModule() && USE_EAR_AS_CONTEXT_ROOT_BASE) {
441 webAppInfo.contextRoot = appModule.getModuleId() + "/" + webModule.getContextRoot();
442 } else {
443 webAppInfo.contextRoot = webModule.getContextRoot();
444 }
445
446 webAppInfo.sessionTimeout = 30;
447 if (webModule.getWebApp() != null && webModule.getWebApp().getSessionConfig() != null) {
448 for (final SessionConfig sessionConfig : webModule.getWebApp().getSessionConfig()) {
449 if (sessionConfig.getSessionTimeout() != null) {
450 webAppInfo.sessionTimeout = sessionConfig.getSessionTimeout();
451 break;
452 }
453 }
454 }
455
456 jndiEncInfoBuilder.build(webApp, webModule.getJarLocation(), webAppInfo.moduleId, webModule.getModuleUri(), webAppInfo.jndiEnc, webAppInfo.jndiEnc);
457
458 webAppInfo.portInfos.addAll(this.configureWebservices(webModule.getWebservices()));
459 // configureWebserviceSecurity(webAppInfo, webModule);: was empty
460
461 for (final Servlet servlet : webModule.getWebApp().getServlet()) {
462 final ServletInfo servletInfo = new ServletInfo();
463 servletInfo.servletName = servlet.getServletName();
464 servletInfo.servletClass = servlet.getServletClass();
465 servletInfo.mappings = webModule.getWebApp().getServletMappings(servletInfo.servletName);
466 for (final ParamValue pv : servlet.getInitParam()) {
467 final ParamValueInfo pvi = new ParamValueInfo();
468 pvi.name = pv.getParamName();
469 pvi.value = pv.getParamValue();
470 servletInfo.initParams.add(pvi);
471 }
472 webAppInfo.servlets.add(servletInfo);
473 }
474
475 for (final Listener listener : webModule.getWebApp().getListener()) {
476 final ListenerInfo listenerInfo = new ListenerInfo();
477 listenerInfo.classname = listener.getListenerClass();
478 webAppInfo.listeners.add(listenerInfo);
479 }
480
481 for (final Filter filter : webModule.getWebApp().getFilter()) {
482 final FilterInfo filterInfo = new FilterInfo();
483 filterInfo.name = filter.getFilterName();
484 filterInfo.classname = filter.getFilterClass();
485 filterInfo.mappings = webModule.getWebApp().getFilterMappings(filter.getFilterName());
486 for (final ParamValue pv : filter.getInitParam()) {
487 filterInfo.initParams.put(pv.getParamName(), pv.getParamValue());
488 }
489 webAppInfo.filters.add(filterInfo);
490 }
491
492 appInfo.webApps.add(webAppInfo);
493 }
494 }
495
496 private void buildConnectorModules(final AppModule appModule, final AppInfo appInfo) throws OpenEJBException {
497 final String appId = appModule.getModuleId();
498
499 for (final ConnectorModule connectorModule : appModule.getConnectorModules()) {
500 //
501 // DEVELOPERS NOTE: if you change the id generation code here, you must change
502 // the id generation code in AutoConfig$AppResources
503 //
504
505 final Connector connector = connectorModule.getConnector();
506
507 final ConnectorInfo connectorInfo = new ConnectorInfo();
508 connectorInfo.description = connector.getDescription();
509 connectorInfo.displayName = connector.getDisplayName();
510 connectorInfo.path = connectorModule.getJarLocation();
511 connectorInfo.moduleId = connectorModule.getModuleId();
512 connectorInfo.watchedResources.addAll(connectorModule.getWatchedResources());
513 connectorInfo.validationInfo = ValidatorBuilder.getInfo(connectorModule.getValidationConfig());
514 connectorInfo.uniqueId = connectorModule.getUniqueId();
515 connectorInfo.mbeans = connectorModule.getMbeans();
516
517 final List<URL> libraries = connectorModule.getLibraries();
518 for (final URL url : libraries) {
519 final File file = toFile(url);
520 try {
521 connectorInfo.libs.add(file.getCanonicalPath());
522 } catch (final IOException e) {
523 throw new IllegalArgumentException("Invalid application lib path " + file.getAbsolutePath());
524 }
525 }
526
527 final ResourceAdapter resourceAdapter = connector.getResourceAdapter();
528 if (resourceAdapter.getResourceAdapterClass() != null) {
529 final String id = this.getId(connectorModule);
530 final String className = resourceAdapter.getResourceAdapterClass();
531
532 final ServiceProvider provider = new ServiceProvider(className, id, "Resource");
533 provider.getTypes().add(className);
534
535 ServiceUtils.registerServiceProvider(appId, provider);
536
537 final Resource resource = new Resource(id, className, appId + "#" + id);
538
539 for (final ConfigProperty property : resourceAdapter.getConfigProperty()) {
540 final String name = property.getConfigPropertyName();
541 final String value = property.getConfigPropertyValue();
542 if (value != null) {
543 resource.getProperties().setProperty(name, value);
544 }
545 }
546 connectorInfo.resourceAdapter = this.configFactory.configureService(resource, ResourceInfo.class);
547 }
548
549 final OutboundResourceAdapter outbound = resourceAdapter.getOutboundResourceAdapter();
550 if (outbound != null) {
551 String transactionSupport = "none";
552 final TransactionSupportType transactionSupportType = outbound.getTransactionSupport();
553 if (transactionSupportType != null) {
554 switch (transactionSupportType) {
555 case LOCAL_TRANSACTION:
556 transactionSupport = "local";
557 break;
558 case NO_TRANSACTION:
559 transactionSupport = "none";
560 break;
561 case XA_TRANSACTION:
562 transactionSupport = "xa";
563 break;
564 }
565 }
566 for (final ConnectionDefinition connection : outbound.getConnectionDefinition()) {
567
568 final String id = this.getId(connection, outbound, connectorModule);
569 final String className = connection.getManagedConnectionFactoryClass();
570 final String type = connection.getConnectionFactoryInterface();
571
572 final ServiceProvider provider = new ServiceProvider(className, id, "Resource");
573 provider.getTypes().add(type);
574
575 ServiceUtils.registerServiceProvider(appId, provider);
576
577 final Resource resource = new Resource(id, type, appId + "#" + id);
578 final Properties properties = resource.getProperties();
579 for (final ConfigProperty property : connection.getConfigProperty()) {
580 final String name = property.getConfigPropertyName();
581 final String value = property.getConfigPropertyValue();
582 if (value != null) {
583 properties.setProperty(name, value);
584 }
585 }
586 properties.setProperty("TransactionSupport", transactionSupport);
587 if (connectorInfo.resourceAdapter != null) {
588 properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
589 }
590
591 final ResourceInfo resourceInfo = this.configFactory.configureService(resource, ResourceInfo.class);
592 connectorInfo.outbound.add(resourceInfo);
593 }
594 }
595
596 final InboundResourceadapter inbound = resourceAdapter.getInboundResourceAdapter();
597 if (inbound != null) {
598 for (final MessageListener messageListener : inbound.getMessageAdapter().getMessageListener()) {
599 final String id = this.getId(messageListener, inbound, connectorModule);
600
601 final Container container = new Container(id, "MESSAGE", null);
602
603 final Properties properties = container.getProperties();
604 properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
605 properties.setProperty("MessageListenerInterface", messageListener.getMessageListenerType());
606 properties.setProperty("ActivationSpecClass", messageListener.getActivationSpec().getActivationSpecClass());
607
608 final MdbContainerInfo mdbContainerInfo = this.configFactory.configureService(container, MdbContainerInfo.class);
609 connectorInfo.inbound.add(mdbContainerInfo);
610 }
611 }
612
613 for (final AdminObject adminObject : resourceAdapter.getAdminObject()) {
614
615 final String id = this.getId(adminObject, resourceAdapter, connectorModule);
616 final String className = adminObject.getAdminObjectClass();
617 final String type = adminObject.getAdminObjectInterface();
618
619 final ServiceProvider provider = new ServiceProvider(className, id, "Resource");
620 provider.getTypes().add(type);
621
622 ServiceUtils.registerServiceProvider(appId, provider);
623
624 final Resource resource = new Resource(id, type, appId + "#" + id);
625 final Properties properties = resource.getProperties();
626 for (final ConfigProperty property : adminObject.getConfigProperty()) {
627 final String name = property.getConfigPropertyName();
628 final String value = property.getConfigPropertyValue();
629 if (value != null) {
630 properties.setProperty(name, value);
631 }
632 }
633 final ResourceInfo resourceInfo = this.configFactory.configureService(resource, ResourceInfo.class);
634 connectorInfo.adminObject.add(resourceInfo);
635 }
636
637 appInfo.connectors.add(connectorInfo);
638 }
639 }
640
641 private String getId(final AdminObject adminObject, final ResourceAdapter resourceAdapter, final ConnectorModule connectorModule) {
642 final String id;
643 if (adminObject.getId() != null) {
644 id = adminObject.getId();
645 } else if (resourceAdapter.getAdminObject().size() == 1) {
646 id = connectorModule.getModuleId();
647 } else {
648 id = connectorModule.getModuleId() + "-" + adminObject.getAdminObjectInterface();
649 }
650 return id;
651 }
652
653 private String getId(final MessageListener messageListener, final InboundResourceadapter inbound, final ConnectorModule connectorModule) {
654 final String id;
655 if (messageListener.getId() != null) {
656 id = messageListener.getId();
657 } else if (inbound.getMessageAdapter().getMessageListener().size() == 1) {
658 id = connectorModule.getModuleId();
659 } else {
660 id = connectorModule.getModuleId() + "-" + messageListener.getMessageListenerType();
661 }
662 return id;
663 }
664
665 private String getId(final ConnectionDefinition connection, final OutboundResourceAdapter outbound, final ConnectorModule connectorModule) {
666 final String id;
667 if (connection.getId() != null) {
668 id = connection.getId();
669 } else if (outbound.getConnectionDefinition().size() == 1) {
670 id = connectorModule.getModuleId();
671 } else {
672 id = connectorModule.getModuleId() + "-" + connection.getConnectionFactoryInterface();
673 }
674 return id;
675 }
676
677 private String getId(final ConnectorModule connectorModule) {
678 String id = connectorModule.getConnector().getResourceAdapter().getId();
679 if (id == null) {
680 id = connectorModule.getModuleId() + "RA";
681 }
682 return id;
683 }
684
685 private void buildPersistenceModules(final AppModule appModule, final AppInfo appInfo) {
686 for (final PersistenceModule persistenceModule : appModule.getPersistenceModules()) {
687 final String rootUrl = persistenceModule.getRootUrl();
688 final Persistence persistence = persistenceModule.getPersistence();
689 for (final PersistenceUnit persistenceUnit : persistence.getPersistenceUnit()) {
690 final PersistenceUnitInfo info = new PersistenceUnitInfo();
691 info.id = appModule.persistenceUnitId(rootUrl, persistenceUnit.getName());
692 info.name = persistenceUnit.getName();
693 info.watchedResources.addAll(persistenceModule.getWatchedResources());
694 info.persistenceUnitRootUrl = rootUrl;
695 info.provider = persistenceUnit.getProvider();
696 info.transactionType = persistenceUnit.getTransactionType().toString();
697 info.webappName = findRelatedWebApp(appModule, rootUrl);
698
699 final Boolean excludeUnlistedClasses = persistenceUnit.isExcludeUnlistedClasses();
700 info.excludeUnlistedClasses = persistenceUnit.isScanned() || excludeUnlistedClasses != null && excludeUnlistedClasses;
701
702 info.jtaDataSource = persistenceUnit.getJtaDataSource();
703 info.nonJtaDataSource = persistenceUnit.getNonJtaDataSource();
704
705 info.jarFiles.addAll(persistenceUnit.getJarFile());
706 info.classes.addAll(persistenceUnit.getClazz());
707 info.mappingFiles.addAll(persistenceUnit.getMappingFile());
708
709 info.persistenceXMLSchemaVersion = persistence.getVersion();
710 info.sharedCacheMode = persistenceUnit.getSharedCacheMode().toString();
711 info.validationMode = persistenceUnit.getValidationMode().toString();
712
713 // Handle Properties
714 info.properties.putAll(persistenceUnit.getProperties());
715
716 PersistenceProviderProperties.apply(appModule, info);
717
718
719 // Persistence Unit Root Url
720 appInfo.persistenceUnits.add(info);
721 }
722 }
723 }
724
725 @SuppressWarnings("unchecked")
726 private String findRelatedWebApp(final AppModule appModule, final String rootUrl) {
727 for (final WebModule webModule : appModule.getWebModules()) {
728 final List<URL> pXmls = (List<URL>) webModule.getAltDDs().get(DeploymentLoader.EAR_WEBAPP_PERSISTENCE_XML_JARS);
729 if (pXmls != null) {
730 for (final URL url : pXmls) {
731 if (url.toExternalForm().contains(rootUrl)) {
732 return webModule.getModuleId();
733 }
734 }
735 }
736 }
737 return null;
738 }
739
740 public static class PersistenceProviderProperties {
741 public static final String OPENJPA_RUNTIME_UNENHANCED_CLASSES = "openjpa.RuntimeUnenhancedClasses";
742 public static final String DEFAULT_RUNTIME_UNENHANCED_CLASSES = "supported";
743 public static final String REMOVE_DEFAULT_RUNTIME_UNENHANCED_CLASSES = "disable";
744
745 public static final String TABLE_PREFIX = "openejb.jpa.table_prefix";
746 public static final String OPENJPA_METADATA_REPOSITORY = "openjpa.MetaDataRepository";
747 public static final String PREFIX_METADATA_REPOSITORY = "org.apache.openejb.openjpa.PrefixMappingRepository";
748 public static final String OPENJPA_SEQUENCE = "openjpa.Sequence";
749 public static final String PREFIX_SEQUENCE = "org.apache.openejb.openjpa.PrefixTableJdbcSeq";
750
751 public static final String PROVIDER_PROP = "javax.persistence.provider";
752 public static final String TRANSACTIONTYPE_PROP = "javax.persistence.transactionType";
753 public static final String JTADATASOURCE_PROP = "javax.persistence.jtaDataSource";
754 public static final String NON_JTADATASOURCE_PROP = "javax.persistence.nonJtaDataSource";
755 private static final String DEFAULT_PERSISTENCE_PROVIDER = PersistenceBootstrap.DEFAULT_PROVIDER;
756 public static final String FORCE_PROVIDER_ENV = "openejb.jpa.force." + PROVIDER_PROP;
757
758 public static final String HIBERNATE_TRANSACTION_MANAGER_LOOKUP_CLASS = "hibernate.transaction.manager_lookup_class";
759 public static final String HIBERNATE_JTA_PLATFORM = "hibernate.transaction.jta.platform";
760 public static final String HIBERNATE_EJB_NAMING_STRATEGY_PROP = "hibernate.ejb.naming_strategy";
761 private static final String HIBERNATE_EJB_NAMING_STRATEGY = "org.apache.openejb.jpa.integration.hibernate.PrefixNamingStrategy";
762
763 private static final String ECLIPSELINK_SESSION_CUSTOMIZER = "eclipselink.session.customizer";
764 private static final String ECLIPSELINK_TARGET_SERVER = "eclipselink.target-server";
765 private static final String PREFIX_SESSION_CUSTOMIZER = "org.apache.openejb.jpa.integration.eclipselink.PrefixSessionCustomizer";
766 private static final String OPENEJB_TARGET_SERVER = "org.apache.openejb.jpa.integration.eclipselink.OpenEJBServerPlatform";
767
768 private static final String providerEnv;
769 private static final boolean forceProviderEnv;
770 private static final String transactionTypeEnv;
771 private static final String jtaDataSourceEnv;
772 private static final String nonJtaDataSourceEnv;
773
774 static {
775 providerEnv = SystemInstance.get().getOptions().get(PROVIDER_PROP, (String) null);
776 forceProviderEnv = SystemInstance.get().getOptions().get(FORCE_PROVIDER_ENV, true);
777 transactionTypeEnv = SystemInstance.get().getOptions().get(TRANSACTIONTYPE_PROP, (String) null);
778 jtaDataSourceEnv = SystemInstance.get().getOptions().get(JTADATASOURCE_PROP, (String) null);
779 nonJtaDataSourceEnv = SystemInstance.get().getOptions().get(NON_JTADATASOURCE_PROP, (String) null);
780 }
781
782 /**
783 * @param appModule the app module with its config and its temp classloader, take care to only use getResource here
784 * @param info the persistence unit info
785 */
786 private static void apply(final AppModule appModule, final PersistenceUnitInfo info) {
787 final ClassLoader classLoader = appModule.getClassLoader();
788 overrideFromSystemProp(info);
789
790 // The result is that OpenEJB-specific configuration can be avoided when
791 // using OpenEJB + Hibernate or another vendor. A second benefit is that
792 // if another vendor is used in production, the value will automatically
793 // be reset for using OpenEJB in the test environment. Ensuring the strategy
794 // doesn't start with "org.hibernate.transaction" allows for a custom lookup
795 // strategy to be used and not overridden.
796
797 // DMB: This whole block could be a map, but I left it this way just
798 // in case we decided we wanted to do other custom handing for the
799 // providers listed.
800 if ("org.hibernate.ejb.HibernatePersistence".equals(info.provider) || "org.hibernate.jpa.HibernatePersistenceProvider".equals(info.provider)) {
801
802 // Apply the overrides that apply to all persistence units of this provider
803 override(appModule.getProperties(), info, "hibernate");
804
805 String className = info.properties.getProperty(HIBERNATE_JTA_PLATFORM);
806 if (className == null) {
807 className = info.properties.getProperty(HIBERNATE_TRANSACTION_MANAGER_LOOKUP_CLASS);
808 }
809 // info.persistenceUnitRootUrl = null; // to avoid HHH015010
810
811 final String prefix = info.properties.getProperty(TABLE_PREFIX);
812 if (prefix != null) {
813 if (info.properties.containsKey(HIBERNATE_EJB_NAMING_STRATEGY_PROP)) {
814 logger.warning("can't statisfy table prefix since you provided a " + HIBERNATE_EJB_NAMING_STRATEGY_PROP + " property");
815 } else {
816 // to pass the config to the impl
817 info.properties.setProperty(HIBERNATE_EJB_NAMING_STRATEGY_PROP, HIBERNATE_EJB_NAMING_STRATEGY);
818 }
819 }
820
821 if (className == null || className.startsWith("org.hibernate.transaction") || className.startsWith("org.hibernate.service.jta.platform")) {
822 // hibernate 4.3
823 String key = HIBERNATE_JTA_PLATFORM;
824 String value = MakeTxLookup.HIBERNATE_NEW_FACTORY2;
825
826 if (classLoader.getResource(ClassLoaderUtil.resourceName("org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform")) == null) {
827 // previous hibernate 4
828 value = MakeTxLookup.HIBERNATE_NEW_FACTORY;
829
830 if (classLoader.getResource(ClassLoaderUtil.resourceName("org.hibernate.service.jta.platform.spi.JtaPlatform")) == null) {
831 // hibernate 3. In the worse case it is set with a hibernate 4 and hibernate will convert it.
832 key = HIBERNATE_TRANSACTION_MANAGER_LOOKUP_CLASS;
833 value = MakeTxLookup.HIBERNATE_FACTORY;
834 }
835 }
836
837 if (classLoader.getResource(ClassLoaderUtil.resourceName(value)) != null) {
838 info.properties.setProperty(key, value);
839 logger.debug("Adjusting PersistenceUnit(name=" + info.name + ") property to " + key + "=" + value);
840 } else {
841 logger.debug("can't adjust hibernate jta bridge to openejb one");
842 }
843
844 }
845 } else if ("oracle.toplink.essentials.PersistenceProvider".equals(info.provider) ||
846 "oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider".equals(info.provider)) {
847
848 // Apply the overrides that apply to all persistence units of this provider
849 override(appModule.getProperties(), info, "toplink");
850
851 final String lookupProperty = "toplink.target-server";
852 final String openejbLookupClass = MakeTxLookup.TOPLINK_FACTORY;
853
854 final String prefix = info.properties.getProperty(TABLE_PREFIX);
855 if (prefix != null) {
856 logger.warning("table prefix feature is not supported for toplink");
857 }
858
859 final String className = info.properties.getProperty(lookupProperty);
860
861 if (className == null || className.startsWith("oracle.toplink.transaction")) {
862 info.properties.setProperty(lookupProperty, openejbLookupClass);
863 logger.debug("Adjusting PersistenceUnit(name=" + info.name + ") property to " + lookupProperty + "=" + openejbLookupClass);
864 }
865 } else if ("org.eclipse.persistence.jpa.PersistenceProvider".equals(info.provider) || "org.eclipse.persistence.jpa.osgi.PersistenceProvider".equals(info.provider)) {
866
867 // Apply the overrides that apply to all persistence units of this provider
868 override(appModule.getProperties(), info, "eclipselink");
869
870 final String className = info.properties.getProperty(ECLIPSELINK_TARGET_SERVER);
871
872 if (className == null || className.startsWith("org.eclipse.persistence.transaction")) {
873 if (classLoader.getResource(ClassLoaderUtil.resourceName(OPENEJB_TARGET_SERVER)) != null) {
874 info.properties.setProperty(ECLIPSELINK_TARGET_SERVER, OPENEJB_TARGET_SERVER);
875 logger.debug("Adjusting PersistenceUnit(name=" + info.name + ") property to " + ECLIPSELINK_TARGET_SERVER + "=" + OPENEJB_TARGET_SERVER);
876 } else {
877 logger.debug("Can't adjusting PersistenceUnit(name=" + info.name + ") property to " + ECLIPSELINK_TARGET_SERVER + "=" + OPENEJB_TARGET_SERVER + ", using default one");
878 }
879 }
880
881 final String prefix = info.properties.getProperty(TABLE_PREFIX);
882 if (prefix != null) {
883 if (info.properties.containsKey(ECLIPSELINK_SESSION_CUSTOMIZER)) {
884 logger.warning("can't statisfy table prefix since you provided a " + ECLIPSELINK_SESSION_CUSTOMIZER + " property, add a call to org.apache.openejb.jpa.integration.eclipselink.PrefixSessionCustomizer");
885 } else {
886 // force eager loading otherwise we'll not get the prefix in the customizer
887 info.properties.setProperty(EntityManagerFactoryCallable.OPENEJB_JPA_INIT_ENTITYMANAGER, "true");
888 // to pass the config to the impl
889 info.properties.setProperty(ECLIPSELINK_SESSION_CUSTOMIZER, PREFIX_SESSION_CUSTOMIZER);
890 }
891 }
892
893 for (final String key : singletonList("eclipselink.jdbc.sequence-connection-pool.non-jta-data-source")) {
894 final String ds = info.properties.getProperty(key);
895 if (ds != null && !ds.contains(":") /* java:, openejb:, other: namespace */ ) {
896 info.properties.setProperty(key, "java:openejb/Resource/" + ds);
897 }
898 }
899 } else if (info.provider == null || "org.apache.openjpa.persistence.PersistenceProviderImpl".equals(info.provider)) {
900
901 // Apply the overrides that apply to all persistence units of this provider
902 override(appModule.getProperties(), info, "openjpa");
903
904 final String existing = info.properties.getProperty(OPENJPA_RUNTIME_UNENHANCED_CLASSES);
905
906 if (existing == null) {
907 info.properties.setProperty(OPENJPA_RUNTIME_UNENHANCED_CLASSES, DEFAULT_RUNTIME_UNENHANCED_CLASSES);
908 logger.debug("Adjusting PersistenceUnit(name=" + info.name + ") property to "
909 + OPENJPA_RUNTIME_UNENHANCED_CLASSES + "=" + DEFAULT_RUNTIME_UNENHANCED_CLASSES);
910 } else if (REMOVE_DEFAULT_RUNTIME_UNENHANCED_CLASSES.equals(existing.trim())) {
911 info.properties.remove(OPENJPA_RUNTIME_UNENHANCED_CLASSES);
912 logger.info("Adjusting PersistenceUnit(name=" + info.name + ") removing property "
913 + OPENJPA_RUNTIME_UNENHANCED_CLASSES);
914 }
915
916 final String prefix = info.properties.getProperty(TABLE_PREFIX);
917 if (prefix != null) {
918 final String mapping = info.properties.getProperty(OPENJPA_METADATA_REPOSITORY);
919 if (mapping != null && !"org.apache.openjpa.jdbc.meta.MappingRepository".equals(mapping)) {
920 throw new OpenEJBRuntimeException("can't honor table prefixes since you provided a custom mapping repository: " + mapping);
921 }
922 info.properties.setProperty(OPENJPA_METADATA_REPOSITORY, PREFIX_METADATA_REPOSITORY + "(prefix=" + prefix + ")");
923 if (!info.properties.containsKey(OPENJPA_SEQUENCE)) {
924 info.properties.setProperty(OPENJPA_SEQUENCE, PREFIX_SEQUENCE + "(prefix=" + prefix + ")");
925 } else {
926 logger.warning("you configured a custom sequence so the prefix will be ignored");
927 }
928 }
929
930 final Set<String> keys = new HashSet<String>(info.properties.stringPropertyNames());
931 for (final String key : keys) {
932 if (key.matches("openjpa.Connection(DriverName|URL|UserName|Password)")) {
933 final Object o = info.properties.remove(key);
934 logger.warning("Removing PersistenceUnit(name=" + info.name + ") property " + key + "=" + o + " [not valid in a container environment]");
935 } else { // try to convert it if necessary
936 final JPAPropertyConverter.Pair pair = JPAPropertyConverter.toOpenJPAValue(key, info.properties.getProperty(key), info.properties);
937 if (pair != null && !info.properties.containsKey(pair.getKey())) {
938 logger.info("Converting PersistenceUnit(name=" + info.name + ") property "
939 + key + "=" + info.properties.getProperty(key) + " to " + pair.toString());
940 info.properties.remove(key);
941 info.properties.setProperty(pair.getKey(), pair.getValue());
942 }
943 }
944 }
945 }
946
947 // Apply the overrides that apply to just this persistence unit
948 override(appModule.getProperties(), info);
949
950 for (final String key : asList("javax.persistence.jtaDataSource", "javax.persistence.nonJtaDataSource")) {
951 final String ds = info.properties.getProperty(key);
952 if (ds != null && !ds.contains(":") /* java:, openejb:, other: namespace */ ) {
953 info.properties.setProperty(key, "java:openejb/Resource/" + ds);
954 }
955 }
956 }
957
958 private static void overrideFromSystemProp(final PersistenceUnitInfo info) {
959 if (providerEnv != null && (info.provider == null || forceProviderEnv)) {
960 info.provider = providerEnv;
961 }
962 if (info.provider == null) {
963 info.provider = DEFAULT_PERSISTENCE_PROVIDER;
964 }
965 if (jtaDataSourceEnv != null) {
966 info.jtaDataSource = jtaDataSourceEnv;
967 }
968 if (transactionTypeEnv != null) {
969 info.transactionType = transactionTypeEnv.toUpperCase();
970 }
971 if (nonJtaDataSourceEnv != null) {
972 info.nonJtaDataSource = nonJtaDataSourceEnv;
973 }
974 }
975
976 private static void override(final Properties appProperties, final PersistenceUnitInfo info) {
977 override(appProperties, info, info.name);
978 }
979
980 private static void override(final Properties appProperties, final PersistenceUnitInfo info, final String prefix) {
981 final Properties propertiesToCheckForOverridings = new Properties();
982 propertiesToCheckForOverridings.putAll(appProperties);
983 propertiesToCheckForOverridings.putAll(JavaSecurityManagers.getSystemProperties());
984 propertiesToCheckForOverridings.putAll(SystemInstance.get().getProperties());
985 final Properties overrides = ConfigurationFactory.getOverrides(propertiesToCheckForOverridings, prefix, "PersistenceUnit");
986
987 for (final Map.Entry<Object, Object> entry : overrides.entrySet()) {
988 final String property = (String) (prefix.equalsIgnoreCase(info.name) ? entry.getKey() : prefix + "." + entry.getKey());
989 String value = (String) entry.getValue();
990
991 if ("openjpa.Log".equals(property) && "org.apache.openejb.openjpa.JULOpenJPALogFactory".equals(value)) { // we set a default
992 if (info.properties.containsKey("openjpa.Log")) {
993 continue;
994 }
995 if (appProperties.containsKey("openjpa.Log")) {
996 value = appProperties.getProperty(property, value);
997 } else {
998 continue;
999 }
1000 }
1001
1002 if (info.properties.containsKey(property)) {
1003 logger.debug("Overriding persistence-unit " + info.name + " property " + property + "=" + value);
1004 } else {
1005 logger.debug("Adding persistence-unit " + info.name + " property " + property + "=" + value);
1006 }
1007 info.properties.put(property, value);
1008
1009 if (property.endsWith("openjpa.Specification")) {
1010 info.persistenceXMLSchemaVersion = value.replace("JPA ", "");
1011 }
1012 }
1013 }
1014 }
1015
1016 private static String getClientModuleId(final ClientModule clientModule) {
1017 return clientModule.getModuleId();
1018 }
1019
1020
1021 private List<PortInfo> configureWebservices(final Webservices webservices) {
1022 final List<PortInfo> portMap = new ArrayList<PortInfo>();
1023 if (webservices == null) {
1024 return portMap;
1025 }
1026
1027 for (final WebserviceDescription desc : webservices.getWebserviceDescription()) {
1028 final String wsdlFile = desc.getWsdlFile();
1029 final String serviceName = desc.getWebserviceDescriptionName();
1030
1031 for (final PortComponent port : desc.getPortComponent()) {
1032 final PortInfo portInfo = new PortInfo();
1033
1034 final ServiceImplBean serviceImplBean = port.getServiceImplBean();
1035 portInfo.serviceId = desc.getId();
1036 portInfo.portId = port.getId();
1037 portInfo.serviceLink = serviceImplBean.getEjbLink();
1038 if (portInfo.serviceLink == null) {
1039 portInfo.serviceLink = serviceImplBean.getServletLink();
1040 }
1041
1042 portInfo.seiInterfaceName = port.getServiceEndpointInterface();
1043 portInfo.portName = port.getPortComponentName();
1044 portInfo.binding = port.getProtocolBinding();
1045 portInfo.serviceName = serviceName;
1046 portInfo.wsdlFile = wsdlFile;
1047 portInfo.mtomEnabled = port.isEnableMtom();
1048 portInfo.wsdlPort = port.getWsdlPort();
1049 portInfo.wsdlService = port.getWsdlService();
1050 portInfo.location = port.getLocation();
1051
1052 final List<HandlerChainInfo> handlerChains = ConfigurationFactory.toHandlerChainInfo(port.getHandlerChains());
1053 portInfo.handlerChains.addAll(handlerChains);
1054
1055 // todo configure jaxrpc mappings here
1056
1057 portMap.add(portInfo);
1058 }
1059 }
1060 return portMap;
1061 }
1062
1063 /*
1064 * left package-local for a unit test
1065 */
1066 void configureWebserviceSecurity(final EjbJarInfo ejbJarInfo, final EjbModule ejbModule) {
1067 final Object altDD = ejbModule.getOpenejbJar();
1068 final List<PortInfo> infoList = ejbJarInfo.portInfos;
1069
1070 this.configureWebserviceScurity(infoList, altDD);
1071 }
1072
1073 private void configureWebserviceScurity(final List<PortInfo> infoList, final Object altDD) {
1074 if (altDD == null || !(altDD instanceof OpenejbJar)) {
1075 return;
1076 }
1077
1078 final OpenejbJar openejbJar = (OpenejbJar) altDD;
1079 final Map<String, EjbDeployment> deploymentsByEjbName = openejbJar.getDeploymentsByEjbName();
1080
1081 for (final PortInfo portInfo : infoList) {
1082 final EjbDeployment deployment = deploymentsByEjbName.get(portInfo.serviceLink);
1083
1084 if (deployment == null) {
1085 continue;
1086 }
1087 portInfo.realmName = deployment.getProperties().getProperty("webservice.security.realm");
1088 portInfo.securityRealmName = deployment.getProperties().getProperty("webservice.security.securityRealm");
1089 if (deployment.getProperties().getProperty("webservice.security.transportGarantee") != null) {
1090 portInfo.transportGuarantee = deployment.getProperties().getProperty("webservice.security.transportGarantee");
1091 } else {
1092 portInfo.transportGuarantee = "NONE";
1093 }
1094
1095 if (deployment.getProperties().getProperty("webservice.security.authMethod") != null) {
1096 portInfo.authMethod = deployment.getProperties().getProperty("webservice.security.authMethod");
1097 } else {
1098 portInfo.authMethod = "NONE";
1099 }
1100 portInfo.properties = deployment.getProperties();
1101 }
1102 }
1103
1104 private static boolean skipMdb(final EnterpriseBeanInfo bean) {
1105 return bean instanceof MessageDrivenBeanInfo && SystemInstance.get().hasProperty("openejb.geronimo");
1106 }
1107
1108 }