| Method from com.opensymphony.xwork2.ognl.OgnlValueStack Detail: |
public String findString(String expr) {
return (String) findValue(expr, String.class);
}
|
public Object findValue(String expr) {
try {
if (expr == null) {
return null;
}
if ((overrides != null) && overrides.containsKey(expr)) {
expr = (String) overrides.get(expr);
}
if (defaultType != null) {
return findValue(expr, defaultType);
}
Object value = ognlUtil.getValue(expr, context, root);
if (value != null) {
return value;
} else {
checkForInvalidProperties(expr);
return findInContext(expr);
}
} catch (OgnlException e) {
checkForInvalidProperties(expr);
return findInContext(expr);
} catch (Exception e) {
logLookupFailure(expr, e);
return findInContext(expr);
} finally {
ReflectionContextState.clear(context);
}
}
|
public Object findValue(String expr,
Class asType) {
try {
if (expr == null) {
return null;
}
if ((overrides != null) && overrides.containsKey(expr)) {
expr = (String) overrides.get(expr);
}
Object value = ognlUtil.getValue(expr, context, root, asType);
if (value != null) {
return value;
} else {
return findInContext(expr);
}
} catch (OgnlException e) {
return findInContext(expr);
} catch (Exception e) {
logLookupFailure(expr, e);
return findInContext(expr);
} finally {
ReflectionContextState.clear(context);
}
}
|
public Map getContext() {
return context;
}
|
public Map getExprOverrides() {
return this.overrides;
}
|
public CompoundRoot getRoot() {
return root;
}
|
public static void link(Map context,
Class clazz,
String name) {
context.put("__link", new Object[]{clazz, name});
}
|
public Object peek() {
return root.peek();
}
|
public Object pop() {
return root.pop();
}
|
public void push(Object o) {
root.push(o);
}
|
public void set(String key,
Object o) {
//set basically is backed by a Map
//pushed on the stack with a key
//being put on the map and the
//Object being the value
Map setMap = null;
//check if this is a Map
//put on the stack for setting
//if so just use the old map (reduces waste)
Object topObj = peek();
if (topObj instanceof Map
&& ((Map) topObj).get(MAP_IDENTIFIER_KEY) != null) {
setMap = (Map) topObj;
} else {
setMap = new HashMap();
//the map identifier key ensures
//that this map was put there
//for set purposes and not by a user
//whose data we don't want to touch
setMap.put(MAP_IDENTIFIER_KEY, "");
push(setMap);
}
setMap.put(key, o);
}
|
public void setDefaultType(Class defaultType) {
this.defaultType = defaultType;
}
|
public void setDevMode(String mode) {
devMode = "true".equalsIgnoreCase(mode);
}
|
public void setExprOverrides(Map overrides) {
if (this.overrides == null) {
this.overrides = overrides;
} else {
this.overrides.putAll(overrides);
}
}
|
public void setOgnlUtil(OgnlUtil ognlUtil) {
this.ognlUtil = ognlUtil;
}
|
protected void setRoot(XWorkConverter xworkConverter,
CompoundRootAccessor accessor,
CompoundRoot compoundRoot,
boolean allowStaticMethodAccess) {
this.root = compoundRoot;
this.context = Ognl.createDefaultContext(this.root, accessor, new OgnlTypeConverterWrapper(xworkConverter),
new StaticMemberAccess(allowStaticMethodAccess));
context.put(VALUE_STACK, this);
Ognl.setClassResolver(context, accessor);
((OgnlContext) context).setTraceEvaluations(false);
((OgnlContext) context).setKeepLastEvaluation(false);
}
|
public void setValue(String expr,
Object value) {
setValue(expr, value, devMode);
}
|
public void setValue(String expr,
Object value,
boolean throwExceptionOnFailure) {
Map context = getContext();
try {
context.put(XWorkConverter.CONVERSION_PROPERTY_FULLNAME, expr);
context.put(REPORT_ERRORS_ON_NO_PROP, (throwExceptionOnFailure) ? Boolean.TRUE : Boolean.FALSE);
ognlUtil.setValue(expr, context, root, value);
} catch (OgnlException e) {
if (throwExceptionOnFailure) {
e.printStackTrace(System.out);
System.out.println("expr: " + expr + " val: " + value + " context: " + context + " root:" + root + " value: " + value);
String msg = "Error setting expression '" + expr + "' with value '" + value + "'";
throw new XWorkException(msg, e);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Error setting value", e);
}
}
} catch (RuntimeException re) { //XW-281
if (throwExceptionOnFailure) {
StringBuffer msg = new StringBuffer();
msg.append("Error setting expression '");
msg.append(expr);
msg.append("' with value ");
if (value instanceof Object[]) {
Object[] valueArray = (Object[]) value;
msg.append("[");
for (int index = 0; index < valueArray.length; index++) {
msg.append("'");
msg.append(valueArray[index]);
msg.append("'");
if (index < (valueArray.length + 1))
msg.append(", ");
}
msg.append("]");
} else {
msg.append("'");
msg.append(value);
msg.append("'");
}
throw new XWorkException(msg.toString(), re);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Error setting value", re);
}
}
} finally {
ReflectionContextState.clear(context);
context.remove(XWorkConverter.CONVERSION_PROPERTY_FULLNAME);
context.remove(REPORT_ERRORS_ON_NO_PROP);
}
}
|
public int size() {
/* (non-Javadoc)
* @see com.opensymphony.xwork2.util.ValueStack#size()
*/
return root.size();
}
|