View Javadoc

1   package org.apache.commons.ognl;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.ognl.enhance.ExpressionAccessor;
23  
24  /**
25   * JJTree interface for AST nodes, as modified to handle the OGNL operations getValue and setValue. JJTree's original
26   * comment: All AST nodes must implement this interface. It provides basic machinery for constructing the parent and
27   * child relationships between nodes.
28   * 
29   * @author Luke Blanshard (blanshlu@netscape.net)
30   * @author Drew Davidson (drew@ognl.org)
31   */
32  public interface Node
33      extends JavaSource
34  {
35  
36      /**
37       * This method is called after the node has been made the current node. It indicates that child nodes can now be
38       * added to it.
39       */
40      void jjtOpen();
41  
42      /**
43       * This method is called after all the child nodes have been added.
44       */
45      void jjtClose();
46  
47      /**
48       * This pair of methods are used to inform the node of its parent.
49       */
50      void jjtSetParent( Node n );
51  
52      Node jjtGetParent();
53  
54      /**
55       * This method tells the node to add its argument to the node's list of children.
56       */
57      void jjtAddChild( Node n, int i );
58  
59      /**
60       * This method returns a child node. The children are numbered from zero, left to right.
61       */
62      Node jjtGetChild( int i );
63  
64      /** Return the number of children the node has. */
65      int jjtGetNumChildren();
66  
67      // OGNL additions to Node:
68  
69      /**
70       * Extracts the value from the given source object that is appropriate for this node within the given context.
71       */
72      Object getValue( OgnlContext context, Object source )
73          throws OgnlException;
74  
75      /**
76       * Sets the given value in the given target as appropriate for this node within the given context.
77       */
78      void setValue( OgnlContext context, Object target, Object value )
79          throws OgnlException;
80  
81      /**
82       * Gets the compiled bytecode enhanced expression accessor for getting/setting values.
83       * 
84       * @return The accessor for this node, or null if none has been compiled for it.
85       */
86      ExpressionAccessor getAccessor();
87  
88      /**
89       * Sets a new compiled accessor for this node expression.
90       * 
91       * @param accessor The compiled representation of this node.
92       */
93      void setAccessor( ExpressionAccessor accessor );
94  
95  
96      /**
97       * Supports the Visitor pattern. The method which corresponds to
98       * the runtime type of this Node will be called.
99       *
100      * @param visitor The visitor to accept.
101      * @param data    The second parameter to pass through to visitor.visit
102      * @param <R>     The return type of the visitor.visit method.
103      * @param <P>     The type of the second parameter type.
104      * @return the value returned by visitor.visit
105      * @throws NullPointerException if visitor is null
106      * @throws RuntimeException     if visitor.visit throws an exception.
107      */
108     <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
109         throws OgnlException;
110 
111 }