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.ExpressionCompiler;
23  
24  /**
25   * $Id: ASTRootVarRef.java 1194869 2011-10-29 11:10:16Z mcucchiara $
26   * @author Luke Blanshard (blanshlu@netscape.net)
27   * @author Drew Davidson (drew@ognl.org)
28   */
29  public class ASTRootVarRef
30      extends ASTVarRef
31  {
32      public ASTRootVarRef( int id )
33      {
34          super( id );
35      }
36  
37      public ASTRootVarRef( OgnlParser p, int id )
38      {
39          super( p, id );
40      }
41  
42      protected Object getValueBody( OgnlContext context, Object source )
43          throws OgnlException
44      {
45          return context.getRoot();
46      }
47  
48      protected void setValueBody( OgnlContext context, Object target, Object value )
49          throws OgnlException
50      {
51          context.setRoot( value );
52      }
53  
54      public String toGetSourceString( OgnlContext context, Object target )
55      {
56          if ( target != null )
57          {
58              getterClass = target.getClass();
59          }
60          
61          if ( getterClass != null )
62          {
63  
64              context.setCurrentType( getterClass );
65          }
66  
67          if ( parent == null || ( getterClass != null && getterClass.isArray() ) )
68          {
69              return "";
70          }
71          else
72          {
73              return ExpressionCompiler.getRootExpression( this, target, context );
74          }
75      }
76  
77      public String toSetSourceString( OgnlContext context, Object target )
78      {
79          if ( parent == null || ( getterClass != null && getterClass.isArray() ) )
80          {
81              return "";
82          }
83          else
84          {
85              return "$3";
86          }
87      }
88      
89      public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
90          throws OgnlException
91      {
92          return visitor.visit( this, data );
93      }
94  }