Package com.buschmais.xo.impl.proxy.entity

Source Code of com.buschmais.xo.impl.proxy.entity.InstanceInvocationHandler

package com.buschmais.xo.impl.proxy.entity;

import com.buschmais.xo.api.XOException;
import com.buschmais.xo.impl.proxy.ProxyMethodService;

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

public class InstanceInvocationHandler<DatastoreType> implements InvocationHandler {

    private DatastoreType datastoreType;
    private final ProxyMethodService<DatastoreType, ?> proxyMethodService;

    public InstanceInvocationHandler(DatastoreType datastoreType, ProxyMethodService<DatastoreType, ?> 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;
    }
}
TOP

Related Classes of com.buschmais.xo.impl.proxy.entity.InstanceInvocationHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.