1 16 package org.apache.commons.jxpath.ri.model.dynamic; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 import java.util.Vector ; 21 22 import org.apache.commons.jxpath.AbstractFactory; 23 import org.apache.commons.jxpath.JXPathContext; 24 import org.apache.commons.jxpath.NestedTestBean; 25 import org.apache.commons.jxpath.Pointer; 26 import org.apache.commons.jxpath.TestBean; 27 28 34 public class TestDynamicPropertyFactory extends AbstractFactory { 35 36 40 public boolean createObject( 41 JXPathContext context, 42 Pointer pointer, 43 Object parent, 44 String name, 45 int index) 46 { 47 if (name.equals("map")) { 48 ((TestBean) parent).setMap(new HashMap ()); 49 return true; 50 } 51 else if (name.equals("TestKey1")) { 52 ((Map ) parent).put(name, ""); 53 return true; 54 } 55 else if (name.equals("TestKey2")) { 56 ((Map ) parent).put(name, new NestedTestBean("newName")); 57 return true; 58 } 59 else if (name.equals("TestKey3")) { 60 Vector v = new Vector (); 61 for (int i = 0; i <= index; i++) { 62 v.add(null); 63 } 64 ((Map ) parent).put(name, v); 65 return true; 66 } 67 else if (name.equals("TestKey4")) { 68 ((Map ) parent).put(name, new Object [] { new TestBean()}); 69 return true; 70 } 71 return false; 72 } 73 74 public boolean declareVariable(JXPathContext context, String name) { 75 return false; 76 } 77 } 78 | Popular Tags |