| Method from com.opensymphony.xwork2.config.impl.DefaultConfiguration Detail: |
public void addPackageConfig(String name,
PackageConfig packageContext) {
PackageConfig check = packageContexts.get(name);
if (check != null) {
if (check.getLocation() != null && packageContext.getLocation() != null
&& check.getLocation().equals(packageContext.getLocation())) {
if (LOG.isDebugEnabled()) {
LOG.debug("The package name '" + name
+ "' is already been loaded by the same location and could be removed: "
+ packageContext.getLocation());
}
} else {
throw new ConfigurationException("The package name '" + name
+ "' at location "+packageContext.getLocation()
+ " is already been used by another package at location " + check.getLocation(),
packageContext);
}
}
packageContexts.put(name, packageContext);
}
|
protected synchronized RuntimeConfiguration buildRuntimeConfiguration() throws ConfigurationException {
Map< String, Map< String, ActionConfig > > namespaceActionConfigs = new LinkedHashMap< String, Map< String, ActionConfig > >();
Map< String, String > namespaceConfigs = new LinkedHashMap< String, String >();
for (PackageConfig packageConfig : packageContexts.values()) {
if (!packageConfig.isAbstract()) {
String namespace = packageConfig.getNamespace();
Map< String, ActionConfig > configs = namespaceActionConfigs.get(namespace);
if (configs == null) {
configs = new LinkedHashMap< String, ActionConfig >();
}
Map< String, ActionConfig > actionConfigs = packageConfig.getAllActionConfigs();
for (Object o : actionConfigs.keySet()) {
String actionName = (String) o;
ActionConfig baseConfig = actionConfigs.get(actionName);
configs.put(actionName, buildFullActionConfig(packageConfig, baseConfig));
}
namespaceActionConfigs.put(namespace, configs);
if (packageConfig.getFullDefaultActionRef() != null) {
namespaceConfigs.put(namespace, packageConfig.getFullDefaultActionRef());
}
}
}
return new RuntimeConfigurationImpl(namespaceActionConfigs, namespaceConfigs);
}
This builds the internal runtime configuration used by Xwork for finding and configuring Actions from the
programmatic configuration data structures. All of the old runtime configuration will be discarded and rebuilt.
It basically flattens the data structures to make the information easier to access. It will take
an ActionConfig and combine its data with all inherited dast. For example, if the ActionConfig
is in a package that contains a global result and it also contains a result, the resulting ActionConfig
will have two results. |
protected Container createBootstrapContainer() {
ContainerBuilder builder = new ContainerBuilder();
builder.factory(ObjectFactory.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(XWorkBasicConverter.class, Scope.SINGLETON);
builder.factory(TextProvider.class, "system", DefaultTextProvider.class, Scope.SINGLETON);
builder.factory(ObjectTypeDeterminer.class, DefaultObjectTypeDeterminer.class, Scope.SINGLETON);
builder.factory(PropertyAccessor.class, CompoundRoot.class.getName(), CompoundRootAccessor.class, Scope.SINGLETON);
builder.factory(OgnlUtil.class, Scope.SINGLETON);
builder.constant("devMode", "false");
builder.constant("logMissingProperties", "false");
return builder.create(true);
}
|
public void destroy() {
packageContexts.clear();
loadedFileNames.clear();
}
Allows the configuration to clean up any resources used |
public Container getContainer() {
return container;
}
|
public Set<String> getLoadedFileNames() {
return loadedFileNames;
}
|
public PackageConfig getPackageConfig(String name) {
return packageContexts.get(name);
}
|
public Set<String> getPackageConfigNames() {
return packageContexts.keySet();
}
|
public Map<String, PackageConfig> getPackageConfigs() {
return packageContexts;
}
|
public RuntimeConfiguration getRuntimeConfiguration() {
return runtimeConfiguration;
}
|
public List<UnknownHandlerConfig> getUnknownHandlerStack() {
return unknownHandlerStack;
}
|
public void rebuildRuntimeConfiguration() {
runtimeConfiguration = buildRuntimeConfiguration();
}
|
public synchronized void reload(List<ConfigurationProvider> providers) throws ConfigurationException {
// Silly copy necessary due to lack of ability to cast generic lists
List< ContainerProvider > contProviders = new ArrayList< ContainerProvider >();
contProviders.addAll(providers);
reloadContainer(contProviders);
}
Calls the ConfigurationProviderFactory.getConfig() to tell it to reload the configuration and then calls
buildRuntimeConfiguration(). |
public synchronized List<PackageProvider> reloadContainer(List<ContainerProvider> providers) throws ConfigurationException {
packageContexts.clear();
loadedFileNames.clear();
List< PackageProvider > packageProviders = new ArrayList< PackageProvider >();
ContainerProperties props = new ContainerProperties();
ContainerBuilder builder = new ContainerBuilder();
for (final ContainerProvider containerProvider : providers)
{
containerProvider.init(this);
containerProvider.register(builder, props);
}
props.setConstants(builder);
builder.factory(Configuration.class, new Factory< Configuration >() {
public Configuration create(Context context) throws Exception {
return DefaultConfiguration.this;
}
});
ActionContext oldContext = ActionContext.getContext();
try {
// Set the bootstrap container for the purposes of factory creation
Container bootstrap = createBootstrapContainer();
setContext(bootstrap);
container = builder.create(false);
setContext(container);
objectFactory = container.getInstance(ObjectFactory.class);
// Process the configuration providers first
for (final ContainerProvider containerProvider : providers)
{
if (containerProvider instanceof PackageProvider) {
container.inject(containerProvider);
((PackageProvider)containerProvider).loadPackages();
packageProviders.add((PackageProvider)containerProvider);
}
}
// Then process any package providers from the plugins
Set< String > packageProviderNames = container.getInstanceNames(PackageProvider.class);
if (packageProviderNames != null) {
for (String name : packageProviderNames) {
PackageProvider provider = container.getInstance(PackageProvider.class, name);
provider.init(this);
provider.loadPackages();
packageProviders.add(provider);
}
}
rebuildRuntimeConfiguration();
} finally {
if (oldContext == null) {
ActionContext.setContext(null);
}
}
return packageProviders;
}
Calls the ConfigurationProviderFactory.getConfig() to tell it to reload the configuration and then calls
buildRuntimeConfiguration(). |
public PackageConfig removePackageConfig(String packageName) {
return packageContexts.remove(packageName);
}
|
protected ActionContext setContext(Container cont) {
ActionContext context = ActionContext.getContext();
if (context == null) {
ValueStack vs = cont.getInstance(ValueStackFactory.class).createValueStack();
context = new ActionContext(vs.getContext());
ActionContext.setContext(context);
}
return context;
}
|
public void setUnknownHandlerStack(List<UnknownHandlerConfig> unknownHandlerStack) {
this.unknownHandlerStack = unknownHandlerStack;
}
|