use of com.google.inject.ConfigurationException in project druid by druid-io.
the class JettyServerModule method initializeServer.
static void initializeServer(Injector injector, Lifecycle lifecycle, final Server server) {
JettyServerInitializer initializer = injector.getInstance(JettyServerInitializer.class);
try {
initializer.initialize(server, injector);
} catch (ConfigurationException e) {
throw new ProvisionException(Iterables.getFirst(e.getErrorMessages(), null).getMessage());
}
lifecycle.addHandler(new Lifecycle.Handler() {
@Override
public void start() throws Exception {
server.start();
}
@Override
public void stop() {
try {
server.stop();
} catch (Exception e) {
log.warn(e, "Unable to stop Jetty server.");
}
}
});
}
use of com.google.inject.ConfigurationException in project guice by google.
the class InjectionPoint method forConstructorOf.
/**
* Returns a new injection point for the injectable constructor of {@code type}.
*
* @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject},
* or a no-arguments constructor that is not private.
* @throws ConfigurationException if there is no injectable constructor, more than one injectable
* constructor, or if parameters of the injectable constructor are malformed, such as a
* parameter with multiple binding annotations.
*/
public static InjectionPoint forConstructorOf(TypeLiteral<?> type) {
Class<?> rawType = getRawType(type.getType());
Errors errors = new Errors(rawType);
Constructor<?> injectableConstructor = null;
for (Constructor<?> constructor : rawType.getDeclaredConstructors()) {
boolean optional;
Inject guiceInject = constructor.getAnnotation(Inject.class);
if (guiceInject == null) {
javax.inject.Inject javaxInject = constructor.getAnnotation(javax.inject.Inject.class);
if (javaxInject == null) {
continue;
}
optional = false;
} else {
optional = guiceInject.optional();
}
if (optional) {
errors.optionalConstructor(constructor);
}
if (injectableConstructor != null) {
errors.tooManyConstructors(rawType);
}
injectableConstructor = constructor;
checkForMisplacedBindingAnnotations(injectableConstructor, errors);
}
errors.throwConfigurationExceptionIfErrorsExist();
if (injectableConstructor != null) {
return new InjectionPoint(type, injectableConstructor);
}
// If no annotated constructor is found, look for a no-arg constructor instead.
try {
Constructor<?> noArgConstructor = rawType.getDeclaredConstructor();
// Disallow private constructors on non-private classes (unless they have @Inject)
if (Modifier.isPrivate(noArgConstructor.getModifiers()) && !Modifier.isPrivate(rawType.getModifiers())) {
errors.missingConstructor(rawType);
throw new ConfigurationException(errors.getMessages());
}
checkForMisplacedBindingAnnotations(noArgConstructor, errors);
return new InjectionPoint(type, noArgConstructor);
} catch (NoSuchMethodException e) {
errors.missingConstructor(rawType);
throw new ConfigurationException(errors.getMessages());
}
}
use of com.google.inject.ConfigurationException in project dsl-devkit by dsldevkit.
the class ResourceServiceProviderLocator method getResourceServiceProviderById.
/**
* 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;
}
use of com.google.inject.ConfigurationException in project dsl-devkit by dsldevkit.
the class CheckCfgUtil method getAllLanguages.
/**
* 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;
}
use of com.google.inject.ConfigurationException in project google-gin by gwtplus.
the class FactoryBindingTest method testTwoUnnamedStringAnnotations.
public void testTwoUnnamedStringAnnotations() {
try {
new FactoryBinding(Collections.<Key<?>, TypeLiteral<?>>emptyMap(), Key.get(TwoUnnamedStringsFactory.class), CONTEXT, new GuiceUtil(createInjectableCollector()), null);
fail("Expected ConfigurationException.");
} catch (ConfigurationException e) {
assertTrue(e.getMessage().contains("has more than one parameter of type " + "java.lang.String annotated with @Assisted(\"\")."));
}
}
Aggregations