// Gets URL of the archive
final URL url;
try {
url = getArchive().getURL();
} catch (ArchiveException e) {
throw new EZBContainerException("Cannot get URL on the archive '" + getName() + "'.", e);
}
final ClassLoader old = Thread.currentThread().getContextClassLoader();
// Define classloader if it was not yet defined (ear case -->
// classloader already set)
if (this.classLoader == null) {
PrivilegedAction<EasyBeansClassLoader> privilegedAction = new PrivilegedAction<EasyBeansClassLoader>() {
public EasyBeansClassLoader run() {
return new EasyBeansClassLoader(new URL[] {url}, old);
}
};
this.classLoader = AccessController.doPrivileged(privilegedAction);
}
// FIXME keep resolve ? keep classloader ?
// Resolve deployment stuff if not already done
if (!this.resolved) {
resolve();
}
try {
Thread.currentThread().setContextClassLoader(this.classLoader);
Enhancer enhancer = new Enhancer(this.classLoader, this.deployment.getEjbJarArchiveMetadata(), this.enhancerMap);
long tStartEnhancing = System.currentTimeMillis();
try {
enhancer.enhance();
} catch (EnhancerException ee) {
throw new EZBContainerException("Cannot run enhancer on archive '" + getName() + "'.", ee);
} catch (RuntimeException e) {
// Catch Exception as some exceptions can be runtime exception
throw new EZBContainerException("Cannot run enhancer on archive '" + getName() + "'.", e);
}
if (logger.isDebugEnabled()) {
logger.debug("Enhancement elapsed during : " + (System.currentTimeMillis() - tStartEnhancing) + " ms");
}
// Check if there is META-INF/persistence.xml file
PersistenceUnitManager analyzedPersistenceUnitManager = null;
try {
JPersistenceUnitInfo[] persistenceUnitInfos =
PersistenceXmlFileAnalyzer.analyzePersistenceXmlFile(getArchive());
// Dispatch life cycle event.
this.dispatcher.dispatch(new EventContainerStarting(this.j2eeManagedObjectId, getArchive(),
persistenceUnitInfos, this.configuration));
if (persistenceUnitInfos != null) {
analyzedPersistenceUnitManager =
PersistenceXmlFileAnalyzer.loadPersistenceProvider(persistenceUnitInfos, getClassLoader());
}
} catch (PersistenceXmlFileAnalyzerException e) {
throw new EZBContainerException("Cannot analyze the persistence.xml file in the archive", e);
}
// No previous manager
if (this.persistenceUnitManager == null) {
this.persistenceUnitManager = analyzedPersistenceUnitManager;
} else {
// merge old and new.
if (analyzedPersistenceUnitManager != null) {
analyzedPersistenceUnitManager.merge(this.persistenceUnitManager);
// update persistence manager with the merged one.
this.persistenceUnitManager = analyzedPersistenceUnitManager;
}
}
// Create Beans Factories
createBeanFactories();
// cleanup
this.deployment.reset();
enhancer = null;
} finally {
Thread.currentThread().setContextClassLoader(old);
}
// Send notification to callbacks
if (getCallbacksLifeCycle().size() > 0) {
EZBContainerCallbackInfo info = getContainer3CallbackInfo();
for (EZBContainerLifeCycleCallback callback : getCallbacksLifeCycle()) {
try {
callback.start(info);
} catch (Throwable t) {
// Protection from malicious code
logger.error("{0}.start() failed", callback.getClass().getName(), t);
}
}
}
try {
MBeansHelper.getInstance().registerMBean(this);
} catch (MBeansException e) {
// TODO what to do here ? log or exception ?
logger.error("Cannot register Container MBeans for " + getArchive().getName(), e);
}
// Register resolver
getEmbedded().getJNDIResolver().addContainerResolver(this.configuration.getContainerJNDIResolver());
// Start factories
// TODO: apply an order for singletons
for (Factory<?, ?> factory : this.factories.values()) {
try {
factory.start();
} catch (FactoryException e) {
throw new EZBContainerException("Cannot start the given factory '" + factory + "'", e);
}
}
// Display infos
if (logger.isInfoEnabled()) {