1 16 package org.apache.commons.jxpath.ri.model; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import org.apache.commons.jxpath.AbstractFactory; 22 import org.apache.commons.jxpath.JXPathContext; 23 import org.apache.commons.jxpath.NestedTestBean; 24 import org.apache.commons.jxpath.Pointer; 25 import org.apache.commons.jxpath.TestBean; 26 import org.apache.commons.jxpath.TestMixedModelBean; 27 28 34 public class TestMixedModelFactory 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("nestedBean")) { 48 ((TestBean) parent).setNestedBean(new NestedTestBean("newName")); 49 return true; 50 } 51 else if (name.equals("beans")) { 52 TestBean bean = (TestBean) parent; 53 if (bean.getBeans() == null || index >= bean.getBeans().length) { 54 bean.setBeans(new NestedTestBean[index + 1]); 55 } 56 bean.getBeans()[index] = new NestedTestBean("newName"); 57 return true; 58 } 59 else if (name.equals("map")) { 60 ((TestBean) parent).setMap(new HashMap ()); 61 return true; 62 } 63 else if (name.equals("TestKey5")) { 64 TestBean tb = new TestBean(); 65 tb.setNestedBean(null); 66 tb.setBeans(null); 67 ((Map ) parent).put(name, tb); 68 return true; 69 } 70 else if (name.equals("matrix")) { 71 int[][] matrix = new int[2][]; 72 matrix[0] = new int[1]; 73 ((TestMixedModelBean) parent).setMatrix(matrix); 75 return true; 76 } 77 return false; 78 } 79 80 public boolean declareVariable(JXPathContext context, String name) { 81 return false; 82 } 83 } 84 | Popular Tags |