www.pudn.com > struts2.rar > PointConverter.java, change:2009-08-17,size:818b


package com.test.converter; 
 
import java.lang.reflect.Member; 
import java.util.Map; 
 
import com.test.bean.Point; 
 
import ognl.DefaultTypeConverter; 
 
public class PointConverter extends DefaultTypeConverter { 
 
	public Object convertValue(Map context, Object value, Class toType) { 
 
		if(Point.class == toType) 
		{ 
			Point point = new Point(); 
			String[] str = (String[])value; 
			String[] paramValues = str[0].split(","); 
			int x = Integer.parseInt(paramValues[0]); 
			int y = Integer.parseInt(paramValues[1]); 
			 
			point.setX(x); 
			point.setY(y); 
			 
			return point; 
		} 
		if(String.class==toType) 
		{ 
			Point point = new Point(); 
			point = (Point)value; 
			String result = "[x=" + point.getX() + ",y=" + point.getY() + "]"; 
			return result; 
		} 
		 
		return null; 
	} 
 
}