1 46 package groovy.lang; 47 48 import org.codehaus.groovy.runtime.InvokerHelper; 49 50 56 public class Reference extends GroovyObjectSupport { 57 58 private Object value; 59 60 public Reference() { 61 } 62 63 public Reference(Object value) { 64 this.value = value; 65 } 66 67 public Object getProperty(String property) { 68 Object value = get(); 69 if (value != null) { 70 return InvokerHelper.getProperty(value, property); 71 } 72 return super.getProperty(property); 73 } 74 75 public void setProperty(String property, Object newValue) { 76 Object value = get(); 77 if (value != null) { 78 InvokerHelper.setProperty(value, property, newValue); 79 } 80 else { 81 super.setProperty(property, newValue); 82 } 83 } 84 85 public Object invokeMethod(String name, Object args) { 86 Object value = get(); 87 if (value != null) { 88 try { 89 return InvokerHelper.invokeMethod(value, name, args); 90 } 91 catch (Exception e) { 92 return super.invokeMethod(name, args); 93 } 94 } 95 else { 96 return super.invokeMethod(name, args); 97 } 98 } 99 100 public Object get() { 101 return value; 102 } 103 104 public void set(Object value) { 105 this.value = value; 106 } 107 } 108 | Popular Tags |