当前位置: 首页>>代码示例>>Java>>正文


Java ConfigurationException类代码示例

本文整理汇总了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");
}
 
开发者ID:KyoriPowered,项目名称:violet,代码行数:25,代码来源:DuplexTest.java

示例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);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:23,代码来源:DependencyAnalyzer.java

示例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
        }

    }

}
 
开发者ID:after-the-sunrise,项目名称:cryptotrader,代码行数:25,代码来源:ServiceFactoryImplTest.java

示例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);
}
 
开发者ID:Cognifide,项目名称:bobcat,代码行数:28,代码来源:SelectorPageObjectProvider.java

示例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);
}
 
开发者ID:Cognifide,项目名称:bobcat,代码行数:26,代码来源:ScopedPageObjectProvider.java

示例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;
}
 
开发者ID:apiman,项目名称:apiman-cli,代码行数:24,代码来源:AbstractCommand.java

示例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());
}
 
开发者ID:bootique,项目名称:bootique-jersey-client,代码行数:22,代码来源:ClientGuiceInjectInjector.java

示例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;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:31,代码来源:ResourceServiceProviderLocator.java

示例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;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:25,代码来源:CheckCfgUtil.java

示例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();
    }
}
 
开发者ID:prestodb,项目名称:tempto,代码行数:19,代码来源:TestFrameworkLoggingAppender.java

示例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);
  }
}
 
开发者ID:kurtraschke,项目名称:wsf-gtfsrealtime,代码行数:20,代码来源:WSFRealtimeMain.java

示例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);
  }
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:17,代码来源:BindingsProcessor.java

示例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;
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:23,代码来源:GuiceBerryUniverse.java

示例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();
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:25,代码来源:GuiceBerryUniverseTest.java

示例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));
  }
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:22,代码来源:GuiceBerryJunit3Test.java


注:本文中的com.google.inject.ConfigurationException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。