From: <wan...@us...> - 2003-07-16 14:25:34
|
Update of /cvsroot/webmacro/webmacro/src/org/webmacro/engine In directory sc8-pr-cvs1:/tmp/cvs-serv5350 Modified Files: PropertyOperatorCache.java Log Message: Attempted fix for "binary set" method not found bug. May have implications but works for now. Index: PropertyOperatorCache.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/engine/PropertyOperatorCache.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** PropertyOperatorCache.java 12 Jun 2003 00:47:45 -0000 1.18 --- PropertyOperatorCache.java 16 Jul 2003 14:25:31 -0000 1.19 *************** *** 247,250 **** --- 247,310 ---- } + public static class Wrapper + { + + private Map params = new Hashtable(); + + public String getParameters( String key ) + { + return (String) params.get( key ); + } + + public void setParameters( String key, Object value ) + { + params.put( key, value ); + } + } + + public static class Wrapper2 + { + + private Map params = new Hashtable(); + + public Wrapper2() + { + this.params.put( "Parameters", new Hashtable() ); + } + + public Object get( Object key ) + { + return params.get( key ); + } + + public void put( Object key, Object value ) + { + params.put( key, value ); + } + } + + public static void main( String[] args ) + { + final String templateText = + "#set $test.Parameters.Name = 'marc'\n" + + "#set $test2.Parameters.Name = 'eric'\n" + + "Current value is: $test.Parameters.Name\n"+ + "Current value2 is: $test2.Parameters.Name\n"; + try + { + WebMacro wm = new WM( "testconfig.properties" ); + Template t = new StringTemplate( wm.getBroker(), templateText ); + Context context = wm.getContext(); + context.put( "test", new Wrapper() ); + context.put( "test2", new Wrapper2() ); + t.write( System.out, context ); + } + catch ( Exception e ) + { + e.printStackTrace(); //To change body of catch statement use Options | File Templates. + } + + } + } *************** *** 693,713 **** throws PropertyException { ! String prop; ! Object nextProp = null; Accessor acc = null; if (names[start] instanceof String) { ! prop = (String) names[start]; } else if (names[start] instanceof PropertyMethod) { PropertyMethod pm = (PropertyMethod) names[start]; ! prop = pm.getName(); ! acc = (Accessor) _directAccessors.get(prop); Object[] args = pm.getArguments(context); if (acc == null) { ! if (isMethodRestricted(instance.getClass(), prop)) throw new PropertyException.RestrictedMethodException( pm.toString(), --- 753,773 ---- throws PropertyException { ! String propName; ! Object nextPropValue = null; Accessor acc = null; if (names[start] instanceof String) { ! propName = (String) names[start]; } else if (names[start] instanceof PropertyMethod) { PropertyMethod pm = (PropertyMethod) names[start]; ! propName = pm.getName(); ! acc = (Accessor) _directAccessors.get(propName); Object[] args = pm.getArguments(context); if (acc == null) { ! if (isMethodRestricted(instance.getClass(), propName)) throw new PropertyException.RestrictedMethodException( pm.toString(), *************** *** 721,725 **** try { ! nextProp = acc.get(instance, args); start++; } --- 781,785 ---- try { ! nextPropValue = acc.get(instance, args); start++; } *************** *** 735,739 **** else { ! prop = names[start].toString(); } --- 795,799 ---- else { ! propName = names[start].toString(); } *************** *** 741,750 **** if (acc == null) { ! acc = (Accessor) _unaryAccessors.get(prop); if (acc != null) { try { ! nextProp = acc.get(instance); start++; } --- 801,810 ---- if (acc == null) { ! acc = (Accessor) _unaryAccessors.get(propName); if (acc != null) { try { ! nextPropValue = acc.get(instance); start++; } *************** *** 759,768 **** if (acc == null) { ! acc = (Accessor) _binaryAccessors.get(prop); ! if ((acc != null) && ((start + 1) <= end)) { try { ! nextProp = acc.get(instance, (String) names[start + 1]); start += 2; } --- 819,829 ---- if (acc == null) { ! acc = (Accessor) _binaryAccessors.get(propName); ! // if ((acc != null) && ((start + 1) <= end)) ! if ((acc != null) && ((start + 1) <= names.length)) { try { ! nextPropValue = acc.get(instance, (String) names[start + 1]); start += 2; } *************** *** 793,797 **** if (acc != null) { ! nextProp = acc.get(instance, prop); start++; } --- 854,858 ---- if (acc != null) { ! nextPropValue = acc.get(instance, propName); start++; } *************** *** 809,828 **** // check if object is restricted ! if (isMethodRestricted(instance.getClass(), "get" + prop) ! || isMethodRestricted(instance.getClass(), "set" + prop)) throw new PropertyException.RestrictedPropertyException( ! prop, fillInName(names, start), instance.getClass().getName()); throw new PropertyException.NoSuchPropertyException( ! prop, fillInName(names, start), instance.getClass().getName()); } ! if (start <= end) { try { ! return _cache.getOperator(nextProp) ! .getProperty(context, nextProp, names, start, end); } catch (NullPointerException e) --- 870,889 ---- // check if object is restricted ! if (isMethodRestricted(instance.getClass(), "get" + propName) ! || isMethodRestricted(instance.getClass(), "set" + propName)) throw new PropertyException.RestrictedPropertyException( ! propName, fillInName(names, start), instance.getClass().getName()); throw new PropertyException.NoSuchPropertyException( ! propName, fillInName(names, start), instance.getClass().getName()); } ! if ( start <= end) { try { ! return _cache.getOperator(nextPropValue) ! .getProperty(context, nextPropValue, names, start, end); } catch (NullPointerException e) *************** *** 834,838 **** else { ! return nextProp; } } --- 895,899 ---- else { ! return nextPropValue; } } *************** *** 878,883 **** // names[pos] is what we could set from here ! int parentPos = names.length - 1; ! int binPos = parentPos - 1; // if we're not yet at the binary-settable parent, go there --- 939,943 ---- // names[pos] is what we could set from here ! int binPos = names.length - 2; // if we're not yet at the binary-settable parent, go there *************** *** 931,934 **** --- 991,995 ---- } } + return false; } *************** *** 1048,1051 **** --- 1109,1113 ---- } } + } |