Java Code Examples for com.google.inject.util.Providers

The following are top voted examples for showing how to use com.google.inject.util.Providers. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: rotabuilder   File: DomainApplication.java   Source Code and License 6 votes vote down vote up
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module overrides = new AbstractModule() {
        @Override
        protected void configure() {
            bind(ComponentFactoryRegistrar.class).to(MyComponentFactoryRegistrar.class);

            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("RotaBuilder");
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("RotaBuilder");
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(
                    Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
            // if uncommented, then overrides isis.appManifest in config file.
            // bind(AppManifest.class).toInstance(new DomainAppAppManifest());
        }
    };

    return Modules.override(isisDefaults).with(overrides);
}
 
Example 2
Project: Proyecto2017Seguros   File: PacinetesApplication.java   Source Code and License 6 votes vote down vote up
@Override
 protected Module newIsisWicketModule() {
     final Module isisDefaults = super.newIsisWicketModule();
     
     final Module overrides = new AbstractModule() {
         @Override
         protected void configure() {
             bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("SiGeSe");
             bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
             bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
	bind(String.class).annotatedWith(Names.named("brandLogoSignin")).toInstance("/about/images/login.png");
	bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
	bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("SiGeSe");
	bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
}
     };

     return Modules.override(isisDefaults).with(overrides);
 }
 
Example 3
Project: gossip   File: Formatter.java   Source Code and License 6 votes vote down vote up
Formatter(final String pattern) {
    final List<String> patterns = Splitter.on(VAR_BEGIN).omitEmptyStrings().splitToList(pattern);

    patterns.forEach(pt -> {
        if (!pt.contains(VAR_END)) {
            appenderList.add(Providers.of(pt));
        } else {
            StringTokenizer token = new StringTokenizer(pt, VAR_END);
            String guiceKey = token.nextToken();
            String rawString = null;
            if (token.hasMoreTokens()) {
                rawString = token.nextToken();
            }
            final KeyResolver resolver = new KeyResolver(guiceKey);
            appenderList.add(resolver);
            resolvers.add(resolver);
            appenderList.add(Providers.of(rawString));
        }
    });
}
 
Example 4
Project: isis-agri   File: DomainApplication.java   Source Code and License 6 votes vote down vote up
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module overrides = new AbstractModule() {
        @Override
        protected void configure() {
            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("Food App");
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("Food App");
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(
                    Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
            // if uncommented, then overrides isis.appManifest in config file.
            // bind(AppManifest.class).toInstance(new DomainAppAppManifest());
        }
    };

    return Modules.override(isisDefaults).with(overrides);
}
 
Example 5
Project: riposte-microservice-template   File: AppServerConfigTest.java   Source Code and License 6 votes vote down vote up
@Test
public void constructor_does_not_blow_up_if_metricsListener_is_null() {
    // given
    AppServerConfig asc = new AppServerConfig(configForTesting) {
        @Override
        protected List<Module> getAppGuiceModules(Config appConfig) {
            return Arrays.asList(
                Modules.override(new AppGuiceModule(appConfig)).with(
                    binder -> binder
                        .bind(new TypeLiteral<CodahaleMetricsListener>() {})
                        .toProvider(Providers.of(null))),
                new BackstopperRiposteConfigGuiceModule()
            );
        }
    };

    // expect
    assertThat(asc.metricsListener()).isNull();
}
 
Example 6
Project: ecpcrm   File: EcpCrmApplication.java   Source Code and License 6 votes vote down vote up
@Override
    protected Module newIsisWicketModule() {
        final Module isisDefaults = super.newIsisWicketModule();
        
        final Module overrides = new AbstractModule() {
            @Override
            protected void configure() {

                bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("ECP CRM");
                bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
                bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
//                bind(String.class).annotatedWith(Names.named("brandLogoHeader")).toInstance("/images/domainapp-logo-header.png");
//                bind(String.class).annotatedWith(Names.named("brandLogoSignin")).toInstance("/images/domainapp-logo-signin.png");
                bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
                bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("ECP CRM");
                bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
            }
        };

        return Modules.override(isisDefaults).with(overrides);
    }
 
Example 7
Project: guice-persist-neo4j   File: Neo4jPersistModule.java   Source Code and License 6 votes vote down vote up
protected void configurePersistence() {
	bind(String[].class).annotatedWith(Neo4j.class).toInstance(packages);

	if (null != properties) {
		bind(Properties.class).annotatedWith(Neo4j.class).toInstance(properties);
	} else {
		bind(Properties.class).annotatedWith(Neo4j.class).toProvider(Providers.of(null));
	}

	bind(Neo4jPersistService.class).in(Singleton.class);
	bind(PersistService.class).to(Neo4jPersistService.class);
	bind(UnitOfWork.class).to(Neo4jPersistService.class);
	bind(Session.class).toProvider(Neo4jPersistService.class);

	transactionInterceptor = new Neo4jLocalTxnInterceptor();
	requestInjection(transactionInterceptor);
}
 
Example 8
Project: salta   File: Jsr330Test.java   Source Code and License 6 votes vote down vote up
public void testGuicify330Provider() {
    Provider<String> jsr330Provider = new Provider<String>() {
        @Override
        public String get() {
            return "A";
        }

        @Override
        public String toString() {
            return "jsr330Provider";
        }
    };

    com.google.inject.Provider<String> guicified = Providers
            .guicify(jsr330Provider);
    assertEquals("guicified(jsr330Provider)", guicified.toString());
    assertEquals("A", guicified.get());

    // when you guicify the Guice-friendly, it's a no-op
    assertSame(guicified, Providers.guicify(guicified));

}
 
Example 9
Project: salta   File: ProvisionListenerTest.java   Source Code and License 6 votes vote down vote up
public void testBindToInjectorWithListeningGivesSaneException() {
    try {
        Guice.createInjector(new AbstractModule() {
            @Override
            protected void configure() {
                bindListener(Matchers.any(), new Counter());
                bind(Injector.class)
                        .toProvider(Providers.<Injector> of(null));
            }
        });
        fail();
    } catch (SaltaException ce) {
        assertContains(ce.getMessage(),
                "Binding to core guice framework type is not allowed: Injector.");
    }
}
 
Example 10
Project: salta   File: BinderTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testBindingToProvider() {
    try {
        Guice.createInjector(new AbstractModule() {
            @Override
            protected void configure() {
                bind(new TypeLiteral<Provider<String>>() {
                }).toInstance(Providers.of("A"));
            }
        });
        fail();
    } catch (SaltaException expected) {
        assertContains(expected.getMessage(),
                "Binding to core guice framework type is not allowed: Provider.");
    }
}
 
Example 11
Project: salta   File: BinderTest.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
    bind(AbstractModule.class).annotatedWith(red)
            .toProvider(Providers.<AbstractModule> of(null));
    bind(Binder.class).annotatedWith(red)
            .toProvider(Providers.<Binder> of(null));
    bind(Binding.class).annotatedWith(red)
            .toProvider(Providers.<Binding> of(null));
    bind(Injector.class).annotatedWith(red)
            .toProvider(Providers.<Injector> of(null));
    bind(Key.class).annotatedWith(red)
            .toProvider(Providers.<Key> of(null));
    bind(Module.class).annotatedWith(red)
            .toProvider(Providers.<Module> of(null));
    bind(Provider.class).annotatedWith(red)
            .toProvider(Providers.<Provider> of(null));
    bind(Scope.class).annotatedWith(red)
            .toProvider(Providers.<Scope> of(null));
    bind(Stage.class).annotatedWith(red)
            .toProvider(Providers.<Stage> of(null));
    bind(TypeLiteral.class).annotatedWith(red)
            .toProvider(Providers.<TypeLiteral> of(null));
    bind(new TypeLiteral<Key<String>>() {
    }).toProvider(Providers.<Key<String>> of(null));
}
 
Example 12
Project: keywhiz   File: CliModule.java   Source Code and License 6 votes vote down vote up
@Override protected void configure() {
  bind(CliConfiguration.class).toInstance(config);

  bind(JCommander.class).annotatedWith(Names.named("ParentCommander"))
      .toInstance(parentCommander);

  if (commander == null) {
    bind(JCommander.class).annotatedWith(Names.named("Commander"))
        .toProvider(Providers.of((JCommander) null));
    bind(String.class).annotatedWith(Names.named("Command"))
        .toProvider(Providers.of((String) null));
  } else {
    bind(JCommander.class).annotatedWith(Names.named("Commander")).toInstance(commander);
    bindConstant().annotatedWith(Names.named("Command")).to(command);
  }

  bind(Map.class).annotatedWith(Names.named("CommandMap")).toInstance(commands);
}
 
Example 13
Project: isis-app-quickstart   File: DomainApplication.java   Source Code and License 6 votes vote down vote up
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module overrides = new AbstractModule() {
        @Override
        protected void configure() {

            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("Domain App");
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("brandLogoHeader")).toInstance("/images/domainapp-logo-header.png");
            bind(String.class).annotatedWith(Names.named("brandLogoSignin")).toInstance("/images/domainapp-logo-signin.png");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("Domain App");
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
        }
    };

    return Modules.override(isisDefaults).with(overrides);
}
 
Example 14
Project: isis-app-simpledsl   File: DomainApplication.java   Source Code and License 6 votes vote down vote up
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module overrides = new AbstractModule() {
        @Override
        protected void configure() {
            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("Simple App");
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("Simple App");
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(
                    Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
            // if uncommented, then overrides isis.appManifest in config file.
            // bind(AppManifest.class).toInstance(new DomainAppAppManifest());
        }
    };

    return Modules.override(isisDefaults).with(overrides);
}
 
Example 15
Project: TarjetasISIS   File: SimpleApplication.java   Source Code and License 6 votes vote down vote up
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module overrides = new AbstractModule() {
        @Override
        protected void configure() {
            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance(" Mejorar ");
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance(" Mejorar ");
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
        }
    };

    return Modules.override(isisDefaults).with(overrides);
}
 
Example 16
Project: isis-app-todoapp   File: ToDoApplication.java   Source Code and License 6 votes vote down vote up
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module overrides = new AbstractModule() {
        @Override
        protected void configure() {

            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("ToDo App");
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("brandLogoHeader")).toInstance("/images/todoapp-logo-header.png");
            bind(String.class).annotatedWith(Names.named("brandLogoSignin")).toInstance("/images/todoapp-logo-signin.png");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("ToDo App");
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
        }
    };

    return Modules.override(isisDefaults).with(overrides);
}
 
Example 17
Project: presto   File: BackupModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void setup(Binder binder)
{
    configBinder(binder).bindConfig(BackupConfig.class);

    String provider = buildConfigObject(BackupConfig.class).getProvider();
    if (provider == null) {
        binder.bind(BackupStore.class).toProvider(Providers.of(null));
    }
    else {
        Module module = providers.get(provider);
        if (module == null) {
            binder.addError("Unknown backup provider: %s", provider);
        }
        else {
            binder.install(module);
        }
    }
    binder.bind(BackupService.class).to(BackupServiceManager.class).in(Scopes.SINGLETON);
}
 
Example 18
Project: isis-app-petclinic   File: PetClinicApplication.java   Source Code and License 6 votes vote down vote up
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module overrides = new AbstractModule() {
        @Override
        protected void configure() {
            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("Simple App");
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("Simple App");
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
        }
    };

    return Modules.override(isisDefaults).with(overrides);
}
 
Example 19
Project: gerrit   File: Init.java   Source Code and License 6 votes vote down vote up
@Override
protected void afterInit(SiteRun run) throws Exception {
  List<Module> modules = new ArrayList<>();
  modules.add(
      new AbstractModule() {
        @Override
        protected void configure() {
          bind(Path.class).annotatedWith(SitePath.class).toInstance(getSitePath());
          bind(Browser.class);
          bind(String.class)
              .annotatedWith(SecureStoreClassName.class)
              .toProvider(Providers.of(getConfiguredSecureStoreClass()));
        }
      });
  modules.add(new GerritServerConfigModule());
  Guice.createInjector(modules).injectMembers(this);
  start(run);
}
 
Example 20
Project: gerrit   File: Passwd.java   Source Code and License 6 votes vote down vote up
private Injector getSysInjector() {
  List<Module> modules = new ArrayList<>();
  modules.add(
      new FactoryModule() {
        @Override
        protected void configure() {
          bind(Path.class).annotatedWith(SitePath.class).toInstance(getSitePath());
          bind(ConsoleUI.class).toInstance(ConsoleUI.getInstance(password != null));
          factory(Section.Factory.class);
          bind(Boolean.class).annotatedWith(InstallAllPlugins.class).toInstance(Boolean.FALSE);
          bind(new TypeLiteral<List<String>>() {})
              .annotatedWith(InstallPlugins.class)
              .toInstance(new ArrayList<String>());
          bind(String.class)
              .annotatedWith(SecureStoreClassName.class)
              .toProvider(Providers.of(getConfiguredSecureStoreClass()));
        }
      });
  modules.add(new GerritServerConfigModule());
  return Guice.createInjector(modules);
}
 
Example 21
Project: gerrit   File: InProcessProtocol.java   Source Code and License 6 votes vote down vote up
Context(
    SchemaFactory<ReviewDb> schemaFactory,
    IdentifiedUser.GenericFactory userFactory,
    Account.Id accountId,
    Project.NameKey project) {
  this.schemaFactory = schemaFactory;
  this.userFactory = userFactory;
  this.accountId = accountId;
  this.project = project;
  map = new HashMap<>();
  cleanup = new RequestCleanup();
  map.put(DB_KEY, new RequestScopedReviewDbProvider(schemaFactory, Providers.of(cleanup)));
  map.put(RC_KEY, cleanup);

  IdentifiedUser user = userFactory.create(accountId);
  user.setAccessPath(AccessPath.GIT);
  map.put(USER_KEY, user);
}
 
Example 22
Project: gerrit   File: GuiceRequestScopePropagator.java   Source Code and License 6 votes vote down vote up
/** @see RequestScopePropagator#wrap(Callable) */
// ServletScopes#continueRequest is deprecated, but it's not obvious their
// recommended replacement is an appropriate drop-in solution; see
// https://gerrit-review.googlesource.com/83971
@SuppressWarnings("deprecation")
@Override
protected <T> Callable<T> wrapImpl(Callable<T> callable) {
  Map<Key<?>, Object> seedMap = new HashMap<>();

  // Request scopes appear to use specific keys in their map, instead of only
  // providers. Add bindings for both the key to the instance directly and the
  // provider to the instance to be safe.
  seedMap.put(Key.get(typeOfProvider(String.class), CanonicalWebUrl.class), Providers.of(url));
  seedMap.put(Key.get(String.class, CanonicalWebUrl.class), url);

  seedMap.put(Key.get(typeOfProvider(SocketAddress.class), RemotePeer.class), Providers.of(peer));
  seedMap.put(Key.get(SocketAddress.class, RemotePeer.class), peer);

  return ServletScopes.continueRequest(callable, seedMap);
}
 
Example 23
Project: gerrit   File: IdentifiedUser.java   Source Code and License 6 votes vote down vote up
/**
 * Returns a materialized copy of the user with all dependencies.
 *
 * <p>Invoke all providers and factories of dependent objects and store the references to a copy
 * of the current identified user.
 *
 * @return copy of the identified user
 */
public IdentifiedUser materializedCopy() {
  Provider<SocketAddress> remotePeer;
  try {
    remotePeer = Providers.of(remotePeerProvider.get());
  } catch (OutOfScopeException | ProvisionException e) {
    remotePeer =
        new Provider<SocketAddress>() {
          @Override
          public SocketAddress get() {
            throw e;
          }
        };
  }
  return new IdentifiedUser(
      authConfig,
      realm,
      anonymousCowardName,
      Providers.of(canonicalUrl.get()),
      accountCache,
      groupBackend,
      disableReverseDnsLookup,
      remotePeer,
      state,
      realUser);
}
 
