use of com.google.inject.ConfigurationException in project roboguice by roboguice.
the class FactoryProvider method newFactory.
public static <F> Provider<F> newFactory(TypeLiteral<F> factoryType, TypeLiteral<?> implementationType) {
Map<Method, AssistedConstructor<?>> factoryMethodToConstructor = createMethodMapping(factoryType, implementationType);
if (!factoryMethodToConstructor.isEmpty()) {
return new FactoryProvider<F>(factoryType, implementationType, factoryMethodToConstructor);
} else {
BindingCollector collector = new BindingCollector();
// Preserving backwards-compatibility: Map all return types in a factory
// interface to the passed implementation type.
Errors errors = new Errors();
Key<?> implementationKey = Key.get(implementationType);
try {
for (Method method : factoryType.getRawType().getMethods()) {
Key<?> returnType = getKey(factoryType.getReturnType(method), method, method.getAnnotations(), errors);
if (!implementationKey.equals(returnType)) {
collector.addBinding(returnType, implementationType);
}
}
} catch (ErrorsException e) {
throw new ConfigurationException(e.getErrors().getMessages());
}
return new FactoryProvider2<F>(Key.get(factoryType), collector);
}
}
use of com.google.inject.ConfigurationException in project guice by google.
the class InjectionPoint method forMember.
private ImmutableList<Dependency<?>> forMember(Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) {
Errors errors = new Errors(member);
List<Dependency<?>> dependencies = Lists.newArrayList();
int index = 0;
for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
try {
Annotation[] parameterAnnotations = paramterAnnotations[index];
Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors);
dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index));
index++;
} catch (ConfigurationException e) {
errors.merge(e.getErrorMessages());
} catch (ErrorsException e) {
errors.merge(e.getErrors());
}
}
errors.throwConfigurationExceptionIfErrorsExist();
return ImmutableList.copyOf(dependencies);
}
use of com.google.inject.ConfigurationException in project OpenAM by OpenRock.
the class ConfigLoader method validateClass.
/**
* Validates that the specified class can be loaded and implements the proper interface so that we don't have to do
* that for every request.
*
* @param cfg
* @return the class of the RequestHandler to be used for this client config, or null if the class is invalid.
*/
@SuppressWarnings("unchecked")
private Class validateClass(ClientConfig cfg) {
Class clazz = null;
try {
clazz = Class.forName(cfg.getAccessRequestHandlerClassname());
} catch (final ClassNotFoundException e) {
LOG.error("Unable to load Handler Class '" + cfg.getAccessRequestHandlerClassname() + "' for RADIUS client '" + cfg.getName() + "'. Requests from this client will be ignored.", e);
return null;
}
Object inst = null;
try {
inst = InjectorHolder.getInstance(clazz);
} catch (ConfigurationException | ProvisionException e) {
LOG.error("Unable to instantiate Handler Class '" + cfg.getAccessRequestHandlerClassname() + "' for RADIUS client '" + cfg.getName() + "'. Requests from this client will be ignored.", e);
return null;
}
AccessRequestHandler handler = null;
try {
handler = (AccessRequestHandler) inst;
} catch (final ClassCastException e) {
LOG.error("Unable to use Handler Class '" + cfg.getAccessRequestHandlerClassname() + "' for RADIUS client '" + cfg.getName() + "'. Requests from this client will be ignored.", e);
return null;
}
return clazz;
}
use of com.google.inject.ConfigurationException in project dsl-devkit by dsldevkit.
the class RegistryBuilderParticipant method buildLanguageSpecificParticipants.
/**
* For each {@link IResourceDescription.Delta} searches and calls the responsible {@link ILanguageSpecificBuilderParticipant}s.
*
* @param buildContext
* the {@link IBuildContext}, must not be {@code null}
* @param monitor
* the {@link IProgressMonitor}, must not be {@code null}
*/
protected void buildLanguageSpecificParticipants(final IBuildContext buildContext, final IProgressMonitor monitor) {
initParticipants();
SubMonitor progress = SubMonitor.convert(monitor, buildContext.getDeltas().size() * MONITOR_PARTICIPANTS_PER_LANGUAGE);
Map<String, BuildContext> languageIdToBuildContext = Maps.newHashMap();
for (IResourceDescription.Delta delta : buildContext.getDeltas()) {
IResourceServiceProvider resourceServiceProvider = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(delta.getUri());
if (resourceServiceProvider == null) {
progress.worked(MONITOR_PARTICIPANTS_PER_LANGUAGE);
continue;
}
IGrammarAccess grammarAccess = null;
try {
grammarAccess = resourceServiceProvider.get(IGrammarAccess.class);
} catch (ConfigurationException e) {
progress.worked(MONITOR_PARTICIPANTS_PER_LANGUAGE);
continue;
}
if (grammarAccess == null) {
progress.worked(MONITOR_PARTICIPANTS_PER_LANGUAGE);
continue;
}
String languageId = grammarAccess.getGrammar().getName();
BuildContext entryBuildContext = languageIdToBuildContext.get(languageId);
if (entryBuildContext == null) {
entryBuildContext = new BuildContext(buildContext.getBuiltProject(), buildContext.getResourceSet(), buildContext.getBuildType());
languageIdToBuildContext.put(languageId, entryBuildContext);
}
entryBuildContext.addDelta(delta);
}
builLanguageSpecificContext(buildContext, progress, languageIdToBuildContext);
}
use of com.google.inject.ConfigurationException in project opt4j by felixreimann.
the class Opt4JModule method configure.
/*
* (non-Javadoc)
*
* @see com.google.inject.AbstractModule#configure()
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void configure() {
/**
* Configure injected constants.
*/
PropertyModule module = new PropertyModule(this);
for (Property property : module.getProperties()) {
for (Annotation annotation : property.getAnnotations()) {
if (annotation.annotationType().getAnnotation(BindingAnnotation.class) != null) {
Class<?> type = property.getType();
Object value = property.getValue();
ConstantBindingBuilder builder = bindConstant(annotation);
if (type.equals(Integer.TYPE)) {
builder.to((Integer) value);
} else if (type.equals(Long.TYPE)) {
builder.to((Long) value);
} else if (type.equals(Double.TYPE)) {
builder.to((Double) value);
} else if (type.equals(Float.TYPE)) {
builder.to((Float) value);
} else if (type.equals(Byte.TYPE)) {
builder.to((Byte) value);
} else if (type.equals(Short.TYPE)) {
builder.to((Short) value);
} else if (type.equals(Boolean.TYPE)) {
builder.to((Boolean) value);
} else if (type.equals(Character.TYPE)) {
builder.to((Character) value);
} else if (type.equals(String.class)) {
builder.to((String) value);
} else if (type.equals(Class.class)) {
builder.to((Class<?>) value);
} else if (value instanceof Enum<?>) {
builder.to((Enum) value);
} else {
String message = "Constant type not bindable: " + type + " of field " + property.getName() + " in module " + this.getClass().getName();
throw new ConfigurationException(Arrays.asList(new Message(message)));
}
}
}
}
multi(OptimizerStateListener.class);
multi(OptimizerIterationListener.class);
multi(IndividualStateListener.class);
config();
}
Aggregations