All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.buschmais.xo.impl.proxy.InstanceInvocationHandler Maven / Gradle / Ivy

The newest version!
package com.buschmais.xo.impl.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import com.buschmais.xo.api.XOException;

import lombok.ToString;

@ToString(onlyExplicitlyIncluded = true)
public class InstanceInvocationHandler implements InvocationHandler {

    @ToString.Include
    private DatastoreType datastoreType;
    private final ProxyMethodService proxyMethodService;

    public InstanceInvocationHandler(DatastoreType datastoreType, ProxyMethodService proxyMethodService) {
        this.datastoreType = datastoreType;
        this.proxyMethodService = proxyMethodService;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (datastoreType == null) {
            throw new XOException("Invalid access to an un-managed instance.");
        }
        return proxyMethodService.invoke(datastoreType, proxy, method, args);
    }

    public DatastoreType getDatastoreType() {
        return datastoreType;
    }

    public void close() {
        datastoreType = null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy