As subclass of MetaClass, ProxyMetaClass manages calls from Groovy Objects to POJOs. It enriches MetaClass with the feature of making method invocations interceptable by an Interceptor. To this end, it acts as a decorator (decorator pattern) allowing to add or withdraw this feature at runtime. See g
| 35 | * @see groovy.lang.MetaClassRegistry |
| 36 | */ |
| 37 | public class ProxyMetaClass extends MetaClassImpl implements AdaptingMetaClass { |
| 38 | |
| 39 | /** |
| 40 | * Wrapped meta class that performs the underlying dispatch. |
| 41 | */ |
| 42 | protected MetaClass adaptee; |
| 43 | /** |
| 44 | * Optional interceptor applied around meta-object protocol calls. |
| 45 | */ |
| 46 | protected Interceptor interceptor; |
| 47 | |
| 48 | /** |
| 49 | * convenience factory method for the most usual case. |
| 50 | */ |
| 51 | public static ProxyMetaClass getInstance(final Class theClass) { |
| 52 | MetaClassRegistry metaRegistry = GroovySystem.getMetaClassRegistry(); |
| 53 | MetaClass meta = metaRegistry.getMetaClass(theClass); |
| 54 | return new ProxyMetaClass(metaRegistry, theClass, meta); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @param adaptee the MetaClass to decorate with interceptability |
| 59 | */ |
| 60 | public ProxyMetaClass(final MetaClassRegistry registry, final Class theClass, final MetaClass adaptee) { |
| 61 | super(registry, theClass); |
| 62 | this.adaptee = Objects.requireNonNull(adaptee, "adaptee must not be null"); |
| 63 | super.initialize(); |
| 64 | } |
| 65 | |
| 66 | /** {@inheritDoc} */ |
| 67 | @Override |
| 68 | public synchronized void initialize() { |
| 69 | this.adaptee.initialize(); |
| 70 | } |
| 71 | |
| 72 | /** {@inheritDoc} */ |
| 73 | @Override |
| 74 | public MetaClass getAdaptee() { |
| 75 | return this.adaptee; |
| 76 | } |
| 77 | |
| 78 | /** {@inheritDoc} */ |
| 79 | @Override |
| 80 | public void setAdaptee(final MetaClass metaClass) { |
| 81 | this.adaptee = metaClass; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @return the interceptor in use or null if no interceptor is used |
| 86 | */ |
| 87 | public Interceptor getInterceptor() { |
| 88 | return interceptor; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * @param interceptor may be null to reset any interception |
| 93 | */ |
| 94 | public void setInterceptor(final Interceptor interceptor) { |
nothing calls this directly
no outgoing calls
no test coverage detected