001    package org.apache.commons.ognl;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.commons.ognl.enhance.ExpressionAccessor;
023    
024    /**
025     * JJTree interface for AST nodes, as modified to handle the OGNL operations getValue and setValue. JJTree's original
026     * comment: All AST nodes must implement this interface. It provides basic machinery for constructing the parent and
027     * child relationships between nodes.
028     * 
029     * @author Luke Blanshard (blanshlu@netscape.net)
030     * @author Drew Davidson (drew@ognl.org)
031     */
032    public interface Node
033        extends JavaSource
034    {
035    
036        /**
037         * This method is called after the node has been made the current node. It indicates that child nodes can now be
038         * added to it.
039         */
040        void jjtOpen();
041    
042        /**
043         * This method is called after all the child nodes have been added.
044         */
045        void jjtClose();
046    
047        /**
048         * This pair of methods are used to inform the node of its parent.
049         */
050        void jjtSetParent( Node n );
051    
052        Node jjtGetParent();
053    
054        /**
055         * This method tells the node to add its argument to the node's list of children.
056         */
057        void jjtAddChild( Node n, int i );
058    
059        /**
060         * This method returns a child node. The children are numbered from zero, left to right.
061         */
062        Node jjtGetChild( int i );
063    
064        /** Return the number of children the node has. */
065        int jjtGetNumChildren();
066    
067        // OGNL additions to Node:
068    
069        /**
070         * Extracts the value from the given source object that is appropriate for this node within the given context.
071         */
072        Object getValue( OgnlContext context, Object source )
073            throws OgnlException;
074    
075        /**
076         * Sets the given value in the given target as appropriate for this node within the given context.
077         */
078        void setValue( OgnlContext context, Object target, Object value )
079            throws OgnlException;
080    
081        /**
082         * Gets the compiled bytecode enhanced expression accessor for getting/setting values.
083         * 
084         * @return The accessor for this node, or null if none has been compiled for it.
085         */
086        ExpressionAccessor getAccessor();
087    
088        /**
089         * Sets a new compiled accessor for this node expression.
090         * 
091         * @param accessor The compiled representation of this node.
092         */
093        void setAccessor( ExpressionAccessor accessor );
094    
095    
096        /**
097         * Supports the Visitor pattern. The method which corresponds to
098         * the runtime type of this Node will be called.
099         *
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    }