appPrefix = webApp.contextRoot; // if multiple application classes reinit it
if (!appPrefix.endsWith("/")) {
appPrefix += "/";
}
Application appInstance;
Class<?> appClazz;
try {
appClazz = classLoader.loadClass(app);
appInstance = Application.class.cast(appClazz.newInstance());
} catch (Exception e) {
throw new OpenEJBRestRuntimeException("can't create class " + app, e);
}
ApplicationPath path = appClazz.getAnnotation(ApplicationPath.class);
if (path != null) {
String appPath = path.value();
if (appPath.startsWith("/")) {
appPrefix += appPath.substring(1);
} else {
appPrefix += appPath;
}
}
Set<Object> singletons = appInstance.getSingletons();
for (Object o : singletons) {
if (o == null) {
continue;
}
if (restEjbs.containsKey(o.getClass().getName())) {
// no more a singleton if the ejb i not a singleton...but it is a weird case
deployEJB(appPrefix, restEjbs.get(o.getClass().getName()).context);
} else {
deploySingleton(appPrefix, o, appInstance, classLoader);
}
}
Set<Class<?>> classes = appInstance.getClasses();
for (Class<?> clazz : classes) {
if (restEjbs.containsKey(clazz.getName())) {
deployEJB(appPrefix, restEjbs.get(clazz.getName()).context);
} else {
deployPojo(appPrefix, clazz, appInstance, classLoader, injections, context, owbCtx);