1 /*
2 * Copyright 2003-2007 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.codehaus.groovy.runtime.callsite;
17
18 import org.codehaus.groovy.runtime.ScriptBytecodeAdapter;
19
20 import groovy.lang.GroovyObject;
21 import groovy.lang.GroovyRuntimeException;
22
23 public class PogoGetPropertySite extends AbstractCallSite {
24 private final Class aClass;
25
26 public PogoGetPropertySite(CallSite parent, Class aClass) {
27 super(parent);
28 this.aClass = aClass;
29 }
30
31 public CallSite acceptGetProperty(Object receiver) {
32 if (receiver.getClass() != aClass)
33 return createGetPropertySite(receiver);
34 else
35 return this;
36 }
37
38 public CallSite acceptGroovyObjectGetProperty(Object receiver) {
39 if (receiver.getClass() != aClass)
40 return createGroovyObjectGetPropertySite(receiver);
41 else
42 return this;
43 }
44
45 public Object getProperty(Object receiver) throws Throwable {
46 try{
47 return ((GroovyObject)receiver).getProperty(name);
48 } catch (GroovyRuntimeException gre) {
49 throw ScriptBytecodeAdapter.unwrap(gre);
50 }
51 }
52 }