JXPath is a java library for Object Graph Navigation using the XPath syntax.
This requires the libraries commons-jxpath-1.3.jar, commons-beanutils.jar and commons-logging.jar to be in classpath.
The following example shows creating relative context in JXPath.
Student std1 = new Student("Sriram", 2, "Chess", new String [] { "Sri", "Ram", "Bunny", "Sweety", "Honey"});
Student std2 = new Student("Sudhakar", 29, "Cricket", new String [] { "Venkat", "Munna", "Sudha" });
Student std3 = new Student("Anuradha", 2, "Cooking", new String [] { "Anu", "Radha" });
StudentClass stCls = new StudentClass("MPC");
stCls.setStudents(Arrays.asList(std1, std2, std3));
//Create JXPathContext with StudentClass instance as ROOT node
JXPathContext context = JXPathContext.newContext(stCls);
Pointer sriramPointer = context.getPointer("/students[name='Sriram']");
System.out.println(sriramPointer);
//Create relative context with reference to the given pointer
JXPathContext relativeContext = context.getRelativeContext(sriramPointer);
System.out.println(relativeContext.getValue(".")); //Current node which is 'Student' object
System.out.println(relativeContext.getValue("./age")); //Get Student's age
System.out.println(relativeContext.getValue("./hobby")); //Get Student's hobby
System.out.println(relativeContext.getValue("./nickNames")); //Get Student's nick names