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

net.lightoze.gwt.i18n.server.ConstantsWithLookupProxy Maven / Gradle / Ivy

There is a newer version: 0.26
Show newest version
package net.lightoze.gwt.i18n.server;

import com.google.gwt.i18n.client.ConstantsWithLookup;
import com.google.gwt.i18n.client.LocalizableResource;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
import java.util.MissingResourceException;
import java.util.Set;

/**
 * @author Vladimir Kulev
 */
public class ConstantsWithLookupProxy implements InvocationHandler {
    private final Set methods;
    private final Class cls;
    private final InvocationHandler handler;

    protected ConstantsWithLookupProxy(Class cls, InvocationHandler handler) {
        this.cls = cls;
        this.handler = handler;
        methods = new HashSet(Arrays.asList(ConstantsWithLookup.class.getDeclaredMethods()));
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (methods.contains(method)) {
            try {
                method = cls.getMethod((String) args[0]);
            } catch (NoSuchMethodException e) {
                throw new MissingResourceException(e.getMessage(), cls.getCanonicalName(), method.getName());
            }
            args = null;
        }
        return handler.invoke(proxy, method, args);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy