Search in sources :

Example 1 with DSNCreator

use of org.nhindirect.gateway.smtp.dsn.DSNCreator in project nhin-d by DirectProject.

the class AbstractNotificationAwareMailet method createDSNGenerator.

/**
	 * Creates the DSNCreator object
	 * @param initModules The initial Guice modules created by the init() method
	 */
protected void createDSNGenerator(final Collection<Module> initModules) {
    Collection<Module> modules = initModules;
    // attempt to use the existing modules first
    final boolean usingDefaultMoudles = (modules == null);
    if (modules == null) {
        // create a default module
        final Provider<DSNCreator> provider = getDSNProvider();
        if (provider == null)
            return;
        final DSNCreatorProviderModule module = DSNCreatorProviderModule.create(provider);
        modules = Arrays.asList((Module) module);
    }
    Injector dsnInjector = Guice.createInjector(modules);
    try {
        dsnCreator = dsnInjector.getInstance(DSNCreator.class);
    } catch (Exception e) {
        ///CLOVER:OFF
        LOGGER.debug("First attempt to create DSNCreator failed.", e);
        if (!usingDefaultMoudles)
            LOGGER.debug("Will attempt to create from default DSNCreator from Guice module.");
        else
            LOGGER.warn("DSNCreator already attempted to use the defualt DSNCreator Guice module.  DSN creation will be disabled.");
    ///CLOVER:ON
    }
    // try again using the default Guice module
    if (dsnCreator == null && !usingDefaultMoudles) {
        try {
            // create a default module
            final Provider<DSNCreator> provider = getDSNProvider();
            if (provider == null)
                return;
            final DSNCreatorProviderModule module = DSNCreatorProviderModule.create(provider);
            modules = Arrays.asList((Module) module);
            dsnInjector = Guice.createInjector(modules);
            dsnCreator = dsnInjector.getInstance(DSNCreator.class);
        }///CLOVER:OFF
         catch (Exception e) {
            LOGGER.warn("Failed to create DSNCreator.  DSN creation will be disabled.");
        }
    ///CLOVER:ON
    }
}
Also used : Injector(com.google.inject.Injector) DSNCreator(org.nhindirect.gateway.smtp.dsn.DSNCreator) Module(com.google.inject.Module) DefaultTxDetailParserModule(org.nhindirect.common.tx.module.DefaultTxDetailParserModule) ProviderTxServiceModule(org.nhindirect.common.tx.module.ProviderTxServiceModule) DSNCreatorProviderModule(org.nhindirect.gateway.smtp.dsn.module.DSNCreatorProviderModule) DSNCreatorProviderModule(org.nhindirect.gateway.smtp.dsn.module.DSNCreatorProviderModule) MessagingException(javax.mail.MessagingException)

Aggregations

Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 MessagingException (javax.mail.MessagingException)1 DefaultTxDetailParserModule (org.nhindirect.common.tx.module.DefaultTxDetailParserModule)1 ProviderTxServiceModule (org.nhindirect.common.tx.module.ProviderTxServiceModule)1 DSNCreator (org.nhindirect.gateway.smtp.dsn.DSNCreator)1 DSNCreatorProviderModule (org.nhindirect.gateway.smtp.dsn.module.DSNCreatorProviderModule)1