Java tutorial
//package com.java2s; import java.io.*; import java.lang.reflect.Method; import java.util.HashMap; public class Main { private static HashMap UNMARSHAL_METHOD_MAP = new HashMap(); public static Object getBeanFromXml(String xml, Class xmlBeanClass) throws Exception { Method method = (Method) UNMARSHAL_METHOD_MAP.get(xmlBeanClass.getName()); if (method == null) { method = xmlBeanClass.getMethod("unmarshal", new Class[] { Reader.class }); UNMARSHAL_METHOD_MAP.put(xmlBeanClass.getName(), method); } StringReader stringReader = new StringReader(xml); return method.invoke(null, new Object[] { stringReader }); } }