Code example for Method

Methods: getName, getReturnType, invoke

0
	private PropertyChangeSupport propertySupport;
	public GeneratedInstanceInterceptor(Class clazz) {
		this.clazz = clazz;
	} 
	public Object intercept(Object obj, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
		String name = method.getName();
		Implementor implementor = new Implementor(obj);
		 
		// Fake setters 
		if( name.startsWith("set") && args.length == 1 && method.getReturnType() == Void.TYPE ) {
			char propName[] = name.substring("set".length()).toCharArray();
			propName[0] = Character.toLowerCase( propName[0] );
			implementor.set(new String( propName ), args[0]);
			return null; 
		} 
		else if( name.startsWith("get") && args.length == 0 ) {
			char propName[] = name.substring("get".length()).toCharArray();
			propName[0] = Character.toLowerCase( propName[0] );
			return implementor.get(new String( propName ));
		} else 
		  return method.invoke(implementor, args);		
	} 
 
	/** 
	 *  Sets the property of an instance by using the setter if it exists or 
	 *  by using the PropertySetter interface for generated classes