📄 scopeinterceptor.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: ScopeInterceptor.java
package org.apache.struts2.interceptor;
import com.opensymphony.xwork2.*;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.PreResultListener;
import com.opensymphony.xwork2.util.ValueStack;
import java.io.Serializable;
import java.util.IdentityHashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsException;
import org.apache.struts2.dispatcher.SessionMap;
public class ScopeInterceptor extends AbstractInterceptor
implements PreResultListener
{
private static class NULLClass
implements Serializable
{
public String toString()
{
return "NULL";
}
public boolean equals(Object obj)
{
return obj == null || (obj instanceof NULLClass);
}
private NULLClass()
{
}
}
private static final long serialVersionUID = 0x7e937559f64b487bL;
private static final Log LOG = LogFactory.getLog(org/apache/struts2/interceptor/ScopeInterceptor);
private String application[];
private String session[];
private String key;
private String type;
private boolean autoCreateSession;
private String sessionReset;
private boolean reset;
private static final Object NULL = new NULLClass();
private static Map locks = new IdentityHashMap();
public void setApplication(String s)
{
if (s != null)
application = s.split(" *, *");
}
public void setSession(String s)
{
if (s != null)
session = s.split(" *, *");
}
public void setAutoCreateSession(String value)
{
if (value != null && value.length() > 0)
autoCreateSession = (new Boolean(value)).booleanValue();
}
private String getKey(ActionInvocation invocation)
{
ActionProxy proxy = invocation.getProxy();
if (key == null || "CLASS".equals(key))
return (new StringBuilder()).append("struts.ScopeInterceptor:").append(proxy.getAction().getClass()).toString();
if ("ACTION".equals(key))
return (new StringBuilder()).append("struts.ScopeInterceptor:").append(proxy.getNamespace()).append(":").append(proxy.getActionName()).toString();
else
return key;
}
public ScopeInterceptor()
{
application = null;
session = null;
type = null;
autoCreateSession = true;
sessionReset = "session.reset";
reset = false;
}
private static final Object nullConvert(Object o)
{
if (o == null)
return NULL;
if (o == NULL || NULL.equals(o))
return null;
else
return o;
}
static final void lock(Object o, ActionInvocation invocation)
throws Exception
{
Object obj = o;
JVM INSTR monitorenter ;
int count;
count = 3;
Object previous = null;
_L2:
Object previous;
if ((previous = locks.get(o)) == null)
break MISSING_BLOCK_LABEL_75;
if (previous != invocation)
break MISSING_BLOCK_LABEL_33;
return;
if (count-- <= 0)
{
locks.remove(o);
o.notify();
throw new StrutsException("Deadlock in session lock");
}
o.wait(10000L);
if (true) goto _L2; else goto _L1
_L1:
locks.put(o, invocation);
break MISSING_BLOCK_LABEL_98;
Exception exception;
exception;
throw exception;
}
static final void unlock(Object o)
{
synchronized (o)
{
locks.remove(o);
o.notify();
}
}
protected void after(ActionInvocation invocation, String result)
throws Exception
{
Map ses = ActionContext.getContext().getSession();
if (ses != null)
unlock(ses);
}
protected void before(ActionInvocation invocation)
throws Exception
{
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();
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((new StringBuilder()).append(key).append(string).toString());
if (attribute == null)
continue;
if (LOG.isDebugEnabled())
LOG.debug((new StringBuilder()).append("application scoped variable set ").append(string).append(" = ").append(String.valueOf(attribute)).toString());
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((new StringBuilder()).append(key).append(string).toString());
if (attribute == null)
continue;
if (LOG.isDebugEnabled())
LOG.debug((new StringBuilder()).append("session scoped variable set ").append(string).append(" = ").append(String.valueOf(attribute)).toString());
stack.setValue(string, nullConvert(attribute));
}
}
}
public void setKey(String key)
{
this.key = key;
}
public void beforeResult(ActionInvocation invocation, String resultCode)
{
String key = getKey(invocation);
Map app = ActionContext.getContext().getApplication();
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((new StringBuilder()).append("application scoped variable saved ").append(string).append(" = ").append(String.valueOf(value)).toString());
app.put((new StringBuilder()).append(key).append(string).toString(), 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((new StringBuilder()).append(key).append(string).toString());
continue;
}
Object value = stack.findValue(string);
if (LOG.isDebugEnabled())
LOG.debug((new StringBuilder()).append("session scoped variable saved ").append(string).append(" = ").append(String.valueOf(value)).toString());
ses.put((new StringBuilder()).append(key).append(string).toString(), 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)");
}
public String getType()
{
return type;
}
public void setType(String type)
{
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");
}
public String getSessionReset()
{
return sessionReset;
}
public void setSessionReset(String sessionReset)
{
this.sessionReset = sessionReset;
}
public String intercept(ActionInvocation invocation)
throws Exception
{
String result;
Map ses;
result = null;
ses = ActionContext.getContext().getSession();
before(invocation);
result = invocation.invoke();
after(invocation, result);
if (ses != null)
unlock(ses);
break MISSING_BLOCK_LABEL_51;
Exception exception;
exception;
if (ses != null)
unlock(ses);
throw exception;
return result;
}
public boolean isReset()
{
return reset;
}
public void setReset(boolean reset)
{
this.reset = reset;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -