use of com.ibm.xsp.application.ApplicationEx in project org.openntf.xsp.jakartaee by OpenNTF.
the class NSFCDIProvider method getCDI.
@SuppressWarnings("unchecked")
@Override
public synchronized CDI<Object> getCDI() {
CDI<Object> result = null;
CDIContainerUtility util = LibraryUtil.findRequiredExtension(CDIContainerUtility.class);
String databasePath = util.getThreadContextDatabasePath();
if (StringUtil.isNotEmpty(databasePath)) {
try {
NotesSession session = new NotesSession();
try {
NotesDatabase database = session.getDatabase(databasePath);
if (database != null) {
database.open();
try {
result = (CDI<Object>) util.getContainer(database);
} finally {
database.recycle();
}
}
} finally {
session.recycle();
}
} catch (Throwable t) {
t.printStackTrace();
}
}
if (result != null) {
return result;
}
ApplicationEx application = ApplicationEx.getInstance();
if (application != null) {
result = (CDI<Object>) util.getContainer(application);
}
if (result != null) {
return result;
}
try {
NotesDatabase database = ContextInfo.getServerDatabase();
if (database != null) {
result = (CDI<Object>) util.getContainer(database);
}
} catch (Throwable t) {
t.printStackTrace();
}
if (result != null) {
return result;
}
// Check in any available locator extensions
List<CDIContainerLocator> locators = LibraryUtil.findExtensions(CDIContainerLocator.class);
NotesSession session = new NotesSession();
try {
for (CDIContainerLocator locator : locators) {
String nsfPath = locator.getNsfPath();
if (StringUtil.isNotEmpty(nsfPath)) {
try {
NotesDatabase database = session.getDatabaseByPath(nsfPath);
try {
database.open();
result = (CDI<Object>) util.getContainer(database);
if (result != null) {
return result;
}
} finally {
if (database != null) {
database.recycle();
}
}
} catch (NotesAPIException | IOException e) {
// Log and move on
e.printStackTrace();
}
}
String bundleId = locator.getBundleId();
if (StringUtil.isNotEmpty(bundleId)) {
Optional<Bundle> bundle = LibraryUtil.getBundle(bundleId);
if (bundle.isPresent()) {
return (CDI<Object>) util.getContainer(bundle.get());
}
}
}
} finally {
try {
session.recycle();
} catch (NotesAPIException e) {
// Ignore
}
}
return null;
}
use of com.ibm.xsp.application.ApplicationEx in project org.openntf.xsp.jakartaee by OpenNTF.
the class NSFCdiInjectorFactory method lookupBeanManager.
@Override
@SuppressWarnings("nls")
protected BeanManager lookupBeanManager() {
ApplicationEx application = ApplicationEx.getInstance();
if (application != null) {
return ContainerUtil.getBeanManager(application);
}
NotesContext ctx = NotesContext.getCurrentUnchecked();
if (ctx != null) {
try {
NotesDatabase database = ctx.getNotesDatabase();
if (database != null) {
return ContainerUtil.getBeanManager(database);
}
} catch (NotesAPIException e) {
throw new RuntimeException(e);
}
}
throw new IllegalStateException("Unable to locate active application!");
}
use of com.ibm.xsp.application.ApplicationEx in project org.openntf.domino by OpenNTF.
the class FormulaContextXsp method getValueBinding.
/**
* Create a value binding for {@link #getField(String)} and {@link #setField(String, ValueHolder)}
*
* @param variable
* the variableName, like <code>"document2.Form"</code>
* @return a {@link ValueBinding}
*/
protected ValueBinding getValueBinding(final String variable) {
ValueBinding ret = valueBindings.get(variable);
if (ret == null) {
ApplicationEx app = (ApplicationEx) context.getApplication();
// $NON-NLS-1$ //$NON-NLS-2$
ret = app.createValueBinding("#{" + variable + "}");
if ((ret instanceof ValueBindingEx)) {
ValueBindingEx valueEx = (ValueBindingEx) ret;
valueEx.setComponent(component);
// TODO RPr: What to set here
valueEx.setSourceReferenceId(null);
valueEx.setExpectedType(Object.class);
} else if ((ret instanceof ComponentBindingObject)) {
((ComponentBindingObject) ret).setComponent(component);
}
valueBindings.put(variable, ret);
}
return ret;
}
use of com.ibm.xsp.application.ApplicationEx in project org.openntf.xsp.jakartaee by OpenNTF.
the class AbstractXspLifecycleServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setBufferSize(0);
initializeSessionAsSigner();
FacesContext facesContext = null;
try {
if (!initialized) {
// initialization has do be done after NotesContext is initialized with session to support SessionAsSigner operations
doInit(config);
initialized = true;
}
facesContext = getFacesContext(request, response);
FacesContextEx exc = (FacesContextEx) facesContext;
ApplicationEx application = exc.getApplicationEx();
this.doService(request, response, application);
} catch (NoAccessSignal t) {
throw t;
} catch (Throwable t) {
try (PrintWriter w = response.getWriter()) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
XSPErrorPage.handleException(w, t, request.getRequestURL().toString(), false);
} catch (javax.servlet.ServletException e) {
throw new IOException(e);
} catch (IllegalStateException e) {
// Happens when the writer or output has already been opened
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} finally {
if (facesContext != null) {
releaseContext(facesContext);
}
}
}
use of com.ibm.xsp.application.ApplicationEx in project org.openntf.domino by OpenNTF.
the class OpenntfDominoImplicitObjectFactory method createImplicitObjects.
/**
* Creates the "cheap" objects
*/
@Override
public void createImplicitObjects(final FacesContextEx ctx) {
if (!implicitsDone_) {
implicitsDone_ = true;
if (!ODAPlatform.isAPIEnabled(null))
return;
Session session = Factory.getSession(SessionType.CURRENT);
Database db = session.getCurrentDatabase();
Map<String, Object> ecMap = TypedUtil.getRequestMap(ctx.getExternalContext());
// $NON-NLS-1$
ecMap.put("openSession", session);
// $NON-NLS-1$
ecMap.put("openDatabase", db);
// Attach NSA
if (ODAPlatform.isAppFlagSet("nsa")) {
// $NON-NLS-1$
Application app = ctx.getApplication();
if (app instanceof ApplicationEx) {
NSA.INSTANCE.registerApplication((ApplicationEx) app);
NSA.INSTANCE.registerSession((ApplicationEx) app, (HttpSession) ctx.getExternalContext().getSession(true));
}
}
}
}
Aggregations