Refactoring in gen_java.py script
Merge pull request #3344 from mshabunin:java_automation