1 16 package org.apache.commons.jxpath.ri.compiler; 17 18 import org.apache.commons.jxpath.AbstractFactory; 19 import org.apache.commons.jxpath.JXPathContext; 20 import org.apache.commons.jxpath.Pointer; 21 import org.apache.commons.jxpath.TestBean; 22 23 29 public class VariableFactory extends AbstractFactory { 30 31 33 public boolean createObject( 34 JXPathContext context, 35 Pointer pointer, 36 Object parent, 37 String name, 38 int index) 39 { 40 if (name.equals("testArray")) { 41 ((TestBean[]) parent)[index] = new TestBean(); 42 return true; 43 } 44 else if (name.equals("stringArray")) { 45 ((String []) parent)[index] = ""; 46 return true; 47 } 48 else if (name.equals("array")) { 49 ((String []) parent)[index] = ""; 50 return true; 51 } 52 return false; 53 } 54 55 58 public boolean declareVariable(JXPathContext context, String name) { 59 if (name.equals("test")) { 60 context.getVariables().declareVariable(name, new TestBean()); 61 return true; 62 } 63 else if (name.equals("testArray")) { 64 context.getVariables().declareVariable(name, new TestBean[0]); 65 return true; 66 } 67 else if (name.equals("stringArray")) { 68 context.getVariables().declareVariable( 69 name, 70 new String [] { "Value1" }); 71 return true; 72 } 73 context.getVariables().declareVariable(name, null); 74 return true; 75 } 76 } 77 | Popular Tags |