You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by cb...@apache.org on 2008/08/10 08:00:22 UTC
svn commit: r684410 [3/16] - in /ibatis/trunk/java/ibatis-3: ./
ibatis-3-core/src/main/java/org/apache/ibatis/ognl/
ibatis-3-core/src/test/java/org/apache/ibatis/ognl/
ibatis-3-core/src/test/java/org/apache/ibatis/ognl/objects/
ibatis-3-core/src/test/j...
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTThisVarRef.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTThisVarRef.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTThisVarRef.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTThisVarRef.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,61 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+/**
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+class ASTThisVarRef extends ASTVarRef
+{
+ private String name;
+
+ public ASTThisVarRef(int id) {
+ super(id);
+ }
+
+ public ASTThisVarRef(OgnlParser p, int id) {
+ super(p, id);
+ }
+
+ protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException {
+ return context.getCurrentObject();
+ }
+
+ protected void setValueBody( OgnlContext context, Object target, Object value ) throws OgnlException {
+ context.setCurrentObject( value );
+ }
+
+ public String toString()
+ {
+ return "#this";
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTUnsignedShiftRight.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTUnsignedShiftRight.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTUnsignedShiftRight.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTUnsignedShiftRight.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,58 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+/**
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+class ASTUnsignedShiftRight extends ExpressionNode
+{
+ public ASTUnsignedShiftRight(int id) {
+ super(id);
+ }
+
+ public ASTUnsignedShiftRight(OgnlParser p, int id) {
+ super(p, id);
+ }
+
+ protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException
+ {
+ Object v1 = children[0].getValue( context, source );
+ Object v2 = children[1].getValue( context, source );
+ return OgnlOps.unsignedShiftRight( v1, v2 );
+ }
+
+ public String getExpressionOperator(int index)
+ {
+ return ">>>";
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTVarRef.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTVarRef.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTVarRef.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTVarRef.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,64 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+/**
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+class ASTVarRef extends SimpleNode
+{
+ private String name;
+
+ public ASTVarRef(int id) {
+ super(id);
+ }
+
+ public ASTVarRef(OgnlParser p, int id) {
+ super(p, id);
+ }
+
+ void setName( String name ) {
+ this.name = name;
+ }
+
+ protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException {
+ return context.get(name);
+ }
+
+ protected void setValueBody( OgnlContext context, Object target, Object value ) throws OgnlException {
+ context.put( name, value );
+ }
+
+ public String toString() {
+ return "#" + name;
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTXor.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTXor.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTXor.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ASTXor.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,63 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+/**
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+class ASTXor extends ExpressionNode
+{
+ public ASTXor(int id) {
+ super(id);
+ }
+
+ public ASTXor(OgnlParser p, int id) {
+ super(p, id);
+ }
+
+ public void jjtClose() {
+ flattenTree();
+ }
+
+ protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException
+ {
+ Object result = children[0].getValue( context, source );
+ for ( int i=1; i < children.length; ++i )
+ result = OgnlOps.binaryXor( result, children[i].getValue(context, source) );
+ return result;
+ }
+
+ public String getExpressionOperator(int index)
+ {
+ return "^";
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ArrayElementsAccessor.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ArrayElementsAccessor.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ArrayElementsAccessor.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ArrayElementsAccessor.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,56 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.lang.reflect.Array;
+import java.util.Enumeration;
+
+/**
+ * Implementation of ElementsAccessor that returns an iterator over a Java array.
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public class ArrayElementsAccessor implements ElementsAccessor
+{
+ public Enumeration getElements( final Object target )
+ {
+ return new Enumeration() {
+ private int count = Array.getLength( target );
+ private int index = 0;
+ public boolean hasMoreElements() {
+ return index < count;
+ }
+ public Object nextElement() {
+ return Array.get( target, index++ );
+ }
+ };
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ArrayPropertyAccessor.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ArrayPropertyAccessor.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ArrayPropertyAccessor.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ArrayPropertyAccessor.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,132 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.lang.reflect.Array;
+import java.util.Map;
+
+/**
+ * Implementation of PropertyAccessor that uses numbers and dynamic subscripts as
+ * properties to index into Java arrays.
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public class ArrayPropertyAccessor extends ObjectPropertyAccessor
+ implements PropertyAccessor // This is here to make javadoc show this class as an implementor
+{
+ public Object getProperty( Map context, Object target, Object name ) throws OgnlException
+ {
+ Object result = null;
+
+ if (name instanceof String) {
+ if (name.equals("length")) {
+ result = new Integer( Array.getLength(target) );
+ } else {
+ result = super.getProperty( context, target, name );
+ }
+ } else {
+ Object index = name;
+
+ if (index instanceof DynamicSubscript) {
+ int len = Array.getLength(target);
+
+ switch (((DynamicSubscript)index).getFlag()) {
+ case DynamicSubscript.ALL:
+ result = Array.newInstance( target.getClass().getComponentType(), len );
+ System.arraycopy( target, 0, result, 0, len );
+ break;
+ case DynamicSubscript.FIRST:
+ index = new Integer((len > 0) ? 0 : -1);
+ break;
+ case DynamicSubscript.MID:
+ index = new Integer((len > 0) ? (len / 2) : -1);
+ break;
+ case DynamicSubscript.LAST:
+ index = new Integer((len > 0) ? (len - 1) : -1);
+ break;
+ }
+ }
+ if (result == null) {
+ if (index instanceof Number) {
+ int i = ((Number)index).intValue();
+
+ result = (i >= 0) ? Array.get(target, i) : null;
+ } else {
+ throw new NoSuchPropertyException(target, index);
+ }
+ }
+ }
+ return result;
+ }
+
+ public void setProperty( Map context, Object target, Object name, Object value ) throws OgnlException
+ {
+ Object index = name;
+ boolean isNumber = (index instanceof Number);
+
+ if (isNumber || (index instanceof DynamicSubscript)) {
+ TypeConverter converter = ((OgnlContext)context).getTypeConverter();
+ Object convertedValue;
+
+ convertedValue = converter.convertValue(context, target, null, name.toString(), value, target.getClass().getComponentType());
+ if (isNumber) {
+ int i = ((Number)index).intValue();
+
+ if (i >= 0) {
+ Array.set(target, i, convertedValue);
+ }
+ } else {
+ int len = Array.getLength(target);
+
+ switch ( ((DynamicSubscript)index).getFlag() ) {
+ case DynamicSubscript.ALL:
+ System.arraycopy(target, 0, convertedValue, 0, len);
+ return;
+ case DynamicSubscript.FIRST:
+ index = new Integer((len > 0) ? 0 : -1);
+ break;
+ case DynamicSubscript.MID:
+ index = new Integer((len > 0) ? (len / 2) : -1);
+ break;
+ case DynamicSubscript.LAST:
+ index = new Integer((len > 0 ) ? (len - 1) : -1);
+ break;
+ }
+ }
+ } else {
+ if (name instanceof String) {
+ super.setProperty(context, target, name, value);
+ } else {
+ throw new NoSuchPropertyException(target, index);
+ }
+ }
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ClassResolver.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ClassResolver.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ClassResolver.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ClassResolver.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,44 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.util.Map;
+
+/**
+ * This interface defines an object that will resolve a class from a string
+ * and a ognl context table.
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public interface ClassResolver
+{
+ public Class classForName(String className, Map context) throws ClassNotFoundException;
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/CollectionElementsAccessor.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/CollectionElementsAccessor.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/CollectionElementsAccessor.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/CollectionElementsAccessor.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,46 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.util.*;
+
+/**
+ * Implementation of ElementsAccessor that returns a collection's iterator.
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public class CollectionElementsAccessor implements ElementsAccessor
+{
+ public Enumeration getElements( Object target )
+ {
+ return new IteratorEnumeration( ((Collection)target).iterator() );
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DefaultClassResolver.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DefaultClassResolver.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DefaultClassResolver.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DefaultClassResolver.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,68 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.util.*;
+
+/**
+ * Default class resolution. Uses Class.forName() to look up classes by name.
+ * It also looks in the "java.lang" package if the class named does not give
+ * a package specifier, allowing easier usage of these classes.
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public class DefaultClassResolver extends Object implements ClassResolver
+{
+ private Map classes = new HashMap(101);
+
+ public DefaultClassResolver()
+ {
+ super();
+ }
+
+ public Class classForName(String className, Map context) throws ClassNotFoundException
+ {
+ Class result = null;
+
+ if ((result = (Class)classes.get(className)) == null) {
+ try {
+ result = Class.forName(className);
+ } catch (ClassNotFoundException ex) {
+ if (className.indexOf('.') == -1) {
+ result = Class.forName("java.lang." + className);
+ classes.put("java.lang." + className, result);
+ }
+ }
+ classes.put(className, result);
+ }
+ return result;
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DefaultMemberAccess.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DefaultMemberAccess.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DefaultMemberAccess.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DefaultMemberAccess.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,150 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+/**
+ * This class provides methods for setting up and restoring
+ * access in a Field. Java 2 provides access utilities for setting
+ * and getting fields that are non-public. This object provides
+ * coarse-grained access controls to allow access to private, protected
+ * and package protected members. This will apply to all classes
+ * and members.
+ *
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ * @version 15 October 1999
+ */
+public class DefaultMemberAccess implements MemberAccess
+{
+ public boolean allowPrivateAccess = false;
+ public boolean allowProtectedAccess = false;
+ public boolean allowPackageProtectedAccess = false;
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public DefaultMemberAccess(boolean allowAllAccess)
+ {
+ this(allowAllAccess, allowAllAccess, allowAllAccess);
+ }
+
+ public DefaultMemberAccess(boolean allowPrivateAccess, boolean allowProtectedAccess, boolean allowPackageProtectedAccess)
+ {
+ super();
+ this.allowPrivateAccess = allowPrivateAccess;
+ this.allowProtectedAccess = allowProtectedAccess;
+ this.allowPackageProtectedAccess = allowPackageProtectedAccess;
+ }
+
+ /*===================================================================
+ Public methods
+ ===================================================================*/
+ public boolean getAllowPrivateAccess()
+ {
+ return allowPrivateAccess;
+ }
+
+ public void setAllowPrivateAccess(boolean value)
+ {
+ allowPrivateAccess = value;
+ }
+
+ public boolean getAllowProtectedAccess()
+ {
+ return allowProtectedAccess;
+ }
+
+ public void setAllowProtectedAccess(boolean value)
+ {
+ allowProtectedAccess = value;
+ }
+
+ public boolean getAllowPackageProtectedAccess()
+ {
+ return allowPackageProtectedAccess;
+ }
+
+ public void setAllowPackageProtectedAccess(boolean value)
+ {
+ allowPackageProtectedAccess = value;
+ }
+
+ /*===================================================================
+ MemberAccess interface
+ ===================================================================*/
+ public Object setup(Map context, Object target, Member member, String propertyName)
+ {
+ Object result = null;
+
+ if (isAccessible(context, target, member, propertyName)) {
+ AccessibleObject accessible = (AccessibleObject)member;
+
+ if (!accessible.isAccessible()) {
+ result = Boolean.TRUE;
+ accessible.setAccessible(true);
+ }
+ }
+ return result;
+ }
+
+ public void restore(Map context, Object target, Member member, String propertyName, Object state)
+ {
+ if (state != null) {
+ ((AccessibleObject)member).setAccessible(((Boolean)state).booleanValue());
+ }
+ }
+
+ /**
+ Returns true if the given member is accessible or can be made accessible
+ by this object.
+ */
+ public boolean isAccessible(Map context, Object target, Member member, String propertyName)
+ {
+ int modifiers = member.getModifiers();
+ boolean result = Modifier.isPublic(modifiers);
+
+ if (!result) {
+ if (Modifier.isPrivate(modifiers)) {
+ result = getAllowPrivateAccess();
+ } else {
+ if (Modifier.isProtected(modifiers)) {
+ result = getAllowProtectedAccess();
+ } else {
+ result = getAllowPackageProtectedAccess();
+ }
+ }
+ }
+ return result;
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DefaultTypeConverter.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DefaultTypeConverter.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DefaultTypeConverter.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DefaultTypeConverter.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,58 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.lang.reflect.Member;
+import java.util.Map;
+
+/**
+ * Default type conversion. Converts among numeric types and also strings.
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public class DefaultTypeConverter implements TypeConverter
+{
+ public DefaultTypeConverter()
+ {
+ super();
+ }
+
+ public Object convertValue(Map context, Object value, Class toType)
+ {
+ return OgnlOps.convertValue(value, toType);
+ }
+
+ public Object convertValue(Map context, Object target, Member member, String propertyName, Object value, Class toType)
+ {
+ return convertValue(context, value, toType);
+ }
+}
+
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DynamicSubscript.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DynamicSubscript.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DynamicSubscript.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/DynamicSubscript.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,77 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+
+/**
+ * This class has predefined instances that stand for OGNL's special "dynamic subscripts"
+ * for getting at the first, middle, or last elements of a list. In OGNL expressions,
+ * these subscripts look like special kinds of array indexes: [^] means the first element,
+ * [$] means the last, [|] means the middle, and [*] means the whole list.
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public class DynamicSubscript
+{
+ public static final int FIRST = 0;
+ public static final int MID = 1;
+ public static final int LAST = 2;
+ public static final int ALL = 3;
+
+ public static final DynamicSubscript first = new DynamicSubscript(FIRST);
+ public static final DynamicSubscript mid = new DynamicSubscript(MID);
+ public static final DynamicSubscript last = new DynamicSubscript(LAST);
+ public static final DynamicSubscript all = new DynamicSubscript(ALL);
+
+ private int flag;
+
+ private DynamicSubscript( int flag )
+ {
+ this.flag = flag;
+ }
+
+ public int getFlag()
+ {
+ return flag;
+ }
+
+ public String toString()
+ {
+ switch (flag)
+ {
+ case FIRST: return "^";
+ case MID: return "|";
+ case LAST: return "$";
+ case ALL: return "*";
+ default: return "?"; // Won't happen
+ }
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ElementsAccessor.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ElementsAccessor.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ElementsAccessor.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ElementsAccessor.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,56 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.util.Enumeration;
+
+/**
+ * This interface defines a method for getting the "elements" of an object, which means
+ * any objects that naturally would be considered to be contained by the object. So for a
+ * collection, you would expect this method to return all the objects in that collection;
+ * while for an ordinary object you would expect this method to return just that object.
+ *
+ * <p> An implementation of this interface will often require that its target objects all
+ * be of some particular type. For example, the MapElementsAccessor class requires that
+ * its targets all implement the Map interface.
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public interface ElementsAccessor
+{
+ /**
+ * Returns an iterator over the elements of the given target object.
+ * @param target the object to get the elements of
+ * @return an iterator over the elements of the given object
+ * @exception OgnlException if there is an error getting the given object's elements
+ */
+ public Enumeration getElements( Object target ) throws OgnlException;
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EnumerationElementsAccessor.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EnumerationElementsAccessor.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EnumerationElementsAccessor.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EnumerationElementsAccessor.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,48 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.util.Enumeration;
+
+
+/**
+ * Implementation of the ElementsAccessor interface for Enumerations, which returns an
+ * iterator that passes its calls through to the target Enumeration.
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public class EnumerationElementsAccessor implements ElementsAccessor
+{
+ public Enumeration getElements( Object target )
+ {
+ return (Enumeration)target;
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EnumerationIterator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EnumerationIterator.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EnumerationIterator.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EnumerationIterator.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,64 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.util.*;
+
+/**
+ * Object that implements Iterator from an Enumeration
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public class EnumerationIterator implements Iterator
+{
+ private Enumeration e;
+
+ public EnumerationIterator(Enumeration e)
+ {
+ super();
+ this.e = e;
+ }
+
+ public boolean hasNext()
+ {
+ return e.hasMoreElements();
+ }
+
+ public Object next()
+ {
+ return e.nextElement();
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException("remove() not supported by Enumeration");
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EnumerationPropertyAccessor.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EnumerationPropertyAccessor.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EnumerationPropertyAccessor.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EnumerationPropertyAccessor.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,70 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.util.*;
+
+/**
+ * Implementation of PropertyAccessor that provides "property" reference to
+ * "nextElement" (aliases to "next" also) and "hasMoreElements" (also aliased
+ * to "hasNext").
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public class EnumerationPropertyAccessor extends ObjectPropertyAccessor
+ implements PropertyAccessor // This is here to make javadoc show this class as an implementor
+{
+ public Object getProperty( Map context, Object target, Object name ) throws OgnlException
+ {
+ Object result;
+ Enumeration e = (Enumeration)target;
+
+ if ( name instanceof String ) {
+ if (name.equals("next") || name.equals("nextElement")) {
+ result = e.nextElement();
+ } else {
+ if (name.equals("hasNext") || name.equals("hasMoreElements")) {
+ result = e.hasMoreElements() ? Boolean.TRUE : Boolean.FALSE;
+ } else {
+ result = super.getProperty( context, target, name );
+ }
+ }
+ } else {
+ result = super.getProperty(context, target, name);
+ }
+ return result;
+ }
+
+ public void setProperty( Map context, Object target, Object name, Object value ) throws OgnlException
+ {
+ throw new IllegalArgumentException( "can't set property " + name + " on Enumeration" );
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/Evaluation.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/Evaluation.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/Evaluation.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/Evaluation.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,334 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+/**
+ An <code>Evaluation</code> is and object that holds a node being evaluated
+ and the source from which that node will take extract its
+ value. It refers to child evaluations that occur as
+ a result of the nodes' evaluation.
+ */
+public class Evaluation extends Object
+{
+ private SimpleNode node;
+ private Object source;
+ private boolean setOperation;
+ private Object result;
+ private Throwable exception;
+ private Evaluation parent;
+ private Evaluation next;
+ private Evaluation previous;
+ private Evaluation firstChild;
+ private Evaluation lastChild;
+
+ /**
+ Constructs a new "get" <code>Evaluation</code> from the node and source given.
+ */
+ public Evaluation(SimpleNode node, Object source)
+ {
+ super();
+ this.node = node;
+ this.source = source;
+ }
+
+ /**
+ Constructs a new <code>Evaluation</code> from the node and source given.
+ If <code>setOperation</code> is true this <code>Evaluation</code> represents
+ a "set" as opposed to a "get".
+ */
+ public Evaluation(SimpleNode node, Object source, boolean setOperation)
+ {
+ this(node, source);
+ this.setOperation = setOperation;
+ }
+
+ /**
+ Returns the <code>SimpleNode</code> for this <code>Evaluation</code>
+ */
+ public SimpleNode getNode()
+ {
+ return node;
+ }
+
+ /**
+ Sets the node of the evaluation. Normally applications do not need to
+ set this. Notable exceptions to this rule are custom evaluators that
+ choose between navigable objects (as in a multi-root evaluator where
+ the navigable node is chosen at runtime).
+ */
+ public void setNode(SimpleNode value)
+ {
+ node = value;
+ }
+
+ /**
+ Returns the source object on which this Evaluation operated.
+ */
+ public Object getSource()
+ {
+ return source;
+ }
+
+ /**
+ Sets the source of the evaluation. Normally applications do not need to
+ set this. Notable exceptions to this rule are custom evaluators that
+ choose between navigable objects (as in a multi-root evaluator where
+ the navigable node is chosen at runtime).
+ */
+ public void setSource(Object value)
+ {
+ source = value;
+ }
+
+ /**
+ Returns true if this Evaluation represents a set operation.
+ */
+ public boolean isSetOperation()
+ {
+ return setOperation;
+ }
+
+ /**
+ Marks the Evaluation as a set operation if the value is true, else
+ marks it as a get operation.
+ */
+ public void setSetOperation(boolean value)
+ {
+ setOperation = value;
+ }
+
+ /**
+ Returns the result of the Evaluation, or null if it was a set operation.
+ */
+ public Object getResult()
+ {
+ return result;
+ }
+
+ /**
+ Sets the result of the Evaluation. This method is normally only used
+ interally and should not be set without knowledge of what you are doing.
+ */
+ public void setResult(Object value)
+ {
+ result = value;
+ }
+
+ /**
+ Returns the exception that occurred as a result of evaluating the
+ Evaluation, or null if no exception occurred.
+ */
+ public Throwable getException()
+ {
+ return exception;
+ }
+
+ /**
+ Sets the exception that occurred as a result of evaluating the
+ Evaluation. This method is normally only used interally and
+ should not be set without knowledge of what you are doing.
+ */
+ public void setException(Throwable value)
+ {
+ exception = value;
+ }
+
+ /**
+ Returns the parent evaluation of this evaluation. If this returns
+ null then it is is the root evaluation of a tree.
+ */
+ public Evaluation getParent()
+ {
+ return parent;
+ }
+
+ /**
+ Returns the next sibling of this evaluation. Returns null if
+ this is the last in a chain of evaluations.
+ */
+ public Evaluation getNext()
+ {
+ return next;
+ }
+
+ /**
+ Returns the previous sibling of this evaluation. Returns null if
+ this is the first in a chain of evaluations.
+ */
+ public Evaluation getPrevious()
+ {
+ return previous;
+ }
+
+ /**
+ Returns the first child of this evaluation. Returns null if
+ there are no children.
+ */
+ public Evaluation getFirstChild()
+ {
+ return firstChild;
+ }
+
+ /**
+ Returns the last child of this evaluation. Returns null if
+ there are no children.
+ */
+ public Evaluation getLastChild()
+ {
+ return lastChild;
+ }
+
+ /**
+ Gets the first descendent. In any Evaluation tree this will the
+ Evaluation that was first executed.
+ */
+ public Evaluation getFirstDescendant()
+ {
+ if (firstChild != null) {
+ return firstChild.getFirstDescendant();
+ }
+ return this;
+ }
+
+ /**
+ Gets the last descendent. In any Evaluation tree this will the
+ Evaluation that was most recently executing.
+ */
+ public Evaluation getLastDescendant()
+ {
+ if (lastChild != null) {
+ return lastChild.getLastDescendant();
+ }
+ return this;
+ }
+
+ /**
+ Adds a child to the list of children of this evaluation. The
+ parent of the child is set to the receiver and the children
+ references are modified in the receiver to reflect the new child.
+ The lastChild of the receiver is set to the child, and the
+ firstChild is set also if child is the first (or only) child.
+ */
+ public void addChild(Evaluation child)
+ {
+ if (firstChild == null) {
+ firstChild = lastChild = child;
+ } else {
+ if (firstChild == lastChild) {
+ firstChild.next = child;
+ lastChild = child;
+ lastChild.previous = firstChild;
+ } else {
+ child.previous = lastChild;
+ lastChild.next = child;
+ lastChild = child;
+ }
+ }
+ child.parent = this;
+ }
+
+ /**
+ Reinitializes this Evaluation to the parameters specified.
+ */
+ public void init(SimpleNode node, Object source, boolean setOperation)
+ {
+ this.node = node;
+ this.source = source;
+ this.setOperation = setOperation;
+ result = null;
+ exception = null;
+ parent = null;
+ next = null;
+ previous = null;
+ firstChild = null;
+ lastChild = null;
+ }
+
+ /**
+ Resets this Evaluation to the initial state.
+ */
+ public void reset()
+ {
+ init(null, null, false);
+ }
+
+ /**
+ Produces a String value for the Evaluation. If compact is
+ true then a more compact form of the description only including
+ the node type and unique identifier is shown, else a full
+ description including source and result are shown. If showChildren
+ is true the child evaluations are printed using the depth string
+ given as a prefix.
+ */
+ public String toString(boolean compact, boolean showChildren, String depth)
+ {
+ String stringResult;
+
+ if (compact) {
+ stringResult = depth + "<" + node.getClass().getName() + " " + System.identityHashCode(this) + ">";
+ } else {
+ String ss = (source != null) ? source.getClass().getName() : "null",
+ rs = (result != null) ? result.getClass().getName() : "null";
+
+ stringResult = depth + "<" + node.getClass().getName() + ": [" + (setOperation ? "set" : "get") + "] source = " + ss + ", result = " + result + " [" + rs + "]>";
+ }
+ if (showChildren) {
+ Evaluation child = firstChild;
+
+ stringResult += "\n";
+ while (child != null) {
+ stringResult += child.toString(compact, depth + " ");
+ child = child.next;
+ }
+ }
+ return stringResult;
+ }
+
+ /**
+ Produces a String value for the Evaluation. If compact is
+ true then a more compact form of the description only including
+ the node type and unique identifier is shown, else a full
+ description including source and result are shown. Child
+ evaluations are printed using the depth string given as a prefix.
+ */
+ public String toString(boolean compact, String depth)
+ {
+ return toString(compact, true, depth);
+ }
+
+ /**
+ Returns a String description of the Evaluation.
+ */
+ public String toString()
+ {
+ return toString(false, "");
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EvaluationPool.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EvaluationPool.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EvaluationPool.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/EvaluationPool.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,160 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.util.*;
+
+public final class EvaluationPool extends Object
+{
+ private List evaluations = new ArrayList();
+ private int size = 0;
+ private int created = 0;
+ private int recovered = 0;
+ private int recycled = 0;
+
+ public EvaluationPool()
+ {
+ this(0);
+ }
+
+ public EvaluationPool(int initialSize)
+ {
+ super();
+ for (int i = 0; i < initialSize; i++) {
+ evaluations.add(new Evaluation(null, null));
+ }
+ created = size = initialSize;
+ }
+
+ /**
+ Returns an Evaluation that contains the node, source and whether it
+ is a set operation. If there are no Evaluation objects in the
+ pool one is created and returned.
+ */
+ public Evaluation create(SimpleNode node, Object source)
+ {
+ return create(node, source, false);
+ }
+
+ /**
+ Returns an Evaluation that contains the node, source and whether it
+ is a set operation. If there are no Evaluation objects in the
+ pool one is created and returned.
+ */
+ public synchronized Evaluation create(SimpleNode node, Object source, boolean setOperation)
+ {
+ Evaluation result;
+
+ if (size > 0) {
+ result = (Evaluation)evaluations.remove(size - 1);
+ result.init(node, source, setOperation);
+ size--;
+ recovered++;
+ } else {
+ result = new Evaluation(node, source, setOperation);
+ created++;
+ }
+ return result;
+ }
+
+ /**
+ Recycles an Evaluation
+ */
+ public synchronized void recycle(Evaluation value)
+ {
+ if (value != null) {
+ value.reset();
+ evaluations.add(value);
+ size++;
+ recycled++;
+ }
+ }
+
+ /**
+ Recycles an of Evaluation and all of it's siblings
+ and children.
+ */
+ public void recycleAll(Evaluation value)
+ {
+ if (value != null) {
+ recycleAll(value.getNext());
+ recycleAll(value.getFirstChild());
+ recycle(value);
+ }
+ }
+
+ /**
+ Recycles a List of Evaluation objects
+ */
+ public void recycleAll(List value)
+ {
+ if (value != null) {
+ for (int i = 0, icount = value.size(); i < icount; i++) {
+ recycle((Evaluation)value.get(i));
+ }
+ }
+ }
+
+ /**
+ Returns the number of items in the pool
+ */
+ public int getSize()
+ {
+ return size;
+ }
+
+ /**
+ Returns the number of items this pool has created since
+ it's construction.
+ */
+ public int getCreatedCount()
+ {
+ return created;
+ }
+
+ /**
+ Returns the number of items this pool has recovered from
+ the pool since its construction.
+ */
+ public int getRecoveredCount()
+ {
+ return recovered;
+ }
+
+ /**
+ Returns the number of items this pool has recycled since
+ it's construction.
+ */
+ public int getRecycledCount()
+ {
+ return recycled;
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ExpressionNode.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ExpressionNode.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ExpressionNode.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ExpressionNode.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,94 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+/**
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public abstract class ExpressionNode extends SimpleNode
+{
+ public ExpressionNode(int i) {
+ super(i);
+ }
+
+ public ExpressionNode(OgnlParser p, int i) {
+ super(p, i);
+ }
+ /**
+ Returns true iff this node is constant without respect to the children.
+ */
+ public boolean isNodeConstant( OgnlContext context ) throws OgnlException
+ {
+ return false;
+ }
+
+ public boolean isConstant( OgnlContext context ) throws OgnlException
+ {
+ boolean result = isNodeConstant(context);
+
+ if ((children != null) && (children.length > 0)) {
+ result = true;
+ for ( int i=0; result && (i < children.length); ++i ) {
+ if (children[i] instanceof SimpleNode) {
+ result = ((SimpleNode)children[i]).isConstant( context );
+ } else {
+ result = false;
+ }
+ }
+ }
+ return result;
+ }
+
+ public String getExpressionOperator(int index)
+ {
+ throw new RuntimeException("unknown operator for " + OgnlParserTreeConstants.jjtNodeName[id]);
+ }
+
+ public String toString()
+ {
+ String result;
+
+ result = (parent == null) ? "" : "(";
+ if ((children != null) && (children.length > 0)) {
+ for ( int i = 0; i < children.length; ++i ) {
+ if (i > 0) {
+ result += " " + getExpressionOperator(i) + " ";
+ }
+ result += children[i].toString();
+ }
+ }
+ if (parent != null) {
+ result = result + ")";
+ }
+ return result;
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ExpressionSyntaxException.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ExpressionSyntaxException.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ExpressionSyntaxException.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/ExpressionSyntaxException.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,45 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+
+/**
+ * Exception thrown if a malformed OGNL expression is encountered.
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public class ExpressionSyntaxException extends OgnlException
+{
+ public ExpressionSyntaxException( String expression, Throwable reason )
+ {
+ super( "Malformed OGNL expression: " + expression, reason );
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/InappropriateExpressionException.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/InappropriateExpressionException.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/InappropriateExpressionException.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/ognl/InappropriateExpressionException.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,47 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 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.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS 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
+// COPYRIGHT OWNER OR 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.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+
+/**
+ * Exception thrown if an OGNL expression is evaluated in the wrong context; the usual
+ * case is when an expression that does not end in a property reference is passed to
+ * <code>setValue</code>.
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public class InappropriateExpressionException extends OgnlException
+{
+ public InappropriateExpressionException( Node tree )
+ {
+ super( "Inappropriate OGNL expression: " + tree );
+ }
+}