Methods Summary |
---|
protected void | after(com.opensymphony.xwork2.ActionInvocation invocation, java.lang.String result)
Map ses = ActionContext.getContext().getSession();
if ( ses != null) {
unlock(ses);
}
|
protected void | before(com.opensymphony.xwork2.ActionInvocation invocation)
invocation.addPreResultListener(this);
Map ses = ActionContext.getContext().getSession();
if (ses == null && autoCreateSession) {
ses = new SessionMap(ServletActionContext.getRequest());
ActionContext.getContext().setSession(ses);
}
if ( ses != null) {
lock(ses, invocation);
}
String key = getKey(invocation);
Map app = ActionContext.getContext().getApplication();
final ValueStack stack = ActionContext.getContext().getValueStack();
if (LOG.isDebugEnabled()) {
LOG.debug("scope interceptor before");
}
if (application != null)
for (int i = 0; i < application.length; i++) {
String string = application[i];
Object attribute = app.get(key + string);
if (attribute != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("application scoped variable set " + string + " = " + String.valueOf(attribute));
}
stack.setValue(string, nullConvert(attribute));
}
}
if (ActionContext.getContext().getParameters().get(sessionReset) != null) {
return;
}
if (reset) {
return;
}
if (ses == null) {
LOG.debug("No HttpSession created... Cannot set session scoped variables");
return;
}
if (session != null && (!"start".equals(type))) {
for (int i = 0; i < session.length; i++) {
String string = session[i];
Object attribute = ses.get(key + string);
if (attribute != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("session scoped variable set " + string + " = " + String.valueOf(attribute));
}
stack.setValue(string, nullConvert(attribute));
}
}
}
|
public void | beforeResult(com.opensymphony.xwork2.ActionInvocation invocation, java.lang.String resultCode)
String key = getKey(invocation);
Map app = ActionContext.getContext().getApplication();
final ValueStack stack = ActionContext.getContext().getValueStack();
if (application != null)
for (int i = 0; i < application.length; i++) {
String string = application[i];
Object value = stack.findValue(string);
if (LOG.isDebugEnabled()) {
LOG.debug("application scoped variable saved " + string + " = " + String.valueOf(value));
}
//if( value != null)
app.put(key + string, nullConvert(value));
}
boolean ends = "end".equals(type);
Map ses = ActionContext.getContext().getSession();
if (ses != null) {
if (session != null) {
for (int i = 0; i < session.length; i++) {
String string = session[i];
if (ends) {
ses.remove(key + string);
} else {
Object value = stack.findValue(string);
if (LOG.isDebugEnabled()) {
LOG.debug("session scoped variable saved " + string + " = " + String.valueOf(value));
}
// Null value should be scoped too
//if( value != null)
ses.put(key + string, nullConvert(value));
}
}
}
unlock(ses);
} else {
LOG.debug("No HttpSession created... Cannot save session scoped variables.");
}
if (LOG.isDebugEnabled()) {
LOG.debug("scope interceptor after (before result)");
}
|
private java.lang.String | getKey(com.opensymphony.xwork2.ActionInvocation invocation)
ActionProxy proxy = invocation.getProxy();
if (key == null || "CLASS".equals(key)) {
return "struts.ScopeInterceptor:" + proxy.getAction().getClass();
} else if ("ACTION".equals(key)) {
return "struts.ScopeInterceptor:" + proxy.getNamespace() + ":" + proxy.getActionName();
}
return key;
|
public java.lang.String | getSessionReset()
return sessionReset;
|
public java.lang.String | getType()
return type;
|
public java.lang.String | intercept(com.opensymphony.xwork2.ActionInvocation invocation)
String result = null;
Map ses = ActionContext.getContext().getSession();
before(invocation);
try {
result = invocation.invoke();
after(invocation, result);
} finally {
if (ses != null) {
unlock(ses);
}
}
return result;
|
public boolean | isReset()
return reset;
|
static final void | lock(java.lang.Object o, com.opensymphony.xwork2.ActionInvocation invocation)
synchronized (o) {
int count = 3;
Object previous = null;
while ((previous = locks.get(o)) != null) {
if (previous == invocation) {
return;
}
if (count-- <= 0) {
locks.remove(o);
o.notify();
throw new StrutsException("Deadlock in session lock");
}
o.wait(10000);
}
;
locks.put(o, invocation);
}
|
private static final java.lang.Object | nullConvert(java.lang.Object o)
if (o == null) {
return NULL;
}
if (o == NULL || NULL.equals(o)) {
return null;
}
return o;
|
public void | setApplication(java.lang.String s)Sets a list of application scoped properties
if (s != null) {
application = s.split(" *, *");
}
|
public void | setAutoCreateSession(java.lang.String value)Sets if the session should be automatically created
if (value != null && value.length() > 0) {
this.autoCreateSession = new Boolean(value).booleanValue();
}
|
public void | setKey(java.lang.String key)
this.key = key;
|
public void | setReset(boolean reset)
this.reset = reset;
|
public void | setSession(java.lang.String s)Sets a list of session scoped properties
if (s != null) {
session = s.split(" *, *");
}
|
public void | setSessionReset(java.lang.String sessionReset)
this.sessionReset = sessionReset;
|
public void | setType(java.lang.String type)Sets the type of scope operation
type = type.toLowerCase();
if ("start".equals(type) || "end".equals(type)) {
this.type = type;
} else {
throw new IllegalArgumentException("Only start or end are allowed arguments for type");
}
|
static final void | unlock(java.lang.Object o)
synchronized (o) {
locks.remove(o);
o.notify();
}
|