Example 24
Project: gerrit   File: DynamicSetTest.java   Source Code and License 6 votes vote down vote up
@Test
public void containsDynamic() throws Exception {
  DynamicSet<Integer> ds = new DynamicSet<>();
  ds.add(2);

  Key<Integer> key = Key.get(Integer.class);
  ReloadableRegistrationHandle<Integer> handle = ds.add(key, Providers.of(4));

  ds.add(6);

  // At first, 4 is contained.
  assertThat(ds.contains(4)).isTrue(); //See above comment about ds.contains

  // Then we remove 4.
  handle.remove();

  // And now 4 should no longer be contained.
  assertThat(ds.contains(4)).isFalse(); //See above comment about ds.contains
}
 
Example 25
Project: gerrit   File: CommitsCollectionTest.java   Source Code and License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  Injector injector = Guice.createInjector(new InMemoryModule());
  injector.injectMembers(this);
  lifecycle = new LifecycleManager();
  lifecycle.add(injector);
  lifecycle.start();

  db = schemaFactory.open();
  schemaCreator.create(db);
  // Need to create at least one user to be admin before creating a "normal"
  // registered user.
  // See AccountManager#create().
  accountManager.authenticate(AuthRequest.forUser("admin")).getAccountId();
  admins = groupCache.get(new AccountGroup.NameKey("Administrators")).orElse(null).getGroupUUID();
  setUpPermissions();

  Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
  user = userFactory.create(userId);

  Project.NameKey name = new Project.NameKey("project");
  InMemoryRepository inMemoryRepo = repoManager.createRepository(name);
  project = new ProjectConfig(name);
  project.load(inMemoryRepo);
  repo = new TestRepository<>(inMemoryRepo);

  requestContext.setContext(
      new RequestContext() {
        @Override
        public CurrentUser getUser() {
          return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
          return Providers.of(db);
        }
      });
}
 
Example 26
Project: DataCleaner   File: OpenAnalysisJobActionListener.java   Source Code and License 6 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent event) {
    final DCFileChooser fileChooser = new DCFileChooser(_userPreferences.getAnalysisJobDirectory());

    final OpenAnalysisJobFileChooserAccessory accessory =
            new OpenAnalysisJobFileChooserAccessory(_windowContext, _configuration, fileChooser,
                    Providers.of(this));
    fileChooser.setAccessory(accessory);

    fileChooser.addChoosableFileFilter(FileFilters.ANALYSIS_XML);
    fileChooser.addChoosableFileFilter(FileFilters.ANALYSIS_RESULT_SER);
    fileChooser.setFileFilter(FileFilters
            .combined("DataCleaner analysis files", FileFilters.ANALYSIS_XML, FileFilters.ANALYSIS_RESULT_SER));
    final int openFileResult = fileChooser.showOpenDialog(_parentWindow.toComponent());

    if (openFileResult == JFileChooser.APPROVE_OPTION) {
        final FileObject file = fileChooser.getSelectedFileObject();
        openFile(file);
    }
}
 
Example 27
Project: DataCleaner   File: OpenAnalysisJobAsTemplateDialogTest.java   Source Code and License 6 votes vote down vote up
private OpenAnalysisJobAsTemplateDialog getDialog() {
    if (_dialog == null) {
        try {
            final WindowContext windowContext = new SimpleWindowContext();
            final Datastore datastore = TestHelper.createSampleDatabaseDatastore("orderdb");
            final DatastoreCatalog datastoreCatalog = new DatastoreCatalogImpl(datastore);
            final SimpleDescriptorProvider descriptorProvider = new SimpleDescriptorProvider();
            final DataCleanerConfiguration configuration =
                    new DataCleanerConfigurationImpl().withDatastoreCatalog(datastoreCatalog).withEnvironment(
                            new DataCleanerEnvironmentImpl().withDescriptorProvider(descriptorProvider));
            final FileObject file = VFSUtils.getFileSystemManager()
                    .resolveFile("src/test/resources/cli-examples/date_analysis_job.xml");
            final Provider<OpenAnalysisJobActionListener> providerMock = Providers.of(null);

            _dialog = new OpenAnalysisJobAsTemplateDialog(windowContext, configuration, file, createMetadata(),
                    providerMock);
        } catch (final FileSystemException e) {
            logger.error("Problem occurred while creating dialog instance. \n" + e.getMessage());
        }
    }

    return _dialog;
}
 
