1

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?

  1. 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.

  1. 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.

  1. ?

Help

Any ideas and/or suggestions?

Community
  • 1
  • 1
elysch
  • 1,846
  • 4
  • 25
  • 43
  • Does storing a **checksum** with the file (zipping the file for instance) not give enough info? – Joop Eggen Apr 29 '15 at 17:56
  • Where I need that functionality doesn't have a file yet. In certain circumstances I make a final calculation and change some values, for example. In that case I must do the "expensive" transformation. Otherwise I shouldn't – elysch Apr 29 '15 at 18:04
  • Still with CRC32 one might stream the java model to bytes calculating the checksum on the fly. Expensive yes. A VCS would even be nicer. One even might store the version at the root, excluding it in the CRC calculation. – Joop Eggen Apr 29 '15 at 18:10
  • @JoopEggen I need to do it for every instance, at runtime. Do yo mean do something like [InputStream stream = c.getClassLoader().getResourceAsStream(...](http://stackoverflow.com/a/2036139/2796922) then calculate the crc? The problem would be how to exclude some of it's values. How do I do that? – elysch Apr 29 '15 at 19:17
  • In fact I meant when having the object hierarchy doing a marshal to a stream doing a CRC, The latter either with a second thread and a java.nio pipe or some self-made CrcCalculatingNullOutputStream. – Joop Eggen Apr 30 '15 at 06:47

0 Answers0