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.ExpressionCompiler; 023 024 /** 025 * $Id: ASTRootVarRef.java 1194869 2011-10-29 11:10:16Z mcucchiara $ 026 * @author Luke Blanshard (blanshlu@netscape.net) 027 * @author Drew Davidson (drew@ognl.org) 028 */ 029 public class ASTRootVarRef 030 extends ASTVarRef 031 { 032 public ASTRootVarRef( int id ) 033 { 034 super( id ); 035 } 036 037 public ASTRootVarRef( OgnlParser p, int id ) 038 { 039 super( p, id ); 040 } 041 042 protected Object getValueBody( OgnlContext context, Object source ) 043 throws OgnlException 044 { 045 return context.getRoot(); 046 } 047 048 protected void setValueBody( OgnlContext context, Object target, Object value ) 049 throws OgnlException 050 { 051 context.setRoot( value ); 052 } 053 054 public String toGetSourceString( OgnlContext context, Object target ) 055 { 056 if ( target != null ) 057 { 058 getterClass = target.getClass(); 059 } 060 061 if ( getterClass != null ) 062 { 063 064 context.setCurrentType( getterClass ); 065 } 066 067 if ( parent == null || ( getterClass != null && getterClass.isArray() ) ) 068 { 069 return ""; 070 } 071 else 072 { 073 return ExpressionCompiler.getRootExpression( this, target, context ); 074 } 075 } 076 077 public String toSetSourceString( OgnlContext context, Object target ) 078 { 079 if ( parent == null || ( getterClass != null && getterClass.isArray() ) ) 080 { 081 return ""; 082 } 083 else 084 { 085 return "$3"; 086 } 087 } 088 089 public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data ) 090 throws OgnlException 091 { 092 return visitor.visit( this, data ); 093 } 094 }