package jp.co.nttdata.autofill.test; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.jelly.JellyContext; import org.apache.commons.jelly.XMLOutput; import bsh.Interpreter; import edu.emory.mathcs.backport.java.util.Collections; public class TestMapping { public static void main(String[] args) throws Exception { System.out.println("mapped by BeanShell :"); testBeanShell(); System.out.println("mapped by Apache Commons - Jelly :"); testJelly(); } public static void testBeanShell() throws Exception { List<Map<String, ?>> destList = new ArrayList<Map<String, ?>>(); List<Map<String, String>> srcList = new ArrayList<Map<String, String>>(); Map<String, String> srcMap = new HashMap<String, String>(); srcMap.put("name", "btpka3"); srcMap.put("age", "18"); srcMap.put("mail", "btpka3@163.com"); srcList.add(srcMap); srcMap = new HashMap<String, String>(); srcMap.put("name", "mp3f4"); srcMap.put("age", "25"); srcMap.put("sex", "F"); srcMap.put("mail", "mp3f4@gmail.com"); srcList.add(srcMap); Interpreter intp = new Interpreter(); intp.set("srcList", Collections.unmodifiableCollection(srcList)); intp.set("destList", destList); String script = "/autofill/jp/co/nttdata/autofill/test/test.bsh"; intp.source(script); System.out.println(destList); } public static void testJelly() throws Exception { List<Map<String, ?>> destList = new ArrayList<Map<String, ?>>(); List<Map<String, String>> srcList = new ArrayList<Map<String, String>>(); Map<String, String> srcMap = new HashMap<String, String>(); srcMap.put("name", "btpka3"); srcMap.put("age", "18"); srcMap.put("mail", "btpka3@163.com"); srcList.add(srcMap); srcMap = new HashMap<String, String>(); srcMap.put("name", "mp3f4"); srcMap.put("age", "25"); srcMap.put("sex", "F"); srcMap.put("mail", "mp3f4@gmail.com"); srcList.add(srcMap); JellyContext context = new JellyContext(); context.setVariable("srcList", Collections .unmodifiableCollection(srcList)); context.setVariable("destList", destList); String script = "/autofill/jp/co/nttdata/autofill/test/test.xml"; XMLOutput xmlOutput = XMLOutput.createXMLOutput(new NullOutputStream()); context.runScript(script, xmlOutput); System.out.println(destList); } }
|