本文整理汇总了Java中com.google.inject.ConfigurationException类的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationException类的具体用法?Java ConfigurationException怎么用?Java ConfigurationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationException类属于com.google.inject包,在下文中一共展示了ConfigurationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNotExposed
import com.google.inject.ConfigurationException; //导入依赖的package包/类
@Test
public void testNotExposed() {
final Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
DuplexBinder.create(this.binder()).install(new DuplexModule() {
@Override
protected void configure() {
this.bind(Thing.class).annotatedWith(Names.named("r0")).toInstance(new Thing("r0"));
}
});
}
});
try {
injector.getInstance(ShouldNotWork.class);
} catch(final ConfigurationException expected) {
final String message = expected.getMessage();
if(message.contains("It was already configured on one or more child injectors or private modules")
&& message.contains("If it was in a PrivateModule, did you forget to expose the binding?")) {
return;
}
}
fail("should not be exposed");
}
示例2: analyzeImplementation
import com.google.inject.ConfigurationException; //导入依赖的package包/类
private void analyzeImplementation(final TypeLiteral<?> type, boolean ignoreConstructor)
{
if( !scannedTypes.contains(type) )
{
try
{
if( (type.getRawType().getModifiers() & (Modifier.INTERFACE | Modifier.ABSTRACT)) == 0 )
{
analyzeInjectionPoints(InjectionPoint.forInstanceMethodsAndFields(type));
if( !ignoreConstructor )
{
analyzeDependencies(InjectionPoint.forConstructorOf(type).getDependencies());
}
}
}
catch( ConfigurationException ce )
{
errors.merge(ce.getErrorMessages());
}
scannedTypes.add(type);
}
}
示例3: testLoadMap
import com.google.inject.ConfigurationException; //导入依赖的package包/类
@Test
public void testLoadMap() throws Exception {
Map<String, TestInterface> services = target.loadMap(TestInterface.class);
assertTrue(services.get("TestImpl1") instanceof TestInterface.TestImpl1);
assertTrue(services.get("TestImpl3") instanceof TestInterface.TestImpl3);
assertEquals(services.size(), 2, services.toString());
for (TestInterface s : services.values()) {
assertNotNull(s.getInjector());
assertNotNull(s.getInjector().getInstance(ImmutableConfiguration.class));
try {
s.getInjector().getInstance(ServiceFactory.class);
fail();
} catch (ConfigurationException e) {
// Success
}
}
}
示例4: provideValue
import com.google.inject.ConfigurationException; //导入依赖的package包/类
/**
* This method produces value for the field. It constructs the context for the creation out of
* paren't context and the field's own frame info.
*/
@Override
public Optional<Object> provideValue(Object pageObject, Field field, PageObjectContext context) {
By selector = PageObjectProviderHelper.getSelectorFromPageObject(field);
ElementLocatorFactory elementLocatorFactory =
new NestedSelectorScopedLocatorFactory(webDriver, selector,
context.getElementLocatorFactory(), AnnotationsHelper.isGlobal(field));
final FramePath framePath = frameMap.get(pageObject);
contextStack.push(new PageObjectContext(elementLocatorFactory, framePath));
Object scopedPageObject = null;
try {
scopedPageObject = injector.getInstance(field.getType());
} catch (Exception e) {
if (e instanceof ConfigurationException) {
ConfigurationException ce = (ConfigurationException) e;
throw new BobcatRuntimeException(
"Configuration exception: " + ce.getErrorMessages().toString(), e);
}
throw new BobcatRuntimeException(e.getMessage(), e);
} finally {
contextStack.pop();
}
return Optional.ofNullable(scopedPageObject);
}
示例5: provideValue
import com.google.inject.ConfigurationException; //导入依赖的package包/类
/**
* This method produces value for the field. It constructs the context for the creation out of
* parent's context and the field's own frame info.
*/
@Override
public Optional<Object> provideValue(Object pageObject, Field field, PageObjectContext context) {
final ElementLocatorFactory elementLocatorFactory = new ScopedElementLocatorFactory(webDriver,
context.getElementLocatorFactory(), field);
final FramePath framePath = frameMap.get(pageObject);
contextStack.push(new PageObjectContext(elementLocatorFactory, framePath));
Object scopedPageObject = null;
try {
scopedPageObject = injector.getInstance(field.getType());
} catch (Exception e) {
if (e instanceof ConfigurationException) {
ConfigurationException ce = (ConfigurationException) e;
throw new BobcatRuntimeException(
"Configuration exception: " + ce.getErrorMessages().toString(), e);
}
throw new BobcatRuntimeException(e.getMessage(), e);
} finally {
contextStack.pop();
}
return Optional.ofNullable(scopedPageObject);
}
示例6: getChildAction
import com.google.inject.ConfigurationException; //导入依赖的package包/类
/**
* @param args the arguments
* @param parser the command line parser containing usage information
* @return a child Command for the given args, or <code>null</code> if not found
*/
protected Command getChildAction(List<String> args, CmdLineParser parser) {
final String commandName = args.get(0);
// find implementation
final Class<? extends Command> commandClass = commandMap.get(commandName);
if (null != commandClass) {
try {
final Command command = InjectionUtil.getInjector().getInstance(commandClass);
command.setParent(this);
command.setCommandName(commandName);
return command;
} catch (ProvisionException | ConfigurationException e) {
throw new CommandException(String.format("Error getting child command for args: %s", args), e);
}
}
return null;
}
示例7: resolve
import com.google.inject.ConfigurationException; //导入依赖的package包/类
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> serviceHandle) {
if (injectee.getRequiredType() instanceof Class) {
TypeLiteral<?> typeLiteral = TypeLiteral.get(injectee.getRequiredType());
Errors errors = new Errors(injectee.getParent());
Key<?> key;
try {
key = Annotations.getKey(typeLiteral, (Member) injectee.getParent(),
injectee.getParent().getDeclaredAnnotations(), errors);
} catch (ErrorsException e) {
errors.merge(e.getErrors());
throw new ConfigurationException(errors.getMessages());
}
return injector.getInstance(key);
}
throw new IllegalStateException("Can't process injection point: " + injectee.getRequiredType());
}
示例8: getResourceServiceProviderById
import com.google.inject.ConfigurationException; //导入依赖的package包/类
/**
* Finds the {@link IResourceServiceProvider} for a language by given its id.
*
* @param languageId
* the language id (grammar name)
* @return the {@link IResourceServiceProvider} for the given language id
*/
public IResourceServiceProvider getResourceServiceProviderById(final String languageId) {
ImmutableMap<Map<String, Object>, ? extends Function<String, IResourceServiceProvider>> resourceProvidersMap = getProviderMaps();
for (Map.Entry<Map<String, Object>, ? extends Function<String, IResourceServiceProvider>> mapEntry : resourceProvidersMap.entrySet()) {
Map<String, Object> map = mapEntry.getKey();
for (Map.Entry<String, Object> entry : map.entrySet()) {
try {
IResourceServiceProvider resourceServiceProvider = mapEntry.getValue().apply(entry.getKey());
if (resourceServiceProvider == null) {
continue;
}
IGrammarAccess grammarAccess = resourceServiceProvider.get(IGrammarAccess.class);
if (grammarAccess != null && grammarAccess.getGrammar().getName().equals(languageId)) {
return resourceServiceProvider;
}
// CHECKSTYLE:OFF
} catch (ConfigurationException ex) {
// CHECKSTYLE:ON
// ignore
}
}
}
return null;
}
示例9: getAllLanguages
import com.google.inject.ConfigurationException; //导入依赖的package包/类
/**
* Gets the all languages available in the workbench.
*
* @return set of all languages
*/
public Set<String> getAllLanguages() {
Set<String> languages = new HashSet<String>();
for (String extension : Registry.INSTANCE.getExtensionToFactoryMap().keySet()) {
final URI dummyUri = URI.createURI("foo:/foo." + extension);
IResourceServiceProvider resourceServiceProvider = Registry.INSTANCE.getResourceServiceProvider(dummyUri);
// By checking that description manager is AbstractCachingResourceDescriptionManager we exclude technical languages of the framework
if (resourceServiceProvider != null && resourceServiceProvider.getResourceDescriptionManager() instanceof AbstractCachingResourceDescriptionManager) {
try {
IGrammarAccess grammarAccess = resourceServiceProvider.get(IGrammarAccess.class);
if (grammarAccess != null && grammarAccess.getGrammar() != null) {
languages.add(grammarAccess.getGrammar().getName());
}
} catch (ConfigurationException e) {
// Will happen if no binding for IGrammarAccess was present.
}
}
}
return languages;
}
示例10: getCurrentTestLogFileName
import com.google.inject.ConfigurationException; //导入依赖的package包/类
private Optional<String> getCurrentTestLogFileName()
{
Optional<TestContext> testContext = testContextIfSet();
try {
String testName = "SUITE";
if (testContext.isPresent()) {
Optional<TestMetadata> testMetadata = testContext.get().getOptionalDependency(TestMetadata.class);
if (testMetadata.isPresent()) {
testName = testMetadata.get().testName;
}
}
return Optional.of(logsDirectory + "/" + testName);
}
catch (ConfigurationException e) {
System.err.append("Could not load TestMetadata from guice context");
return Optional.empty();
}
}
示例11: main
import com.google.inject.ConfigurationException; //导入依赖的package包/类
public static void main(String... args) {
WSFRealtimeMain m = new WSFRealtimeMain();
ArgumentParser parser = ArgumentParsers.newArgumentParser("wsf-gtfsrealtime");
parser.description("Produces a GTFS-realtime feed from the Washington State Ferries API");
parser.addArgument("--" + ARG_CONFIG_FILE).type(File.class).help("configuration file path");
Namespace parsedArgs;
try {
parsedArgs = parser.parseArgs(args);
File configFile = parsedArgs.get(ARG_CONFIG_FILE);
m.run(configFile);
} catch (CreationException | ConfigurationException | ProvisionException e) {
_log.error("Error in startup:", e);
System.exit(-1);
} catch (ArgumentParserException ex) {
parser.handleError(ex);
}
}
示例12: createBindingsForFactories
import com.google.inject.ConfigurationException; //导入依赖的package包/类
private void createBindingsForFactories(GinjectorBindings bindings) {
for (final FactoryModule<?> factoryModule : bindings.getFactoryModules()) {
FactoryBinding binding;
try {
binding = bindingFactory.getFactoryBinding(
factoryModule.getBindings(),
factoryModule.getFactoryType(),
Context.forText(factoryModule.getSource()));
} catch (ConfigurationException e) {
errorManager.logError("Factory %s could not be created", e, factoryModule.getFactoryType());
continue;
}
bindings.addBinding(factoryModule.getFactoryType(), binding);
}
}
示例13: buildTestWrapperInstance
import com.google.inject.ConfigurationException; //导入依赖的package包/类
private static TestWrapper buildTestWrapperInstance(Injector injector) {
TestWrapper result = NoOpTestScopeListener.NO_OP_INSTANCE;
try {
boolean hasTestScopeListenerBinding = hasTestScopeListenerBinding(injector);
boolean hasDeprecatedTestScopeListenerBinding = hasDeprecatedTestScopeListenerBinding(injector);
if (hasTestScopeListenerBinding && hasDeprecatedTestScopeListenerBinding) {
throw new RuntimeException(
"Your GuiceBerry Env has bindings for both the new TestScopeListener and the deprecated one. Please fix.");
} else if (hasTestScopeListenerBinding) {
result = injector.getInstance(TestWrapper.class);
} else if (hasDeprecatedTestScopeListenerBinding) {
result = adapt(
injector.getInstance(com.google.inject.testing.guiceberry.TestScopeListener.class),
injector.getInstance(TearDownAccepter.class));
}
} catch (ConfigurationException e) {
String msg = String.format("Error while creating a TestWrapper: '%s'.",
e.getMessage());
throw new RuntimeException(msg, e);
}
return result;
}
示例14: testFailsInjectionBeforeRunningGuiceBerryEnvMain_MissingTestBinding
import com.google.inject.ConfigurationException; //导入依赖的package包/类
/**
* This test makes sure that if the test has a missing binding, GuiceBerry
* will fail before it runs the {@link GuiceBerryEnvMain#run()} method.
*/
@Test public void testFailsInjectionBeforeRunningGuiceBerryEnvMain_MissingTestBinding() {
GuiceBerryEnvSelector guiceBerryEnvSelector =
DefaultEnvSelector.of(MyGuiceBerryEnvWithGuiceBerryEnvMainThatThrows.class);
TestDescription testDescription = new TestDescription(new ClassWithUnsatisfiedDependency(), "bogus test case");
GuiceBerryUniverse.TestCaseScaffolding testCaseScaffolding =
new GuiceBerryUniverse.TestCaseScaffolding(testDescription, guiceBerryEnvSelector, universe);
try {
testCaseScaffolding.runBeforeTest();
Assert.fail("The test has an unsatisfied injection, and the GuiceBerryEnvMain "
+ "throws an Exception. Either of these reasons should have prevented the "
+ "test from having gotten here.");
} catch (MyGuiceBerryEnvWithGuiceBerryEnvMainThatThrows.GuiceBerryEnvMainWasExecutedException toThrow) {
throw toThrow;
} catch (RuntimeException maybeExpected) {
Assert.assertEquals(ConfigurationException.class, maybeExpected.getCause().getClass());
}
testCaseScaffolding.runAfterTest();
}
示例15: testGbeThatHasMissingBindingsThrowsException
import com.google.inject.ConfigurationException; //导入依赖的package包/类
public void testGbeThatHasMissingBindingsThrowsException() {
try {
TestWithGbeThatHasMissingBindings test =
TestWithGbeThatHasMissingBindings.createInstance();
instance().doSetUp(test);
fail();
} catch (RuntimeException expectedActualException) {
//TODO: we should assert expected's cause is ConfigurationException, but
//that exception is private
Throwable actualCause = expectedActualException.getCause();
assertEquals(ConfigurationException.class, actualCause.getClass());
assertEquals(String.format(
"Binding error in the GuiceBerry Env '%s': '%s'.",
GuiceBerryEnvWithoutBindingsForFooOrBar.GUICE_BERRY_ENV_WITHOUT_BINDINGS_FOR_FOO_OR_BAR,
actualCause.getMessage()),
expectedActualException.getMessage());
String configurationExceptionMeat = String.format(
"No implementation for %s was bound.", BarService.class.getName());
assertTrue(actualCause.getMessage().contains(configurationExceptionMeat));
}
}