2012년 7월 22일 일요일

JXPath Tutorial





java object tree search....
나중에 유용하게 쓰일듯..

package test;
import org.apache.commons.jxpath.JXPathContext;
public class JXPathTester {
    public static void main(String[] args) {
        //Create the ValueHolder lister object
        SimpleValueLister holderList = new SimpleValueLister();
        for(int j = 0; j < 5; j++){
            SimpleValueHolder holder = new SimpleValueHolder();
            //Every other instance gets different values
            if((j%2)==0) {
                holder.setSomeValue("no");
                holder.setSomeOtherValue("blue");
            }
            if((j%4)==0) {
                //one instance gets totally different values
                holder.setSomeOtherValue("green");
            }
            holderList.addValue(holder);
        }
        //Create a 'object tree root object'
        JXPathContext context = JXPathContext.newContext(holderList);
        Object o = context.getValue(".");
        System.out.println(((SimpleValueLister)o).getCheckValue());
       
        for(Iterator iter = context.iterate("/valueList"); iter.hasNext();){
            System.out.println(((SimpleValueHolder)iter.next()).getSomeValue());
        }
    }
}


댓글 없음: