use of com.ibm.designer.domino.napi.NotesDatabase in project org.openntf.xsp.jakartaee by OpenNTF.
the class OSGiServletBeanArchiveHandler method handle.
@Override
public BeanArchiveBuilder handle(String beanArchiveReference) {
try {
Bundle bundle = PROCESSING_BUNDLE.get();
if (bundle == null) {
NotesDatabase database = ContextInfo.getServerDatabase();
if (database != null) {
String bundleName = ContainerUtil.getApplicationCDIBundle(database);
if (StringUtil.isNotEmpty(bundleName)) {
bundle = LibraryUtil.getBundle(bundleName).orElse(null);
} else {
bundleName = ContainerUtil.getApplicationCDIBundleBase(database);
if (StringUtil.isNotEmpty(bundleName)) {
bundle = LibraryUtil.getBundle(bundleName).orElse(null);
}
}
}
}
if (bundle != null) {
String symbolicName = bundle.getSymbolicName();
// Slightly customize the builder to keep some extra metadata
BeanArchiveBuilder builder = new BeanArchiveBuilder() {
{
super.setBeansXml(BeansXml.EMPTY_BEANS_XML);
super.setId(symbolicName);
}
@Override
public BeanArchiveBuilder setBeansXml(BeansXml beansXml) {
return this;
}
};
return builder;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of com.ibm.designer.domino.napi.NotesDatabase 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.designer.domino.napi.NotesDatabase 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.designer.domino.napi.NotesDatabase in project org.openntf.nsfodp by OpenNTF.
the class DarwinoNCompositeData method writeJavaScriptLibraryData.
@Override
public void writeJavaScriptLibraryData(OutputStream os) throws IOException {
try {
// TODO figure out why the Darwino implementation chops data
// https://github.com/OpenNTF/org.openntf.nsfodp/issues/271
// this.data.writeJavaScriptLibraryData(os);
long dbHandle = this.note.getParent().getHandle();
NotesSession notesSession = new NotesSession();
try {
NotesDatabase notesDatabase = notesSession.getDatabase((int) dbHandle);
NotesNote notesNote = notesDatabase.openNote(this.note.getNoteID(), 0);
FileAccess.readFileContent(notesNote, os);
} finally {
notesSession.recycle();
}
} catch (NotesAPIException e) {
throw new NDominoException(e.getNativeErrorCode(), e);
} catch (DominoException e) {
throw new NDominoException(e.getStatus(), e);
}
}
Aggregations