/**
* Mad-Advertisement
* Copyright (C) 2011 Thorsten Marx <thmarx@gmx.net>
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.mad.ads.base.api.utils;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import net.mad.ads.base.api.BaseObject;
public class BaseObjectProxyHandler extends BaseObject implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
String methodName = method.getName();
if (methodName.startsWith("get")) {
String name = methodName.substring(methodName.indexOf("get") + 3);
return get(name);
} else if (methodName.startsWith("set")) {
String name = methodName.substring(methodName.indexOf("set") + 3);
put(name, args[0]);
return null;
} else if (methodName.startsWith("is")) {
String name = methodName.substring(methodName.indexOf("is") + 2);
return (get(name));
}
return null;
}
}