use of org.apache.openejb.assembler.classic.EnterpriseBeanInfo in project tomee by apache.
the class EjbJarInfoBuilder method initSessionBean.
private EnterpriseBeanInfo initSessionBean(final SessionBean s, final EjbJarInfo ejbJar, final Map m) throws OpenEJBException {
EnterpriseBeanInfo bean;
if (s.getSessionType() == SessionType.STATEFUL) {
bean = new StatefulBeanInfo();
bean.passivable = s.getPassivationCapable() == null || s.getPassivationCapable();
final StatefulBeanInfo stateful = (StatefulBeanInfo) bean;
copyCallbacks(s.getPostActivate(), stateful.postActivate);
copyCallbacks(s.getPrePassivate(), stateful.prePassivate);
copyCallbacks(s.getAfterBegin(), stateful.afterBegin);
copyCallbacks(s.getBeforeCompletion(), stateful.beforeCompletion);
copyCallbacks(s.getAfterCompletion(), stateful.afterCompletion);
for (final InitMethod initMethod : s.getInitMethod()) {
final InitMethodInfo init = new InitMethodInfo();
init.beanMethod = toInfo(initMethod.getBeanMethod());
init.createMethod = toInfo(initMethod.getCreateMethod());
stateful.initMethods.add(init);
}
for (final RemoveMethod removeMethod : s.getRemoveMethod()) {
final RemoveMethodInfo remove = new RemoveMethodInfo();
remove.beanMethod = toInfo(removeMethod.getBeanMethod());
remove.retainIfException = removeMethod.getRetainIfException();
stateful.removeMethods.add(remove);
}
copyConcurrentMethods(s, ejbJar, m);
} else if (s.getSessionType() == SessionType.MANAGED) {
bean = new ManagedBeanInfo();
final ManagedBeanInfo managed = (ManagedBeanInfo) bean;
// this way we support managed beans in ejb-jar.xml (not in the spec but can be useful)
managed.hidden = !(s instanceof ManagedBean) || ((ManagedBean) s).isHidden();
copyCallbacks(s.getPostActivate(), managed.postActivate);
copyCallbacks(s.getPrePassivate(), managed.prePassivate);
for (final RemoveMethod removeMethod : s.getRemoveMethod()) {
final RemoveMethodInfo remove = new RemoveMethodInfo();
remove.beanMethod = toInfo(removeMethod.getBeanMethod());
remove.retainIfException = removeMethod.getRetainIfException();
managed.removeMethods.add(remove);
}
} else if (s.getSessionType() == SessionType.SINGLETON) {
bean = new SingletonBeanInfo();
final ConcurrencyManagementType type = s.getConcurrencyManagementType();
bean.concurrencyType = type != null ? type.toString() : ConcurrencyManagementType.CONTAINER.toString();
bean.loadOnStartup = s.getInitOnStartup();
copyCallbacks(s.getAroundTimeout(), bean.aroundTimeout);
copySchedules(s.getTimer(), bean.methodScheduleInfos);
// See JndiEncInfoBuilder.buildDependsOnRefs for processing of DependsOn
// bean.dependsOn.addAll(s.getDependsOn());
copyConcurrentMethods(s, ejbJar, m);
} else {
bean = new StatelessBeanInfo();
copySchedules(s.getTimer(), bean.methodScheduleInfos);
}
if (s.getSessionType() != SessionType.STATEFUL) {
copyCallbacks(s.getAroundTimeout(), bean.aroundTimeout);
}
bean.localbean = s.getLocalBean() != null;
bean.timeoutMethod = toInfo(s.getTimeoutMethod());
copyCallbacks(s.getAroundInvoke(), bean.aroundInvoke);
copyCallbacks(s.getPostConstruct(), bean.postConstruct);
copyCallbacks(s.getPreDestroy(), bean.preDestroy);
copyAsynchronous(s.getAsyncMethod(), bean.asynchronous);
bean.asynchronousClasses.addAll(s.getAsynchronousClasses());
final EjbDeployment d = (EjbDeployment) m.get(s.getEjbName());
if (d == null) {
throw new OpenEJBException("No deployment information in openejb-jar.xml for bean " + s.getEjbName() + ". Please redeploy the jar");
}
bean.ejbDeploymentId = d.getDeploymentId();
bean.containerId = d.getContainerId();
final Icon icon = s.getIcon();
bean.largeIcon = icon == null ? null : icon.getLargeIcon();
bean.smallIcon = icon == null ? null : icon.getSmallIcon();
bean.description = s.getDescription();
bean.displayName = s.getDisplayName();
bean.ejbClass = s.getEjbClass();
bean.ejbName = s.getEjbName();
bean.home = s.getHome();
bean.remote = s.getRemote();
bean.localHome = s.getLocalHome();
bean.local = s.getLocal();
bean.proxy = s.getProxy();
bean.parents.addAll(s.getParents());
bean.businessLocal.addAll(s.getBusinessLocal());
bean.businessRemote.addAll(s.getBusinessRemote());
final TransactionType txType = s.getTransactionType();
bean.transactionType = txType != null ? txType.toString() : TransactionType.CONTAINER.toString();
bean.serviceEndpoint = s.getServiceEndpoint();
bean.properties.putAll(d.getProperties());
bean.statefulTimeout = toInfo(s.getStatefulTimeout());
bean.restService = s.isRestService() && !(s instanceof StatefulBean);
return bean;
}
use of org.apache.openejb.assembler.classic.EnterpriseBeanInfo in project tomee by apache.
the class EjbJarInfoBuilder method initRelationshipRole.
private CmrFieldInfo initRelationshipRole(final EjbRelationshipRole role, final EjbRelationshipRole relatedRole, final Map<String, EnterpriseBeanInfo> infos) throws OpenEJBException {
final CmrFieldInfo cmrFieldInfo = new CmrFieldInfo();
// find the entityBeanInfo info for this role
final String ejbName = role.getRelationshipRoleSource().getEjbName();
final EnterpriseBeanInfo enterpriseBeanInfo = infos.get(ejbName);
if (enterpriseBeanInfo == null) {
throw new OpenEJBException("Relation role source ejb not found " + ejbName);
}
if (!(enterpriseBeanInfo instanceof EntityBeanInfo)) {
throw new OpenEJBException("Relation role source ejb is not an entity bean " + ejbName);
}
final EntityBeanInfo entityBeanInfo = (EntityBeanInfo) enterpriseBeanInfo;
cmrFieldInfo.roleSource = entityBeanInfo;
// RoleName: this may be null
cmrFieldInfo.roleName = role.getEjbRelationshipRoleName();
cmrFieldInfo.synthetic = role.getCmrField() == null;
// CmrFieldName: is null for uni-directional relationships
if (role.getCmrField() != null) {
cmrFieldInfo.fieldName = role.getCmrField().getCmrFieldName();
// CollectionType: java.util.Collection or java.util.Set
if (role.getCmrField().getCmrFieldType() != null) {
cmrFieldInfo.fieldType = role.getCmrField().getCmrFieldType().toString();
}
if (cmrFieldInfo.fieldType == null && relatedRole.getMultiplicity() == Multiplicity.MANY) {
cmrFieldInfo.fieldType = Collection.class.getName();
}
} else {
final String relatedEjbName = relatedRole.getRelationshipRoleSource().getEjbName();
final EnterpriseBeanInfo relatedEjb = infos.get(relatedEjbName);
if (relatedEjb == null) {
throw new OpenEJBException("Relation role source ejb not found " + relatedEjbName);
}
if (!(relatedEjb instanceof EntityBeanInfo)) {
throw new OpenEJBException("Relation role source ejb is not an entity bean " + relatedEjbName);
}
final EntityBeanInfo relatedEntity = (EntityBeanInfo) relatedEjb;
relatedRole.getRelationshipRoleSource();
cmrFieldInfo.fieldName = relatedEntity.abstractSchemaName + "_" + relatedRole.getCmrField().getCmrFieldName();
if (relatedRole.getMultiplicity() == Multiplicity.MANY) {
cmrFieldInfo.fieldType = Collection.class.getName();
}
}
// CascadeDelete
cmrFieldInfo.cascadeDelete = role.getCascadeDelete();
// Multiplicity: one or many
cmrFieldInfo.many = role.getMultiplicity() == Multiplicity.MANY;
// add the field to the entityBean
entityBeanInfo.cmrFields.add(cmrFieldInfo);
return cmrFieldInfo;
}
use of org.apache.openejb.assembler.classic.EnterpriseBeanInfo in project tomee by apache.
the class AppInfoBuilder method build.
public AppInfo build(final AppModule appModule) throws OpenEJBException {
// send an event so that it becomes pretty easy at this step to dynamically change the module description
// before going into the info tree. Pretty easy to hack on portability issues.
SystemInstance.get().fireEvent(new BeforeAppInfoBuilderEvent(appModule));
final AppInfo appInfo = new AppInfo();
appInfo.appId = appModule.getModuleId();
appInfo.path = appModule.getJarLocation();
appInfo.standaloneModule = appModule.isStandaloneModule() || appModule.isWebapp();
appInfo.delegateFirst = appModule.isDelegateFirst();
appInfo.watchedResources.addAll(appModule.getWatchedResources());
appInfo.mbeans.addAll(appModule.getAdditionalLibMbeans());
appInfo.jaxRsProviders.addAll(appModule.getJaxRsProviders());
appInfo.properties.putAll(appModule.getProperties());
if (appInfo.appId == null) {
throw new IllegalArgumentException("AppInfo.appId cannot be null");
}
if (appInfo.path == null) {
appInfo.path = appInfo.appId;
}
this.buildPojoConfiguration(appModule, appInfo);
this.buildAppResources(appModule, appInfo);
this.buildAppServices(appModule, appInfo);
//
// J2EE Connectors
//
this.buildConnectorModules(appModule, appInfo);
//
// Persistence Units
//
this.buildPersistenceModules(appModule, appInfo);
final List<String> containerIds = this.configFactory.getContainerIds();
for (final ConnectorInfo connectorInfo : appInfo.connectors) {
for (final MdbContainerInfo containerInfo : connectorInfo.inbound) {
containerIds.add(containerInfo.id);
}
}
containerIds.addAll(appInfo.containerIds);
//
// EJB Jars
//
final Map<EjbModule, EjbJarInfo> ejbJarInfos = new HashMap<EjbModule, EjbJarInfo>();
for (final EjbModule ejbModule : appModule.getEjbModules()) {
try {
final EjbJarInfo ejbJarInfo = this.ejbJarInfoBuilder.buildInfo(ejbModule);
ejbJarInfo.mbeans = ejbModule.getMbeans();
final Map<String, EjbDeployment> deploymentsByEjbName = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
for (final EnterpriseBeanInfo bean : ejbJarInfo.enterpriseBeans) {
final EjbDeployment d = deploymentsByEjbName.get(bean.ejbName);
if (d.getContainerId() != null && !containerIds.contains(d.getContainerId())) {
for (final String cId : appInfo.containerIds) {
if (cId.endsWith("/" + d.getContainerId())) {
d.setContainerId(cId);
break;
}
}
}
/*
* JRG - there's probably a better way of handling this, but this code handles the case when:
*
* A connector with two or more inbound adapter is registered, causing two containers named with the format:
* <moduleId>-<message listener interface>
*
* This code adjusts the container id for the associated MDBs by sticking the message listener interface on the end.
*
*/
if (bean instanceof MessageDrivenBeanInfo && !containerIds.contains(d.getContainerId()) && !skipMdb(bean)) {
final MessageDrivenBeanInfo mdb = (MessageDrivenBeanInfo) bean;
final String newContainerId = d.getContainerId() + "-" + mdb.mdbInterface;
if (containerIds.contains(newContainerId)) {
d.setContainerId(newContainerId);
}
}
if (!containerIds.contains(d.getContainerId()) && !skipMdb(bean)) {
final String msg = new Messages("org.apache.openejb.util.resources").format("config.noContainerFound", d.getContainerId(), d.getEjbName());
logger.fatal(msg);
throw new OpenEJBException(msg);
}
bean.containerId = d.getContainerId();
}
for (final PojoDeployment pojoDeployment : ejbModule.getOpenejbJar().getPojoDeployment()) {
final IdPropertiesInfo info = new IdPropertiesInfo();
info.id = pojoDeployment.getClassName();
info.properties.putAll(pojoDeployment.getProperties());
ejbJarInfo.pojoConfigurations.add(info);
}
ejbJarInfo.validationInfo = ValidatorBuilder.getInfo(ejbModule.getValidationConfig());
ejbJarInfo.portInfos.addAll(this.configureWebservices(ejbModule.getWebservices()));
ejbJarInfo.uniqueId = ejbModule.getUniqueId();
ejbJarInfo.webapp = ejbModule.isWebapp();
this.configureWebserviceSecurity(ejbJarInfo, ejbModule);
ejbJarInfos.put(ejbModule, ejbJarInfo);
appInfo.ejbJars.add(ejbJarInfo);
} catch (final OpenEJBException e) {
ConfigUtils.logger.warning("conf.0004", ejbModule.getJarLocation(), e.getMessage());
throw e;
}
}
// Create the JNDI info builder
final JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(appInfo);
if (appModule.getApplication() != null) {
//TODO figure out how to prevent adding stuff to the module and comp contexts from the application
//or maybe validate the xml so this won't happen.
jndiEncInfoBuilder.build(appModule.getApplication(), appInfo.appId, null, appModule.getModuleUri(), new JndiEncInfo(), new JndiEncInfo());
}
final List<EnterpriseBeanInfo> beans = new ArrayList<EnterpriseBeanInfo>();
// Build the JNDI tree for each ejb
for (final EjbModule ejbModule : appModule.getEjbModules()) {
final EjbJarInfo ejbJar = ejbJarInfos.get(ejbModule);
final Map<String, EnterpriseBean> beanData = ejbModule.getEjbJar().getEnterpriseBeansByEjbName();
for (final EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
beans.add(beanInfo);
// Get the ejb-jar.xml object
final EnterpriseBean enterpriseBean = beanData.get(beanInfo.ejbName);
// Build the JNDI info tree for the EJB
jndiEncInfoBuilder.build(enterpriseBean, beanInfo.ejbName, ejbJar.moduleName, ejbModule.getModuleUri(), ejbJar.moduleJndiEnc, beanInfo.jndiEnc);
jndiEncInfoBuilder.buildDependsOnRefs(enterpriseBean, beanInfo, ejbJar.moduleName);
}
}
// Check for circular references in Singleton @DependsOn
try {
References.sort(beans, new References.Visitor<EnterpriseBeanInfo>() {
@Override
public String getName(final EnterpriseBeanInfo bean) {
return bean.ejbDeploymentId;
}
@Override
public Set<String> getReferences(final EnterpriseBeanInfo bean) {
return new LinkedHashSet<String>(bean.dependsOn);
}
});
} catch (final CircularReferencesException e) {
// List<List> circuits = e.getCircuits();
// TODO Seems we lost circular reference detection, or we do it elsewhere and don't need it here
}
//
// Application Clients
//
this.buildClientModules(appModule, appInfo, jndiEncInfoBuilder);
//
// Webapps
//
this.buildWebModules(appModule, jndiEncInfoBuilder, appInfo);
//
// Final AppInfo creation
//
final List<URL> additionalLibraries = appModule.getAdditionalLibraries();
for (final URL url : additionalLibraries) {
final File file = toFile(url);
try {
appInfo.libs.add(file.getCanonicalPath());
} catch (final IOException e) {
throw new OpenEJBException("Invalid application lib path " + file.getAbsolutePath());
}
}
if (appModule.getCmpMappings() != null) {
try {
appInfo.cmpMappingsXml = JpaJaxbUtil.marshal(EntityMappings.class, appModule.getCmpMappings());
} catch (final JAXBException e) {
throw new OpenEJBException("Unable to marshal cmp entity mappings", e);
}
}
final ReportValidationResults reportValidationResults = new ReportValidationResults();
reportValidationResults.deploy(appModule);
logger.info("config.appLoaded", appInfo.path);
appInfo.webAppAlone = appModule.isWebapp();
return appInfo;
}
use of org.apache.openejb.assembler.classic.EnterpriseBeanInfo in project tomee by apache.
the class SystemAppInfo method preComputedInfo.
//
//
// DONT MODIFY IT WITHOUT UPDATING org.apache.openejb.config.SystemApps
//
//
public static AppInfo preComputedInfo(final ConfigurationFactory factory) {
final String singletonContainerId;
try {
singletonContainerId = findSingletonContainer(factory);
} catch (final OpenEJBException e) {
throw new IllegalStateException(e);
}
final EjbJarInfo ejbJarInfo = new EjbJarInfo();
ejbJarInfo.moduleId = "openejb";
ejbJarInfo.moduleName = ejbJarInfo.moduleId;
ejbJarInfo.moduleUri = URI.create(ejbJarInfo.moduleId);
ejbJarInfo.properties.setProperty("openejb.deploymentId.format", "{ejbName}");
ejbJarInfo.properties.setProperty("openejb.jndiname.format", "{deploymentId}{interfaceType.openejbLegacyName}");
final SingletonBeanInfo deployer = new SingletonBeanInfo();
deployer.ejbDeploymentId = "openejb/Deployer";
deployer.ejbName = deployer.ejbDeploymentId;
deployer.ejbClass = "org.apache.openejb.assembler.DeployerEjb";
deployer.businessRemote.add("org.apache.openejb.assembler.Deployer");
deployer.parents.add(deployer.ejbClass);
deployer.transactionType = "BEAN";
deployer.concurrencyType = "CONTAINER";
deployer.containerId = singletonContainerId;
ejbJarInfo.enterpriseBeans.add(deployer);
final SingletonBeanInfo configuration = new SingletonBeanInfo();
configuration.ejbDeploymentId = "openejb/ConfigurationInfo";
configuration.ejbName = deployer.ejbDeploymentId;
configuration.ejbClass = "org.apache.openejb.assembler.classic.cmd.ConfigurationInfoEjb";
configuration.businessRemote.add("org.apache.openejb.assembler.classic.cmd.ConfigurationInfo");
configuration.parents.add(deployer.ejbClass);
configuration.transactionType = "CONTAINER";
configuration.concurrencyType = "CONTAINER";
configuration.containerId = singletonContainerId;
ejbJarInfo.enterpriseBeans.add(configuration);
final SingletonBeanInfo mejb = new SingletonBeanInfo();
mejb.ejbDeploymentId = "MEJB";
mejb.ejbName = deployer.ejbDeploymentId;
mejb.ejbClass = "org.apache.openejb.mgmt.MEJBBean";
mejb.home = "javax.management.j2ee.ManagementHome";
mejb.remote = "javax.management.j2ee.Management";
mejb.parents.add(deployer.ejbClass);
mejb.transactionType = "CONTAINER";
mejb.concurrencyType = "CONTAINER";
mejb.containerId = singletonContainerId;
ejbJarInfo.enterpriseBeans.add(mejb);
for (final EnterpriseBeanInfo ebi : ejbJarInfo.enterpriseBeans) {
final MethodInfo methodInfo = new MethodInfo();
methodInfo.ejbDeploymentId = ebi.ejbDeploymentId;
methodInfo.ejbName = ebi.ejbName;
methodInfo.methodName = "*";
methodInfo.className = ebi.ejbClass;
final MethodConcurrencyInfo methodConcurrencyInfo = new MethodConcurrencyInfo();
methodConcurrencyInfo.concurrencyAttribute = "READ";
methodConcurrencyInfo.methods.add(methodInfo);
ejbJarInfo.methodConcurrency.add(methodConcurrencyInfo);
}
final CallbackInfo callbackInfo = new CallbackInfo();
callbackInfo.className = "org.apache.openejb.security.internal.InternalSecurityInterceptor";
callbackInfo.method = "invoke";
final InterceptorInfo interceptorInfo = new InterceptorInfo();
interceptorInfo.clazz = "org.apache.openejb.security.internal.InternalSecurityInterceptor";
interceptorInfo.aroundInvoke.add(callbackInfo);
ejbJarInfo.interceptors.add(interceptorInfo);
final InterceptorBindingInfo interceptorBindingInfo = new InterceptorBindingInfo();
interceptorBindingInfo.ejbName = "*";
interceptorBindingInfo.interceptors.add("org.apache.openejb.security.internal.InternalSecurityInterceptor");
ejbJarInfo.interceptorBindings.add(interceptorBindingInfo);
ejbJarInfo.mbeans.add("org.apache.openejb.assembler.monitoring.JMXDeployer");
// we start at 1 so no conflict using 0
ejbJarInfo.uniqueId = "0";
final AppInfo appInfo = new AppInfo();
appInfo.appId = ejbJarInfo.moduleId;
appInfo.path = appInfo.appId;
appInfo.ejbJars.add(ejbJarInfo);
return appInfo;
}
use of org.apache.openejb.assembler.classic.EnterpriseBeanInfo in project tomee by apache.
the class AutoConfigResourceRefsTest method testCaseInsensitive.
public void testCaseInsensitive() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("DeFAultDataSource", "DataSource", null), ResourceInfo.class));
assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("YeLLowDataSource", "DataSource", null), ResourceInfo.class));
assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("PurpLEDataSource", "DataSource", null), ResourceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
final Map<String, ResourceReferenceInfo> refs = new HashMap<String, ResourceReferenceInfo>();
for (final ResourceReferenceInfo ref : beanInfo.jndiEnc.resourceRefs) {
refs.put(ref.referenceName.replaceAll(".*/", ""), ref);
}
ResourceReferenceInfo info;
info = refs.get("yellowDataSource");
assertNotNull(info);
assertEquals("YeLLowDataSource", info.resourceID);
info = refs.get("orangeDataSource");
assertNotNull(info);
assertEquals("DeFAultDataSource", info.resourceID);
info = refs.get("purpleDataSource");
assertNotNull(info);
assertEquals("PurpLEDataSource", info.resourceID);
}
Aggregations