Maybe I didn't use the right words for my many searches on the topic, but I couldn't find an answer.
Intro
I have this xsd file that contains some complex types. I need to do some ("expensive") xslt transformation that returns a string before marshal. But do it only when something has changed since last marshal, otherwise use the previous transformation output. I need that string value in some other places too, not just upon doing the marshal.
(By the way, the xsd file changes almost every year or two)
The problem
To prevent the transformation from happening when nothing has changed, I need some kind of flag that is "true" whenever a field is changed. I think the best place for that flag is the base extracted class, so each instance of it keeps it updated. The problem comes when I need to change the flag from within a contained class, since it doesn't have a reference to the base class.
I remember asking something like this a few years back in the jaxb mailing-list. Don't remember exactly what was the answer but I ended up making the base class a singleton and also added some static fields in it using binding files. Using AOP I changed one of the added fields every time a setter was invoked (for short).
Now, I need this class not to be a singleton. I need to have more than one instance of it, since the same class needs to be used differently than before and I don't want to implement a "busy flag" and create a bottle neck.
Since the xsd file is specified by a third party and changes quite often, I don't want to do many fixed transformations by hand since maintenance would be hard and expensive.
Thoughts:
If the inner classes created by XJC weren't static, I could do something like Parent.this.setFlag()
If I do something like <jaxb:globalBindings localScoping="toplevel"/>
, the contained complexType attributes aren't static anymore, but because every complexType gets generated in its own file, they doesn't find the base class either. The complexType class has no reference to the container one.
Thought of having a map somewhere with references to every complexTyple class instance, but can't imagine how to implement it without doing it all by hand...so what's the use of XJC, Right?
How to do it?
- Find a way to make the inner classes not-static
I think it would be the best solution, since its the easier one to implement.
- Find a way to add a reference to the base class on every inner one.
This is difficult to implement, since I would need to define a binding file with a modification for every inner class, and I could need to change the ObjectFactore (somehow) to make every constructor have a parameter with the base class instance.
- ?
Help
Any ideas and/or suggestions?