Example 28
Project: isis-module-devutils   File: DevUtilsModuleApplication.java   Source Code and License 6 votes vote down vote up
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module simpleOverrides = new AbstractModule() {
        @Override
        protected void configure() {

            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance(APP_NAME);
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance(APP_NAME);
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
        }
    };

    return Modules.override(isisDefaults).with(simpleOverrides);
}
 
Example 29
Project: isis-app-kitchensink   File: KitchensinkApplication.java   Source Code and License 6 votes vote down vote up
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module simpleOverrides = new AbstractModule() {
        @Override
        protected void configure() {
            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance(APP_NAME);
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance(APP_NAME);
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
        }
    };

    return Modules.override(isisDefaults).with(simpleOverrides);
}
 
Example 30
Project: isis-module-pdf   File: PdfModuleApplication.java   Source Code and License 6 votes vote down vote up
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module simpleOverrides = new AbstractModule() {
        @Override
        protected void configure() {
            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance(APP_NAME);
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance(APP_NAME);
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
        }
    };

    return Modules.override(isisDefaults).with(simpleOverrides);
}
 
Example 31
Project: isis-module-audit   File: AuditModuleApplication.java   Source Code and License 6 votes vote down vote up
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module overrides = new AbstractModule() {
        @Override
        protected void configure() {
            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance(APP_NAME);
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance(APP_NAME);
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
        }
    };

    return Modules.override(isisDefaults).with(overrides);
}
 
Example 32
Project: guice-old   File: DuplicateBindingsTest.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void testMixedTargetsFails() {
  try {
    Guice.createInjector(
        new SimpleModule(foo, pFoo, pclFoo, clFoo, cFoo),
        new SimpleModule(new FooImpl(), Providers.<Foo>of(new FooImpl()), 
            (Class)BarProvider.class, (Class)Bar.class, (Constructor)Bar.cxtor())
    );
    fail("expected exception");
  } catch(CreationException ce) {
    assertContains(ce.getMessage(), 
        "A binding to " + Foo.class.getName() + " annotated with " + named("pInstance") + " was already configured at " + SimpleModule.class.getName(),
        "at " + SimpleModule.class.getName(), 
        "A binding to " + Foo.class.getName() + " annotated with " + named("pKey") + " was already configured at " + SimpleModule.class.getName(),
        "at " + SimpleModule.class.getName(), 
        "A binding to " + Foo.class.getName() + " annotated with " + named("linkedKey") + " was already configured at " + SimpleModule.class.getName(),
        "at " + SimpleModule.class.getName(),
        "A binding to " + Foo.class.getName() + " annotated with " + named("constructor") + " was already configured at " + SimpleModule.class.getName(),
        "at " + SimpleModule.class.getName());
  }
}
 
Example 33
Project: system   File: EmailServiceTest.java   Source Code and License 6 votes vote down vote up
@Test
public void sendMailAsapTest() throws EmailException, MessagingException, IOException {
    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override
        protected void configure() {
            bind(IQueueService.class).toProvider(Providers.<IQueueService>of(null));
        }
    });

    IEmailService emailService = injector.getInstance(EmailService.class);

    emailService.sendASAP("[email protected]", "[email protected]", "This is the content", "Subject");

    Mailbox box = Mailbox.get("[email protected]");

    assertThat(box, is(Matchers.<Message>iterableWithSize(1)));

    Message message = box.get(0);
    assertThat(message.getFrom()[0].toString(), is(equalTo("[email protected]")));
    assertThat(message.getSubject(), is(equalTo("Subject")));
    assertThat(message.getContent(), is(Matchers.<Object>equalTo("This is the content")));
    assertThat(message.getContentType(), startsWith("text/html"));

}
 
Example 34
Project: isis-module-security   File: SecurityModuleApplication.java   Source Code and License 6 votes vote down vote up
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module simpleOverrides = new AbstractModule() {
        @Override
        protected void configure() {
            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance(APP_NAME);
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance(APP_NAME);
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
        }
    };

    return Modules.override(isisDefaults).with(simpleOverrides);
}
 
