org.apache.commons.ognl
Class SimpleNode

java.lang.Object
  extended by org.apache.commons.ognl.SimpleNode
All Implemented Interfaces:
Serializable, JavaSource, Node
Direct Known Subclasses:
ASTChain, ASTConst, ASTCtor, ASTInstanceof, ASTList, ASTMethod, ASTProperty, ASTSequence, ASTStaticField, ASTStaticMethod, ASTVarRef, ExpressionNode

public abstract class SimpleNode
extends Object
implements Node, Serializable

Author:
Luke Blanshard (blanshlu@netscape.net), Drew Davidson (drew@ognl.org)
See Also:
Serialized Form

Field Summary
protected  Node[] children
           
protected  int id
           
protected  Node parent
           
protected  OgnlParser parser
           
 
Constructor Summary
SimpleNode(int i)
           
SimpleNode(OgnlParser p, int i)
           
 
Method Summary
 void dump(PrintWriter writer, String prefix)
           
protected  Object evaluateGetValueBody(OgnlContext context, Object source)
           
protected  void evaluateSetValueBody(OgnlContext context, Object target, Object value)
           
protected  void flattenTree()
          This method may be called from subclasses' jjtClose methods.
 ExpressionAccessor getAccessor()
          Gets the compiled bytecode enhanced expression accessor for getting/setting values.
 int getIndexInParent()
           
 Node getNextSibling()
           
 Object getValue(OgnlContext context, Object source)
          Extracts the value from the given source object that is appropriate for this node within the given context.
protected abstract  Object getValueBody(OgnlContext context, Object source)
          Subclasses implement this method to do the actual work of extracting the appropriate value from the source object.
 boolean isConstant(OgnlContext context)
           
 boolean isEvalChain(OgnlContext context)
           
 boolean isNodeConstant(OgnlContext context)
          Returns true iff this node is constant without respect to the children.
 boolean isNodeSimpleProperty(OgnlContext context)
           
 boolean isSimpleNavigationChain(OgnlContext context)
           
 boolean isSimpleProperty(OgnlContext context)
           
 void jjtAddChild(Node n, int i)
          This method tells the node to add its argument to the node's list of children.
 void jjtClose()
          This method is called after all the child nodes have been added.
 Node jjtGetChild(int i)
          This method returns a child node.
 int jjtGetNumChildren()
          Return the number of children the node has.
 Node jjtGetParent()
           
 void jjtOpen()
          This method is called after the node has been made the current node.
 void jjtSetParent(Node n)
          This pair of methods are used to inform the node of its parent.
protected  boolean lastChild(OgnlContext context)
           
 void setAccessor(ExpressionAccessor accessor)
          Sets a new compiled accessor for this node expression.
 void setValue(OgnlContext context, Object target, Object value)
          Sets the given value in the given target as appropriate for this node within the given context.
protected  void setValueBody(OgnlContext context, Object target, Object value)
          Subclasses implement this method to do the actual work of setting the appropriate value in the target object.
 String toGetSourceString(OgnlContext context, Object target)
          Expected to return a java source representation of itself such that it could be turned into a literal java expression to be compiled and executed for ExpressionAccessor.get(OgnlContext, Object) calls.
 String toSetSourceString(OgnlContext context, Object target)
          Expected to return a java source representation of itself such that it could be turned into a literal java expression to be compiled and executed for ExpressionAccessor.get(OgnlContext, Object) calls.
 String toString()
           
 String toString(String prefix)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.ognl.Node
accept
 

Field Detail

parent

protected Node parent

children

protected Node[] children

id

protected int id

parser

protected OgnlParser parser
Constructor Detail

SimpleNode

public SimpleNode(int i)

SimpleNode

public SimpleNode(OgnlParser p,
                  int i)
Method Detail

jjtOpen

public void jjtOpen()
Description copied from interface: Node
This method is called after the node has been made the current node. It indicates that child nodes can now be added to it.

Specified by:
jjtOpen in interface Node

jjtClose

public void jjtClose()
Description copied from interface: Node
This method is called after all the child nodes have been added.

Specified by:
jjtClose in interface Node

jjtSetParent

public void jjtSetParent(Node n)
Description copied from interface: Node
This pair of methods are used to inform the node of its parent.

Specified by:
jjtSetParent in interface Node

jjtGetParent

public Node jjtGetParent()
Specified by:
jjtGetParent in interface Node

jjtAddChild

public void jjtAddChild(Node n,
                        int i)
Description copied from interface: Node
This method tells the node to add its argument to the node's list of children.

Specified by:
jjtAddChild in interface Node

jjtGetChild

public Node jjtGetChild(int i)
Description copied from interface: Node
This method returns a child node. The children are numbered from zero, left to right.

Specified by:
jjtGetChild in interface Node

jjtGetNumChildren

public int jjtGetNumChildren()
Description copied from interface: Node
Return the number of children the node has.

Specified by:
jjtGetNumChildren in interface Node

toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(String prefix)

toGetSourceString

public String toGetSourceString(OgnlContext context,
                                Object target)
Description copied from interface: JavaSource
Expected to return a java source representation of itself such that it could be turned into a literal java expression to be compiled and executed for ExpressionAccessor.get(OgnlContext, Object) calls.

Specified by:
toGetSourceString in interface JavaSource
Returns:
Literal java string representation of an object get.

toSetSourceString

public String toSetSourceString(OgnlContext context,
                                Object target)
Description copied from interface: JavaSource
Expected to return a java source representation of itself such that it could be turned into a literal java expression to be compiled and executed for ExpressionAccessor.get(OgnlContext, Object) calls.

Specified by:
toSetSourceString in interface JavaSource
Returns:
Literal java string representation of an object get.

dump

public void dump(PrintWriter writer,
                 String prefix)

getIndexInParent

public int getIndexInParent()

getNextSibling

public Node getNextSibling()

evaluateGetValueBody

protected Object evaluateGetValueBody(OgnlContext context,
                                      Object source)
                               throws OgnlException
Throws:
OgnlException

evaluateSetValueBody

protected void evaluateSetValueBody(OgnlContext context,
                                    Object target,
                                    Object value)
                             throws OgnlException
Throws:
OgnlException

getValue

public final Object getValue(OgnlContext context,
                             Object source)
                      throws OgnlException
Description copied from interface: Node
Extracts the value from the given source object that is appropriate for this node within the given context.

Specified by:
getValue in interface Node
Throws:
OgnlException

getValueBody

protected abstract Object getValueBody(OgnlContext context,
                                       Object source)
                                throws OgnlException
Subclasses implement this method to do the actual work of extracting the appropriate value from the source object.

Throws:
OgnlException

setValue

public final void setValue(OgnlContext context,
                           Object target,
                           Object value)
                    throws OgnlException
Description copied from interface: Node
Sets the given value in the given target as appropriate for this node within the given context.

Specified by:
setValue in interface Node
Throws:
OgnlException

setValueBody

protected void setValueBody(OgnlContext context,
                            Object target,
                            Object value)
                     throws OgnlException
Subclasses implement this method to do the actual work of setting the appropriate value in the target object. The default implementation throws an InappropriateExpressionException, meaning that it cannot be a set expression.

Throws:
OgnlException

isNodeConstant

public boolean isNodeConstant(OgnlContext context)
                       throws OgnlException
Returns true iff this node is constant without respect to the children.

Throws:
OgnlException

isConstant

public boolean isConstant(OgnlContext context)
                   throws OgnlException
Throws:
OgnlException

isNodeSimpleProperty

public boolean isNodeSimpleProperty(OgnlContext context)
                             throws OgnlException
Throws:
OgnlException

isSimpleProperty

public boolean isSimpleProperty(OgnlContext context)
                         throws OgnlException
Throws:
OgnlException

isSimpleNavigationChain

public boolean isSimpleNavigationChain(OgnlContext context)
                                throws OgnlException
Throws:
OgnlException

isEvalChain

public boolean isEvalChain(OgnlContext context)
                    throws OgnlException
Throws:
OgnlException

lastChild

protected boolean lastChild(OgnlContext context)

flattenTree

protected void flattenTree()
This method may be called from subclasses' jjtClose methods. It flattens the tree under this node by eliminating any children that are of the same class as this node and copying their children to this node.


getAccessor

public ExpressionAccessor getAccessor()
Description copied from interface: Node
Gets the compiled bytecode enhanced expression accessor for getting/setting values.

Specified by:
getAccessor in interface Node
Returns:
The accessor for this node, or null if none has been compiled for it.

setAccessor

public void setAccessor(ExpressionAccessor accessor)
Description copied from interface: Node
Sets a new compiled accessor for this node expression.

Specified by:
setAccessor in interface Node
Parameters:
accessor - The compiled representation of this node.


Copyright © 1997-2013 The Apache Software Foundation. All Rights Reserved.