tags:

views:

125

answers:

3

I'm evaluating some potential implementations of a complex object hierarchy model for my current project. I'm wondering if there is an xpath-style meta-language or something like this that would allow me to query these object linkages.

Furthermore, I'm sure there is some very specific jargon used for the problem I am asking about - I just don't know it.

The requirements:

  • Must be done in Java (or at least compiled to Java bytecode).
  • Objects will be hierarchically related to each other with n possible links. obj1->obj2->obj3->...
  • We need to be able to look up any object in the hierarchy based on an objects properties or its relationship to other objects.
  • Objects will be of the same type.
  • Hierarchical lookups should be able to happen at runtime.

I think I could roll my own solution here, but I'm curious if someone smarter than me has already come up with something.

After seeing some answers come in, I think I might need to clarify my question a bit more. Specifically, this tool would be used to traverse a set of Objects that are different versions of a parent object.

For example:

[Object 1 prop1="foo" prop2="bar" prop3="zoop"]

↓ Inherits from above object ↓

[Object 2 prop1="foo and something" prop2="bar" prop3="zoop"]

↓ Inherits from above object ↓

[Object 3 prop1="foo and something" prop2="bar" prop3="zoop 24"]

+1  A: 

Are you after something like OGNL, SPEL or Unified EL?

Jon Skeet
A: 

OK, first you have to take the proviso that I never actually used this myself to build anything, BUT, jaxen is supposed to be able to do that sort of thing as best I can remember and the description on their home page supports that:

"Jaxen is an open source XPath library written in Java. It is adaptable to many different object models, including DOM, XOM, dom4j, and JDOM. Is it also possible to write adapters that treat non-XML trees such as compiled Java byte code or Java beans as XML, thus enabling you to query these trees with XPath too."

John Munsch
+4  A: 

I believe JXPath should do what you want.

JXPath is what you want and it use's XPath syntax to boot. I've used it to navigate complex JAXB generated classes (yes that's a bit backwards if you have the XML anyway...) and it's worked well.
safetydan