Java – Hierarchical object model with property inheritance and event bubbling


I'm writing a document-based client application and I need a DOM or WPF-like, but non-visual model that:

  • Is a tree composed of elements
  • Can accept an unlimited number of custom properties that
    • get/set any CLR type, including collections.
    • Can inherit their values from their parent
    • Can inherit their default values from an ancestor
    • Can be derived/calculated from other properties, ancestors, or descendants
    • Support event bubbling / tunneling
    • There will be a core set of properties but other plugins may add their own or even create custom documents
  • Supports full inspection by the owning document in order to persist the tree and attributes in an XML format.

I realize that's a tall order but I was really hoping there would be something out there to help me get started. Unfortunately WPF DependencyObjects are too closed, proprietary, and coupled to WPF to be of any use as a document model. My needs also have a strong resemblance to the HTML DOM but I haven't been able to find any clean DOM implementations that could be decoupled from HTML or ported to .NET.

My current platform is .NET/C# but if anyone knows of anything that might be useful for inspiration or embedding, regardless of the platform, I'd love to know.

Best Solution

I don't think that it meets all of the requirements you specified, but have you considered working with an XML DOM (as opposed to an HTML DOM)? You can create an XML document programmatically in .NET and manipulate it using DOM methods and properties, and also do things like XPath queries. Check out .NET's XmlDocument object. This might be a reasonable starting point.