commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmi...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jex/xdocs/stylesheets .cvsignore project.xml
Date Wed, 12 Jun 2002 22:31:51 GMT
dmitri      2002/06/12 15:31:50

  Added:       jex      .cvsignore ExpLangs.txt LICENSE PROPOSAL.html
                        build-maven.xml build.properties.sample build.xml
                        project.properties project.xml
               jex/src/conf MANIFEST.MF
               jex/src/java/org/apache/commons/jex Compiler.java
                        Context.java Expression.java Interpreter.java
                        IterationExpression.java MultilingualCompiler.java
                        MultilingualInterpreter.java
                        VariableExpression.java Variables.java
               jex/src/java/org/apache/commons/jex/adapters
                        CompilingInterpreter.java
                        InterpretedExpression.java
                        InterpretingCompiler.java
               jex/src/java/org/apache/commons/jex/bexl Interpreter.java
               jex/src/java/org/apache/commons/jex/javascript Compiler.java
                        JavaScriptExpression.java
                        JavaScriptIterationExpression.java
                        JavaScriptValueExpression.java
                        JavaScriptVariableExpression.java
               jex/src/java/org/apache/commons/jex/jxpath Compiler.java
                        JXPathCompiledExpression.java JXPathVariables.java
               jex/src/java/org/apache/commons/jex/util TypeUtils.java
                        ValueUtils.java
               jex/src/test/org/apache/commons/jex AccountBean.java
                        JexTestCase.java
               jex/xdocs contributors.xml index.xml overview.xml
               jex/xdocs/images jakarta-logo.gif logo.gif
               jex/xdocs/stylesheets .cvsignore project.xml
  Log:
  Initial submission
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/jex/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  build.properties
  dist
  target
  bin
  .classpath
  .project
  build.bat
  maven.bat
  maven.log
  velocity.log
  docs
  test-reports
  
  
  1.1                  jakarta-commons-sandbox/jex/ExpLangs.txt
  
  Index: ExpLangs.txt
  ===================================================================
  XPath 
  	JXPath
  	Jaxen
  
  JavaScript aka ECMAscript
  http://www.mozilla.org/rhino/
  
  Java Expression Library
  http://galaxy.fzu.cz/JEL/
  
  PAX
  http://lists.w3.org/Archives/Public/www-dom-xpath/2000May/att-0100/01-xpathapi1.html
  
  Ptolemy II
  http://ptolemy.eecs.berkeley.edu/~eal/ee225a/lab/expression.pdf
  
  
  SPEL
  http://jakarta.apache.org/taglibs/doc/jsptl-doc/jsptl-ea1/spel/
  
  
  1.1                  jakarta-commons-sandbox/jex/LICENSE
  
  Index: LICENSE
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/LICENSE,v 1.1 2002/06/12 22:31:48 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:48 $
   *
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  
  
  
  
  
  
  
  1.1                  jakarta-commons-sandbox/jex/PROPOSAL.html
  
  Index: PROPOSAL.html
  ===================================================================
  <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
  <html>
  <head>
     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
     <meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
     <title>Proposal for Jex Package</title>
  </head>
  <body bgcolor="#FFFFFF">
  
  <center>
  <h1>
  Proposal for <i>Jex</i> Package</h1></center>
  
  <h3>
  (0) Rationale</h3>
  There is a number of expression language interpreters for Java. They all
  define different APIs, which makes it difficult to introduce new expression
  languages or new implementations of existing ones. The proposed <i>Jex
  </i>component
  provides a plug-in mechanism for expression language interpreters and common
  APIs for invocation of those.
  <h3>
  (1) Scope of the Package</h3>
  The org.apache.commons.jex package will define the following APIs:
  <ul>
  <li>
  Plug-in mechanism that allows introduction of new expression languages
  without changes to the org.apache.commons.jex package.</li>
  
  <li>
  Expression evaluation: given an expression, compute the expression value</li>
  
  <li>
  Modifying expression evaluation: given an expression describing a variable
  (or other left-side type of expression) and a new value, modify the value
  of that variable.</li>
  
  <li>
  Iteration by expression: given an expression, produce an iterator</li>
  
  <li>
  A pool of variables</li>
  
  <li>
  Internationalization.</li>
  
  <li>
  Jex will support both compiled and interpreted expression languages.</li>
  
  <li>
  Out-of-the-box Jex will support at least two languages: JXPath (compiled)
  and Bexl (BeanUtils path language, interpreted).</li>
  </ul>
  
  <h3>
  (1.5) Interaction With Other Packages</h3>
  Jex relies on
  <ul>
  <li>
  Java Development Kit (Version 1.2 or later)</li>
  
  <li>
  BeanUtils (compile time, no run-time dependency)</li>
  
  <li>
  JXPath (compile time, no run-time dependency)</li>
  </ul>
  No external configuration files are utilized.
  <h3>
  (2) Initial Source of the Package</h3>
  The original source of the component was donated by PLOTNIX, Inc (<a href="http://www.plotnix.com">www.plotnix.com</a>).
  <p>The proposed package names for the new component are
  <ul>
  <li>
  <tt>org.apache.commons.jex</tt> for the main API package</li>
  
  <li>
  <tt>org.apache.commons.jex.bexl </tt>for integration with BeanUtils</li>
  
  <li>
  <tt>org.apache.commons.jex.jxpath </tt>for integration with JXPath</li>
  </ul>
  
  <h3>
  (3) Required Jakarta-Commons Resources</h3>
  
  <ul>
  <li>
  CVS Repository - New directory jex in the <tt>jakarta-commons</tt> CVS
  repository.</li>
  
  <li>
  Mailing List - Discussions will take place on the general <i>commons-dev@jakarta.apache.org</i>
  mailing list. To help list subscribers identify messages of interest, it
  is suggested that the message subject of messages about this component
  be prefixed with [jex].</li>
  
  <li>
  Bugzilla - New component "jex" under the "Commons" product category, with
  appropriate version identifiers as needed.</li>
  
  <li>
  Jyve FAQ - New category "commons-jex" (when available).</li>
  </ul>
  
  <h3>
  (4) Initial Committers</h3>
  The initial committer on the JEX component shall be Dmitri Plotnikov.
  </body>
  </html>
  
  
  
  1.1                  jakarta-commons-sandbox/jex/build-maven.xml
  
  Index: build-maven.xml
  ===================================================================
  <!-- $Id: build-maven.xml,v 1.1 2002/06/12 22:31:48 dmitri Exp $ -->
  <project name="commons-jxpath" default="build-java" basedir=".">
  
      <!-- Allow any user specific values to override the defaults -->
      <property file="${user.home}/build.properties" />
      <!-- Allow user defaults for this project -->
      <property file="build.properties" />
      <!-- Set default values for the build -->
      <property file="project.properties" />
  
  <!-- maven:start -->
  
  <!-- ======================================================== -->
  <!-- D E L E G A T O R S                                      -->
  <!-- ======================================================== -->
  
  <target name="maven:gump-descriptor">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="gump-descriptor"/>
  </target>
  
  <target name="maven:maven-update">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="maven-update"/>
  </target>
  
  <target name="maven:update-jars">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="update-jars"/>
  </target>
  
  <target name="maven:jar">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="jar"/>
  </target>
  
  <target name="maven:docs-quick">
    <ant antfile="${maven.home}/plugins/docs/build.xml" target="docs-quick"/>
  </target>
  
  <target name="maven:run-singletest">
    <ant antfile="${maven.home}/plugins/test/build.xml" target="run-singletest"/>
  </target>
  
  <target name="maven:compile">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="compile"/>
  </target>
  
  <target name="maven:fo">
    <ant antfile="${maven.home}/plugins/docs/build.xml" target="fo"/>
  </target>
  
  <target name="maven:cvs-change-log">
    <ant antfile="${maven.home}/plugins/docs/build.xml" target="cvs-change-log"/>
  </target>
  
  <target name="maven:war">
    <ant antfile="${maven.home}/plugins/j2ee/build.xml" target="war"/>
  </target>
  
  <target name="maven:generate-reactor">
    <ant antfile="${maven.home}/plugins/reactor/build.xml" target="generate-reactor"/>
  </target>
  
  <target name="maven:cross-ref">
    <ant antfile="${maven.home}/plugins/docs/build.xml" target="cross-ref"/>
  </target>
  
  <target name="maven:deploy-site">
    <ant antfile="${maven.home}/plugins/docs/build.xml" target="deploy-site"/>
  </target>
  
  <target name="maven:ear">
    <ant antfile="${maven.home}/plugins/j2ee/build.xml" target="ear"/>
  </target>
  
  <target name="maven:install-jar">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="install-jar"/>
  </target>
  
  <target name="maven:task-list">
    <ant antfile="${maven.home}/plugins/docs/build.xml" target="task-list"/>
  </target>
  
  <target name="maven:docs">
    <ant antfile="${maven.home}/plugins/docs/build.xml" target="docs"/>
  </target>
  
  <target name="maven:site">
    <ant antfile="${maven.home}/plugins/docs/build.xml" target="site"/>
  </target>
  
  <target name="maven:deploy-dist">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="deploy-dist"/>
  </target>
  
  <target name="maven:javadocs">
    <ant antfile="${maven.home}/plugins/docs/build.xml" target="javadocs"/>
  </target>
  
  <target name="maven:announce">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="announce"/>
  </target>
  
  <target name="maven:check-source">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="check-source"/>
  </target>
  
  <target name="maven:dist">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="dist"/>
  </target>
  
  <target name="maven:dist-build">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="dist-build"/>
  </target>
  
  <target name="maven:metrics">
    <ant antfile="${maven.home}/plugins/metrics/build.xml" target="metrics"/>
  </target>
  
  <target name="maven:clean">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="clean"/>
  </target>
  
  <target name="maven:env">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="env"/>
  </target>
  
  <target name="maven:test">
    <ant antfile="${maven.home}/plugins/test/build.xml" target="test"/>
  </target>
  
  <target name="maven:pdf">
    <ant antfile="${maven.home}/plugins/docs/build.xml" target="pdf"/>
  </target>
  
  <target name="maven:iutest">
    <ant antfile="${maven.home}/plugins/iutest/build.xml" target="iutest"/>
  </target>
  
  <target name="maven:activity-log">
    <ant antfile="${maven.home}/plugins/docs/build.xml" target="activity-log"/>
  </target>
  
  <target name="maven:verify-project">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="verify-project"/>
  </target>
  
  <target name="maven:validate-pom">
    <ant antfile="${maven.home}/plugins/core/build.xml" target="validate-pom"/>
  </target>
  
  <target name="maven:validate-war">
    <ant antfile="${maven.home}/plugins/j2ee/build.xml" target="validate-war"/>
  </target>
  
  <!-- maven:end -->
  </project>
  
  
  1.1                  jakarta-commons-sandbox/jex/build.properties.sample
  
  Index: build.properties.sample
  ===================================================================
  # -------------------------------------------------------------------
  # build.properties.sample
  #
  # This is an example "build.properties" file, used to customize 
  # building various Commons components for your local environment.  
  # Make any changes you need, and rename this file to 
  # "build.properties" 
  #
  # $Id: build.properties.sample,v 1.1 2002/06/12 22:31:48 dmitri Exp $
  # -------------------------------------------------------------------
  
  
  # -------------------------------------------------------------------
  # EXTERNAL DEPENDENCIES 
  # -------------------------------------------------------------------
  
  junit.jar=${lib.repo}/junit.jar
  
  jaxp.xslt.jar = ${lib.repo}/xalan.jar
  beanutils.jar = ${lib.repo}/commons-beanutils.jar
  servlet.jar = ${lib.repo}/servlet.jar
  commons-collections.jar = ${lib.repo}/commons-collections.jar
  junit.jar = ${lib.repo}/junit.jar
  jaxp.jaxp.jar = ${lib.repo}/jaxp.jar
  jxpath.jar = ${lib.repo}/commons-jxpath.jar
  js.jar = ${lib.repo}/js.jar
  
  # ===================================================================
  # Anakia Properties (used by the xdoc target)
  # ===================================================================
  
  velocity.jar=${lib.repo}/velocity-1.3-dev.jar
  jdom.jar=${lib.repo}/jdom-b7.jar
  xerces.jar=${lib.repo}/xerces.jar
  logkit.jar=${lib.repo}/logkit-1.0.jar
  
  maven.home=${lib.repo}/maven
  
  
  1.1                  jakarta-commons-sandbox/jex/build.xml
  
  Index: build.xml
  ===================================================================
  <project name="JEX" default="compile" basedir=".">
  
  
  <!--
          "Jex" component of the Jakarta Commons Subproject
          $Id: build.xml,v 1.1 2002/06/12 22:31:48 dmitri Exp $
  -->
  
  
  <!-- ========== Initialize Properties ===================================== -->
  
    <property file="${user.home}/build.properties"/>   <!-- User local        -->
    <property file="build.properties"/>                <!-- Component local   -->
    <property file="../build.properties"/>             <!-- Commons local     -->
  
  <!-- ========== Component Declarations ==================================== -->
  
    <!-- The name of this component -->
    <property name="component.name"          value="jex"/>
  
    <!-- The title of this component -->
    <property name="component.title"         value="JEX - APIs for Expression Languages"/>
  
    <!-- The primary package name of this component -->
    <property name="component.package"       value="org.apache.commons.jex"/>
  
    <!-- The current version number of this component -->
    <property name="component.version"       value="0.1-dev"/>
  
    <!-- The jar name of this component -->
    <property name="jar.name"
             value="${component.name}.jar"/>
  
    <!-- The base directory for compilation targets -->
    <property name="build.home"              value="target"/>
  
    <!-- The base directory for component configuration files -->
    <property name="conf.home"               value="src/conf"/>
  
    <!-- The base directory for distribution targets -->
    <property name="dist.home"               value="dist"/>
  
    <!-- The base directory for component sources -->
    <property name="source.home"             value="src/java"/>
  
    <!-- The base directory for unit test sources -->
    <property name="test.home"               value="src/test"/>
  
    <!-- Anakia props -->
    <property name="docs.src" value="./xdocs"/>
    <property name="docs.dest" value="${dist.home}/docs"/>
  
  
  <!-- ========== Compiler Defaults ========================================= -->
  
  
    <!-- Should Java compilations set the 'debug' compiler option? -->
    <property name="compile.debug"           value="true"/>
  
    <!-- Should Java compilations set the 'deprecation' compiler option? -->
    <property name="compile.deprecation"     value="true"/>
  
    <!-- Should Java compilations set the 'optimize' compiler option? -->
    <property name="compile.optimize"        value="true"/>
  
    <!-- Construct compile classpath -->
    <path id="compile.classpath">
      <pathelement location="${build.home}/classes"/>
      <pathelement location="${jaxp.jaxp.jar}"/>
      <pathelement location="${jaxp.xslt.jar}"/>
      <pathelement location="${servlet.jar}"/>
      <pathelement location="${junit.jar}"/>
      <pathelement location="${jxpath.jar}"/>
      <pathelement location="${beanutils.jar}"/>
      <pathelement location="${js.jar}"/>
    </path>
  
  
  <!-- ========== Test Execution Defaults =================================== -->
  
  
    <!-- Construct unit test classpath -->
    <path id="test.classpath">
      <pathelement location="${build.home}/classes"/>
      <pathelement location="${build.home}/tests"/>
      <pathelement location="${jaxp.jaxp.jar}"/>
      <pathelement location="${jaxp.xslt.jar}"/>
      <pathelement location="${servlet.jar}"/>
      <pathelement location="${junit.jar}"/>
      <pathelement location="${jxpath.jar}"/>
      <pathelement location="${beanutils.jar}"/>
      <pathelement location="${js.jar}"/>
    </path>
  
    <!-- Should all tests fail if one does? -->
    <property name="test.failonerror"        value="true"/>
  
    <!-- The test runner to execute -->
    <property name="test.runner"             value="junit.textui.TestRunner"/>
  
  
  <!-- ========== Executable Targets ======================================== -->
  
    <target name="check_available">
      <available 
        classname="junit.framework.Test"
        property="junit.present"
        classpathref="compile.classpath"
      />
  
      <available 
        classname="org.xml.sax.SAXException"
        property="jaxp.jaxp.present"
        classpathref="compile.classpath"
      />
  
      <available 
        classname="javax.xml.transform.Transformer"
        property="jaxp.xslt.present"
        classpathref="compile.classpath"
      />
  
      <available 
        classname="javax.servlet.ServletRequest"
        property="servlet.present"
        classpathref="compile.classpath"
      />
  
    </target>
  
    <target name="init"
      description="Initialize and evaluate conditionals"
      depends="check_available">
      <echo message="-------- ${component.name} ${component.version} --------"/>
      <filter  token="name"                  value="${component.name}"/>
      <filter  token="package"               value="${component.package}"/>
      <filter  token="version"               value="${component.version}"/>
  
      <echo message="junit.jar = ${junit.jar}"/>
      <echo message="jaxp.jaxp.jar = ${jaxp.jaxp.jar}"/>
      <echo message="jaxp.xslt.jar = ${jaxp.xslt.jar}"/>
      <echo message="servlet.jar = ${servlet.jar}"/>
    </target>
  
    <target name="check.junit" unless="junit.present">
      <antcall target="property-warning">
        <param name="name" value="junit.jar"/>
        <param name="value" value="${junit.jar}"/>
      </antcall>
    </target>
  
    <target name="check.jaxp.jaxp" unless="jaxp.jaxp.present">
      <antcall target="property-warning">
        <param name="name" value="jaxp.jaxp.jar"/>
        <param name="value" value="${jaxp.jaxp.jar}"/>
      </antcall>
    </target>
  
    <target name="check.jaxp.xslt" unless="jaxp.xslt.present">
      <antcall target="property-warning">
        <param name="name" value="jaxp.xslt.jar"/>
        <param name="value" value="${jaxp.xslt.jar}"/>
      </antcall>
    </target>
  
    <target name="check.servlet" unless="servlet.present">
      <antcall target="property-warning">
        <param name="name" value="servlet.jar"/>
        <param name="value" value="${servlet.jar}"/>
      </antcall>
    </target>
  
    <target name="property-warning">
      <echo>
        +----------------------------------------------------------------+
        + F A I L E D  R E Q U I R E M E N T                             |
        +----------------------------------------------------------------+
        | You must define the following property in order                |
        | to build ${component.name}:
        |                                                                |
        | ${name} = ${value}
        |                                                                |
        | You can set this property in the provided build.properties     |
        | file, or you may set this property in your                     |
        | ${user.home}/build.properties file.                            
        +----------------------------------------------------------------+
      </echo>
      <fail message="Failed Requirement"/>
    </target>
  
    <target name="prepare" depends="init, 
                           check.junit,check.jaxp.jaxp,check.jaxp.xslt,check.servlet"
     description="Prepare build directory">
      <mkdir dir="${build.home}"/>
      <mkdir dir="${build.home}/classes"/>
      <mkdir dir="${build.home}/conf"/>
      <mkdir dir="${build.home}/tests"/>
    </target>
  
    <target name="static" depends="prepare"
     description="Copy static files to build directory">
      <tstamp/>
      <copy  todir="${build.home}/conf" filtering="on">
        <fileset dir="${conf.home}" includes="*.MF"/>
      </copy>
    </target>
  
  
    <target name="compile" depends="static"
     description="Compile shareable components">
      <javac  srcdir="${source.home}"
             destdir="${build.home}/classes"
               debug="${compile.debug}"
         deprecation="${compile.deprecation}"
            optimize="${compile.optimize}">
        <classpath refid="compile.classpath"/>
      </javac>
      <copy    todir="${build.home}/classes" filtering="on">
        <fileset dir="${source.home}" excludes="**/*.java"/>
      </copy>
    </target>
  
  
    <target name="compile.tests" depends="compile"
     description="Compile unit test cases">
      <javac  srcdir="${test.home}"
             destdir="${build.home}/tests"
               debug="${compile.debug}"
         deprecation="${compile.deprecation}"
            optimize="${compile.optimize}">
        <classpath refid="test.classpath"/>
      </javac>
      <copy    todir="${build.home}/tests" filtering="on">
        <fileset dir="${test.home}" excludes="**/*.java"/>
      </copy>
    </target>
  
  
    <target name="clean"
     description="Clean build and distribution directories">
      <delete    dir="${build.home}"/>
      <delete    dir="${dist.home}"/>
    </target>
  
  
    <target name="all" depends="clean,compile"
     description="Clean and compile all components"/>
  
  
    <target name="javadoc" depends="compile"
     description="Create component Javadoc documentation">
      <mkdir      dir="${dist.home}"/>
      <mkdir      dir="${dist.home}/docs"/>
      <mkdir      dir="${dist.home}/docs/apidocs"/>
      <javadoc sourcepath="${source.home}"
             classpathref="compile.classpath"
                  destdir="${dist.home}/docs/apidocs"
             packagenames="org.apache.commons.*"
                   author="true"
                  private="false"
                  version="true"
                 doctitle="&lt;h1&gt;${component.title}&lt;/h1&gt;"
              windowtitle="${component.title} (Version ${component.version})"
                   bottom="Copyright (c) 2002 - Apache Software Foundation, Inc"/>
    </target>
  
    <!-- ================================================================== -->
    <!-- J A R                                                              -->
    <!-- ================================================================== -->
    <target name="jar" description="Build jar">
      <mkdir      dir="${dist.home}"/>
      <copy      file="LICENSE"
               tofile="${build.home}/classes/META-INF/LICENSE.txt"/>
      <jar    jarfile="${dist.home}/${jar.name}"
              basedir="${build.home}/classes"
             manifest="${build.home}/conf/MANIFEST.MF"/>
    </target>
    
    <!-- ================================================================== -->
    <!-- I N S T A L L  J A R                                               -->
    <!-- ================================================================== -->
  
    <target name="install-jar" depends="jar" 
            description="==> Installs .jar file in ${lib.repo}">
      <copy todir="${lib.repo}" filtering="no">
        <fileset dir="${dist.home}">
          <include name="${jar.name}"/>
        </fileset>
      </copy>
    </target>
  
    <!-- ================================================================== -->
    <!-- D I S T                                                            -->
    <!-- ================================================================== -->
  
    <target name="dist" depends="compile,jar,javadoc,xdoc"
     description="Create binary distribution">
      <mkdir      dir="${dist.home}"/>
      <copy      file="LICENSE"
                todir="${dist.home}"/>
    </target>
  
  <!-- ========== Unit Test Targets ========================================= -->
  
    <target name="test"  depends="compile.tests,
                                  test.jex"
     description="Run all unit test cases">
    </target>
  
    <target name="test.jex">
      <echo message="Running Jex tests ..."/>
      <java classname="${test.runner}" fork="yes"
          failonerror="${test.failonerror}">
        <arg value="org.apache.commons.jex.JexTestCase"/>
        <classpath refid="test.classpath"/>
      </java>
    </target>
  
  <!-- ========== Documentation ========================================= -->
  
    <target name="xdoc.fetch-stylesheet" unless="localstylesheet">
        <echo>
         ####################################################################
         #
         #  Fetching the latest stylesheet from jakarta-site2
         #
         #  NOTE : As this build target is meant for developers, this requires
         #    a properly setup CVS.  But you are encouraged to use this to
         #    experiment with Anakia - if the fetch fails, it may be because
         #    you haven't yet logged into CVS. The way to do it, assuming you
         #    have a resonable CVS client setup is
         #
         #  $ cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic login
         #  password: anoncvs
         #
         #  and that should solve it.
         #
         #  See http://jakarta.apache.org/site/cvsindex.html for more
         #      information, or http://www.cvshome.org/
         #
         #  Ant really is the bee's knees. http://jakarta.apache.org/ant/
         #
         ######################################################################
         </echo>
  
        <cvs cvsRoot=":pserver:anoncvs@cvs.apache.org:/home/cvspublic"
            command="checkout -p jakarta-site2/xdocs/stylesheets/site.vsl"
            output="${docs.src}/stylesheets/site.vsl"
        />
    </target>
  
    <target name="xdoc" depends="xdoc.fetch-stylesheet"
            description="Generates HTML documentation from XML source">
      <mkdir      dir="${dist.home}"/>
      <mkdir      dir="${dist.home}/docs"/>
  
        <taskdef name="anakia" classname="org.apache.velocity.anakia.AnakiaTask">
            <classpath location="${velocity.jar}"/>
            <classpath location="${jdom.jar}"/>
            <classpath location="${xerces.jar}"/>
            <classpath location="${commons-collections.jar}"/>
            <classpath location="${logkit.jar}"/>
        </taskdef>
  
        <echo>
         #######################################################
         #
         #  Now using Anakia to transform our XML documentation
         #  to HTML.
         #
         #######################################################
         </echo>
  
        <anakia basedir="${docs.src}" destdir="${docs.dest}/"
             extension=".html" style="./site.vsl"
             projectFile="stylesheets/project.xml"
             excludes="**/stylesheets/** empty.xml"
             includes="**/*.xml"
             lastModifiedCheck="true"
             templatePath="xdocs/stylesheets">
        </anakia>
  
        <copy todir="${docs.dest}/images" filtering="no">
            <fileset dir="${docs.src}/images">
                <include name="**/*.gif"/>
                <include name="**/*.jpeg"/>
                <include name="**/*.jpg"/>
            </fileset>
        </copy>
    </target>
  
  </project>
  
  
  
  1.1                  jakarta-commons-sandbox/jex/project.properties
  
  Index: project.properties
  ===================================================================
  ##
  # Properties that override Maven build defaults
  ##
  checkstyle.header.file=../LICENSE
  maven.checkstyle.lcurly.type=eol
  maven.checkstyle.lcurly.method=eol
  maven.checkstyle.lcurly.other=eol
  maven.checkstyle.rcurly=alone
  maven.checkstyle.ignore.cast.whitespace=true
  maven.checkstyle.javadoc.scope=protected
  
  
  
  1.1                  jakarta-commons-sandbox/jex/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <project>
    <pomVersion>3</pomVersion>
    <name>JEX</name>
    <id>jakarta-commons-jex</id>
    <currentVersion>1.0-alpha1</currentVersion>
    <organization>
      <name>Apache Software Foundation</name>
      <url>http://jakarta.apache.org/</url>
    </organization>
    <inceptionYear>2001</inceptionYear>
    <package>org.apache.commons.jex</package>
    <shortDescription>Universal APIs for Expression Languages</shortDescription>
  
    <description>A package of Java APIs for expression language evaluation</description>
  
    <url>http://jakarta.apache.org/commons/jex/</url>
    <!-- cvsWebUrl>http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/jex/</cvsWebUrl -->
    <issueTrackingUrl>http://nagoya.apache.org/bugzilla/buglist.cgi?bug_status=UNCONFIRMEDcomponent=JEX</issueTrackingUrl>
    <siteAddress>jakarta.apache.org</siteAddress>
    <siteDirectory>/www/jakarta.apache.org/commons/jex</siteDirectory>
    <distributionDirectory>/www/jakarta.apache.org/builds/jakarta-commons-sandbox/jex</distributionDirectory>
  
    <versions>
      <version>
        <id>alpha</id>
        <name>1.0-A1</name>
        <tag>JEX_1_0_A1</tag>
      </version>
    </versions>
  
    <mailingLists>
      <mailingList>
        <name>Commons Developer List</name>
        <subscribe>commons-dev-subscribe@jakarta.apache.org</subscribe>
        <unsubscribe>commons-dev-unsubscribe@jakarta.apache.org</unsubscribe>
        <archive>http://www.mail-archive.com/commons-dev@jakarta.apache.org/</archive>
      </mailingList>
    </mailingLists>
  
    <developers>
      <developer>
        <name>Dmitri Plotnikov</name>
        <id>dmitri</id>
        <email>dmitri@apache.org</email>
        <organization/>
      </developer>
    </developers>
    <dependencies>
      <dependency>
        <name>commons-jxpath</name>
        <type>required</type>
        <version>1.0</version>
        <jar>commons-jxpath.jar</jar>
      </dependency>
      <dependency>
        <name>commons-beanutils</name>
        <type>required</type>
        <version>1.0</version>
        <jar>commons-beanutils.jar</jar>
      </dependency>
      <dependency>
        <name>Rhino</name>
        <type>required</type>
        <version>1.0</version>
        <jar>js.jar</jar>
      </dependency>
      <dependency>
        <name>junit</name>
        <type>required</type>
        <version>3.7</version>
        <jar>junit-3.7.jar</jar>
      </dependency>
      <dependency>
        <name>junit</name>
        <type>required</type>
        <version>3.7</version>
        <jar>junit-3.7.jar</jar>
      </dependency>
    </dependencies>
    <build>
      <sourceDirectory>src/java</sourceDirectory>
      <unitTestSourceDirectory>src/test</unitTestSourceDirectory>
      <aspectSourceDirectories/>
      <unitTestPatterns>
        <unitTestPattern>include=**/*TestCase.java</unitTestPattern>
      </unitTestPatterns>
      <integrationUnitTestPatterns/>
      <jarResources>
      <!--<jarResource>include = *.properties</jarResource>-->
  </jarResources>
      <jars/>
    </build>
  </project>
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/conf/MANIFEST.MF
  
  Index: MANIFEST.MF
  ===================================================================
  Extension-Name: @name@
  Specification-Vendor: Apache Software Foundation
  Specification-Version: 1.0
  Implementation-Vendor: Apache Software Foundation
  Implementation-Version: @version@
  
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/Compiler.java
  
  Index: Compiler.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/Compiler.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex;
  
  import java.util.HashMap;
  
  import org.apache.commons.jex.adapters.InterpretingCompiler;
  
  
  /**
   * A compiler translates an expression string into an executable form.
   * It validates the syntax of the expression and throws an exception
   * if the syntax is invalid.
   * <p>
   * In order to introduce a new compiler, create a class called
   * <code>"org.apache.commons.jex.<i>language-prefix</i>.Compiler"</code> that 
   * inherits from this class.  Put it on the classpath. That's it. 
   * Jex will find thenew class by the prefix and invoke it to compile 
   * expressions in that language.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:49 $
   */
  public abstract class Compiler {
  
      /**
       * Serves as a placeholder for a missing compiler.  We don't want
       * to keep retrying to find the same compiler.
       */
      private static final Object KNOWN_MISSING_COMPILER = new Object();
      
      private static HashMap compilerMap = new HashMap();
      private static HashMap compilerImplMap = new HashMap();
      
      /**
       * Locates and returns a Compiler for the specified language.
       * If there is not such compiler, looks up an Interpreter
       * for this language. If one is found, returns an adapter Compiler
       * that makes an interpreter look like a Compiler.
       * If neither a Compiler nor Interpreter exists for the specified
       * language, returns null.
       * 
       * @param language is the name of an expression language (no colon
       *  at the end)
       * @return the Compiler for that language
       */
      public static final Compiler getCompiler(String language){
          Object compiler = compilerMap.get(language);
          if (compiler == null){
              compiler = getCompilerImplementation(language);
              if (compiler == null){
                  Interpreter interpreter = 
                          Interpreter.getInterpreterImplementation(language);
                  if (interpreter != null){
                      compiler = new InterpretingCompiler(interpreter);
                  }
              }
              if (compiler == null){
                  compiler = KNOWN_MISSING_COMPILER;
              }
              compilerMap.put(language, compiler);
          }        
          if (compiler == KNOWN_MISSING_COMPILER){
              return null;
          }
          return (Compiler) compiler;
      }
      
      /**
       * Locates and returns a Compiler for the specified language.
       * If no Compiler exists for the specified language, returns null.
       * 
       * @param language is the name of an expression language (no colon
       *  at the end)
       * @return the Compiler for that language
       */
      protected static final Compiler getCompilerImplementation(String language){
          Object compiler = compilerImplMap.get(language);
          if (compiler == null){
              Class clazz = null;
              try {
                  clazz = Class.forName(
                      "org.apache.commons.jex." + language + ".Compiler");
                  compiler = (Compiler) clazz.newInstance();
              }
              catch (ClassNotFoundException ex){
                  compiler = KNOWN_MISSING_COMPILER;
              }
              catch (Exception ex){
                  // TBD: wrap
                  throw new RuntimeException(ex.getMessage());
              }
              compilerImplMap.put(language, compiler);
          }        
          if (compiler == KNOWN_MISSING_COMPILER){
              return null;
          }
          return (Compiler) compiler;
      }
      
      /**
       * Compiles an expression intended for evaluation 
       * that produces a <i>value</i>.  For example,
       * <code>"2+2"</code> will be a valid argument for this method
       * for many expression languages.
       * <p>
       * May throw an UnsupportedOperationException.
       * 
       * @param expression 
       *  is an expression in the corresponding language
       * @return an executable object that can be used to compute 
       *  the value of this expression in a {@link Context Context}. 
       */ 
      public abstract Expression compileExpression(String expression);
  
      /**
       * Compiles an expression describing an iteration.
       * For example, <code>"addressBook//phone"</code> is a valid
       * argument for this method for an XPath compiler.
       * <p>
       * May throw an UnsupportedOperationException.
       * 
       * @param expression 
       *  is an iteration expression in the corresponding language
       * @return an executable object that can be used to 
       *  iterate over some values in a {@link Context Context}. 
       */ 
      public abstract IterationExpression compileIterationExpression(
              String expression);
  
      /**
       * Compiles an expression describing the left hand side
       * of an assignment.
       * 
       * For example, <code>"addressBook/contact[name="John Doe"]/phone"</code> 
       * is a valid argument for this method for an XPath compiler.
       * <p>
       * May throw an UnsupportedOperationException.
       * 
       * @param expression 
       *  is a variable expression in the corresponding language
       * @return an executable object that can be used to 
       *  modify a value in a {@link Context Context}. 
       */
      public abstract VariableExpression compileVariableExpression(
              String expression);            
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/Context.java
  
  Index: Context.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/Context.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Locale;
  
  
  /**
   * Expressions are evaluated in a Context, which provides access
   * to shared pieces of the environment: variables, locale, expression
   * language compilers etc.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:49 $
   */
  public class Context {
  
      private Context parentContext;
      private String language;
      private boolean multilingual = true;
      private HashMap properties;
      private Variables variables;
      private Locale locale;
      
      /**
       * Creates a new Context
       */
      public Context(){
      }
      
      /**
       * Creates a new Context with the given parent Context. The child context
       * will provide access to the parent's variable, extension functions etc.
       * It can override and augment those.  The use of nested contexts
       * allows you to avoid re-configuring contexts all the time.
       * 
       * @param parentContext is the parent context
       */
      public Context(Context parentContext){
          this.parentContext = parentContext;
      }
  
      /**
       * Returns the Context's parent.
       * 
       * @return The parent Context or null if there is no parent.
       */
      public Context getParentContext(){
          return parentContext;
      }
          
      /**
       * Set the name of the expression language for this context. 
       * If the context is multilingual 
       * (see {@link #setMultilingual setMultilingual}), this language will 
       * function as the default - expressions in this language will 
       * not require a <code>"<i>lang</i>"</code> prefix.
       * 
       * @param language 
       *  is the name of an expression language. The compiler for
       *  this language should be available.
       */
      public void setExpressionLanguage(String language) {
          this.language = language;
      }
      
      /**
       * Returns the name of this context's (default) expression language.
       * 
       * @return the name of the language.
       */
      public String getExpressionLanguage() {
          return language;
      }
      
      /**
       * If set to true, this context will support multiple expression
       * languages. Expressions will start with the 
       * <code>"<i>lang:</i>"</code> prefix.  If the default expression
       * language has been specified, the expressions in that language
       * do not require a language prefix.
       * 
       * @param multilingual is the new setting
       */
      public void setMultilingual(boolean multilingual){
          this.multilingual = multilingual;
      }
  
      /**
       * Returns true if the Context is <code>multilingual</code>.
       * 
       * @see #setMultilingual
       */    
      public boolean isMultilingual(){
          return multilingual;
      }
  
      /**
       * Returns the compiler for the Context's expression language
       * or a multilingual compiler if the Context is multilingual.
       * <p>
       * Will throw an exception if the Context is not multilingual
       * and the expression language has not been specified.
       *
       * @see Compiler
       * @see MultilingualCompiler
       * 
       * @return The compiler
       */
      public Compiler getCompiler(){
          if (multilingual){
              return MultilingualCompiler.getMultilingualCompiler(language);
          }
          else if (language != null){
              return Compiler.getCompiler(language);
          }
          else {
              throw new RuntimeException(
                 "No expression language has been specified for the context");
          }
      }
      
      /**
       * Returns the interpreter for the Context's expression language
       * or a multilingual interpreter if the Context is multilingual.
       * <p>
       * Will throw an exception if the Context is not multilingual
       * and the expression language has not been specified.
       *
       * @see Interpreter
       * @see MultilingualInterpreter
       * 
       * @return The interpreter
       */
      public Interpreter getInterpreter(){
          if (multilingual){
              return MultilingualInterpreter.getMultilingualInterpreter(language);
          }
          else if (language != null){
              return Interpreter.getInterpreter(language);
          }
          else {
              throw new RuntimeException(
                  "No expression language has been specified for the context");
          }        
      }
      
      /**
       * Sets a configuration property that can be used by
       * expression language implementations. If the property
       * is language-specific, the name of the property should start
       * with "<i>lang.</i>" by convention.
       * 
       * @param property is the name of of the property
       * @param value is the value of the property
       */
      public void setProperty(String property, Object value){
          if (properties == null){
              properties = new HashMap();
          }
          properties.put(property, value);
      }
      
      /**
       * Returns the value of the specified property.
       * 
       * @param property is a property name
       * @return the value of the property
       */
      public Object getProperty(String property){
          if (properties != null){
              return properties.get(property);
          }
          return null;
      }
      
      /**
       * Returns the value of the specified property. If the property
       * is undefined on this context, tries to find it on the chain
       * of parent contexts.  Returns null if the property is undefined.
       * 
       * @param property is a property name
       * @return the value of the property
       */
      public Object findProperty(String property){
          if (parentContext != null){
              if (properties != null && properties.containsKey(property)){
                  return properties.get(property);
              }
              return parentContext.getProperty(property);
          }
          if (properties != null){
              return properties.get(property);
          }
          return null;
      }
      
      /**
       * Install a custom implementation of a Variable pool. Initially
       * the context has the default variable pool, which is implemented
       * with a simple HashMap.
       * 
       * @param variables are custom Variables
       */
      public void setVariables(Variables variables){
          this.variables = variables;
      }
  
      /**
       * Returns the variable pool associated with the context. If no such
       * pool was specified during the construction of the context,
       * returns the default implementation of Variables which uses a HashMap.
       * 
       * @return variables - default or custom
       */
      public Variables getVariables(){
          if (variables == null){
              variables = new BasicVariables();
          }
          return variables;
      }
  
      /**
       * Set the locale for this context. By default, Jex uses
       * <code>Locale.getDefault()</code>
       * 
       * @param locale is the locale this context is associated with
       */
      public void setLocale(Locale locale){
          this.locale = locale;
      }
  
      /**
       * Returns the locale set with setLocale or, if none was set 
       * parent context's locale or Locale.getDefault().
       * 
       * @return The context's locale
       */
      public Locale getLocale(){
          if (locale == null){
              locale = Locale.getDefault();
          }
          if (parentContext != null){
              return parentContext.getLocale();
          }
          return locale;
      }
      
      /**
       * Invokes the context's interpreter to evaluate the supplied expression.
       * 
       * @see #getInterpreter()
       * 
       * @param expression is the expression that needs to be evaluated
       * @param arguments are argument of the expression. Can be null
       *  if the expression does not take any arguments.
       * @return the result of the evaluation of this expression
       */
      public Object evaluate(String expression, Object[] arguments){
          return getInterpreter().evaluate(this, expression, arguments);
      }
  
      /**
       * Evaluates the expression and casts the result to the supplied type.
       * 
       * @see #evaluate(String, Object[])
       */
      public Object evaluate(String expression, Object[] arguments, 
                             Class valueType){
          return getInterpreter().
              evaluate(this, expression, arguments, valueType);
      }
  
      /**
       * Invokes the context's interpreter to evaluate the supplied 
       * iteration expression.
       * 
       * @see #getInterpreter()
       * 
       * @param expression is the expression that needs to be evaluated
       * @param arguments are argument of the expression. Can be null
       *  if the expression does not take any arguments.
       * @return the result of the evaluation of this expression
       */
      public Iterator iterate(String expression, Object[] arguments){
          return getInterpreter().iterate(this, expression, arguments);
      }
      
      /**
       * Invokes the context's interpreter to modify the value
       * described by the supplied left-hand side expression.
       * Casts the type of the value if necessary.
       * 
       * @see #getInterpreter()
       * 
       * @param expression is the expression that needs to be evaluated
       * @param value is the new value
       * @param arguments are argument of the expression. Can be null
       *  if the expression does not take any arguments.
       */
      public void assign(String expression, Object value, Object[] arguments){
          getInterpreter().assign(this, expression, value, arguments);
      }    
      
      /**
       * The default implementation of Variables based on a HashMap.
       */ 
      private static class BasicVariables implements Variables {
          /**
           * Contains the values of declared variables
           */
          private HashMap vars = new HashMap();
      
          public boolean isDeclaredVariable(String varName){
              return vars.containsKey(varName);
          }
      
          public Object getVariable(String varName){
              // Note that a variable may be defined with a null value
      
              if (vars.containsKey(varName)){
                  return vars.get(varName);
              }
      
              throw new IllegalArgumentException("No such variable: '" + 
                      varName + "'");
          }
      
          public void declareVariable(String varName, Object value){
              vars.put(varName, value);
          }
      
          public String toString(){
              return vars.toString();
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/Expression.java
  
  Index: Expression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/Expression.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex;
  
  /**
   * Compiled form of a value expression, which can be evaluated in
   * a {@link Context Context}.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:49 $
   */
  public interface Expression {
  
      /**
       * Produces the value described by the expression in the
       * specified context with the supplied arguments.
       * 
       * @param context is an evaluation context.
       * @param arguments are argument of the expression. Can be null
       *  if the expression does not take any arguments.
       * @return the result of the evaluation of this expression
       */
      Object evaluate(Context context, Object[] arguments);
  
      /**
       * Evaluates the expression and casts the result to the supplied type.
       * 
       * @see #evaluate(Context, Object[])
       */
      Object evaluate(Context context, Object[] arguments, Class valueType);
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/Interpreter.java
  
  Index: Interpreter.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/Interpreter.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex;
  
  import java.util.Iterator;
  import java.util.HashMap;
  
  import org.apache.commons.jex.adapters.CompilingInterpreter;
  
  /**
   * An interpreter directly evaluates an expression string.
   * It validates the syntax of the expression and throws an exception
   * if the syntax is invalid.
   * <p>
   * In order to introduce a new interpreter, create a class called
   * "org.apache.commons.jex.<i>language-prefix</i>.Interpreter" that inherits from
   * this class.  Jex will find the class by the language prefix and 
   * invoke it to interpret expressions in that language.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $
   */
  public abstract class Interpreter {
      
      /**
       * Serves as a placeholder for a missing interpreter.  We don't want
       * to keep retrying to find the same interpreter.
       */
      private static final Object KNOWN_MISSING_INTERPRETER = new Object();
      
      private static HashMap interpreterImplMap = new HashMap();
      private static HashMap interpreterMap = new HashMap();
      
      /**
       * Locates and returns an Interpreter for the specified language.
       * If there is not such interpreter, looks up a Compiler
       * for this language. If one is found, returns an adapter Interpreter
       * that makes a compiler look like an Interpreter.
       * If neither an Interpreter nor a Compiler exist for the specified
       * language, returns null.
       * 
       * @param language is the name of an expression language (no colon
       *  at the end)
       * @return the Interpreter for that language
       */
      public static final Interpreter getInterpreter(String language){
          Object interpreter = interpreterMap.get(language);
          if (interpreter == null){
              interpreter = getInterpreterImplementation(language);
              if (interpreter == null){
                  Compiler compiler = 
                          Compiler.getCompilerImplementation(language);
                  if (compiler != null){
                      interpreter = new CompilingInterpreter(compiler);
                  }
              }
              if (interpreter == null){
                  interpreter = KNOWN_MISSING_INTERPRETER;
              }
              interpreterMap.put(language, interpreter);
          }        
          if (interpreter == KNOWN_MISSING_INTERPRETER){
              return null;
          }
          return (Interpreter) interpreter;
      }
      
      /**
       * Locates and returns an Interpreter for the specified language.
       * If no Interpreter exists for the specified language, returns null.
       * 
       * @param language is the name of an expression language (no colon
       *  at the end)
       * @return the Interpreter for that language
       */
      protected static final Interpreter getInterpreterImplementation(
              String language){
          Object interpreter = interpreterImplMap.get(language);
          if (interpreter == null){
              Class clazz = null;
              try {
                  clazz = Class.forName(
                      "org.apache.commons.jex." + language + ".Interpreter");
                  interpreter = (Interpreter) clazz.newInstance();
              }
              catch (ClassNotFoundException ex){
                  interpreter = KNOWN_MISSING_INTERPRETER;
              }
              catch (Exception ex){
                  // TBD: wrap
                  throw new RuntimeException(ex.getMessage());
              }
              interpreterImplMap.put(language, interpreter);
          }        
          if (interpreter == KNOWN_MISSING_INTERPRETER){
              return null;
          }
          return (Interpreter) interpreter;
      }
      
      /**
       * Evaluates the expression in the supplied context.
       * 
       * @param context is an evaluation context.
       * @param expression is the expression to be evaluated
       * @param arguments are argument of the expression. Can be null
       *  if the expression does not take any arguments.
       * @return the result of the evaluation of this expression
       */
      public abstract Object evaluate(Context context, String expression, 
              Object[] arguments);
  
      /**
       * Evaluates the expression and casts the result to the supplied type.
       * 
       * @see #evaluate(Context, String, Object[])
       */
      public abstract Object evaluate(Context context, String expression, 
              Object[] arguments, Class valueType);
  
      /**
       * Produces the iterator described by the expression in the
       * specified context.
       * 
       * @param context is an evaluation context.
       * @param expression is the expression to be evaluated
       * @param arguments are argument of the expression. Can be null
       *  if the expression does not take any arguments.
       * @return the result of the evaluation of this expression
       */
      public abstract Iterator iterate(Context context, String expression, 
              Object[] arguments);
      
      /**
       * Modifies a value in the specified context according to the
       * expression and the supplied arguments.  Casts the type of 
       * the value if necessary.
       * 
       * @param context is an evaluation context.
       * @param expression is the expression to be evaluated
       * @param value is the new value
       * @param arguments are argument of the expression. Can be null
       *  if the expression does not take any arguments.
       */
      public abstract void assign(Context context, String expression, 
              Object value,  Object[] arguments);
  
      /**
       * Checks the syntax of an expression intended for evaluation
       * with {@link #evaluate evaluate} and throws an exception
       * if there is an error.
       * 
       * @param expression is the expression to be checked
       */
      public void validateExpression(String expression){
      }
  
      /**
       * Checks the syntax of an expression intended for evaluation
       * with {@link #iterate iterate} and throws an exception
       * if there is an error.
       * 
       * @param expression is the expression to be checked
       */
      public void validateIterationExpression(String expression){
      }
      
      /**
       * Checks the syntax of an expression intended for evaluation
       * with {@link #assign assign} and throws an exception
       * if there is an error.
       * 
       * @param expression is the expression to be checked
       */
      public void validateVariableExpression(String expression){
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/IterationExpression.java
  
  Index: IterationExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/IterationExpression.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex;
  
  import java.util.Iterator;
  
  /**
   * Compiled form of an iteration expression, which can be evaluated in
   * a {@link Context Context}.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:49 $
   */
  public interface IterationExpression {
      
      /**
       * Produces the iterator described by the expression in the
       * specified context with the supplied arguments.
       * 
       * @param context is an evaluation context.
       * @param arguments are argument of the expression. Can be null
       *  if the expression does not take any arguments.
       * @return the result of the evaluation of this expression
       */
      Iterator iterate(Context context, Object[] arguments);
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/MultilingualCompiler.java
  
  Index: MultilingualCompiler.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/MultilingualCompiler.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex;
  
  
  import java.util.HashMap;
  
  /**
   * A MultilingualCompiler determines the language for each expression and
   * then compiles it using that language's compiler.
   * <p>
   * If the expression string passed to this compiler starts with 
   * <code>"<i>language</i>:"</code>, the compiler strips the prefix off and
   * passes the remainder of the expression to the compiler for 
   * the corresponding language. 
   * <p>The prefix is required if the MultilingualCompiler's default
   * language is null.
   * <p>If the default language is not null and the expression is missing
   * a prefix, or the prefix does not match an existing compiler,
   * the multilingual compiler passes the expression unchanged to the default 
   * language compiler.
   * 
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:49 $
   */
  public class MultilingualCompiler extends Compiler {
  
      private String defaultLanguage;
      private Compiler defaultCompiler;
      private static HashMap compilers = new HashMap();
  
  
      /**
       * Returns a MultilingualCompiler with the specified default language.
       * If the specified default language is not null, a compiler 
       * (or an interpreter) for that language should be available.
       * 
       * @param defaultLanguage is the default language or null
       * @return A MultilingualCompiler
       */
      public static final Compiler getMultilingualCompiler(
                  String defaultLanguage){
          Compiler compiler = (Compiler) compilers.get(defaultLanguage);
          if (compiler == null){
              compiler = new MultilingualCompiler(defaultLanguage);
              compilers.put(defaultLanguage, compiler);
          }
          return compiler;
      }
      
      private MultilingualCompiler(String defaultLanguage){
          this.defaultLanguage = defaultLanguage;
          if (defaultLanguage != null){
             defaultCompiler = Compiler.getCompiler(defaultLanguage);
              if (defaultCompiler == null){
                  throw new RuntimeException(
                      "Compiler not available for expression language " +
                      defaultLanguage);
              }
          }
      }
      
      /**
       * Compiles an expression intended for evaluation using the 
       * appropriate compiler.
       * If the expression has the syntax "<i>lang</i>:<i>expr</i>" and
       * a compiler is available for the language "<i>lang</i>", 
       * passes the expression to that compiler. Otherwise, passes the
       * whole unparsed expression to the default language compiler.
       * 
       * @param expression is the expression to be compiled with 
       *      an optional "lang:" prefix
       * 
       * @return the compiled expression
       */
      public Expression compileExpression(String expression) {        
          int inx = expression.indexOf(':');
          if (inx != -1){
              String language = expression.substring(0, inx);
              Compiler compiler = Compiler.getCompiler(language);
              if (compiler != null){
                  String body = expression.substring(inx + 1);
                  return compiler.compileExpression(body);
              }
          }
          if (defaultCompiler != null){
              return defaultCompiler.compileExpression(expression);
          }
          else {
              throw new RuntimeException(
                  "The expression does not have a 'lang:' prefix and " +
                  "no default language has been specified");
          }
      }
  
      /**
       * Compiles an expression that describes an iteration.
       * 
       * @see #compileExpression(String)
       */
      public IterationExpression compileIterationExpression(String expression) {
          int inx = expression.indexOf(':');
          if (inx != -1){
              String language = expression.substring(0, inx);
              Compiler compiler = Compiler.getCompiler(language);
              if (compiler != null){
                  String body = expression.substring(inx + 1);
                  return compiler.compileIterationExpression(body);
              }
          }
          if (defaultCompiler != null){
              return defaultCompiler.compileIterationExpression(expression);
          }
          else {
              throw new RuntimeException(
                  "The expression does not have a 'lang:' prefix and " +
                  "no default language has been specified");
          }
      }
  
      /**
       * Compiles an expression intended to serve as the left hand
       * side of an assignment.
       * 
       * @see #compileExpression(String)
       */
      public VariableExpression compileVariableExpression(String expression) {
          int inx = expression.indexOf(':');
          if (inx != -1){
              String language = expression.substring(0, inx);
              Compiler compiler = Compiler.getCompiler(language);
              if (compiler != null){
                  String body = expression.substring(inx + 1);
                  return compiler.compileVariableExpression(body);
              }
          }
          if (defaultCompiler != null){
              return defaultCompiler.compileVariableExpression(expression);
          }
          else {
              throw new RuntimeException(
                  "The expression does not have a 'lang:' prefix and " +
                  "no default language has been specified");
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/MultilingualInterpreter.java
  
  Index: MultilingualInterpreter.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/MultilingualInterpreter.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex;
  
  import java.util.Iterator;
  import java.util.HashMap;
  
  /**
   * A MultilingualInterpreter determines the language for each expression and
   * then interprets it using that language's interpreter.
   * <p>
   * If the expression string passed to this interpreter starts with 
   * <code>"<i>language</i>:"</code>, the compiler strips the prefix off and
   * passes the remainder of the expression to the interpreter for 
   * the corresponding language. 
   * <p>The prefix is required if the MultilingualInterpreter's default
   * language is null.
   * <p>If the default language is not null and the expression is missing
   * a prefix, or the prefix does not match an existing compiler,
   * the multilingual interpreter passes the expression unchanged to the default 
   * language interpreter.
   * 
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:49 $
   */
  public class MultilingualInterpreter extends Interpreter {
  
      private String defaultLanguage;
      private Interpreter defaultInterpreter;
      private static HashMap genericInterpreters = new HashMap();
  
      /**
       * Returns a MultilingualInterpreter with the specified default language.
       * If the specified default language is not null, an interpreter 
       * (or a compiler) for that language should be available.
       * 
       * @param defaultLanguage is the default language or null
       * @return A MultilingualInterpreter
       */
      public static final Interpreter getMultilingualInterpreter(
              String defaultLanguage){
          Interpreter interpreter = (Interpreter) genericInterpreters.
                  get(defaultLanguage);
          if (interpreter == null){
              interpreter = new MultilingualInterpreter(defaultLanguage);
              genericInterpreters.put(defaultLanguage, interpreter);
          }
          return interpreter;
      }
      
      private MultilingualInterpreter(String defaultLanguage){
          this.defaultLanguage = defaultLanguage;
          if (defaultLanguage != null){
              defaultInterpreter = Interpreter.getInterpreter(defaultLanguage);
              if (defaultInterpreter == null){
                  throw new RuntimeException(
                      "Interpreter not available for expression language " +
                      defaultLanguage);
              }
          }
      }
      
      /**
       * Evaluates the expression using the appropriate Interpreter.
       * If the expression has the syntax "<i>lang</i>:<i>expr</i>" and
       * an interpreter is available for the language "<i>lang</i>", 
       * it passes the expression to that interpreter. Otherwise, passes the
       * whole unparsed expression to the default language interpreter.
       * 
       * @param context is the context in which the expression should be
       *      evaluated
       * @param expression is the expression to be evaluated with 
       *      an optional "lang:" prefix
       * @param arguments is an array of arguments for the expression. Can
       *      be null if the expression does not require any arguments.
       * 
       * @return the result of the evaluation
       */
      public Object evaluate(Context context, String expression, 
              Object[] arguments) {
          int inx = expression.indexOf(':');
          if (inx != -1){
              String language = expression.substring(0, inx);
              Interpreter interpreter = Interpreter.getInterpreter(language);
              if (interpreter != null){
                  String body = expression.substring(inx + 1);
                  return interpreter.evaluate(context, body, arguments);
              }
          }
          if (defaultInterpreter != null){
              return defaultInterpreter.evaluate(context, expression, arguments);
          }
          else {
              throw new RuntimeException(
                  "The expression does not have a 'lang:' prefix and " +
                  "no default language has been specified");
          }
      }
  
      /**
       * Evaluates the expression and casts the result to the supplied type.
       * 
       * @see #evaluate(Context, String, Object[])
       */
      public Object evaluate(Context context, String expression, 
              Object[] arguments, Class valueType) {
          int inx = expression.indexOf(':');
          if (inx != -1){
              String language = expression.substring(0, inx);
              Interpreter interpreter = Interpreter.getInterpreter(language);
              if (interpreter != null){
                  String body = expression.substring(inx + 1);
                  return interpreter.
                      evaluate(context, body, arguments, valueType);
              }
          }
          if (defaultInterpreter != null){
              return defaultInterpreter.
                      evaluate(context, expression, arguments, valueType);
          }
          else {
              throw new RuntimeException(
                  "The expression does not have a 'lang:' prefix and " +
                  "no default language has been specified");
          }
      }
  
      /**
       * See {@link #evaluate(Context, String, Object[]) evaluate}
       * @see Interpreter#iterate(Context, String, Object[])
       */
      public Iterator iterate(Context context, String expression, 
              Object[] arguments) {
          int inx = expression.indexOf(':');
          if (inx != -1){
              String language = expression.substring(0, inx);
              Interpreter interpreter = Interpreter.getInterpreter(language);
              if (interpreter != null){
                  String body = expression.substring(inx + 1);
                  return interpreter.iterate(context, body, arguments);
              }
          }
          if (defaultInterpreter != null){
              return defaultInterpreter.iterate(context, expression, arguments);
          }
          else {
              throw new RuntimeException(
                  "The expression does not have a 'lang:' prefix and " +
                  "no default language has been specified");
          }
      }
  
      /**
       * See {@link #evaluate(Context, String, Object[]) evaluate}
       * @see Interpreter#assign(Context, String, Object, Object[])
       */
      public void assign(Context context, String expression, 
              Object value, Object[] arguments) {
          int inx = expression.indexOf(':');
          if (inx != -1){
              String language = expression.substring(0, inx);
              Interpreter interpreter = Interpreter.getInterpreter(language);
              if (interpreter != null){
                  String body = expression.substring(inx + 1);
                  interpreter.assign(context, body, value, arguments);
                  return;
              }
          }
          if (defaultInterpreter != null){
              defaultInterpreter.assign(context, expression, value, arguments);
          }
          else {
              throw new RuntimeException(
                  "The expression does not have a 'lang:' prefix and " +
                  "no default language has been specified");
          }
      }
      
      /**
       * Identifies the expression language and validates the expression 
       * syntax using the appropriate Interpreter
       * 
       * See {@link #evaluate(Context, String, Object[]) evaluate}
       * @see Interpreter#validateExpression(String)
       */
      public void validateExpression(String expression){
          int inx = expression.indexOf(':');
          if (inx != -1){
              String language = expression.substring(0, inx);
              Interpreter interpreter = Interpreter.getInterpreter(language);
              if (interpreter != null){
                  String body = expression.substring(inx + 1);
                  interpreter.validateExpression(expression);
                  return;
              }
          }
          if (defaultInterpreter != null){
              defaultInterpreter.validateExpression(expression);
          }
          else {
              throw new RuntimeException(
                  "The expression does not have a 'lang:' prefix and " +
                  "no default language has been specified");
          }
      }
  
      /**
       * Identifies the expression language and validates the iteration
       * expression syntax using the appropriate Interpreter
       * 
       * See {@link #evaluate(Context, String, Object[]) evaluate}
       * @see Interpreter#validateIterationExpression(String)
       */
      public void validateIterationExpression(String expression){
          int inx = expression.indexOf(':');
          if (inx != -1){
              String language = expression.substring(0, inx);
              Interpreter interpreter = Interpreter.getInterpreter(language);
              if (interpreter != null){
                  String body = expression.substring(inx + 1);
                  interpreter.validateIterationExpression(expression);
                  return;
              }
          }
          if (defaultInterpreter != null){
              defaultInterpreter.validateIterationExpression(expression);
          }
          else {
              throw new RuntimeException(
                  "The expression does not have a 'lang:' prefix and " +
                  "no default language has been specified");
          }
      }
      
      /**
       * Identifies the expression language and validates the variable
       * expression syntax using the appropriate Interpreter
       * 
       * See {@link #evaluate(Context, String, Object[]) evaluate}
       * @see Interpreter#validateIterationExpression(String)
       */
      public void validateVariableExpression(String expression){
          int inx = expression.indexOf(':');
          if (inx != -1){
              String language = expression.substring(0, inx);
              Interpreter interpreter = Interpreter.getInterpreter(language);
              if (interpreter != null){
                  String body = expression.substring(inx + 1);
                  interpreter.validateVariableExpression(expression);
                  return;
              }
          }
          if (defaultInterpreter != null){
              defaultInterpreter.validateVariableExpression(expression);
          }
          else {
              throw new RuntimeException(
                  "The expression does not have a 'lang:' prefix and " +
                  "no default language has been specified");
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/VariableExpression.java
  
  Index: VariableExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/VariableExpression.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex;
  
  /**
   * Compiled form of a left-hand side expression, which can be assigned
   * a value.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:49 $
   */
  public interface VariableExpression {
      
      /**
       * Modifies a value in the specified context according to the
       * expression and the supplied arguments.  Casts the type of 
       * the value if necessary.
       * 
       * @param context is an evaluation context.
       * @param value is the new value
       * @param arguments are argument of the expression. Can be null
       *  if the expression does not take any arguments.
       */
      void assign(Context context, Object value, Object[] arguments);    
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/Variables.java
  
  Index: Variables.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/Variables.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/Variables.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   */
  package org.apache.commons.jex;
  
  /**
   * Variables provide access to a global set of values accessible via 
   * expressions. To use a custom implementation of this interface, 
   * pass it to the {@link Context#setVariables Context.setVariables()}
   * method
   * <p>
   * Note that a variable may be defined with a null value
   * 
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $
   */
  public interface Variables {
  
      /**
       * Returns true if the specified variable is declared.
       * 
       * @param varName a variable name
       * @return true if the variable exists
       */
      boolean isDeclaredVariable(String varName);
  
      /**
       * Returns the value of the specified variable.
       * Throws IllegalArgumentException if there is no such variable.
       * 
       * @param varName a variable name
       * @return the value of the variable
       */
      Object getVariable(String varName);
  
      /**
       * Defines a new variable with the specified value or modifies
       * the value of an existing variable. May throw 
       * UnsupportedOperationException.
       * 
       * @param varName a variable name
       * @param value the new value of the variable, which can be null
       */
      void declareVariable(String varName, Object value);
  }
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/adapters/CompilingInterpreter.java
  
  Index: CompilingInterpreter.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/adapters/CompilingInterpreter.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.adapters;
  
  import java.util.Iterator;
  
  import org.apache.commons.jex.Compiler;
  import org.apache.commons.jex.Context;
  import org.apache.commons.jex.Expression;
  import org.apache.commons.jex.Interpreter;
  import org.apache.commons.jex.IterationExpression;
  import org.apache.commons.jex.VariableExpression;
  
  /**
   * A wrapper for a compiler that makes it behave like an interpreter.
   * Each expression evaluation method first compiles the expression
   * and then invokes the resulting compiled expression.
   * <p>
   * The syntax checking methods invoke the compiler and throw away
   * the resulting compiled expression.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $
   */
  public class CompilingInterpreter extends Interpreter {
  
      private Compiler compiler;
  
      /**
       * @param compiler is the compiler that needs to be wrapped
       */    
      public CompilingInterpreter(Compiler compiler){
          this.compiler = compiler;
      }
      
      /**
       * @see Interpreter#evaluate(Context, String, Object[])
       */
      public Object evaluate(Context context, String expression, 
              Object[] arguments) {
          Expression expr = compiler.compileExpression(expression);
          return expr.evaluate(context, arguments);
      }
  
      /**
       * @see Interpreter#evaluate(Context, String, Object[], Class)
       */
      public Object evaluate(Context context, String expression, 
              Object[] arguments, Class valueType) {
          Expression expr = compiler.compileExpression(expression);
          return expr.evaluate(context, arguments, valueType);
      }
  
      /**
       * @see Interpreter#iterate(Context, String, Object[])
       */
      public Iterator iterate(Context context, String expression, 
              Object[] arguments) {
          IterationExpression expr = compiler.
              compileIterationExpression(expression);
          return expr.iterate(context, arguments);
      }
  
      /**
       * @see Interpreter#assign(Context, String, Object, Object[])
       */
      public void assign(Context context, String expression, 
              Object value, Object[] arguments) {
          VariableExpression expr = compiler.
                  compileVariableExpression(expression);
          expr.assign(context, value, arguments);
      }
      
      /**
       * @see Interpreter#validateExpression(String)
       */
      public void validateExpression(String expression){
          compiler.compileExpression(expression);
      }
  
      /**
       * @see Interpreter#validateIterationExpression(String)
       */
      public void validateIterationExpression(String expression){
          compiler.compileIterationExpression(expression);
      }
      
      /**
       * @see Interpreter#validateVariableExpression(String)
       */
      public void validateVariableExpression(String expression){
          compiler.compileVariableExpression(expression);
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/adapters/InterpretedExpression.java
  
  Index: InterpretedExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/adapters/InterpretedExpression.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.adapters;
  
  import java.util.Iterator;
  
  import org.apache.commons.jex.Interpreter;
  import org.apache.commons.jex.Context;
  import org.apache.commons.jex.Expression;
  import org.apache.commons.jex.IterationExpression;
  import org.apache.commons.jex.VariableExpression;
  
  /**
   * A wrapper for an expression string associated with an interpreter.
   * When asked to evaluate itself, an InterpreterExpression
   * passes the expression string to the interpreter for evaluation.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $
   */
  public class InterpretedExpression
      implements Expression, IterationExpression, VariableExpression {
          
      private Interpreter interpreter;
      private String expression;
  
      /**
       * @param interpreter is the interpreter for the expression language
       * @param expression is the expression to be interpreted
       */    
      public InterpretedExpression(Interpreter interpreter, String expression){
          this.interpreter = interpreter;
          this.expression = expression;
      }
      
      /**
       * @see Expression#evaluate(Context, Object[])
       */
      public Object evaluate(Context context, Object[] arguments) {
          return interpreter.evaluate(context, expression, arguments);
      }
  
      /**
       * @see Expression#evaluate(Context, Object[], Class)
       */
      public Object evaluate(Context context, Object[] arguments, 
              Class valueType) {
          return interpreter.
              evaluate(context, expression, arguments, valueType);
      }
  
      /**
       * @see IterationExpression#iterate(Context, Object[])
       */
      public Iterator iterate(Context context, Object[] arguments) {
          return interpreter.iterate(context, expression, arguments);
      }
  
      /**
       * @see VariableExpression#assign(Context, Object, Object[])
       */
      public void assign(Context context, Object value, Object[] arguments) {
          interpreter.assign(context, expression, value, arguments);
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/adapters/InterpretingCompiler.java
  
  Index: InterpretingCompiler.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/adapters/InterpretingCompiler.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.adapters;
  
  import org.apache.commons.jex.Interpreter;
  import org.apache.commons.jex.Compiler;
  import org.apache.commons.jex.Expression;
  import org.apache.commons.jex.IterationExpression;
  import org.apache.commons.jex.VariableExpression;
  
  /**
   * A wrapper for an interpreter that makes it behave like a compiler.
   * Each compilation method checks the syntax of the expression and
   * wraps the expression  into an {@link InterpretedExpression
   * InterpretedExpression}, which is a wrapper for the expression string.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $
   */
  public class InterpretingCompiler extends Compiler {
  
      private Interpreter interpreter;
  
      /**
       * @param interpreter is the interpreter that needs to be wrapped
       */    
      public InterpretingCompiler(Interpreter interpreter){
          this.interpreter = interpreter;
      }
      
      /**
       * @see Compiler#compileExpression(String)
       */
      public Expression compileExpression(String expression) {
          interpreter.validateExpression(expression);
          return new InterpretedExpression(interpreter, expression);
      }
  
      /**
       * @see Compiler#compileIterationExpression(String)
       */
      public IterationExpression compileIterationExpression(String expression) {
          interpreter.validateIterationExpression(expression);
          return new InterpretedExpression(interpreter, expression);
      }
  
      /**
       * @see Compiler#compileVariableExpression(String)
       */
      public VariableExpression compileVariableExpression(String expression) {
          interpreter.validateVariableExpression(expression);
          return new InterpretedExpression(interpreter, expression);
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/bexl/Interpreter.java
  
  Index: Interpreter.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/bexl/Interpreter.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.bexl;
  
  import java.util.Iterator;
  
  import org.apache.commons.beanutils.PropertyUtils;
  
  import org.apache.commons.jex.Context;
  import org.apache.commons.jex.util.TypeUtils;
  import org.apache.commons.jex.util.ValueUtils;
  
  /**
   * An Interpreter for the expression language introduced by
   * Jakarta Commons BeanUtils.  It understands properties,
   * indexing, dot-separated paths, mapped properties, DynaBeans.
   * See <a href="http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils/PropertyUtils.html"
   * target="ref">
   * PropertyUtils</a> for the complete description of the language.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $
   */
  public class Interpreter extends org.apache.commons.jex.Interpreter {
      
      /**
       * Invokes PropertyUtils.getProperty(target, expression), where
       * target is passed as the first and only argument.
       * 
       * @see org.apache.commons.jex.Interpreter#evaluate(Context, String, Object[])
       */
      public Object evaluate(Context context, String expression, 
              Object[] arguments){
          if (arguments == null || arguments.length != 1){
              throw new RuntimeException("Incorrect number of arguments; " +
                 "should be 1.");
          }
          Object target = arguments[0];
          try {
              return PropertyUtils.getProperty(target, expression);
          }
          catch (Exception ex){
             // TBD: wrap
             throw new RuntimeException("Cannot get property " + expression + 
                  ex.getMessage());
          }
      }
  
      /**
       * Invokes PropertyUtils.getProperty(target, expression), where
       * target is passed as the first and only argument.
       * 
       * @see org.apache.commons.jex.Interpreter#evaluate(Context, String, Object[], Class)
       */
      public Object evaluate(Context context, String expression, 
              Object[] arguments, Class valueType){
          Object result = evaluate(context, expression, arguments);
          if (!TypeUtils.canConvert(result, valueType)){
              throw new RuntimeException("Cannot convert " + result + " to " +
                  valueType);
          }        
          return TypeUtils.convert(result, valueType);
      }
  
      /**
       * Evaluates the expression, treats the result as a collection and
       * returns an iterator of that collection.
       * 
       * @see org.apache.commons.jex.Interpreter#iterate(Context, String, Object[])
       */
      public Iterator iterate(Context context, String expression, 
              Object[] arguments){
          Object collection = evaluate(context, expression, arguments);
          return ValueUtils.iterate(collection);
      }
      
      /**
       * Invokes PropertyUtils.setProperty(target, expression, value), where
       * target is passed as the first and only argument.
       * 
       * @see org.apache.commons.jex.Interpreter#assign(Context, String, Object, Object[])
       */
      public void assign(Context context, String expression, 
              Object value, Object[] arguments){
          if (arguments == null || arguments.length != 1){
              throw new RuntimeException("Incorrect number of arguments; " +
                 "should be 1.");
          }
          Object target = arguments[0];
          try {
              PropertyUtils.setProperty(target, expression, value);
          }
          catch (Exception ex){
             // TBD: wrap
             throw new RuntimeException("Cannot get property " + expression + 
                  ex.getMessage());
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/javascript/Compiler.java
  
  Index: Compiler.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/javascript/Compiler.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.javascript;
  
  import java.io.IOException;
  import java.io.StringReader;
  
  import org.mozilla.javascript.Context;
  import org.mozilla.javascript.Script;
  
  import org.apache.commons.jex.Expression;
  import org.apache.commons.jex.IterationExpression;
  import org.apache.commons.jex.VariableExpression;
  
  
  
  /**
   * Integrates ECMA-Script (aka JavaScript) with Jex. 
   * See <a href="http://www.mozilla.org/rhino/">Mozilla Rhino</a>
   * 
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:49 $
   */
  public class Compiler extends org.apache.commons.jex.Compiler {
      
      /**
       * @see org.apache.commons.jex.Compiler#compileExpression(String)
       */
      public Expression compileExpression(String expression) {
          Expression expr = null;
          Context cx = Context.enter();
          StringReader sr = new StringReader(expression);
          try {
              Script script = cx.compileReader(null, sr, "source", 1, null);
              expr = new JavaScriptValueExpression(script);
          }
          catch (IOException ex){
              ex.printStackTrace();   // This won't happen
          }
          Context.exit();
  
          return expr;
      }
  
      /**
       * @see org.apache.commons.jex.Compiler#compileIterationExpression(String)
       */
      public IterationExpression compileIterationExpression(String expression) {
          IterationExpression expr = null;
          Context cx = Context.enter();
          StringReader sr = new StringReader(expression);
          try {
              Script script = cx.compileReader(null, sr, "source", 1, null);
              expr = new JavaScriptIterationExpression(script);
          }
          catch (IOException ex){
              ex.printStackTrace();   // This won't happen
          }
          Context.exit();
  
          return expr;
      }
  
      /**
       * @see org.apache.commons.jex.Compiler#compileVariableExpression(String)
       */
      public VariableExpression compileVariableExpression(String expression) {
          VariableExpression expr = null;
          Context cx = Context.enter();
          StringReader sr = new StringReader(expression + 
                  " = " + JavaScriptVariableExpression.JS_PSEUDO_VARIABLE);
          try {
              Script script = cx.compileReader(null, sr, "source", 1, null);
              expr = new JavaScriptVariableExpression(script);
          }
          catch (IOException ex){
              ex.printStackTrace();   // This won't happen
          }
          Context.exit();
  
          return expr;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/javascript/JavaScriptExpression.java
  
  Index: JavaScriptExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/javascript/JavaScriptExpression.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.javascript;
  
  import org.mozilla.javascript.NativeJavaObject;
  import org.mozilla.javascript.Script;
  import org.mozilla.javascript.Scriptable;
  import org.mozilla.javascript.ScriptableObject;
  
  import org.apache.commons.jex.Context;
  import org.apache.commons.jex.Variables;
  
  /**
   * 
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:49 $
   */
  public abstract class JavaScriptExpression {
  
      /**
       * Jex stores the Global Scope for evaluation of JavaScript
       * expressions in the root Jex Context as a property named
       * JS_GLOBAL_SCOPE_PROPERTY
       */
      public static final String JS_GLOBAL_SCOPE_PROPERTY = 
                  "javascript.GLOBAL_SCOPE";
                  
      /**
       * Jex stores the Local Scope for evaluation of JavaScript
       * expressions in the current Jex Context as a property named
       * JS_SCOPE_PROPERTY
       */
      public static final String JS_SCOPE_PROPERTY = "javascript.SCOPE";
  
      /**
       * By default, Jex does not allow assignment to undeclared variables.
       * To relax this restriction, define a property called 
       * JS_AUTODECLARE ("javascript.autodeclare") in the context that
       * will host the new variables.
       */
      public static final String JS_AUTODECLARE = "javascript.autodeclare";    
      
      /**
       * Name of the pseudo-variable used by JavaScriptVariableExpression
       * to hold the value to be assigned.
       */
      protected static final String JS_PSEUDO_VARIABLE = "__value__";
      
      private Script script;
      
      /**
       * @param script is a compiled JavaScript to be associated with
       *  this expression
       */
      public JavaScriptExpression(Script script){
          this.script = script;
      }
  
      /**
       * @return the compiled JavaScript 
       */
      public Script getScript(){
          return script;
      }
      
      /**
       * Creates a new scope for the evaluation of an expression. 
       * Makes the new scope a child of the Scriptable associated 
       * with the Context.
       * 
       * @param context is a Jex Context
       * @param jsContext is a javascript context for this operation
       * @param arguments should have the length of zero or one. The
       *    first argument of the array (or null) is used as the context bean.
       * @return Local scope
       */
      protected Scriptable getLocalScope(Context context, 
              org.mozilla.javascript.Context jsContext, 
              Object[] arguments){
          return getLocalScope(context, jsContext, arguments, false, null);
      }
              
      /**
       * Creates a new scope for the evaluation of an expression. 
       * Makes the new scope a child of the Scriptable associated 
       * with the Context.  Declares a pseudo-variable in the new context
       * that is used by JavaScriptVariableExpression as a holder for
       * the value to be assigned.
       * 
       * @param context is a Jex Context
       * @param jsContext is a javascript context for this operation
       * @param arguments should have the length of zero or one. The
       *    first argument of the array (or null) is used as the context bean.
       * @param value is the value assigned to the pseudo-variable
       * @return Local scope
       */
      protected Scriptable getLocalScope(Context context, 
              org.mozilla.javascript.Context jsContext, 
              Object[] arguments, Object value){
          return getLocalScope(context, jsContext, arguments, true, value);
      }
              
      private Scriptable getLocalScope(Context context, 
              org.mozilla.javascript.Context jsContext, 
              Object[] arguments,
              boolean supportValue, Object value){
          Object root;
          if (arguments == null || arguments.length == 0){
              root = null;
          }
          else if (arguments.length == 1){
              root = arguments[0];
          }
          else {
              throw new RuntimeException("Too many arguments");
          }
  
          Scriptable parentScope = getContextScope(context, jsContext);
          if (root != null){
              Scriptable njo = 
                  new NativeJavaObject(parentScope, root, root.getClass());
              njo.setPrototype(parentScope);
              parentScope = njo;
          }
          
          Scriptable localScope = parentScope;
          if (supportValue){
              localScope = new PseudoVariableScope(value);
              localScope.setPrototype(parentScope);
              localScope.setParentScope(null);
          }
          return localScope;
      }
      
      /**
       * Creates a JavaScript scope for this JexContext. Provides access
       * to the context variables.  Caches the JavaScript scope in the
       * context itself.
       * 
       * @param context is a Jex Context
       * @param jsContext is a javascript context for this operation
       * @return Context scope
       */
      protected Scriptable getContextScope(Context context,
              org.mozilla.javascript.Context jsContext){
          Scriptable scope = (Scriptable) context.getProperty(JS_SCOPE_PROPERTY);
          if (scope == null){
              scope = new ContextScope(context);
              scope.setPrototype(getGlobalScope(context, jsContext));
              scope.setParentScope(null);
              context.setProperty(JS_SCOPE_PROPERTY, scope);
          }   
          return scope;
      }
      
      /**
       * Creates a global JavaScript scope. Caches the scope in the
       * root Jex context.
       * 
       * @param context is a Jex Context
       * @param jsContext is a javascript context for this operation
       * @return Global scope
       */
      protected Scriptable getGlobalScope(Context context,
              org.mozilla.javascript.Context jsContext){        
          Scriptable scope = 
              (Scriptable) context.getProperty(JS_GLOBAL_SCOPE_PROPERTY);
          if (scope == null){
              scope = jsContext.initStandardObjects(null);
              Context root = context;
              while (root.getParentContext() != null){
                  root = root.getParentContext();
              }
              root.setProperty(JS_GLOBAL_SCOPE_PROPERTY, scope);
          }
          return scope;
      }
      
      /**
       * A JavaScript scriptable that provides access to Jex Context
       * variables.
       */
      private static class ContextScope extends ScriptableObject {
          private Context context;
          
          public ContextScope(Context context){
              this.context = context;
          }
          
          public String getClassName(){
              return "JexContext";                
          }
          
          public Object get(String name, Scriptable start){
              Object result = super.get(name, start);
              if (result == NOT_FOUND) {
                  Context varCtx = findVariableContext(context, name);
                  if (varCtx != null){
                      result = varCtx.getVariables().getVariable(name);
                  }
              }
              return result;
          }
          
          
          public void put(String name, Scriptable start, Object value){
              Context varCtx = findVariableContext(context, name);
              if (varCtx == null){
                  varCtx = findAutodeclareContext(context);
              }
              
              if (varCtx != null){
                  varCtx.getVariables().declareVariable(name, value);
              }            
              else {               
                  throw new RuntimeException("Unknown variable: " + name);
              }            
          }
          
          private Context findVariableContext(Context context, String varName){
              while (context != null){
                  Variables vars = context.getVariables();
                  if (vars.isDeclaredVariable(varName)){
                      return context;                    
                  }
                  context = context.getParentContext();
              }
              return null;
          }
          
          private Context findAutodeclareContext(Context context){
              while (context != null){
                  if (context.getProperty(JS_AUTODECLARE) != null){
                      return context;
                  }
                  context = context.getParentContext();
              }
              return null;
          }
      };    
  
      /**
       * A JavaScript scriptable that provides access to Jex Context
       * variables.
       */
      private static class PseudoVariableScope extends ScriptableObject {
          private Object value;
          
          public PseudoVariableScope(Object value){
              this.value = value;
          }
          
          public String getClassName(){
              return "JexContext";                
          }
          
          public Object get(String name, Scriptable start){
              if (name.equals(JS_PSEUDO_VARIABLE)){
                  return value;
              }
              return super.get(name, start);
          }
                  
          public void put(String name, Scriptable start, Object value){
              getPrototype().put(name, start, value);
          }
      };    
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/javascript/JavaScriptIterationExpression.java
  
  Index: JavaScriptIterationExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/javascript/JavaScriptIterationExpression.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.javascript;
  
  import java.util.Iterator;
  
  import org.mozilla.javascript.JavaScriptException;
  import org.mozilla.javascript.Script;
  import org.mozilla.javascript.Scriptable;
  import org.mozilla.javascript.Wrapper;
  
  import org.apache.commons.jex.Context;
  import org.apache.commons.jex.IterationExpression;
  import org.apache.commons.jex.util.ValueUtils;
  
  /**
   * 
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:49 $
   */
  public class JavaScriptIterationExpression extends JavaScriptExpression
      implements IterationExpression {
  
      /**
       * @param script is a compiled JavaScript to be associated with
       *  this expression
       */
      public JavaScriptIterationExpression(Script script){
          super(script);
      }
      
      /**
       * @see IterationExpression#iterate(Context, Object[])
       */
      public Iterator iterate(Context context, Object[] arguments) {
          Object result = null;
          org.mozilla.javascript.Context jsContext = 
                  org.mozilla.javascript.Context.enter();
          try {
              Scriptable scope = getLocalScope(context, jsContext, arguments);
              result = getScript().exec(jsContext, scope);
              if (result instanceof Wrapper){
                  result = ((Wrapper) result).unwrap();
              }
          }
          catch (JavaScriptException ex){
              ex.printStackTrace();
          }
          org.mozilla.javascript.Context.exit();
          return ValueUtils.iterate(result);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/javascript/JavaScriptValueExpression.java
  
  Index: JavaScriptValueExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/javascript/JavaScriptValueExpression.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.javascript;
  
  import org.mozilla.javascript.JavaScriptException;
  import org.mozilla.javascript.Script;
  import org.mozilla.javascript.Scriptable;
  import org.mozilla.javascript.Wrapper;
  
  import org.apache.commons.jex.Context;
  import org.apache.commons.jex.Expression;
  import org.apache.commons.jex.util.TypeUtils;
  
  /**
   * 
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:49 $
   */
  public class JavaScriptValueExpression extends JavaScriptExpression
      implements Expression {
          
      /**
       * @param script is a compiled JavaScript to be associated with
       *  this expression
       */
      public JavaScriptValueExpression(Script script){
          super(script);
      }
  
      /**
       * @see Expression#evaluate(Context, Object[])
       */
      public Object evaluate(Context context, Object[] arguments) {        
          Object result = null;
          org.mozilla.javascript.Context jsContext = 
                  org.mozilla.javascript.Context.enter();
          try {
              Scriptable scope = getLocalScope(context, jsContext, arguments);
              result = getScript().exec(jsContext, scope);
              if (result instanceof Wrapper){
                  result = ((Wrapper) result).unwrap();
              }
          }
          catch (JavaScriptException ex){
              ex.printStackTrace();
          }
          org.mozilla.javascript.Context.exit();
          return result;
      }
  
      /**
       * @see Expression#evaluate(Context, Object[], Class)
       */
      public Object evaluate(Context context, 
              Object[] arguments, Class valueType){
          Object result = evaluate(context, arguments);
          if (!TypeUtils.canConvert(result, valueType)){
              throw new RuntimeException("Cannot convert " + result + " to " +
                  valueType);
          }        
          return TypeUtils.convert(result, valueType);
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/javascript/JavaScriptVariableExpression.java
  
  Index: JavaScriptVariableExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/javascript/JavaScriptVariableExpression.java,v 1.1 2002/06/12 22:31:49 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:49 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.javascript;
  
  import org.mozilla.javascript.JavaScriptException;
  import org.mozilla.javascript.Script;
  import org.mozilla.javascript.Scriptable;
  
  import org.apache.commons.jex.Context;
  import org.apache.commons.jex.VariableExpression;
  
  /**
   * 
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:49 $
   */
  public class JavaScriptVariableExpression extends JavaScriptExpression
      implements VariableExpression {
  
      /**
       * @param script is a compiled JavaScript to be associated with
       *  this expression
       */
      public JavaScriptVariableExpression(Script script){
          super(script);
      }
  
      /**
       * @see VariableExpression#assign(Context, Object, Object[])
       */
      public void assign(Context context, Object value, Object[] arguments) {
          Object result = null;
          org.mozilla.javascript.Context jsContext = 
                  org.mozilla.javascript.Context.enter();
          try {
              Scriptable scope = 
                  getLocalScope(context, jsContext, arguments, value);
              getScript().exec(jsContext, scope);
          }
          catch (JavaScriptException ex){
              ex.printStackTrace();
          }
          org.mozilla.javascript.Context.exit();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/jxpath/Compiler.java
  
  Index: Compiler.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/jxpath/Compiler.java,v 1.1 2002/06/12 22:31:50 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:50 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.jxpath;
  
  import org.apache.commons.jxpath.CompiledExpression;
  import org.apache.commons.jxpath.JXPathContext;
  
  import org.apache.commons.jex.Expression;
  import org.apache.commons.jex.IterationExpression;
  import org.apache.commons.jex.VariableExpression;
  
  /**
   * Integrates JXPath with Jex. 
   * See <a href="http://jakarta.apache.org/commons/jxpath">
   * JXPath home page on Apache</a>.
   * <p>
   * If Jex becomes a part of Jakarta, JXPath will change to implement
   * Jex interfaces directly.  At that point the need for this adaptor
   * will disappear.
   * 
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:50 $
   */
  public class Compiler extends org.apache.commons.jex.Compiler {
  
      private static final JXPathContext COMPILATION_CONTEXT =
          JXPathContext.newContext(null);
      
      
      /**
       * @see org.apache.commons.jex.Compiler#compileExpression(String)
       */
      public Expression compileExpression(String expression) {
          CompiledExpression expr = COMPILATION_CONTEXT.compile(expression);
          return new JXPathCompiledExpression(expr);
      }
  
      /**
       * @see org.apache.commons.jex.Compiler#compileIterationExpression(String)
       */
      public IterationExpression compileIterationExpression(String expression) {
          CompiledExpression expr = COMPILATION_CONTEXT.compile(expression);
          return new JXPathCompiledExpression(expr);
      }
  
      /**
       * @see org.apache.commons.jex.Compiler#compileVariableExpression(String)
       */
      public VariableExpression compileVariableExpression(String expression) {
          CompiledExpression expr = COMPILATION_CONTEXT.compile(expression);
          return new JXPathCompiledExpression(expr);
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/jxpath/JXPathCompiledExpression.java
  
  Index: JXPathCompiledExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/jxpath/JXPathCompiledExpression.java,v 1.1 2002/06/12 22:31:50 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:50 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.jxpath;
  
  import java.util.Iterator;
  
  import org.apache.commons.jxpath.CompiledExpression;
  import org.apache.commons.jxpath.JXPathContext;
  
  import org.apache.commons.jex.Context;
  import org.apache.commons.jex.Expression;
  import org.apache.commons.jex.IterationExpression;
  import org.apache.commons.jex.VariableExpression;
  
  /**
   * A trivial wrapper for JXPath CompiledExpression.
   * <p>
   * If Jex becomes a part of Jakarta, JXPath will change to implement
   * Jex interfaces directly.  At that point the need for this adaptor
   * will disappear.
   * 
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:50 $
   */
  public class JXPathCompiledExpression
      implements Expression, IterationExpression, VariableExpression {
  
      private static final String JXPATH_CONTEXT_PROPERTY = "jxpath.CONTEXT";
      
      private CompiledExpression expression;
      
      /**
       * Wraps a jxpath CompiledExpression into a Jex 
       * Expression/IterationExpression/VariableExpression
       * 
       * @param expression is a jxpath-style Compiled expression
       */
      public JXPathCompiledExpression(CompiledExpression expression){
          this.expression = expression;
      }
      
      /**
       * @see Expression#evaluate(Context, Object[])
       */
      public Object evaluate(Context context, Object[] arguments) {        
          return expression.getValue(getContext(context, arguments));
      }
  
      /**
       * @see Expression#evaluate(Context, Object[], Class)
       */
      public Object evaluate(Context context, 
                  Object[] arguments, Class valueType) {
          return expression.getValue(getContext(context, arguments), valueType);
      }
  
      /**
       * @see IterationExpression#iterate(Context, Object[])
       */
      public Iterator iterate(Context context, Object[] arguments) {
          return expression.iterate(getContext(context, arguments));
      }
  
      /**
       * @see VariableExpression#assign(Context, Object, Object[])
       */
      public void assign(Context context, Object value, Object[] arguments) {
          expression.setValue(getContext(context, arguments), value);
      }
  
      /**
       * Creates a new JXPathContext for the evaluation of an expression. 
       * Makes the new context a child of the JXPathContext associated 
       * with the Context.
       * 
       * @see #getParentContext
       * 
       * @param context is a Jex Context
       * @param arguments should have the length of zero or one. The
       *    first argument of the array (or null) is used as the context bean.
       */
      private JXPathContext getContext(Context context, Object[] arguments){
          Object contextNode;
          if (arguments == null || arguments.length == 0){
              contextNode = null;
          }
          else if (arguments.length == 1){
              contextNode = arguments[0];
          }
          else {
              throw new RuntimeException("Too many arguments");
          }
          
          return JXPathContext.newContext(getParentContext(context), contextNode);
      }
      
      /**
       * Finds a JXPathContext associated with a Jex Context.
       * Creates a JXPathContext for each Jex Context and stores a pointer
       * to it in a Context's property.
       * 
       * @param context is a Jex Context
       * @param arguments should have the length of zero or one. The
       *    first argument of the array (or null) is used as the context bean.
       */
      private JXPathContext getParentContext(Context context){
          if (context == null){
              return null;
          }
          
          JXPathContext ctx = (JXPathContext) context.
                  getProperty(JXPATH_CONTEXT_PROPERTY);
          if (ctx == null){
              JXPathContext parent = getParentContext(context.getParentContext());
              ctx = JXPathContext.newContext(parent, null);    
              ctx.setVariables(new JXPathVariables(context));
              context.setProperty(JXPATH_CONTEXT_PROPERTY, ctx);
          }   
          return ctx;     
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/jxpath/JXPathVariables.java
  
  Index: JXPathVariables.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/jxpath/JXPathVariables.java,v 1.1 2002/06/12 22:31:50 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:50 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.jxpath;
  
  import org.apache.commons.jex.Context;
  import org.apache.commons.jxpath.Variables;
  
  /**
   * Wraps Jex variables into JXPath variables.  This object points to
   * a Jex context and works with variables from that context.
   * <p>
   * If Jex becomes a part of Jakarta, JXPath will change to implement
   * Jex interfaces directly.  At that point the need for this adaptor
   * will disappear.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $
   */
  public class JXPathVariables implements Variables {
  
      private Context context;
  
      /**
       * @param context is the Jex context that hosts the variables
       * represented by the new object.
       */
      public JXPathVariables(Context context){
          this.context = context;
      }
          
      /**
       * @see Variables#isDeclaredVariable(String)
       */
      public boolean isDeclaredVariable(String varName) {
          return context.getVariables().isDeclaredVariable(varName);
      }
  
      /**
       * @see Variables#getVariable(String)
       */
      public Object getVariable(String varName) {
          return context.getVariables().getVariable(varName);
      }
  
      /**
       * @see Variables#declareVariable(String, Object)
       */
      public void declareVariable(String varName, Object value) {
          context.getVariables().declareVariable(varName, value);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/util/TypeUtils.java
  
  Index: TypeUtils.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/util/TypeUtils.java,v 1.1 2002/06/12 22:31:50 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:50 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.util;
  
  import java.lang.reflect.*;
  import java.util.*;
  
  
  /**
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:50 $
   */
  public class TypeUtils {
  
      public static boolean canConvert(Object object, Class toType){
          if (object == null){
              return true;
          }
  
          if (toType == Object.class){
              return true;
          }
  
          Class fromType = object.getClass();
          if (fromType.equals(toType)){
              return true;
          }
  
          if (toType.isAssignableFrom(fromType)){
              return true;
          }
  
          if (toType == String.class){
              return true;
          }
  
          if (object instanceof Boolean){
              if (toType == boolean.class ||
                      Number.class.isAssignableFrom(toType)){
                  return true;
              }
          }
          else if (object instanceof Number){
              if (toType.isPrimitive() ||
                      Number.class.isAssignableFrom(toType)){
                  return true;
              }
          }
          else if (object instanceof Character){
              if (toType == char.class){
                  return true;
              }
          }
          else if (object instanceof String){
              if (toType.isPrimitive()){
                  return true;
              }
              if (toType == Boolean.class ||
                      toType == Character.class ||
                      toType == Byte.class ||
                      toType == Short.class ||
                      toType == Integer.class ||
                      toType == Long.class ||
                      toType == Float.class ||
                      toType == Double.class){
                  return true;
              }
          }
          else if (fromType.isArray()){
              if (Array.getLength(object) == 1){
                  Object value = Array.get(object, 0);
                  return canConvert(value, toType);
              }
          }
          else if (object instanceof List){
              if (((List)object).size() == 1){
                  Object value = ((List)object).get(0);
                  return canConvert(value, toType);
              }
          }
          else if (object instanceof Collection){
              if (!((Collection)object).isEmpty()){
                  Iterator it = ((Collection)object).iterator();
                  Object value = it.next();
                  return canConvert(value, toType);
              }
          }
  
          // TBD: date conversion to/from string
          return false;
      }
  
      public static Object convert(Object object, Class toType){
          if (object == null){
              return null;
          }
  
          if (toType == Object.class){
              return object;
          }
  
  
          Class fromType = object.getClass();
          if (fromType.equals(toType) || toType.isAssignableFrom(fromType)){
              return object;
          }
  
          if (toType == String.class){
              return object.toString();
          }
  
          if (object instanceof Boolean){
              if (toType == boolean.class){
                  return object;
              }
              boolean value = ((Boolean)object).booleanValue();
              return allocateNumber(toType, value ? 1 : 0);
          }
          else if (object instanceof Number){
              double value = ((Number)object).doubleValue();
              if (toType == boolean.class || toType == Boolean.class){
                  return value == 0.0 ? Boolean.FALSE : Boolean.TRUE;
              }
              if (toType.isPrimitive() ||
                      Number.class.isAssignableFrom(toType)){
                  return allocateNumber(toType, value);
              }
          }
          else if (object instanceof Character){
              if (toType == char.class){
                  return object;
              }
          }
          else if (object instanceof String){
              if (toType == boolean.class || toType == Boolean.class){
                  return Boolean.valueOf((String)object);
              }
              if (toType == char.class || toType == Character.class){
                  return new Character(((String)object).charAt(0));
              }
              if (toType == byte.class || toType == Byte.class){
                  return new Byte((String)object);
              }
              if (toType == short.class || toType == Short.class){
                  return new Short((String)object);
              }
              if (toType == int.class || toType == Integer.class){
                  return new Integer((String)object);
              }
              if (toType == long.class || toType == Long.class){
                  return new Long((String)object);
              }
              if (toType == float.class || toType == Float.class){
                  return new Float((String)object);
              }
              if (toType == double.class || toType == Double.class){
                  return new Double((String)object);
              }
          }
          else if (fromType.isArray()){
              Object value = Array.get(object, 0);
              return convert(value, toType);
          }
          else if (object instanceof List){
              Object value = ((List)object).get(0);
              return convert(value, toType);
          }
          else if (object instanceof Collection){
              Iterator it = ((Collection)object).iterator();
              Object value = it.next();
              return convert(value, toType);
          }
          return object;
      }
  
      private static Number allocateNumber(Class type, double value){
          if (type == Byte.class || type == byte.class){
              return new Byte((byte)value);
          }
          if (type == Short.class || type == short.class){
              return new Short((short)value);
          }
          if (type == Integer.class || type == int.class){
              return new Integer((int)value);
          }
          if (type == Long.class || type == long.class){
              return new Long((long)value);
          }
          if (type == Float.class || type == float.class){
              return new Float((float)value);
          }
          if (type == Double.class || type == double.class){
              return new Double(value);
          }
          return null;
      }
  }
  
  
  1.1                  jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/util/ValueUtils.java
  
  Index: ValueUtils.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/java/org/apache/commons/jex/util/ValueUtils.java,v 1.1 2002/06/12 22:31:50 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:50 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex.util;
  
  import java.beans.IndexedPropertyDescriptor;
  import java.beans.PropertyDescriptor;
  import java.lang.reflect.*;
  import java.util.*;
  
  /**
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:50 $
   */
  public class ValueUtils {
      private static Map dynamicPropertyHandlerMap = new HashMap();
  
      public static boolean isCollection(PropertyDescriptor propertyDescriptor){
          return false;
      }
  
      public static boolean isCollection(PropertyDescriptor propertyDescriptor, Object value){
          return isCollection(value);
      }
  
      public static boolean isCollection(Object value){
          if (value == null){
              return false;
          }
          else if (value.getClass().isArray()){
              return true;
          }
          else if (value instanceof Collection){
              return true;
          }
          return false;
      }
  
      public static int getLength(Object collection){
          if (collection == null){
              return 0;
          }
          else if (collection.getClass().isArray()){
              return Array.getLength(collection);
          }
          else if (collection instanceof Collection){
              return ((Collection)collection).size();
          }
          else {
              return 1;
          }
      }
      
      public static Iterator iterate(Object collection){
          if (collection == null){
              return Collections.EMPTY_LIST.iterator();
          }
          if (collection.getClass().isArray()){
              int length = Array.getLength(collection);
              if (length == 0){
                  return Collections.EMPTY_LIST.iterator();
              }
              ArrayList list = new ArrayList();
              for (int i = 0; i < length; i++){
                  list.add(Array.get(collection, i));
              }
              return list.iterator();
          }
          else if (collection instanceof Collection){
              return ((Collection)collection).iterator();
          }
          else {
              return Collections.singletonList(collection).iterator();
          }
      }
  
      public static Object getValue(Object collection, int index){
          Object value = collection;
          if (collection != null){
              if (collection.getClass().isArray()){
                  if (index < 0 || index >= Array.getLength(collection)){
                      return null;
                  }
                  value = Array.get(collection, index);
              }
              else if (collection instanceof List){
                  if (index < 0 || index >= ((List)collection).size()){
                      return null;
                  }
                  value = ((List)collection).get(index);
              }
              else if (collection instanceof Collection){
                  int i = 0;
                  Iterator it = ((Collection)collection).iterator();
                  for (; i < index; i++){
                      it.next();
                  }
                  if (it.hasNext()){
                      value = it.next();
                  }
                  else {
                      value = null;
                  }
              }
          }
          return value;
      }
  
      public static void setValue(Object collection, int index, Object value){
          if (collection != null){
              if (collection.getClass().isArray()){
                  Class type = collection.getClass().getComponentType();
                  if (!TypeUtils.canConvert(value, type)){
                      throw new RuntimeException("Cannot convert " + value + 
                          " to " + type);
                  }
                  Array.set(collection, index, TypeUtils.convert(value, type));
              }
              else if (collection instanceof List){
                  ((List)collection).set(index, value);
              }
              else if (collection instanceof Collection){
                  throw new UnsupportedOperationException("Cannot set value of an element of a " +
                          collection.getClass().getName());
              }
          }
      }
  
      // -------------------------------------------------------- Private Methods
      //
      //  The rest of the code in this file was copied FROM
      //  org.apache.commons.beanutils.PropertyUtil. We don't want to introduce a dependency
      //  on BeanUtils yet - DP.
      //
  
      /**
       * Return an accessible method (that is, one that can be invoked via
       * reflection) that implements the specified Method.  If no such method
       * can be found, return <code>null</code>.
       *
       * @param method The method that we wish to call
       */
      private static Method getAccessibleMethod(Method method) {
  
          // Make sure we have a method to check
          if (method == null) {
              return (null);
          }
  
          // If the requested method is not public we cannot call it
          if (!Modifier.isPublic(method.getModifiers())) {
              return (null);
          }
  
          // If the declaring class is public, we are done
          Class clazz = method.getDeclaringClass();
          if (Modifier.isPublic(clazz.getModifiers())) {
              return (method);
          }
  
          // Check the implemented interfaces and subinterfaces
          String methodName = method.getName();
          Class[] parameterTypes = method.getParameterTypes();
          method =
              getAccessibleMethodFromInterfaceNest(clazz,
                                                   method.getName(),
                                                   method.getParameterTypes());
          return (method);
      }
  
  
      /**
       * Return an accessible method (that is, one that can be invoked via
       * reflection) that implements the specified method, by scanning through
       * all implemented interfaces and subinterfaces.  If no such Method
       * can be found, return <code>null</code>.
       *
       * @param clazz Parent class for the interfaces to be checked
       * @param methodName Method name of the method we wish to call
       * @param parameterTypes The parameter type signatures
       */
      private static Method getAccessibleMethodFromInterfaceNest
          (Class clazz, String methodName, Class parameterTypes[]) {
  
          Method method = null;
  
          // Check the implemented interfaces of the parent class
          Class interfaces[] = clazz.getInterfaces();
          for (int i = 0; i < interfaces.length; i++) {
  
              // Is this interface public?
              if (!Modifier.isPublic(interfaces[i].getModifiers()))
                  continue;
  
              // Does the method exist on this interface?
              try {
                  method = interfaces[i].getDeclaredMethod(methodName,
                                                           parameterTypes);
              } catch (NoSuchMethodException e) {
                  ;
              }
              if (method != null)
                  break;
  
              // Recursively check our parent interfaces
              method =
                  getAccessibleMethodFromInterfaceNest(interfaces[i],
                                                       methodName,
                                                       parameterTypes);
              if (method != null)
                  break;
  
          }
  
          // Return whatever we have found
          return (method);
      }
  }
  
  
  1.1                  jakarta-commons-sandbox/jex/src/test/org/apache/commons/jex/AccountBean.java
  
  Index: AccountBean.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/test/org/apache/commons/jex/AccountBean.java,v 1.1 2002/06/12 22:31:50 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:50 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex;
  
  /**
   * Test bean.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:50 $
   */
  public class AccountBean {
  
      public static String ACCOUNT_NUMBER = "5555 4344 2334 5665";
      
      public String getAccountNumber(){
          return ACCOUNT_NUMBER;
      }
      
      private String[] transactions = new String[]{"First", "Second"};
      
      public String[] getTransactions(){
          return transactions;
      }
      
  //    public String getTransactions(int i){
  //        return transactions[i];
  //    }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/src/test/org/apache/commons/jex/JexTestCase.java
  
  Index: JexTestCase.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jex/src/test/org/apache/commons/jex/JexTestCase.java,v 1.1 2002/06/12 22:31:50 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/12 22:31:50 $
   * 
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Velocity" nor may "Apache" appear in their names without prior 
   *    written permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at (c) 2001, Plotnix, Inc, please see
   * <http://www.plotnix.com/>.
   */
  
  package org.apache.commons.jex;
  
  import junit.framework.TestCase;
  
  import java.util.*;
  
  /**
   * 
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/06/12 22:31:50 $
   */
  public class JexTestCase extends TestCase {
  
      /**
       * Constructor for JexTestCase.
       * @param name of the test
       */
      public JexTestCase(String name) {
          super(name);
      }
  
      public static void main(String[] args) {
          junit.textui.TestRunner.run(JexTestCase.class);
      }
  
      public void testJxpathCompilerIntegration(){
          AccountBean bean = new AccountBean();
          
          Context context = new Context();
          Expression expr = context.getCompiler().
              compileExpression("jxpath:accountNumber");
              
          Object result = expr.evaluate(context, new Object[]{bean});
          assertEquals("jxpath:accountNumber", 
              AccountBean.ACCOUNT_NUMBER, result);
              
          context.getVariables().declareVariable("x", "2");        
          expr = context.getCompiler().
              compileExpression("jxpath:$x+2");
          result = expr.evaluate(context, null);
          assertEquals("jxpath:$x + 2", 
              new Double(4), result);        
      }
  
      public void testJxpathInterpreterIntegration(){
          AccountBean bean = new AccountBean();
          
          Context context = new Context();
          Object result = context.evaluate("jxpath:accountNumber", new Object[]{bean});
          assertEquals("jxpath:accountNumber", 
              AccountBean.ACCOUNT_NUMBER, result);
              
          result = context.evaluate("jxpath:transactions[1]", new Object[]{bean});
          assertEquals("jxpath:transactions[1]", "First", result);
          
          context.getVariables().declareVariable("x", "2");        
          result = context.evaluate("jxpath:$x+2", null);
          assertEquals("jxpath:$x + 2", 
              new Double(4), result);        
  
          List list = new ArrayList();
          Iterator it = context.iterate("jxpath:transactions", new Object[]{bean});
          while (it.hasNext()){
              list.add(it.next());
          }
          assertEquals("jxpath:transactions", 
              Arrays.asList(new String[]{"First", "Second"}), list);
      }
  
      public void testBexlCompilerIntegration(){
          AccountBean bean = new AccountBean();
          
          Context context = new Context();
          Expression expr = context.getCompiler().
              compileExpression("bexl:accountNumber");
              
          Object result = expr.evaluate(context, new Object[]{bean});
          assertEquals("bexl:accountNumber", 
              AccountBean.ACCOUNT_NUMBER, result);
      }
  
      public void testBexlInterpreterIntegration(){
          AccountBean bean = new AccountBean();
          
          Context context = new Context();
              
          Object result = context.evaluate("bexl:accountNumber", new Object[]{bean});
          assertEquals("bexl:accountNumber", 
              AccountBean.ACCOUNT_NUMBER, result);
              
          result = context.evaluate("bexl:transactions[0]", new Object[]{bean});
          assertEquals("bexl:transactions[0]", "First", result);
          
          List list = new ArrayList();
          Iterator it = context.iterate("bexl:transactions", new Object[]{bean});
          while (it.hasNext()){
              list.add(it.next());
          }
          assertEquals("bexl:transactions", 
              Arrays.asList(new String[]{"First", "Second"}), list);
      }    
  
      public void testDefaultLanguageInterpreter(){
          AccountBean bean = new AccountBean();
          
          Context context = new Context();
          context.setExpressionLanguage("bexl");
              
          Object result = context.evaluate("accountNumber", new Object[]{bean});
          assertEquals("accountNumber", 
              AccountBean.ACCOUNT_NUMBER, result);
      }    
  
      public void testDefaultLanguageCompiler(){
          AccountBean bean = new AccountBean();
          
          Context context = new Context();
          context.setExpressionLanguage("jxpath");
          
          Expression expr = context.getCompiler().
              compileExpression("accountNumber");
              
          Object result = expr.evaluate(context, new Object[]{bean});
          assertEquals("jxpath:accountNumber", 
              AccountBean.ACCOUNT_NUMBER, result);
      }
  
      public void testInterpreterSyntaxValidation(){
          Context context = new Context();
          boolean exception = false;
          try {
              // This is an invalid xpath expression
              context.getInterpreter().validateExpression("jxpath:...");
          }
          catch (Exception ex){
              exception = true;
          }
          assertEquals("Syntax checking exception", true, exception);
      }
      
      public void testJavaScriptIntegration(){
          AccountBean bean = new AccountBean();
          
          Context context = new Context();
          context.setExpressionLanguage("javascript");
          Expression expr = context.getCompiler().
              compileExpression("accountNumber");
              
          Object result = expr.evaluate(context, new Object[]{bean});
          assertEquals("accountNumber", 
              AccountBean.ACCOUNT_NUMBER, result);
              
          result = context.evaluate("transactions[0]", new Object[]{bean});
          assertEquals("transactions[0]", "First", result);
          
          context.getVariables().declareVariable("x", new Double(2));        
          result = context.evaluate("x+2", null);
          assertEquals("x + 2",  new Double(4), result);        
          
          context.setProperty("javascript.autodeclare", "true");
          context.assign("name", "John Smith", new Object[]{bean});
          result = context.evaluate("name", null);
          assertEquals("name",  "John Smith", result);
          
          List list = new ArrayList();
          Iterator it = context.iterate("transactions", new Object[]{bean});
          while (it.hasNext()){
              list.add(it.next());
          }
          assertEquals("transactions", 
              Arrays.asList(new String[]{"First", "Second"}), list);
      }
  
      public void testJavascriptSyntaxValidation(){
          Context context = new Context();
          boolean exception = false;
          try {
              // This is an invalid javascript expression
              context.getInterpreter().validateExpression("javascript:...");
          }
          catch (Exception ex){
              exception = true;
          }
          assertEquals("Syntax checking exception", true, exception);
  
          exception = false;
          try {
              // This is an invalid variable expression
              context.getInterpreter().
                      validateVariableExpression("javascript:2");
          }
          catch (Exception ex){
              exception = true;
          }
          assertEquals("Syntax checking exception", true, exception);
      }
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jex/xdocs/contributors.xml
  
  Index: contributors.xml
  ===================================================================
  <?xml version="1.0"?>
  <document>
     <properties>
        <title>Contributors</title>
        <author email="commons-dev@jakarta.apache.org">Commons Documentation Team</author>
        <author email="dmitri@apache.org">Dmitri Plotnikov</author>
        <revision>$Id: contributors.xml,v 1.1 2002/06/12 22:31:50 dmitri Exp $</revision>
     </properties>
  
     <body>
        <section name="Contributors">
           <p>
              The original code of <em>JEX</em> was developed by Dmitri Plotnikov of PLOTNIX, Inc and
              contributed to Jakarta.
           </p>
           <p>
              After the original contribution, the following volunteers have contributed code,
              documentation, testing and support to <em>JEX</em>.
           </p>
           <!-- alphabetical by last name please -->
           <ul>
              <li>Dmitri Plotnikov</li>
           </ul>
        </section>
     </body>
  </document>
  
  
  
  1.1                  jakarta-commons-sandbox/jex/xdocs/index.xml
  
  Index: index.xml
  ===================================================================
  <?xml version="1.0"?>
  <document>
     <properties>
        <title>Home</title>
        <author email="commons-dev@jakarta.apache.org">Commons Documentation Team</author>
        <author email="dmitri@apache.org">Dmitri Plotnikov</author>
        <revision>$Id: index.xml,v 1.1 2002/06/12 22:31:50 dmitri Exp $</revision>
     </properties>
  
     <body>
        <section name="The JEX Component">
            <p>
               The <code>org.apache.commons.jex</code> package defines a 
               universal set of APIs for expression languages. 
               Individual expression languages function as plug-ins. 
               You use the same set of APIs to invoke any of them.
            </p>
        </section>
     </body>
  </document>
  
  
  
  1.1                  jakarta-commons-sandbox/jex/xdocs/overview.xml
  
  Index: overview.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <document>
    <properties>
      <title>
         JEX Overview
      </title>
      <author email="dmitri@apache.org">
         Dmitri Plotnikov
      </author>
    </properties>
    <body>
  
  
      <section name="What's JEX">
        <p>
          JEX is a universal set of APIs for expression languages.
          Individual expression languages function as plug-ins. You use
          the same set of APIs to invoke any of them.
        </p>
        <ul>
          <li><a href="#Supported Expression Languages">Supported Expression Languages</a>
          </li>
          <li><a href="#Context">Context</a>
          </li>
          <li><a href="#Types of Expressions">Types of Expressions</a>
          </li>
          <li><a href="#Multilingual Mode">Multilingual Mode</a>
          </li>
          <li><a href="#Compilers and Interpreters">Compilers and Interpreters</a>
          </li>
          <li><a href="#How to Add a New Compiler or Interpreter">How to Add a New Compiler or Interpreter</a>
          </li>
          <li><a href="#Examples">Examples</a>
            <ul>
              <li><a href="#Example 1: Interpreting an Expression">Example 1: Interpreting an Expression </a>
              </li>
              <li><a href="#Example 2: Interpreting an Expression, Multilingual Mode">Example 2: Interpreting an Expression, Multilingual Mode</a>
              </li>
              <li><a href="#Example 3: Compiling an Expression">Example 3: Compiling an Expression</a>
              </li>
              <li><a href="#Example 4: Compiling an Expression, Multilingual Mode">Example 4: Compiling an Expression, Multilingual Mode</a>
              </li>
              <li><a href="#Example 5: Using an Iteration Expression">Example 5: Using an Iteration Expression</a>
              </li>
              <li><a href="#Example 6: Using a Variable Expression">Example 6: Using a Variable Expression</a>
              </li>
              <li><a href="#Example 7: Using a Variable">Example 7: Using a Variable</a>
              </li>
              <li><a href="#Example 8: Declaring a JavaScript Variable">Example 8: Declaring a JavaScript Variable</a>
              </li>
            </ul>
          </li>
        </ul>
      </section>
  
  
      <section name="Supported Expression Languages">
        <p>
          Out of the box JEX supports the following languages:
        </p>
        <ul>
          <li><b>javascript</b>
            <br/>
             Jex uses
            <a href="http://www.mozilla.org/rhino/">Rhino Mozilla</a>
            implementation of JavaScript (aka ECMA-Script) for Java. In
            order to use Jex with JavaScript, you will need to download
            the js.jar file from
            <a href="http://www.mozilla.org/rhino/download.html">www.mozilla.org</a>.
            <br/>
            <br/>
          </li>
          <li><b>bexl</b>
            <br/>
             This is a made-up name for the expression
            language implicitly introduced by
            <a href="http://jakarta.apache.org/commons/beanutils.html">Jakarta Commons BeanUtils</a>.
            See
            <a href="http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils/PropertyUtils.html">PropertyUtil</a>
            for the definition of the language.
            <br/>
            <br/>
          </li>
          <li><b>jxpath</b>
            <br/>
             An implementation of the XPath expression
            language that applies XPath expressions to graphs of Java
            Objects. See
            <a href="http://jakarta.apache.org/commons/jxpath/index.html">JXPath Home Page on Jakarta Commons</a>.
          </li>
        </ul>
        <p>
          {Other candidates: Jexl, XPath via Jaxen, SPEL, Jpath}
        </p>
      </section>
  
  
      <section name="Context">
        <p>
          Expressions are evaluated in a Context. A context holds various
          pieces of data that are used by expression language processors:
        </p>
        <ul>
          <li><b>Variables</b>
            <br/>
             All expression languages that support the
            notion of a variable can manipulate and share this set of
            variables.
            <br/>
            <br/>
          </li>
          <li><b>Locale</b>
            <br/>
             Languages that support internationalization can
            take advantage of this piece of configuration.
            <br/>
            <br/>
          </li>
          <li><b>Expression Language</b>
            <br/>
             Expressions evaluated in this context are
            expressed in this language.
            <br/>
            <br/>
          </li>
          <li><b>Properties</b>
            <br/>
             Expression language processors can be
            configured with properties specified using this
            language-independant mechanism.
          </li>
        </ul>
        <p>
          {Other potential pieces of context: extension functions, type
          converters}
        </p>
      </section>
  
  
      <section name="Types of Expressions">
        <p>
          There are three types of expressions:
        </p>
        <ul>
          <li><b>Value expression</b>
            <br/>
             These expressions are used compute values. For
            example, <code>"xpath:2+2"</code>  and
            <code>"bexl:address[1].zipCode"</code>  are value
            expressions.
            <br/>
            <br/>
          </li>
          <li><b>Iteration expression</b>
            <br/>
             The evaluation of an iteration expression
            produces an Iterator. For example,
            <code>"xpath:/address/zipCode"</code>  produces an
            iteration over all zipCodes.
            <br/>
            <br/>
          </li>
          <li><b>Variable expression</b>
            <br/>
             Variable expressions are used to modify values.
            Think of them as the left-hand side of an assignment. For
            example, <code>"bexl:address[1].zipCode"</code>  is a
            valid variable expression. The same string can be a valid
            expression of more than one type.
          </li>
        </ul>
      </section>
  
  
      <section name="Multilingual Mode">
        <p>
          A Jex Context is by default configured to be multilingual. What
          this means is that an expression can start with a "lang:"
          prefix, where lang identifies the expression language of the
          expression. Jex will then locate and use the appropriate
          language processor.
        </p>
        <p>
          If the Context is multilingual and also has an expression
          language specified, that language is used as the default for
          the cases when the prefix is missing or does not correspond to
          a known language.
        </p>
      </section>
  
  
      <section name="Compilers and Interpreters">
        <p>
          Jex supports both interpreted and compiled languages. An
          interpreter computes the value of the expression as it parses
          it. A compiler parses the expression into an internal
          executable form first and then uses the internal representation
          for the actual computation. The internal representation can be
          cached and used for faster re-evaluation of the same
          expression.
        </p>
        <p>
          Some languages better lend themselves to compilation, some- to
          interpretation. For example, JXPath, which has relatively
          sophisticated syntax, uses a compiler, while Bexl is so simple
          that a separate compilation step would not speed it up by much
          and perhaps would even slow it down.
        </p>
        <p>
          Jex supports both types of language processors equally well.
          Better yet, if needed, Jex allows an interpreter to be invoked
          like a compiler and a compiler like an interpreter. This
          flexibility lets the user choose the mode, compilation or
          interpretation, that best suits the application's needs and not
          worry whether the actual expression languages are compiled or
          interpreted.
        </p>
      </section>
  
  
      <section name="How to Add a New Compiler or Interpreter">
        <p>
          To add a new Compiler, create a class called
          <code>org.apache.commons.jex.<i>language</i>.Compiler</code>
          that extends the
          <a href="apidocs/org/apache/commons/jex/Compiler.html"><code>org.apache.commons.jex.Compiler</code></a>
          abstract class. Jex will find it by name.
        </p>
        <p>
          Similarly, to add a new Interpreter, create a class named
          <code>org.apache.commons.jex.<i>language</i>.Interpreter</code>
          that extends the
          <a href="apidocs/org/apache/commons/jex/Interpreter.html"><code>org.apache.commons.jex.Interpreter</code></a>
          abstract class.
        </p>
      </section>
  
  
      <section name="Examples">
        <p>
          In all following examples, we will assume that we have an
          object graph constructed like this:
        </p>
  
  <!--============================ + SOURCE + ============================-->
  <source>
                                                                         <br/>
  public class AddressBook {
     private Vector addresses = new Vector();
     public Vector getAddresses(){
         return addresses;
     }
  }
  
  
  public class Address {
      private String zipCode;
      public String getZipCode(){
          return zipCode;
      }
      public void setZipCode(){
          this.zipCode = zipCode;
      }
  }
  
  
  // Create an address book with two entries
  
  AddressBook book = new AddressBook();
  Address addr1 = new Address();
  add1.setZipCode("90210");
  Address addr2 = new Address();
  add2.setZipCode("20191");
  book.getAddresses().add(addr1);
  book.getAddresses().add(addr2);
  
  // Create a Jex context
  
  Context context = new Context();
  </source>
  <!--============================ - SOURCE - ============================-->
  
        <p/>
  
  
        <subsection name="Example 1: Interpreting an Expression">
          <p>
            In the following example, we invoke an interpreter to
            process a Bexl expression:
          </p>
  
  <!--============================ + SOURCE + ============================-->
  <source>
                                                                         <br/>
  context.setExpressionLanguage("bexl");
  
  String zipCode = (String)context.
      evaluate("addresses[1].zipCode", new Object[]{book});
  </source>
  <!--============================ - SOURCE - ============================-->
  
        </subsection>
  
  
        <subsection name="Example 2: Interpreting an Expression, Multilingual Mode">
          <p>
            Here we are using the multilingual capabilities of Jex:
          </p>
  
  <!--============================ + SOURCE + ============================-->
  <source>
                                                                         <br/>
  // Use Bexl
  String zipCode = (String)context.
      evaluate("bexl:addresses[1].zipCode", new Object[]{book});
  
  // Same with JXPath
  zipCode = (String)context.
      evaluate("jxpath:addresses[2]/zipCode", new Object[]{book});
  
  </source>
  <!--============================ - SOURCE - ============================-->
  
        </subsection>
  
  
        <subsection name="Example 3: Compiling an Expression">
          <p>
            Here we use the compiler and cache the compiled expression:
          </p>
  
  <!--============================ + SOURCE + ============================-->
  <source>
                                                                         <br/>
  context.setExpressionLanguage("bexl");
  
  Expression expr = context.getCompiler().
       compileExpression("addresses[1].zipCode");
  
  ...
  // Later, when we need to compute the expression,
  // use the compiled form
  
  String zipCode = (String)expr.evaluate(context, new Object[]{bean});
  </source>
  <!--============================ - SOURCE - ============================-->
  
        </subsection>
  
  
        <subsection name="Example 4: Compiling an Expression, Multilingual Mode">
          <p>
            In this example, we compile an expression in the
            multilingual mode:
          </p>
  
  <!--============================ + SOURCE + ============================-->
  <source>
                                                                         <br/>
  Expression expr = context.getCompiler().
       compileExpression("bexl:addresses[1].zipCode");
  
  ...
  
  String zipCode = (String)expr.evaluate(context, new Object[]{bean});
  </source>
  <!--============================ - SOURCE - ============================-->
  
        </subsection>
  
  
        <subsection name="Example 5: Using an Iteration Expression">
          <p>
            An iteration expression produces an Iterator.
          </p>
  
  <!--============================ + SOURCE + ============================-->
  <source>
                                                                         <br/>
  context.setExpressionLanguage("jxpath");
  
  Iterator iter = context.iterate("addresses", new Object[]{book});
  while (iter.hasNext()){
      Address address = (Address)iter.next();
      ...
  }
  </source>
  <!--============================ - SOURCE - ============================-->
  
          <p>
            An iteration expression can also be used in both
            interpreted and compiled modes.
          </p>
        </subsection>
  
  
        <subsection name="Example 6: Using a Variable Expression">
          <p>
            A variable expression is used to modify a value:
          </p>
  
  <!--============================ + SOURCE + ============================-->
  <source>
                                                                         <br/>
  context.assign("jxpath:addresses[1].zipCode",
                 "22190", new Object[]{book});
  </source>
  <!--============================ - SOURCE - ============================-->
  
        </subsection>
  
  
        <subsection name="Example 7: Using a Variable">
          <p>
            The notion of a variable is common for many expression
            languages. With Jex they all share the same pool of
            variables.
          </p>
  
  <!--============================ + SOURCE + ============================-->
  <source>
                                                                         <br/>
  // Set a variable first
  context.getVariables().declareVariable("i", new Integer(2));
  
  // Now we can use the variable
  String zipCode = (String)context.
      evaluate("jxpath:addresses[$i]/zipCode", new Object[]{book});
  
  // Same with JavaScript
  zipCode = (String)context.
      evaluate("javascript:addresses[i].zipCode", new Object[]{book});
  </source>
  <!--============================ - SOURCE - ============================-->
  
        </subsection>
  
  
        <subsection name="Example 8: Declaring a JavaScript Variable">
          <p>
            By default Jex requires that all variables be declared
            explicitly. However, if you are using JavaScript, you can
            configure Jex to allow automatic declaration of variables.
          </p>
  
  <!--============================ + SOURCE + ============================-->
  <source>
                                                                         <br/>
  // Allow automatic declaration of variables
  context.setProperty("javascript.autodeclare", "true");
  
  // Let's declare a new variable
  context.assign("javascript:company", "PLOTNIX", null);
  </source>
  <!--============================ - SOURCE - ============================-->
  
        </subsection>
      </section>
    </body>
  </document>
  
  
  1.1                  jakarta-commons-sandbox/jex/xdocs/images/jakarta-logo.gif
  
  	<<Binary file>>
  
  
  1.1                  jakarta-commons-sandbox/jex/xdocs/images/logo.gif
  
  	<<Binary file>>
  
  
  1.1                  jakarta-commons-sandbox/jex/xdocs/stylesheets/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  site.vsl
  .cvsignore
  
  
  
  1.1                  jakarta-commons-sandbox/jex/xdocs/stylesheets/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <project name="Commons - JEX" href="http://jakarta.apache.org/commons/jex">
      <title>JEX</title>
      <!-- logo href="/images/logo.jpg">Commons</logo -->
      <logo href="/images/logo.gif">JEX</logo>
  
      <!--
        Note: Per the .vsl file, "/site" links will be prefixed with "http://jakarta.apache.org/site"
              Other links starting with "/" become "./...".
      -->
      <body>
         <menu name="Home">
             <item name="Jakarta&amp;nbsp;Commons"          href="http://jakarta.apache.org/commons/index.html" />
             <item name="JEX"                        href="/index.html" />
         </menu>
         <menu name="Information">
             <item name="Overview"                      href="/overview.html"/>
             <item name="API&amp;nbsp;Docs"             href="/apidocs/index.html"/>
             <!-- item name="JEX Design"                 href="/design.html"/ -->
         </menu>
         <menu name="Project Files">
             <item name="Status"                        href="http://cvs.apache.org/viewcvs/~checkout~/jakarta-commons-sandbox/jex/STATUS.html?content-type=text/html"/>
             <item name="CVS"                           href="http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/jex/"/>
             <item name="Original&amp;nbsp;Proposal"        href="http://cvs.apache.org/viewcvs/~checkout~/jakarta-commons-sandbox/jex/PROPOSAL.html?content-type=text/html"/>
         </menu>
         <menu name="Downloads">
             <item name="Release"                       href="http://jakarta.apache.org/builds/jakarta-commons/release/commons-jex/"/>
             <item name="Nightly Build"                 href="http://jakarta.apache.org/builds/jakarta-commons/nightly/commons-jex/"/>
         </menu>
         <menu name="About Us">
             <item name="Contributors"                  href="/contributors.html"/>
             <item name="License"                       href="http://jakarta.apache.org/commons/license.html"/>
         </menu>
         <menu name="Jakarta Community">
             <item name="Get&amp;nbsp;Involved"             href="http://jakarta.apache.org/site/getinvolved.html"/>
             <item name="Mailing&amp;nbsp;Lists"            href="http://jakarta.apache.org/site/mail.html"/>
             <item name="CVS&amp;nbsp;Repositories"         href="http://jakarta.apache.org/site/cvsindex.html"/>
         </menu>
      </body>
  </project>
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message