public T doBundle(ModuleDescriptor bundle) throws Exception;
}
private ExtendedDeploymentContext subContext(final Application application, final DeploymentContext context, final String moduleUri) {
ExtendedDeploymentContext moduleContext = ((ExtendedDeploymentContext)context).getModuleDeploymentContexts().get(moduleUri);
if (moduleContext != null) {
return moduleContext;
}
final ReadableArchive subArchive;
try {
subArchive = context.getSource().getSubArchive(moduleUri);
subArchive.setParentArchive(context.getSource());
} catch(IOException ioe) {
deplLogger.log(Level.WARNING,
ERROR_OCCURRED,
ioe);
return null;
}
final Properties moduleProps =
getModuleProps(context, moduleUri);
ActionReport subReport =
context.getActionReport().addSubActionsReport();
moduleContext = new DeploymentContextImpl(subReport, context.getSource(),
context.getCommandParameters(OpsParams.class), env) {
@Override
public ClassLoader getClassLoader() {
try {
if (context.getClassLoader() == null) {
return null;
}
EarClassLoader appCl = EarClassLoader.class.cast(context.getClassLoader());
if (((ExtendedDeploymentContext)context).
getPhase() == Phase.PREPARE) {
return appCl;
} else {
return appCl.getModuleClassLoader(moduleUri);
}
} catch (ClassCastException e) {
return context.getClassLoader();
}
}
@Override
public ClassLoader getFinalClassLoader() {
try {
EarClassLoader finalEarCL = (EarClassLoader) context.getFinalClassLoader();
return finalEarCL.getModuleClassLoader(moduleUri);
} catch (ClassCastException e) {
return context.getClassLoader();
}
}
@Override
public ReadableArchive getSource() {
return subArchive;
}
@Override
public Properties getAppProps() {
return context.getAppProps();
}
@Override
public <U extends OpsParams> U getCommandParameters(Class<U> commandParametersType) {
return context.getCommandParameters(commandParametersType);
}
@Override
public void addTransientAppMetaData(String metaDataKey,
Object metaData) {
context.addTransientAppMetaData(metaDataKey,
metaData);
}
@Override
public <T> T getTransientAppMetaData(String metaDataKey,
Class<T> metadataType) {
return context.getTransientAppMetaData(metaDataKey,
metadataType);
}
@Override
public Properties getModuleProps() {
return moduleProps;
}
@Override
public ReadableArchive getOriginalSource() {
try {
File appRoot = context.getSourceDir();
File origModuleFile = new File(appRoot, moduleUri);
return archiveFactory.openArchive(
origModuleFile);
} catch (IOException ioe) {
return null;
}
}
@Override
public File getScratchDir(String subDirName) {
String modulePortion = Util.getURIName(
getSource().getURI());
return (new File(super.getScratchDir(subDirName),
modulePortion));
}
@Override
public <T> T getModuleMetaData(Class<T> metadataType) {
try {
return metadataType.cast(application.getModuleByUri(moduleUri));
} catch (Exception e) {
// let's first try the extensions mechanisms...
if (RootDeploymentDescriptor.class.isAssignableFrom(metadataType)) {
for (RootDeploymentDescriptor extension : application.getModuleByUri(moduleUri).getExtensionsDescriptors((Class<RootDeploymentDescriptor>) metadataType)) {
// we assume there can only be one type of
if (extension!=null) {
try {
return metadataType.cast(extension);
} catch (Exception e1) {
// next one...
}
}
}
}
return context.getModuleMetaData(metadataType);
}
}
};
((ExtendedDeploymentContext)context).getModuleDeploymentContexts().put(moduleUri, moduleContext);
moduleContext.setParentContext((ExtendedDeploymentContext)context);
moduleContext.setModuleUri(moduleUri);
ArchiveHandler subHandler = context.getModuleArchiveHandlers().get(moduleUri);
moduleContext.setArchiveHandler(subHandler);
return moduleContext;
}