Proper use of TransformationFeedback
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 4
- Joined: Fri Sep 11, 2015 9:56 am
Proper use of TransformationFeedback
Hi,
As a novice Java programmer, I'm having trouble figuring out how to use TransformationFeedback properly within an AuthorOperation. I'm using AuthorEditorAccess.runTransformationScenarios() to execute a transformation on the current document. The transformation is not supposed to modify the document itself, and so far everything works. The problem occurs when I try to add more functionality which modifies the current document by deleting nodes as well as certain external resources on which the transformation depends. In order to make sure that the transformation succeeds, I need to prevent these other operations from executing prematurely. I've tried to set a flag using TransformationFeedback.transformationFinished(). However, I can't seem to avoid an infinite loop while checking the flag. My first attempt was a naive busy loop, but I have also tried synchronized blocks calling wait() from doOperation() and notify() from transformationFinished(), but neither works. As you can probably tell, my grasp on threading and concurrency issues is rather shaky. Any help will be much appreciated.
The outline of my code is basically as follows:
As a novice Java programmer, I'm having trouble figuring out how to use TransformationFeedback properly within an AuthorOperation. I'm using AuthorEditorAccess.runTransformationScenarios() to execute a transformation on the current document. The transformation is not supposed to modify the document itself, and so far everything works. The problem occurs when I try to add more functionality which modifies the current document by deleting nodes as well as certain external resources on which the transformation depends. In order to make sure that the transformation succeeds, I need to prevent these other operations from executing prematurely. I've tried to set a flag using TransformationFeedback.transformationFinished(). However, I can't seem to avoid an infinite loop while checking the flag. My first attempt was a naive busy loop, but I have also tried synchronized blocks calling wait() from doOperation() and notify() from transformationFinished(), but neither works. As you can probably tell, my grasp on threading and concurrency issues is rather shaky. Any help will be much appreciated.
The outline of my code is basically as follows:
Code: Select all
private volatile boolean transformationFinished;
public void doOperation() {
runTransformationScenarios();
while (!transformationFinished) continue;
modifyDocument();
}
private class Feedback extends TransformationFeedback {
public void transformationFinished() {
transformationFinished = true;
}
public void transformationStopped() {
transformationFinished = true;
}
}
-
- Posts: 9476
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Proper use of TransformationFeedback
Hi,
Doing that while (!transformationFinished) continue; blocks the entire thread which has called the doOperation method. And that thread is the AWT thread which is very important to the GUI interraction.
Indeed the runTransformationScenarios runs on a separate thread but it also sometimes calls events on the AWT thread (like updating the status). But because you blocked the AWT thread with the while loop, the transformation will never finish.
But you could try to do something like this instead:
Regards,
Radu
Doing that while (!transformationFinished) continue; blocks the entire thread which has called the doOperation method. And that thread is the AWT thread which is very important to the GUI interraction.
Indeed the runTransformationScenarios runs on a separate thread but it also sometimes calls events on the AWT thread (like updating the status). But because you blocked the AWT thread with the while loop, the transformation will never finish.
But you could try to do something like this instead:
Code: Select all
editor.runTransformationScenarios(null, new TransformationFeedback() {
@Override
public void transformationStopped() {
}
@Override
public void transformationFinished(boolean success) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
modifyDocument();
}
});
}
});
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service