{
public DefaultTypeConverter() {
super();
}
public Object convertValue(C context, Object value, Class> toType) {
return OgnlOps.convertValue(value, toType);
}
public Object convertValue(C context, Object target, Member member, String propertyName, Object value, Class> toType) {
return convertValue(context, value, toType);
}
}
================================================
FILE: ognl/src/main/java/ognl/DynamicSubscript.java
================================================
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package 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.
*/
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 final 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
}
}
}
================================================
FILE: ognl/src/main/java/ognl/ElementsAccessor.java
================================================
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package 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.
*
* 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.
*/
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
* @throws OgnlException if there is an error getting the given object's elements
*/
Enumeration> getElements(Object target) throws OgnlException;
}
================================================
FILE: ognl/src/main/java/ognl/EnumerationElementsAccessor.java
================================================
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package 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.
*/
public class EnumerationElementsAccessor implements ElementsAccessor {
public Enumeration> getElements(Object target) {
return (Enumeration>) target;
}
}
================================================
FILE: ognl/src/main/java/ognl/EnumerationIterator.java
================================================
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package ognl;
import java.util.Enumeration;
import java.util.Iterator;
/**
* Object that implements Iterator from an Enumeration
*/
public class EnumerationIterator implements Iterator {
private Enumeration enumeration;
public EnumerationIterator(Enumeration enumeration) {
this.enumeration = enumeration;
}
public boolean hasNext() {
return enumeration.hasMoreElements();
}
public T next() {
return enumeration.nextElement();
}
public void remove() {
throw new UnsupportedOperationException("remove() not supported by Enumeration");
}
}
================================================
FILE: ognl/src/main/java/ognl/EnumerationPropertyAccessor.java
================================================
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package ognl;
import java.util.Enumeration;
/**
* Implementation of PropertyAccessor that provides "property" reference to
* "nextElement" (aliases to "next" also) and "hasMoreElements" (also aliased
* to "hasNext").
*/
public class EnumerationPropertyAccessor> extends ObjectPropertyAccessor implements PropertyAccessor {
public Object getProperty(C 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(C context, Object target, Object name, Object value) throws OgnlException {
throw new IllegalArgumentException("can't set property " + name + " on Enumeration");
}
}
================================================
FILE: ognl/src/main/java/ognl/Evaluation.java
================================================
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package ognl;
/**
* An Evaluation 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> {
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" Evaluation from the node and source given.
*
* @param node a SimpleNode for this Evaluation.
* @param source a source Object for this Evaluation.
*/
public Evaluation(SimpleNode node, Object source) {
super();
this.node = node;
this.source = source;
}
/**
* Constructs a new Evaluation from the node and source given.
* If setOperation is true this Evaluation represents
* a "set" as opposed to a "get".
*
* @param node a SimpleNode for this Evaluation.
* @param source a source Object for this Evaluation.
* @param setOperation true to identify this Evaluation as a set operation, false to identify it as a get operation.
*/
public Evaluation(SimpleNode node, Object source, boolean setOperation) {
this(node, source);
this.setOperation = setOperation;
}
/**
* Returns the SimpleNode for this Evaluation
*
* @return the SimpleNode for this Evaluation.
*/
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).
*
* @param value the SimpleNode to set for this Evaluation.
*/
public void setNode(SimpleNode value) {
node = value;
}
/**
* Returns the source object on which this Evaluation operated.
*
* @return the source Object operated upon by this Evaluation.
*/
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).
*
* @param value the source Object to be set for this Evaluation.
*/
public void setSource(Object value) {
source = value;
}
/**
* Returns true if this Evaluation represents a set operation.
*
* @return true if this Evaluation represents a set operation, false otherwise.
*/
public boolean isSetOperation() {
return setOperation;
}
/**
* Marks the Evaluation as a set operation if the value is true, else
* marks it as a get operation.
*
* @param value true to identify this Evaluation as a set operation, false to identify 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.
*
* @return the result of the Evaluation (for a get operation), or null (for 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.
*
* @param value the result Object for this Evaluation.
*/
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.
*
* @return an exception if one occurred during evaluation, or null (no exception) otherwise.
*/
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.
*
* @param value the Throwable exception that occurred during the evaluation of this Evaluation.
*/
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.
*
* @return the parent Evaluation of the current Evaluation, or null if no parent exists.
*/
public Evaluation getParent() {
return parent;
}
/**
* Returns the next sibling of this evaluation. Returns null if
* this is the last in a chain of evaluations.
*
* @return the next sibling Evaluation of the current Evaluation, or null if this is the last Evaluation in a chain.
*/
public Evaluation getNext() {
return next;
}
/**
* Returns the previous sibling of this evaluation. Returns null if
* this is the first in a chain of evaluations.
*
* @return the previous sibling Evaluation of the current Evaluation, or null if this is the first Evaluation in a chain.
*/
public Evaluation getPrevious() {
return previous;
}
/**
* Returns the first child of this evaluation. Returns null if
* there are no children.
*
* @return the first child Evaluation of the current Evaluation, or null if no children exist.
*/
public Evaluation getFirstChild() {
return firstChild;
}
/**
* Returns the last child of this evaluation. Returns null if
* there are no children.
*
* @return the last child Evaluation of the current Evaluation, or null if no children exist.
*/
public Evaluation getLastChild() {
return lastChild;
}
/**
* Gets the first descendent. In any Evaluation tree this will the
* Evaluation that was first executed.
*
* @return the first descendant Evaluation (first Evaluation executed in the tree).
*/
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.
*
* @return the last descendant Evaluation (most recent Evaluation executed in the tree).
*/
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.
*
* @param child an Evaluation to add as a child to the current Evaluation.
*/
public void addChild(Evaluation