/** * Convenience method. Equivalent to {@code factory(type, * Container.DEFAULT_NAME, factory, scope)}. * * @see #factory(Class, String, Factory, Scope) */ public <T> 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, name, factory, * Scope.DEFAULT)}. * * @see #factory(Class, String, Factory, Scope) */ public <T> ContainerBuilder factory(Class<T> type, String name, Factory<? extends T> factory) { return factory(type, name, factory, Scope.DEFAULT); }
@Override public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException { builder.factory(type, name, new Factory() { public Object create(Context context) throws Exception { return impl; } }, Scope.SINGLETON); } });
@Override public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException { builder.factory(type, name, new Factory() { public Object create(Context context) throws Exception { return impl; } }, Scope.SINGLETON); } });
/** * Convenience method. Equivalent to {@code factory(type, * Container.DEFAULT_NAME, implementation)}. * * @see #factory(Class, String, Class) */ public <T> 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, scope)}. * * @see #factory(Class, String, Class, Scope) */ public <T> 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, type, scope)}. * * @see #factory(Class, String, Class, Scope) */ public <T> 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)}. * * @see #factory(Class, String, Class) */ public <T> ContainerBuilder factory(Class<T> type) { return factory(type, Container.DEFAULT_NAME, type); }
/** * Convenience method. Equivalent to {@code factory(type, name, type, * scope)}. * * @see #factory(Class, String, Class, Scope) */ public <T> ContainerBuilder factory(Class<T> type, String name, Scope scope) { return factory(type, name, type, scope); }
/** * Convenience method. Equivalent to {@code factory(type, * Container.DEFAULT_NAME, factory, Scope.DEFAULT)}. * * @see #factory(Class, String, Factory, Scope) */ public <T> 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, name, type)}. * * @see #factory(Class, String, Class) */ public <T> ContainerBuilder factory(Class<T> type, String name) { return factory(type, name, type); }
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException { builder.factory(FileManager.class, name, fileManagerClass, Scope.SINGLETON); }
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException { builder.factory(FileManagerFactory.class, factoryClass.getSimpleName(), factoryClass, Scope.SINGLETON); }
@Override public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException { // Since we're about to override... builder.setAllowDuplicates(true); builder.factory(ObjectFactory.class, new Factory<ObjectFactory>() { public ObjectFactory create(Context xworkContext) throws Exception { SpringObjectFactory f = new SpringObjectFactory(); xworkContext.getContainer().inject(f); f.setApplicationContext(_applicationContext); f.setAutowireStrategy(_autoWireStrategy); return f; } }); } }
/** * Maps an implementation class to a given dependency type and name. Creates * instances using the container, recursively injecting dependencies. * * <p>Sets scope to value from {@link Scoped} annotation on the * implementation class. Defaults to {@link Scope#DEFAULT} if no annotation * is found. * * @param type of dependency * @param name of dependency * @param implementation class * @return this builder */ public <T> ContainerBuilder factory(final Class<T> type, String name, final 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 a constant value to the given type and name. */ private <T> ContainerBuilder constant(final Class<T> type, final String name, final T value) { InternalFactory<T> factory = new InternalFactory<T>() { public T create(InternalContext ignored) { return value; } @Override public String toString() { return new LinkedHashMap<String, Object>() { { put("type", type); put("name", name); put("value", value); } }.toString(); } }; return factory(Key.newInstance(type, name), factory, Scope.DEFAULT); }
return factory(Key.newInstance(type, name), internalFactory, scope);
return factory(Key.newInstance(type, name), factory, scope);
public void setConstants(ContainerBuilder builder) { for (Object keyobj : keySet()) { String key = (String)keyobj; builder.factory(String.class, key, new LocatableConstantFactory<String>(getProperty(key), getPropertyLocation(key))); } } }
public void selfRegister() { //this cannot be done in the constructor, as it causes an infinite loop builder.factory(Configuration.class, MockConfiguration.class, Scope.SINGLETON); LocatableProperties props = new LocatableProperties(); new XWorkConfigurationProvider().register(builder, props); builder.constant(XWorkConstants.DEV_MODE, "false"); builder.constant(XWorkConstants.RELOAD_XML_CONFIGURATION, "true"); builder.constant(XWorkConstants.ENABLE_OGNL_EXPRESSION_CACHE, "true"); container = builder.create(true); }