2

I have a multithreaded application using JAXB. The JAXB object represent state of other system hardware. I have a thread monitoring the system hardware, and it updates the JAXB objects with the setters to update the state.

I have another chunk of code that is supposed to "do something" when the state of an object changes. I'm wondering how to set up event listeners, or some sort of publisher subscriber scheme, so that when a JAXB object changes state, the appropriate response to the change is kicked off. I have not seen anything describing how something could register as a listener with a JAXB object.

Matt Brown
  • 435
  • 4
  • 17

1 Answers1

1

JAXB objects are just POJOs, so you can modify the code to add listeners appropriate to your use case.

bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • But when I regenerate the JAXB objects, the additional code will be overwritten, correct? – Matt Brown Feb 17 '11 at 16:23
  • Correct. You can however write a plug-in for the schema-to-Java compiler (XJC) to add this code to the generated classes for you: http://jaxb.java.net/nonav/2.0.2/docs/vendorCustomizations.html – bdoughan Feb 17 '11 at 16:40