Struts 2ソースコードの浅い分析-Container
Containerコンテナインタフェース定義
コンテナの実装クラス
コンテナの作成はContainerBuilder createメソッドで行います
public interface Container extends Serializable {
/**
* Default dependency name.
*/
String DEFAULT_NAME = "default";
/**
*
* @Inject
* @param o
*/
void inject(Object o);
/**
*
*/
<T> T inject(Class<T> implementation);
/**
* bean
*/
<T> T getInstance(Class<T> type, String name);
/**
* bean
*/
<T> T getInstance(Class<T> type);
/**
* bean
*/
Set<String> getInstanceNames(Class<?> type);
/**
* Sets the scope strategy for the current thread.
*/
void setScopeStrategy(Scope.Strategy scopeStrategy);
/**
* Removes the scope strategy for the current thread.
*/
void removeScopeStrategy();
}
コンテナの実装クラス
class ContainerImpl implements Container {
}
コンテナの作成はContainerBuilder createメソッドで行います
public Container create(boolean loadSingletons) {
ensureNotCreated();
created = true;
//factories bean
//ContainerImpl factories factoryNamesByType
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;
}
});
}
// xml bean static true false
//com.opensymphony.xwork2.config.providers.XmlConfigurationProvider#register() line 210
container.injectStatics(staticInjections);
return container;
}