webwork/src/main/webwork/util ValueStack.java,1.52,1.53
[email protected] Sun, 16 Nov 2003 15:39:18 -0800
| Newsgroups | gmane.comp.java.open-symphony.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/opensymphony/webwork/src/main/webwork/util In directory sc8-pr-cvs1:/tmp/cvs-serv2495 Modified Files: ValueStack.java Log Message: Updated when adding SimpleTest class to fix issue WW-387 Index: ValueStack.java =================================================================== RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/util/ValueStack.java,v retrieving revision 1.52 retrieving revision 1.53 diff -u -d -r1.52 -r1.53 --- ValueStack.java 28 Aug 2003 00:34:07 -0000 1.52 +++ ValueStack.java 16 Nov 2003 23:39:15 -0000 1.53 @@ -24,14 +24,14 @@ * values available by using the push and pop methods. They can then * be accessed by using the find* methods. * - * @author Rickard �berg ([email protected]) + * @author Rickard Öberg ([email protected]) * @author Maurice C. Parker ([email protected]) * @version $Revision$ */ public class ValueStack{ // Static ------------------------------------------------------- public static final String STACK_NAME = "webwork.result"; - static Map classes = new HashMap(); // Method cache + protected static Map classes = new HashMap(); // Method cache private static Log log = LogFactory.getLog(ServletValueStack.class); /** @@ -64,7 +64,7 @@ valueList.add(value); -// log.debug("Push to value stack:"); +// log.debug("Push to value stack:" + value); // log.debug(toString()); // new Throwable().printStackTrace(); } @@ -100,7 +100,7 @@ * @return size of value stack */ public int size() { - return valueList != null?valueList.size():0; + return valueList.size(); } /** @@ -122,19 +122,25 @@ if (expression==null) { throw new NullPointerException("Expression cannot be null."); } - Parser p = getParser(expression); - boolean answer = false; - - try { - answer = p.test(); + try + { + SimpleTest simpleTest = SimpleTest.getSimpleTest(expression); + if (simpleTest != null) + { + answer = simpleTest.test(this, null, null); + } + else + { + Parser p = getParser(expression); + answer = p.test(); + } } catch (Throwable pe) { - log.error("An error occurred while parsing the expression: \"" + expression + "\", throwable: ", pe); - throw new IllegalArgumentException("\n\nAn error occurred while parsing the expression: \n \"" + - expression + "\"\n" + - pe.getMessage()); + log.error("An error occurred while parsing the expression: \"" + expression + "\", throwable: ", pe); + throw new IllegalArgumentException("\n\nAn error occurred while parsing the expression: \n \"" + + expression + "\"\n" + + pe.getMessage()); } - return answer; } @@ -154,25 +160,32 @@ */ public Object findValue(String query) throws IllegalArgumentException { - if (query == null || query.length()==0) - query = "."; + Query q; + if (query == null || query.length()==0 || (query.length()==1 && query.charAt(0)=='.')) + q = Query.CURRENT; + else + { + // The query segments and the current segment + q = Query.getQuery(query); + } + return findValue(q); + } + public Object findValue(Query q) + throws IllegalArgumentException { // The query segments and the current segment - Query q = Query.getQuery(query); QuerySegment[] segments = q.getSegments(); - if (log.isDebugEnabled()) { - log.debug("findValue() for: " + q); - } - +// if (log.isDebugEnabled()) { +// log.debug("findValue() for: " + q); +// } QuerySegment segment = segments[0]; int segmentIdx = 1; - // The working stack, its pointer, and the current object, - List workList = null; + // The current stack pointer, and the current object, int stackIdx = 0; Object value = null; - + ///////////////////////////////////////////////////////////////////////// // evaluate the first element of the expression to see where to // get the requested value. These should be quick and easy objects @@ -186,8 +199,7 @@ if (valueList.size() < 1) return null; // set up the stack, pointer, and current value - workList = valueList; - value = workList.get(valueList.size()-1); + value = valueList.get(valueList.size()-1); if (value instanceof ValueHolder) value = ((ValueHolder) value).getValue(); @@ -198,8 +210,7 @@ if (segment == null) return value; - // Set the stack index to zero so that we don't try to search the stack - stackIdx = 0; + // The stackIdx is already zero so we will not try to search the stack break; // return the id since it is the actual string @@ -219,9 +230,9 @@ // /SK if (value == null) { - if (log.isDebugEnabled()) { - log.debug("value for [" + query + "] is null."); - } +// if (log.isDebugEnabled()) { +// log.debug("value for [" + q + "] is null."); +// } return null; @@ -238,8 +249,7 @@ if (segment == null) return value; - // Set the stack index to zero so that we don't try to search the stack - stackIdx = 0; + // The stackIdx is already zero so we will not try to search the stack break; @@ -265,10 +275,9 @@ if (valueList.size() < 1) return null; - // set up the stack, pointer, and current value - workList = valueList; - stackIdx = 0; - value = workList.get(stackIdx); + // The stackIdx is already zero so we will not try to search the stack + // set up the stack pointer, and current value + value = valueList.get(0); // always have the next segment ready to go segment = segments[segmentIdx++]; @@ -285,15 +294,14 @@ if (valueList.size() < 1) return null; - // set up the stack, pointer, and current value - workList = valueList; - stackIdx = workList.size() - 1; + // set up the stack pointer, and current value + stackIdx = valueList.size() - 1; try { - value = workList.get(stackIdx); + value = valueList.get(stackIdx); } catch (IndexOutOfBoundsException e) { return null; - //throw new IllegalArgumentException("Illegal valuestack query:"+query); + //throw new IllegalArgumentException("Illegal valuestack query:"+q); } break; @@ -369,12 +377,12 @@ break objectWalk; } - List valueList = segment.getValues(); - int vsize = valueList.size(); + List pValueList = segment.getValues(); + int vsize = pValueList.size(); params = new Object[vsize]; for(int i=0; i < vsize; i++) { - Object param = findValue((String) valueList.get(i)); + Object param = findValue((Query) pValueList.get(i)); params[i] = param; } @@ -446,7 +454,7 @@ if (value == null) break objectWalk; - Object key = findValue(segment.getId()); + Object key = findValue(segment.getQuery()); if (key == null) { value = null; break objectWalk; @@ -492,7 +500,7 @@ break objectWalk; //throw new IllegalArgumentException("Parent object not available."); } else { - value = workList.get(workStackIdx); + value = valueList.get(workStackIdx); } break; @@ -501,7 +509,7 @@ //log.debug( "EXPAND: going after: " + segment.getId() ); try { - Object methodName = findValue(segment.getId()); + Object methodName = findValue(segment.getQuery()); if (methodName == null) { value = null; break objectWalk; @@ -525,7 +533,7 @@ // try again. if (value == null && stackIdx > 0) { stackIdx--; - value = workList.get(stackIdx); + value = valueList.get(stackIdx); // reset the segment index to reset the search segmentIdx = saveSegmentIdx; @@ -539,8 +547,8 @@ if (value instanceof ValueHolder) value = ((ValueHolder) value).getValue(); - if (value == null && log.isDebugEnabled()) - log.debug("value for [" + query + "] is null."); +// if (value == null && log.isDebugEnabled()) +// log.debug("value for [" + q + "] is null."); return value; } @@ -591,7 +599,6 @@ * @return the wanted method * @exception IntrospectionException */ - protected MethodInfo[] getMethod(Class cl, String name) throws IntrospectionException { Map methods = (Map) classes.get(cl); ------------------------------------------------------- This SF. Net email is sponsored by: GoToMyPC GoToMyPC is the fast, easy and secure way to access your computer from any Web browser or wireless device. Click here to Try it Free! https://www.gotomypc.com/tr/OSDN/AW/Q4_2003/t/g22lp?Target=mm/g22lp.tmpl