| Method from com.opensymphony.xwork2.inject.ContainerBuilder Detail: |
public ContainerBuilder alias(Class<T> type,
String alias) {
return alias(type, Container.DEFAULT_NAME, alias);
}
Convenience method. Equivalent to {@code alias(type, Container.DEFAULT_NAME,
type)}. |
public ContainerBuilder alias(Class<T> type,
String name,
String alias) {
return alias(Key.newInstance(type, name), Key.newInstance(type, alias));
}
Maps an existing factory to a new name. |
public ContainerBuilder constant(String name,
String value) {
return constant(String.class, name, value);
}
Maps a constant value to the given name. |
public ContainerBuilder constant(String name,
int value) {
return constant(int.class, name, value);
}
Maps a constant value to the given name. |
public ContainerBuilder constant(String name,
long value) {
return constant(long.class, name, value);
}
Maps a constant value to the given name. |
public ContainerBuilder constant(String name,
boolean value) {
return constant(boolean.class, name, value);
}
Maps a constant value to the given name. |
public ContainerBuilder constant(String name,
double value) {
return constant(double.class, name, value);
}
Maps a constant value to the given name. |
public ContainerBuilder constant(String name,
float value) {
return constant(float.class, name, value);
}
Maps a constant value to the given name. |
public ContainerBuilder constant(String name,
short value) {
return constant(short.class, name, value);
}
Maps a constant value to the given name. |
public ContainerBuilder constant(String name,
char value) {
return constant(char.class, name, value);
}
Maps a constant value to the given name. |
public ContainerBuilder constant(String name,
Class value) {
return constant(Class.class, name, value);
}
Maps a class to the given name. |
public ContainerBuilder constant(String name,
E value) {
return constant(value.getDeclaringClass(), name, value);
}
Maps an enum to the given name. |
public boolean contains(Class<?> type) {
return contains(type, Container.DEFAULT_NAME);
}
Convenience method. Equivalent to {@code contains(type,
Container.DEFAULT_NAME)}. |
public boolean contains(Class<?> type,
String name) {
return factories.containsKey(Key.newInstance(type, name));
}
Returns true if this builder contains a mapping for the given type and
name. |
public Container create(boolean loadSingletons) {
ensureNotCreated();
created = true;
final ContainerImpl container = new ContainerImpl(
new HashMap< Key< ? >, InternalFactory< ? > >(factories));
if (loadSingletons) {
container.callInContext(new ContainerImpl.ContextualCallable< Void >() {
public Void call(InternalContext context) {
for (InternalFactory< ? > factory : singletonFactories) {
factory.create(context);
}
return null;
}
});
}
container.injectStatics(staticInjections);
return container;
}
|
public ContainerBuilder factory(Class<T> type) {
return factory(type, Container.DEFAULT_NAME, type);
}
Convenience method. Equivalent to {@code factory(type,
Container.DEFAULT_NAME, type)}. |
public ContainerBuilder factory(Class<T> type,
Factory<? extends T> factory) {
return factory(type, Container.DEFAULT_NAME, factory, Scope.DEFAULT);
}
Convenience method. Equivalent to {@code factory(type,
Container.DEFAULT_NAME, factory, Scope.DEFAULT)}. |
public ContainerBuilder factory(Class<T> type,
Class<? extends T> implementation) {
return factory(type, Container.DEFAULT_NAME, implementation);
}
Convenience method. Equivalent to {@code factory(type,
Container.DEFAULT_NAME, implementation)}. |
public ContainerBuilder factory(Class<T> type,
String name) {
return factory(type, name, type);
}
Convenience method. Equivalent to {@code factory(type, name, type)}. |
public ContainerBuilder factory(Class<T> type,
Scope scope) {
return factory(type, Container.DEFAULT_NAME, type, scope);
}
Convenience method. Equivalent to {@code factory(type,
Container.DEFAULT_NAME, type, scope)}. |
public ContainerBuilder factory(Class<T> type,
Factory<? extends T> factory,
Scope scope) {
return factory(type, Container.DEFAULT_NAME, factory, scope);
}
Convenience method. Equivalent to {@code factory(type,
Container.DEFAULT_NAME, factory, scope)}. |
public ContainerBuilder factory(Class<T> type,
String name,
Factory<? extends T> factory) {
return factory(type, name, factory, Scope.DEFAULT);
}
Convenience method. Equivalent to {@code factory(type, name, factory,
Scope.DEFAULT)}. |
public ContainerBuilder factory(Class<T> type,
String name,
Class<? extends T> implementation) {
Scoped scoped = implementation.getAnnotation(Scoped.class);
Scope scope = scoped == null ? Scope.DEFAULT : scoped.value();
return factory(type, name, implementation, scope);
}
Maps an implementation class to a given dependency type and name. Creates
instances using the container, recursively injecting dependencies.
Sets scope to value from Scoped annotation on the
implementation class. Defaults to Scope#DEFAULT if no annotation
is found. |
public ContainerBuilder factory(Class<T> type,
Class<? extends T> implementation,
Scope scope) {
return factory(type, Container.DEFAULT_NAME, implementation, scope);
}
Convenience method. Equivalent to {@code factory(type,
Container.DEFAULT_NAME, implementation, scope)}. |
public ContainerBuilder factory(Class<T> type,
String name,
Scope scope) {
return factory(type, name, type, scope);
}
Convenience method. Equivalent to {@code factory(type, name, type,
scope)}. |
public ContainerBuilder factory(Class<T> type,
String name,
Factory<? extends T> factory,
Scope scope) {
InternalFactory< T > internalFactory =
new InternalFactory< T >() {
public T create(InternalContext context) {
try {
Context externalContext = context.getExternalContext();
return factory.create(externalContext);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public String toString() {
return new LinkedHashMap< String, Object >() {{
put("type", type);
put("name", name);
put("factory", factory);
}}.toString();
}
};
return factory(Key.newInstance(type, name), internalFactory, scope);
}
Maps a factory to a given dependency type and name. |
public ContainerBuilder factory(Class<T> type,
String name,
Class<? extends T> implementation,
Scope scope) {
// This factory creates new instances of the given implementation.
// We have to lazy load the constructor because the Container
// hasn't been created yet.
InternalFactory< ? extends T > factory = new InternalFactory< T >() {
volatile ContainerImpl.ConstructorInjector< ? extends T > constructor;
@SuppressWarnings("unchecked")
public T create(InternalContext context) {
if (constructor == null) {
this.constructor =
context.getContainerImpl().getConstructor(implementation);
}
return (T) constructor.construct(context, type);
}
@Override
public String toString() {
return new LinkedHashMap< String, Object >() {{
put("type", type);
put("name", name);
put("implementation", implementation);
put("scope", scope);
}}.toString();
}
};
return factory(Key.newInstance(type, name), factory, scope);
}
Maps an implementation class to a given dependency type and name. Creates
instances using the container, recursively injecting dependencies. |
public ContainerBuilder injectStatics(Class<?> types) {
staticInjections.addAll(Arrays.asList(types));
return this;
}
Upon creation, the Container will inject static fields and methods
into the given classes. |
public void setAllowDuplicates(boolean val) {
allowDuplicates = val;
}
|