Example 35
Project: guice   File: BoundFieldModuleTest.java   Source Code and License 6 votes vote down vote up
public void testFieldBoundAsProvider_lazy() {
  LazyProviderClass asProvider = new LazyProviderClass();
  Provider<Integer> provider =
      Guice.createInjector(BoundFieldModule.of(asProvider)).getProvider(Integer.class);
  assertNull(provider.get());
  asProvider.foo = Providers.of(1);
  assertEquals(1, provider.get().intValue());
  asProvider.foo =
      new Provider<Integer>() {
        @Override
        public Integer get() {
          throw new RuntimeException("boom");
        }
      };
  try {
    provider.get();
    fail();
  } catch (ProvisionException e) {
    assertContains(e.getMessage(), "boom");
  }
}
 
Example 36
Project: guice   File: ServletTest.java   Source Code and License 6 votes vote down vote up
private Injector createInjector(Module... modules) throws CreationException {
  return Guice.createInjector(
      Lists.<Module>asList(
          new AbstractModule() {
            @Override
            protected void configure() {
              install(new ServletModule());
              bind(InSession.class);
              bind(IN_SESSION_NULL_KEY)
                  .toProvider(Providers.<InSession>of(null))
                  .in(SessionScoped.class);
              bind(InRequest.class);
              bind(IN_REQUEST_NULL_KEY)
                  .toProvider(Providers.<InRequest>of(null))
                  .in(RequestScoped.class);
            }
          },
          modules));
}
 
Example 37
Project: guice   File: InjectorImpl.java   Source Code and License 6 votes vote down vote up
ConvertedConstantBindingImpl(
    InjectorImpl injector,
    Key<T> key,
    T value,
    Binding<String> originalBinding,
    TypeConverterBinding typeConverterBinding) {
  super(
      injector,
      key,
      originalBinding.getSource(),
      new ConstantFactory<T>(Initializables.of(value)),
      Scoping.UNSCOPED);
  this.value = value;
  provider = Providers.of(value);
  this.originalBinding = originalBinding;
  this.typeConverterBinding = typeConverterBinding;
}
 
Example 38
Project: guice   File: Jsr330Test.java   Source Code and License 6 votes vote down vote up
public void testGuicify330Provider() {
  Provider<String> jsr330Provider =
      new Provider<String>() {
        @Override
        public String get() {
          return "A";
        }

        @Override
        public String toString() {
          return "jsr330Provider";
        }
      };

  com.google.inject.Provider<String> guicified = Providers.guicify(jsr330Provider);
  assertEquals("guicified(jsr330Provider)", guicified.toString());
  assertEquals("A", guicified.get());

  // when you guicify the Guice-friendly, it's a no-op
  assertSame(guicified, Providers.guicify(guicified));

  assertFalse(guicified instanceof HasDependencies);
}
 
Example 39
Project: guice   File: ProvisionListenerTest.java   Source Code and License 6 votes vote down vote up
public void testBindToInjectorWithListeningGivesSaneException() {
  try {
    Guice.createInjector(
        new AbstractModule() {
          @Override
          protected void configure() {
            bindListener(Matchers.any(), new Counter());
            bind(Injector.class).toProvider(Providers.<Injector>of(null));
          }
        });
    fail();
  } catch (CreationException ce) {
    assertContains(
        ce.getMessage(), "Binding to core guice framework type is not allowed: Injector.");
  }
}
 
Example 40
Project: guice   File: BinderTest.java   Source Code and License 6 votes vote down vote up
public void testBindingToProvider() {
  try {
    Guice.createInjector(
        new AbstractModule() {
          @Override
          protected void configure() {
            bind(new TypeLiteral<Provider<String>>() {}).toInstance(Providers.of("A"));
          }
        });
    fail();
  } catch (CreationException expected) {
    assertContains(
        expected.getMessage(),
        "1) Binding to Provider is not allowed.",
        "at " + BinderTest.class.getName(),
        getDeclaringSourcePart(getClass()));
  }
}