com.opensymphony.xwork2.XWork Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xwork Show documentation
Show all versions of xwork Show documentation
XWork is an command-pattern framework that is used to power WebWork
as well as other applications. XWork provides an Inversion of Control
container, a powerful expression language, data type conversion,
validation, and pluggable configuration.
/*
* Copyright (c) 2002-2006 by OpenSymphony
* All rights reserved.
*/
package com.opensymphony.xwork2;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import java.util.Collections;
import java.util.Map;
/**
* Simple facade to make using XWork standalone easier
*/
public class XWork {
ConfigurationManager configurationManager;
public XWork() {
this(new ConfigurationManager());
}
public XWork(ConfigurationManager mgr) {
this.configurationManager = mgr;
}
public void setLoggerFactory(LoggerFactory factory) {
LoggerFactory.setLoggerFactory(factory);
}
/**
* Executes an action
*
* @param namespace The namespace
* @param name The action name
* @param method The method name
* @throws Exception If anything goes wrong
*/
public void executeAction(String namespace, String name, String method) throws XWorkException {
Map extraContext = Collections.emptyMap();
executeAction(namespace, name, method, extraContext);
}
/**
* Executes an action with extra context information
*
* @param namespace The namespace
* @param name The action name
* @param method The method name
* @param extraContext A map of extra context information
* @throws Exception If anything goes wrong
*/
public void executeAction(String namespace, String name, String method, Map extraContext) throws XWorkException {
Configuration config = configurationManager.getConfiguration();
try {
ActionProxy proxy = config.getContainer().getInstance(ActionProxyFactory.class).createActionProxy(
namespace, name, method, extraContext, true, false);
proxy.execute();
} catch (Exception e) {
throw new XWorkException(e);
} finally {
ActionContext.setContext(null);
}
}
}