This project allows the validation of an XSD Schema against it's generated Java-POJOs. The way this prorgram works is as follows:
- Parse the XSD-File using DOM and store the structure in a Hashmap
- Parse Java-POJOs using JavaParser and store the structure in a Hashmap
- Compare both resulting Hashmaps
- Java SDK 8+ (with Java SDK binaries in the PATH or JAVA_HOME set up)
- Gradle
- Go to the javaMetaprogramming folder
$ cd javaMetaprogramming
- If Gradle isn't installed, run the following command
$ ./gradlew
- Command for building the project:
$ ./gradlew build
- Command for preparing the project for Eclipse
$ ./gradlew eclipse
- Put your .XSD-File(s) into the inputs Folder
$ /javaMetaprogramming/inputs/
- Modify or copy a gradle task in the build.gradle file
task xjc(type: Exec) {
commandLine 'xjc'
args = ['inputs/Company.xsd', '-d', 'src/main/java', '-p' , 'org.softlang.metaprogramming.dm.company']
doFirst {
mkdir 'src/main/java/org/softlang/metaprogramming/dm/company'
}
}- Build the project again
$ ./gradlew build
- Test your Schema by supplying the path to your Java data model
String yourTest ="src/main/java/org/softlang/metaprogramming/dm/yourDataModel/";- Parse the data model into a Hashmap
Map<String, HashMap<String, String>> yourTestMap =
JCParser.parseJC(JCParser.initJC(yourTest));- Provide the path to your XSD Schema File
Node yourXSD = XSDParser.initXSD("inputs/yourSchema.xsd");- Parse your Schema into a Hashmap
Map<String, Map<String, String>> yourTestMapX =XSDParser.parseXSD(yourXSD);- Compare
assertTrue(yourTestMap.equals(yourTestMapX));