|
| 1 | +/** |
| 2 | + * Copyright 2009-2018 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.apache.ibatis.scripting.xmltags; |
| 17 | + |
| 18 | +import ognl.MemberAccess; |
| 19 | + |
| 20 | +import java.lang.reflect.AccessibleObject; |
| 21 | +import java.lang.reflect.Member; |
| 22 | +import java.lang.reflect.Modifier; |
| 23 | +import java.util.Map; |
| 24 | + |
| 25 | +/** |
| 26 | + * The {@link MemberAccess} class that based on <a href= |
| 27 | + * 'https://github.com/jkuhnert/ognl/blob/OGNL_3_2_1/src/java/ognl/DefaultMemberAccess.java'>DefaultMemberAccess</a>. |
| 28 | + * |
| 29 | + * @author Kazuki Shimizu |
| 30 | + * @since 3.5.0 |
| 31 | + * |
| 32 | + * @see <a href= |
| 33 | + * 'https://github.com/jkuhnert/ognl/blob/OGNL_3_2_1/src/java/ognl/DefaultMemberAccess.java'>DefaultMemberAccess</a> |
| 34 | + * @see <a href='https://github.com/jkuhnert/ognl/issues/47'>#47 of ognl</a> |
| 35 | + */ |
| 36 | +class OgnlMemberAccess implements MemberAccess { |
| 37 | + |
| 38 | + @Override |
| 39 | + public Object setup(Map context, Object target, Member member, String propertyName) { |
| 40 | + Object result = null; |
| 41 | + if (isAccessible(context, target, member, propertyName)) { |
| 42 | + AccessibleObject accessible = (AccessibleObject) member; |
| 43 | + if (!accessible.isAccessible()) { |
| 44 | + result = Boolean.FALSE; |
| 45 | + accessible.setAccessible(true); |
| 46 | + } |
| 47 | + } |
| 48 | + return result; |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void restore(Map context, Object target, Member member, String propertyName, |
| 53 | + Object state) { |
| 54 | + if (state != null) { |
| 55 | + ((AccessibleObject) member).setAccessible(((Boolean) state)); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public boolean isAccessible(Map context, Object target, Member member, String propertyName) { |
| 61 | + return Modifier.isPublic(member.getModifiers()); |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments