public MockConfiguration() { builder = new ContainerBuilder(); }
/** * Maps a constant value to the given name. */ public ContainerBuilder constant(String name, int value) { return constant(int.class, name, value); }
@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 { // 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; } }); } }
protected Container createBootstrapContainer(List<ContainerProvider> providers) { ContainerBuilder builder = new ContainerBuilder(); boolean fmFactoryRegistered = false; for (ContainerProvider provider : providers) { builder.factory(ObjectFactory.class, Scope.SINGLETON); builder.factory(ActionFactory.class, DefaultActionFactory.class, Scope.SINGLETON); builder.factory(ResultFactory.class, DefaultResultFactory.class, Scope.SINGLETON); builder.factory(InterceptorFactory.class, DefaultInterceptorFactory.class, Scope.SINGLETON); builder.factory(com.opensymphony.xwork2.factory.ValidatorFactory.class, com.opensymphony.xwork2.factory.DefaultValidatorFactory.class, Scope.SINGLETON); builder.factory(ConverterFactory.class, DefaultConverterFactory.class, Scope.SINGLETON); builder.factory(UnknownHandlerFactory.class, DefaultUnknownHandlerFactory.class, Scope.SINGLETON); builder.factory(FileManager.class, "system", DefaultFileManager.class, Scope.SINGLETON); if (!fmFactoryRegistered) { builder.factory(FileManagerFactory.class, DefaultFileManagerFactory.class, Scope.SINGLETON); builder.factory(ReflectionProvider.class, OgnlReflectionProvider.class, Scope.SINGLETON); builder.factory(ValueStackFactory.class, OgnlValueStackFactory.class, Scope.SINGLETON); builder.factory(XWorkConverter.class, Scope.SINGLETON); builder.factory(ConversionPropertiesProcessor.class, DefaultConversionPropertiesProcessor.class, Scope.SINGLETON); builder.factory(ConversionFileProcessor.class, DefaultConversionFileProcessor.class, Scope.SINGLETON); builder.factory(ConversionAnnotationProcessor.class, DefaultConversionAnnotationProcessor.class, Scope.SINGLETON); builder.factory(TypeConverterCreator.class, DefaultTypeConverterCreator.class, Scope.SINGLETON); builder.factory(TypeConverterHolder.class, DefaultTypeConverterHolder.class, Scope.SINGLETON); builder.factory(XWorkBasicConverter.class, Scope.SINGLETON); builder.factory(TypeConverter.class, XWorkConstants.COLLECTION_CONVERTER, CollectionConverter.class, Scope.SINGLETON); builder.factory(TypeConverter.class, XWorkConstants.ARRAY_CONVERTER, ArrayConverter.class, Scope.SINGLETON);
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); }
protected Container createContainer() { ContainerBuilder builder = new ContainerBuilder(); builder.constant("devMode", "false"); return builder.create(true); }
ContainerBuilder builder = new ContainerBuilder(); Container bootstrap = createBootstrapContainer(providers); for (final ContainerProvider containerProvider : providers) builder.factory(Configuration.class, new Factory<Configuration>() { public Configuration create(Context context) throws Exception { return DefaultConfiguration.this; container = builder.create(false); setContext(container); objectFactory = container.getInstance(ObjectFactory.class);
containerBuilder.injectStatics(cimpl); } else { if (containerBuilder.contains(ctype, name)) { Location loc = LocationUtils.getLocation(loadedBeans.get(ctype.getName() + name)); if (throwExceptionOnDuplicateBeans) { LOG.debug("Loaded type:" + type + " name:" + name + " impl:" + impl); containerBuilder.factory(ctype, name, new LocatableFactory(name, ctype, cimpl, scope, childNode), scope);
/** * Maps an existing dependency. All methods in this class ultimately funnel through * here. */ private <T> ContainerBuilder alias(final Key<T> key, final Key<T> aliasKey) { ensureNotCreated(); checkKey(aliasKey); final InternalFactory<? extends T> scopedFactory = (InternalFactory<? extends T>)factories.get(key); if (scopedFactory == null) { throw new DependencyException( "Dependency mapping for " + key + " doesn't exists."); } factories.put(aliasKey, scopedFactory); return this; }
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException { builder.setAllowDuplicates(true); }
/** * Convenience method. Equivalent to {@code alias(type, Container.DEFAULT_NAME, * type)}. * * @see #alias(Class, String, String) */ public <T> ContainerBuilder alias(Class<T> type, String alias) { return alias(type, Container.DEFAULT_NAME, alias); }
/** * Convenience method. Equivalent to {@code contains(type, * Container.DEFAULT_NAME)}. */ public boolean contains(Class<?> type) { return contains(type, Container.DEFAULT_NAME); }
/** * Creates a {@link Container} instance. Injects static members for classes * which were registered using {@link #injectStatics(Class...)}. * * @param loadSingletons If true, the container will load all singletons * now. If false, the container will lazily load singletons. Eager loading * is appropriate for production use while lazy loading can speed * development. * @throws IllegalStateException if called more than once */ 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; }
/** * Maps a dependency. All methods in this class ultimately funnel through * here. */ private <T> ContainerBuilder factory(final Key<T> key, InternalFactory<? extends T> factory, Scope scope) { ensureNotCreated(); checkKey(key); final InternalFactory<? extends T> scopedFactory = scope.scopeFactory(key.getType(), key.getName(), factory); factories.put(key, scopedFactory); if (scope == Scope.SINGLETON) { singletonFactories.add(new InternalFactory<T>() { public T create(InternalContext context) { try { context.setExternalContext(ExternalContext.newInstance( null, key, context.getContainerImpl())); return scopedFactory.create(context); } finally { context.setExternalContext(null); } } }); } return this; }
/** * Maps an existing factory to a new name. * * @param type of dependency * @param name of dependency * @param alias of to the dependency * @return this builder */ public <T> ContainerBuilder alias(Class<T> type, String name, String alias) { return alias(Key.newInstance(type, name), Key.newInstance(type, alias)); }
@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); } });
/** * Maps a constant value to the given name. */ public ContainerBuilder constant(String name, boolean value) { return constant(boolean.class, name, value); }
/** * 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); }
/** * Maps a constant value to the given name. */ public ContainerBuilder constant(String name, String value) { return constant(String.class, name, value); }