From: <ke...@us...> - 2003-03-27 05:16:35
|
Update of /cvsroot/webmacro/webmacro/src/org/webmacro/engine In directory sc8-pr-cvs1:/tmp/cvs-serv21578 Modified Files: BuildContext.java MethodWrapper.java Variable.java Added Files: FunctionVariable.java Log Message: Added FunctionVariable class Removed final modifier from Variable.isSimpleName Changed BuildContext to handle FunctionVariables Changed MethodWrapper to handle null and void return types properly --- NEW FILE: FunctionVariable.java --- /* * FunctionVariable.java * * Created on March 21, 2003, 12:15 AM */ package org.webmacro.engine; import org.webmacro.Context; import org.webmacro.PropertyException; /** * * @author Keats */ public class FunctionVariable extends Variable { final public static Object TYPE = new Object(); /** Creates a new instance of FunctionVariable */ public FunctionVariable(Object names[]) { super(names); } /** The code to get the value represented by the variable from the * supplied context. * */ public Object getValue(Context context) throws PropertyException { return context.getProperty(_names[0]); } /** The code to set the value represented by the variable in the * supplied context. * */ public void setValue(Context c, Object v) throws PropertyException { throw new PropertyException("Cannot set the value of a function: " + _vname); } /** * Return the String name of the variable prefixed with a string * representing its type, in this case "function:". */ public String toString(){ return "function:" + _vname; } public boolean isSimpleName() { return false; } } Index: BuildContext.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/engine/BuildContext.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** BuildContext.java 15 Dec 2002 10:22:36 -0000 1.23 --- BuildContext.java 27 Mar 2003 05:16:32 -0000 1.24 *************** *** 62,68 **** } - - - /** * Find out whether the named variable is a tool, local variable, --- 62,65 ---- *************** *** 168,174 **** ((Builder) names[i]).build(this) : names[i]; } - String firstName = c[0].toString(); ! Object type = getVariableType(firstName); if (type == Variable.PROPERTY_TYPE) { if (containsKey(firstName)) { --- 165,176 ---- ((Builder) names[i]).build(this) : names[i]; } String firstName = c[0].toString(); ! Object type = null; ! if (c[0] instanceof FunctionCall){ ! type = FunctionVariable.TYPE; ! } ! else { ! type = getVariableType(firstName); ! } if (type == Variable.PROPERTY_TYPE) { if (containsKey(firstName)) { *************** *** 192,195 **** --- 194,200 ---- v = new GlobalVariable(c); } + else if (type == FunctionVariable.TYPE) { + v = new FunctionVariable(c); + } else { throw new BuildException("Unrecognized Variable Type: " + type); Index: MethodWrapper.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/engine/MethodWrapper.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MethodWrapper.java 11 Nov 2002 19:22:37 -0000 1.2 --- MethodWrapper.java 27 Mar 2003 05:16:33 -0000 1.3 *************** *** 1,31 **** /* ! * Copyright (C) 1998-2000 Semiotek Inc. All Rights Reserved. ! * ! * Redistribution and use in source and binary forms, with or without ! * modification, are permitted under the terms of either of the following ! * Open Source licenses: ! * ! * The GNU General Public License, version 2, or any later version, as ! * published by the Free Software Foundation ! * (http://www.fsf.org/copyleft/gpl.html); ! * ! * or ! * ! * The Semiotek Public License (http://webmacro.org/LICENSE.) ! * ! * This software is provided "as is", with NO WARRANTY, not even the ! * implied warranties of fitness to purpose, or merchantability. You ! * assume all risks and liabilities associated with its use. * ! * See www.webmacro.org for more information on the WebMacro project. */ package org.webmacro.engine; import java.lang.reflect.Method; import org.webmacro.*; ! /** * * @author Keats - * @since May 24, 2002 */ public class MethodWrapper { --- 1,15 ---- /* ! * MethodWrapper.java * ! * Created on May 24, 2002, 12:01 AM */ + package org.webmacro.engine; import java.lang.reflect.Method; import org.webmacro.*; ! import java.io.IOException; /** * * @author Keats */ public class MethodWrapper { *************** *** 76,85 **** Class[] types = IntrospectionUtils.createTypesFromArgs(args); for (int i = 0; i < _methods.length; i++){ ! Method m = _methods[i]; Class[] sig = m.getParameterTypes(); if (IntrospectionUtils.matches(sig,types)) { try { ! Object ret = _methods[i].invoke(_instance, args); ! return ret; } catch (Exception e){ --- 60,73 ---- Class[] types = IntrospectionUtils.createTypesFromArgs(args); for (int i = 0; i < _methods.length; i++){ ! Method m = (Method) _methods[i]; Class[] sig = m.getParameterTypes(); if (IntrospectionUtils.matches(sig,types)) { try { ! Object obj = m.invoke(_instance, args); ! if (obj == null ! && m.getReturnType() == java.lang.Void.TYPE) ! return org.webmacro.engine.VoidMacro.instance; ! else ! return obj; } catch (Exception e){ Index: Variable.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/engine/Variable.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Variable.java 11 Jun 2002 17:43:22 -0000 1.24 --- Variable.java 27 Mar 2003 05:16:33 -0000 1.25 *************** *** 134,138 **** * one element) */ ! public final boolean isSimpleName() { return (_names.length == 1); } --- 134,138 ---- * one element) */ ! public boolean isSimpleName() { return (_names.length == 1); } |