├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── settings.gradle ├── src ├── main │ └── kotlin │ │ └── com │ │ └── sixrq │ │ └── kaxb │ │ ├── parsers │ │ ├── Include.kt │ │ ├── Sequence.kt │ │ ├── Annotation.kt │ │ ├── Restriction.kt │ │ ├── SimpleContent.kt │ │ ├── Schema.kt │ │ ├── Documentation.kt │ │ ├── AnyElement.kt │ │ ├── Enumeration.kt │ │ ├── Attribute.kt │ │ ├── Extension.kt │ │ ├── Element.kt │ │ ├── SimpleType.kt │ │ ├── ComplexType.kt │ │ ├── Tag.kt │ │ └── XmlParser.kt │ │ ├── generators │ │ ├── Generator.kt │ │ ├── ClassFileGenerator.kt │ │ └── ObjectFactoryGenerator.kt │ │ └── main │ │ └── SchemaGenerator.kt └── test │ ├── resources │ ├── GpxExtensionsv3Include.xsd │ ├── SimpleType.xsd │ ├── SimpleTypeWithMaxOccurs.xsd │ ├── StandAloneComplexType.xsd │ ├── ComplexTypeWithAny.xsd │ ├── QName.xsd │ ├── EnumeratedType.xsd │ ├── ComplexTypeWithSimpleContent.xsd │ ├── ComplexTypeWithInclude.xsd │ └── GpxExtensionsv3.xsd │ └── groovy │ └── com │ └── sixrq │ └── kaxb │ ├── main │ └── SchemaGeneratorTest.groovy │ ├── generators │ ├── ClassFileGeneratorTest.groovy │ └── ObjectFactoryGeneratorTest.groovy │ └── parsers │ └── SchemaParsingTests.groovy ├── README.md ├── gradlew.bat ├── gradlew └── LICENCE /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle 2 | /build 3 | /.idea 4 | /generated -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SixRQ/KAXB/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | rootProject.name = 'kaxb' 18 | 19 | rootProject.buildFileName = 'build.gradle.kts' 20 | -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/Include.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | class Include(xmlns: String) : Tag(xmlns) -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/Sequence.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | class Sequence(xmlns: String) : Tag(xmlns) -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/Annotation.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | class Annotation(xmlns: String) : Tag(xmlns) -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/Restriction.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | class Restriction(xmlns: String) : Tag(xmlns) 20 | -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/SimpleContent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | class SimpleContent(xmlns: String) : Tag(xmlns) -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/Schema.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | class Schema(xmlns: String): Tag(xmlns) { 20 | override fun toString(): String{ 21 | return "Schema() ${super.toString()}" 22 | } 23 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 SixRQ Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | distributionBase=GRADLE_USER_HOME 18 | distributionPath=wrapper/dists 19 | zipStoreBase=GRADLE_USER_HOME 20 | zipStorePath=wrapper/dists 21 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-all.zip 22 | -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/generators/Generator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.generators 18 | 19 | import com.sixrq.kaxb.parsers.XmlParser 20 | 21 | open class Generator(filename: String, packageName: String){ 22 | 23 | protected val parser = XmlParser(filename, packageName) 24 | 25 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/Documentation.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | import org.w3c.dom.Node 20 | 21 | class Documentation(xmlns: String) : Tag(xmlns) { 22 | override fun processText(item: Node) { 23 | value = item.nodeValue 24 | } 25 | 26 | override fun toString(): String{ 27 | return "/**\n* ${value.replace("\n", "\n*")}\n*/" 28 | } 29 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Synopsis 2 | 3 | This project is used to generate native Kotlin classes from an xsd schema, similar to the JAXB tool for Java. The project will include a plugin for gradle and Intellij IDEA. 4 | 5 | ## Build Status 6 | 7 | [![TeamCity](https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:OpenSourceProjects_Kaxb_Build)/statusIcon)](https://teamcity.jetbrains.com/project.html?projectId=OpenSourceProjects_Kaxb) 8 | 9 | ## Motivation 10 | 11 | I needed a tool that would generate native Kotlin classes rather than Java classes and then convert to Kotlin. 12 | 13 | ## Installation 14 | 15 | Download the latest [zip](https://teamcity.jetbrains.com/app/rest/builds/buildType:(id:OpenSourceProjects_Kaxb_Build)/artifacts/content/*.zip)/[tar](https://teamcity.jetbrains.com/app/rest/builds/buildType:(id:OpenSourceProjects_Kaxb_Build)/artifacts/content/*.jar) from TeamCity and extract the contents 16 | 17 | ## Running 18 | 19 | Once the archive has been extracted run the **bin/kaxb --P \ --S \ --T \** 20 | 21 | ## Tests 22 | 23 | ## Contributors 24 | 25 | Simon Wiehe 26 | 27 | ## License 28 | 29 | Apache License 2.0 30 | 31 | -------------------------------------------------------------------------------- /src/test/resources/GpxExtensionsv3Include.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | This schema defines the Garmin extensions to be used with the GPX 1.1 schema. 10 | The root elements defined by this schema are intended to be used as child 11 | elements of the "extensions" elements in the GPX 1.1 schema. The GPX 1.1 12 | schema is available at http://www.topografix.com/GPX/1/1/gpx.xsd. 13 | 14 | 15 | 16 | 17 | This type contains a list of categories to which a waypoint has been assigned. 18 | Note that this list may contain categories which do not exist for a particular 19 | application installation. 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/AnyElement.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | class AnyElement(xmlns: String, primitiveTypeMapping: MutableMap) : Element(xmlns, primitiveTypeMapping) { 20 | init { 21 | name = "Any" 22 | type = "Any" 23 | imports = mutableListOf("javax.xml.bind.annotation.XmlAnyElement") 24 | } 25 | 26 | override fun toString(): String { 27 | return " @XmlAnyElement(${processContents} = true)\n" + 28 | " ${getLateinit()}var ${getPropertyName()} : ${getTypeDefinition()}" 29 | } 30 | } -------------------------------------------------------------------------------- /src/test/resources/SimpleType.xsd: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/test/resources/SimpleTypeWithMaxOccurs.xsd: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/Enumeration.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | import java.util.regex.Pattern 20 | 21 | class Enumeration(xmlns: String) : Tag(xmlns) { 22 | override fun toString(): String{ 23 | val enumeration = StringBuilder() 24 | enumeration.append(" @XmlEnumValue(\"${value}\")\n") 25 | enumeration.append(" ${value.split(Pattern.compile("(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A=Z][a-z])")).joinToString("_").toUpperCase()}") 26 | if (value.isNotEmpty()) { 27 | enumeration.append("(\"$value\")") 28 | } 29 | enumeration.append(",") 30 | return enumeration.toString() 31 | } 32 | } -------------------------------------------------------------------------------- /src/test/resources/StandAloneComplexType.xsd: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | 24 | 25 | A sample complex type for testing 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/Attribute.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | class Attribute(xmlns: String, primitiveTypeMapping: MutableMap) : Element(xmlns, primitiveTypeMapping) { 20 | init { 21 | imports = mutableListOf( 22 | "javax.xml.bind.annotation.XmlValue", 23 | "javax.xml.bind.annotation.XmlJavaTypeAdapter") 24 | } 25 | 26 | override fun toString(): String { 27 | return " @XmlValue\n" + 28 | " @XmlJavaTypeAdapter(CollapsedStringAdapter.class)\n" + 29 | "${getSchemaType()}" + 30 | " ${getLateinit()}var ${getPropertyName()} : ${getTypeDefinition()}\n" 31 | } 32 | } -------------------------------------------------------------------------------- /src/test/resources/ComplexTypeWithAny.xsd: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | 24 | 25 | This type provides the ability to extend any data type that includes it. 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/test/resources/QName.xsd: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | A sample complex type for testing 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/test/resources/EnumeratedType.xsd: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | dType 24 | 25 | A sample enumerated type for testing 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/test/resources/ComplexTypeWithSimpleContent.xsd: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | A name/value pair of Stings 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/test/resources/ComplexTypeWithInclude.xsd: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | A sample complex type for testing 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/Extension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | class Extension(xmlns: String, primitiveTypeMapping: MutableMap) : Element(xmlns, primitiveTypeMapping) { 20 | init { 21 | imports= mutableListOf("javax.xml.bind.annotation.XmlValue", 22 | "javax.xml.bind.annotation.XmlJavaTypeAdapter") 23 | name = "value" 24 | } 25 | 26 | override fun toString(): String { 27 | val result = StringBuilder() 28 | result.append(" @XmlValue\n") 29 | result.append(" @XmlJavaTypeAdapter(CollapsedStringAdapter.class)\n") 30 | result.append("${getSchemaType()}") 31 | result.append(" ${getLateinit()}var ${getPropertyName()} : ${getTypeDefinition()}\n") 32 | children.forEach { result.append(it.toString()) } 33 | return result.toString() 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/generators/ClassFileGenerator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.generators 18 | 19 | 20 | import com.sixrq.kaxb.parsers.Element 21 | import java.io.File 22 | 23 | class ClassFileGenerator(filename: String, val packageName: String, val targetDirectory: String) : Generator(filename, packageName) { 24 | 25 | fun generateClasses() { 26 | val outputDirectory = File("${targetDirectory.replace('\\','/')}/${packageName.replace('.', '/')}".replace("//", "/")) 27 | val objectFactoryGenerator = ObjectFactoryGenerator(packageName) 28 | outputDirectory.mkdirs() 29 | parser.generate().forEach { 30 | val targetFile = "$outputDirectory/${it.component1()}.kt" 31 | if (it.component2() is Element) { 32 | objectFactoryGenerator.addQName(it.component2()) 33 | } else { 34 | File(targetFile).printWriter().use { outputFile -> 35 | outputFile.print(it.component2()) 36 | } 37 | objectFactoryGenerator.addObject(it.component1()) 38 | } 39 | } 40 | val objectFactoryFile = "$outputDirectory/ObjectFactory.kt" 41 | File(objectFactoryFile).printWriter().use { outputFile -> 42 | outputFile.print(objectFactoryGenerator.gerenateObjectFactory()) 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/main/SchemaGenerator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.main 18 | 19 | import com.sixrq.kaxb.generators.ClassFileGenerator 20 | import java.lang.System.exit 21 | 22 | class SchemaGenerator { 23 | companion object { 24 | @JvmStatic fun main(args: Array) { 25 | val schemaGenerator = SchemaGenerator() 26 | exit(schemaGenerator.generate(args)) 27 | } 28 | } 29 | 30 | fun generate(args: Array): Int { 31 | val validArgs = listOf("--P", "--S", "--T") 32 | if (args.size != 6 || 33 | !validArgs.containsAll(args.filter { it.startsWith("--") } ) || 34 | !args.filter { it.startsWith("--") }.containsAll(validArgs)) { 35 | println("Usage: SchemaGenerator --P --S --T ") 36 | return 999 37 | } 38 | 39 | var packageName = "" 40 | var schemaLocation = "" 41 | var targetDirectory = "" 42 | 43 | args.forEachIndexed { index, value -> 44 | when { 45 | value.toUpperCase() == "--P" -> packageName = args[index + 1] 46 | value.toUpperCase() == "--S" -> schemaLocation = args[index + 1] 47 | value.toUpperCase() == "--T" -> targetDirectory = args[index + 1] 48 | } 49 | } 50 | 51 | val classFileGenerator = ClassFileGenerator(schemaLocation, packageName, targetDirectory) 52 | classFileGenerator.generateClasses() 53 | 54 | return 0 55 | } 56 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/Element.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | import org.w3c.dom.Node 20 | 21 | open class Element(xmlns: String, val primitiveTypeMapping: MutableMap) : Tag(xmlns) { 22 | init { 23 | imports = mutableListOf("javax.xml.bind.annotation.XmlElement") 24 | } 25 | 26 | override fun processAttributes(item: Node?) { 27 | super.processAttributes(item) 28 | if (getSchemaType().isNotEmpty()) { 29 | imports.add("javax.xml.bind.annotation.XmlSchemaType") 30 | } 31 | } 32 | 33 | override fun toString(): String { 34 | return " @XmlElement(name = \"${name}\", namespace = \"$xmlns\")\n" + 35 | "${getSchemaType()}" + 36 | " ${getLateinit()}var ${getPropertyName()} : ${getTypeDefinition()}" 37 | } 38 | 39 | override fun extractType(): String { 40 | val className = extractClassName(type) 41 | if (primitiveTypeMapping.containsKey(className)) { 42 | return primitiveTypeMapping[className].toString() 43 | } else { 44 | return super.extractType() 45 | } 46 | } 47 | 48 | open fun getTypeDefinition(): String { 49 | if (maxOccurs.isNotBlank()) { 50 | return "MutableList<${extractType()}> = mutableListOf()" 51 | } 52 | return extractType() 53 | } 54 | 55 | open fun getLateinit(): String { 56 | if (maxOccurs.isNotBlank() || primitiveTypeMapping.containsKey(extractClassName(type))) { 57 | return "" 58 | } 59 | return "lateinit " 60 | } 61 | 62 | open fun getSchemaType(): String { 63 | if (maxOccurs.isBlank()) { 64 | when (type.toLowerCase()) { 65 | "xsd:token" -> return " @XmlSchemaType(\"token\")\n" 66 | else -> return "" 67 | } 68 | } 69 | return "" 70 | } 71 | } -------------------------------------------------------------------------------- /src/test/groovy/com/sixrq/kaxb/main/SchemaGeneratorTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.main 18 | 19 | import spock.lang.Specification 20 | 21 | /** 22 | * Created by simon on 13/01/17. 23 | */ 24 | class SchemaGeneratorTest extends Specification { 25 | def "Generate fails with no arguments"() { 26 | given : "A valid SchemaGenerator" 27 | def schemaGenerator = new SchemaGenerator() 28 | 29 | when : "generate is called with no arguments" 30 | def result = schemaGenerator.generate([] as String[]) 31 | 32 | then : "the return code is not zero" 33 | result == 999 34 | } 35 | 36 | def "Generate fails with invalid arguments"() { 37 | given : "A valid SchemaGenerator" 38 | def schemaGenerator = new SchemaGenerator() 39 | 40 | when : "generate is called with no arguments" 41 | def result = schemaGenerator.generate(["--P", "package", "--T", "/tmp", "--X", "dummy"] as String[]) 42 | 43 | then : "the return code is not zero" 44 | result == 999 45 | } 46 | 47 | def "Generate fails with too few arguments"() { 48 | given : "A valid SchemaGenerator" 49 | def schemaGenerator = new SchemaGenerator() 50 | 51 | when : "generate is called with no arguments" 52 | def result = schemaGenerator.generate(["--P", "package", "--T", "/tmp", "--S"] as String[]) 53 | 54 | then : "the return code is not zero" 55 | result == 999 56 | } 57 | 58 | def "Generate succeeds with valid arguments"() { 59 | given : "A valid SchemaGenerator" 60 | def schemaGenerator = new SchemaGenerator() 61 | 62 | when : "generate is called with no arguments" 63 | def targetDirectory = "${System.getProperty("java.io.tmpdir")}/${UUID.randomUUID()}" 64 | def result = schemaGenerator.generate(["--P", "com.example", "--T", targetDirectory, "--S", "StandAloneComplexType.xsd"] as String[]) 65 | 66 | then : "the return code is not zero" 67 | result == 0 68 | (new File(targetDirectory)).deleteDir() 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/SimpleType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | class SimpleType(xmlns: String, val packageName: String) : Tag(xmlns) { 20 | override fun toString(): String{ 21 | if (children.filter { it.children.isNotEmpty() && it.children.filter { it is Enumeration }.isNotEmpty() }.isNotEmpty()) { 22 | return processEnumerationClass() 23 | } 24 | return "" 25 | } 26 | 27 | private fun processEnumerationClass(): String { 28 | val classDef = StringBuilder() 29 | val documentation = StringBuilder() 30 | 31 | children.filter { it is Annotation }.forEach { 32 | it.children.filter{ document -> document is Documentation }. 33 | forEach { comment -> documentation.append("${comment.toString()}\n")} 34 | } 35 | 36 | classDef.append("package $packageName\n\n") 37 | classDef.append("import javax.xml.bind.annotation.XmlEnum\n") 38 | classDef.append("import javax.xml.bind.annotation.XmlEnumValue\n") 39 | classDef.append("import javax.xml.bind.annotation.XmlType\n") 40 | 41 | if(documentation.isNotBlank()) { 42 | classDef.append("\n$documentation\n") 43 | } 44 | classDef.append("\n@XmlType(name = \"$elementName\", namespace = \"$xmlns\")") 45 | classDef.append("\n@XmlEnum") 46 | classDef.append("\nenum class $name(${appendType()}) {\n") 47 | children.filter{ restriction -> restriction is Restriction }.flatMap { it.children.filter { enum -> enum is Enumeration } }.forEach { member -> 48 | classDef.append("$member\n") 49 | } 50 | classDef.setLength(classDef.length-2) 51 | classDef.append(";\n") 52 | 53 | if (appendType().isNotEmpty()) { 54 | classDef.append("\n companion object {\n") 55 | classDef.append(" fun fromValue(${appendType().replace("val ", "")}): $name = $name.values().first { it.value == value }\n") 56 | classDef.append(" }\n") 57 | } 58 | classDef.append("}\n") 59 | return classDef.toString() 60 | 61 | } 62 | 63 | private fun appendType() : String { 64 | val restriction = (children.filter { it is Restriction })[0] as Restriction 65 | if (restriction.type.isNotBlank()) { 66 | return "val value : ${restriction.extractType()} " 67 | } 68 | return "" 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/ComplexType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | class ComplexType(xmlns: String, val packageName: String): Tag(xmlns) { 20 | override fun toString(): String{ 21 | val classDef = StringBuilder() 22 | val documentation = StringBuilder() 23 | val properties : MutableList = mutableListOf() 24 | 25 | children.filter { annotation -> annotation is Annotation }.forEach { 26 | it.children.filter{ document -> document is Documentation }. 27 | forEach { comment -> documentation.append("${comment.toString()}\n")} 28 | } 29 | 30 | properties.addAll(children.filter{ propertyGroup -> propertyGroup is Sequence || propertyGroup is SimpleContent }. 31 | flatMap { it.children.filter { element -> element is Element || element is AnyElement || element is Restriction } }) 32 | classDef.append("package $packageName\n\n") 33 | classDef.append("import javax.xml.bind.annotation.XmlAccessType\n") 34 | classDef.append("import javax.xml.bind.annotation.XmlAccessorType\n") 35 | classDef.append("import javax.xml.bind.annotation.XmlType\n") 36 | 37 | children.filter{ propertyGroup -> propertyGroup is Sequence || propertyGroup is SimpleContent }. 38 | flatMap { it.children.filter { element -> element is Element || element is AnyElement || element is Restriction } }. 39 | flatMap { it.imports }.distinct().forEach { classDef.append( "import $it\n" ) } 40 | 41 | if(documentation.isNotBlank()) { 42 | classDef.append("\n$documentation\n") 43 | } 44 | classDef.append("\n@XmlAccessorType(XmlAccessType.FIELD)\n") 45 | classDef.append("@XmlType(name = \"$elementName\", namespace = \"$xmlns\", propOrder = arrayOf(\n") 46 | properties.forEach { property -> 47 | classDef.append(" \"${property.getPropertyName()}\",\n") 48 | } 49 | classDef.setLength(classDef.length-2) 50 | classDef.append("\n))") 51 | classDef.append("\nclass $name ${appendType()}{\n") 52 | properties.forEach { property -> 53 | classDef.append("$property\n") 54 | } 55 | classDef.append("}\n") 56 | return classDef.toString() 57 | } 58 | 59 | private fun appendType() : String { 60 | if (type.isNotBlank()) { 61 | return ": $type " 62 | } 63 | return "" 64 | } 65 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/Tag.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | import org.w3c.dom.Node 20 | 21 | open class Tag(val xmlns: String) { 22 | var name: String = "" 23 | var elementName = "" 24 | var type: String = "" 25 | var minOccurs: String = "" 26 | var maxOccurs: String = "" 27 | var value: String = "" 28 | var processContents: String = "" 29 | var base: String = "" 30 | var schemaLocation: String = "" 31 | var imports: MutableList = mutableListOf() 32 | var includes: MutableList = mutableListOf() 33 | 34 | val children: MutableList = mutableListOf() 35 | 36 | open fun processAttributes(item: Node?) { 37 | if (item!!.attributes.getNamedItem("name") != null) { 38 | name = extractClassName(item.attributes.getNamedItem("name").nodeValue) 39 | elementName = item.attributes.getNamedItem("name").nodeValue 40 | } 41 | if (item.attributes.getNamedItem("type") != null) { 42 | type = extractClassName(item.attributes.getNamedItem("type").nodeValue) 43 | } else if (item.attributes.getNamedItem("base") != null) { 44 | type = extractClassName(item.attributes.getNamedItem("base").nodeValue) 45 | } 46 | if (item.attributes.getNamedItem("minOccurs") != null) { 47 | minOccurs = item.attributes.getNamedItem("minOccurs").nodeValue 48 | } 49 | if (item.attributes.getNamedItem("maxOccurs") != null) { 50 | maxOccurs = item.attributes.getNamedItem("maxOccurs").nodeValue 51 | } 52 | if (item.attributes.getNamedItem("value") != null) { 53 | value = item.attributes.getNamedItem("value").nodeValue 54 | } 55 | if (item.attributes.getNamedItem("processContents") != null) { 56 | processContents = item.attributes.getNamedItem("processContents").nodeValue 57 | } 58 | if (item.attributes.getNamedItem("base") != null) { 59 | base = item.attributes.getNamedItem("base").nodeValue 60 | } 61 | if (item.attributes.getNamedItem("schemaLocation") != null) { 62 | schemaLocation = item.attributes.getNamedItem("schemaLocation").nodeValue 63 | } 64 | } 65 | 66 | fun getPropertyName() = name.replaceFirst(name[0], name[0].toLowerCase()) 67 | 68 | fun extractClassName(name: String): String { 69 | val className = StringBuilder() 70 | name.split('_').forEach { 71 | className.append(it.capitalize()) 72 | } 73 | return className.toString() 74 | } 75 | 76 | open fun processText(item: Node) {} 77 | 78 | open fun extractType() : String { 79 | when (type.toLowerCase()) { 80 | "xsd:string" -> return "String" 81 | "xsd:token" -> return "String" 82 | "xsd:decimal" -> return "BigDecimal" 83 | "xsd:double" -> return "Double" 84 | "xsd:hexbinary" -> return "ByteArray" 85 | "xsd:boolean" -> return "Boolean" 86 | "xsd:any" -> return "Any" 87 | else -> return extractClassName(type) 88 | } 89 | } 90 | 91 | override fun toString(): String{ 92 | return "$children" 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/generators/ObjectFactoryGenerator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.generators 18 | 19 | import com.sixrq.kaxb.parsers.Tag 20 | 21 | class ObjectFactoryGenerator(val packageName: String) { 22 | val classNames: MutableList = mutableListOf() 23 | val qNames: MutableList = mutableListOf() 24 | 25 | fun addObject(className: String) { 26 | classNames.add(className) 27 | } 28 | 29 | fun addQName(qname: Tag) { 30 | qNames.add(qname) 31 | } 32 | 33 | fun gerenateObjectFactory(): String { 34 | val builder = StringBuilder() 35 | builder.append("package $packageName\n\n") 36 | builder.append("import javax.xml.bind.JAXBElement\n") 37 | builder.append("import javax.xml.bind.annotation.XmlElementDecl\n") 38 | builder.append("import javax.xml.bind.annotation.XmlRegistry\n") 39 | builder.append("import javax.xml.namespace.QName\n\n") 40 | 41 | builder.append("/**\n") 42 | builder.append(" * This object contains factory methods for each\n") 43 | builder.append(" * Kotlin content interface and Kotlin element interface\n") 44 | builder.append(" * generated in the $packageName package.\n") 45 | builder.append(" *

An ObjectFactory allows you to programatically\n") 46 | builder.append(" * construct new instances of the Kotlin representation\n") 47 | builder.append(" * for XML content. The Kotlin representation of XML\n") 48 | builder.append(" * content can consist of schema derived interfaces\n") 49 | builder.append(" * and classes representing the binding of schema\n") 50 | builder.append(" * type definitions, element declarations and model\n") 51 | builder.append(" * groups. Factory methods for each of these are\n") 52 | builder.append(" * provided in this class.\n") 53 | builder.append(" *\n") 54 | builder.append(" */\n\n") 55 | 56 | builder.append("@XmlRegistry\n") 57 | builder.append("class ObjectFactory {\n\n") 58 | qNames.forEach { qname -> 59 | builder.append(" private val _${qname.elementName}_QNAME = QName(\"${qname.xmlns}\", \"${qname.elementName}\")\n") 60 | } 61 | builder.append("\n") 62 | classNames.forEach { className -> 63 | builder.append(" /**\n") 64 | builder.append(" * Create an instance of {@link $className }\n") 65 | builder.append(" *\n") 66 | builder.append(" */\n") 67 | builder.append(" fun create$className: $className { return $className() }\n\n") 68 | } 69 | qNames.forEach { qname -> 70 | builder.append(" /**\n") 71 | builder.append(" * Create an instance of {@link JAXBElement }{@code <}{@link ${qname.elementName} }{@code >}}\n") 72 | builder.append(" *\n") 73 | builder.append(" */\n") 74 | builder.append(" @XmlElementDecl(namespace = \"${qname.xmlns}\", name = \"${qname.elementName}\")\n") 75 | builder.append(" public JAXBElement<${qname.type}> create${qname.elementName}(${qname.type} value) {\n") 76 | builder.append(" return new JAXBElement<${qname.type}>(_${qname.elementName}_QNAME, ${qname.type}.class, null, value);\n") 77 | builder.append(" }\n\n") 78 | } 79 | builder.append("\n}\n") 80 | return builder.toString() 81 | } 82 | } -------------------------------------------------------------------------------- /src/test/groovy/com/sixrq/kaxb/generators/ClassFileGeneratorTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.generators 18 | 19 | import spock.lang.Specification 20 | 21 | import static groovy.io.FileType.FILES 22 | 23 | class ClassFileGeneratorTest extends Specification { 24 | 25 | def "I can parse an xml document and generate class files"() { 26 | given: "a ClassFileGenerator" 27 | def uuid = UUID.randomUUID() 28 | def targetDirectory = "${System.getProperty("java.io.tmpdir")}/{$uuid}/kaxb/generated" 29 | def generator = new ClassFileGenerator("StandAloneComplexType.xsd", "com.example", targetDirectory) 30 | 31 | when: "the files are generated" 32 | generator.generateClasses() 33 | 34 | then: "the correct files exist" 35 | def directory = new File("${targetDirectory}/com/example") 36 | def files = [] 37 | directory.traverse(type: FILES, maxDepth: 0) { files.add(it.getProperties()["name"]) } 38 | files.size() == 2 39 | files.contains("ObjectFactory.kt") 40 | files.contains("StandAloneComplexType.kt") 41 | expectedStandAloneComplexType == new File("${targetDirectory}/com/example/StandAloneComplexType.kt").text 42 | expectedSingleClassObjectFactory == new File("${targetDirectory}/com/example/ObjectFactory.kt").text 43 | (new File("${System.getProperty("java.io.tmpdir")}/{$uuid}")).deleteDir() 44 | } 45 | 46 | def expectedStandAloneComplexType = "package com.example\n" + 47 | "\n" + 48 | "import javax.xml.bind.annotation.XmlAccessType\n" + 49 | "import javax.xml.bind.annotation.XmlAccessorType\n" + 50 | "import javax.xml.bind.annotation.XmlType\n" + 51 | "import javax.xml.bind.annotation.XmlElement\n" + 52 | "import javax.xml.bind.annotation.XmlSchemaType\n" + 53 | "\n" + 54 | "/**\n" + 55 | "* \n" + 56 | "* A sample complex type for testing\n" + 57 | "* \n" + 58 | "*/\n" + 59 | "\n" + 60 | "\n" + 61 | "@XmlAccessorType(XmlAccessType.FIELD)\n" + 62 | "@XmlType(name = \"StandAloneComplexType\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\", propOrder = arrayOf(\n" + 63 | " \"stringToken\"\n" + 64 | "))\n" + 65 | "class StandAloneComplexType {\n" + 66 | " @XmlElement(name = \"StringToken\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\")\n" + 67 | " @XmlSchemaType(\"token\")\n" + 68 | " lateinit var stringToken : String\n" + 69 | "}\n" 70 | 71 | def expectedSingleClassObjectFactory = "package com.example\n" + 72 | "\n" + 73 | "import javax.xml.bind.JAXBElement\n" + 74 | "import javax.xml.bind.annotation.XmlElementDecl\n" + 75 | "import javax.xml.bind.annotation.XmlRegistry\n" + 76 | "import javax.xml.namespace.QName\n" + 77 | "\n" + 78 | "/**\n" + 79 | " * This object contains factory methods for each\n" + 80 | " * Kotlin content interface and Kotlin element interface\n" + 81 | " * generated in the com.example package.\n" + 82 | " *

An ObjectFactory allows you to programatically\n" + 83 | " * construct new instances of the Kotlin representation\n" + 84 | " * for XML content. The Kotlin representation of XML\n" + 85 | " * content can consist of schema derived interfaces\n" + 86 | " * and classes representing the binding of schema\n" + 87 | " * type definitions, element declarations and model\n" + 88 | " * groups. Factory methods for each of these are\n" + 89 | " * provided in this class.\n" + 90 | " *\n" + 91 | " */\n" + 92 | "\n" + 93 | "@XmlRegistry\n" + 94 | "class ObjectFactory {\n" + 95 | "\n" + 96 | "\n" + 97 | " /**\n" + 98 | " * Create an instance of {@link StandAloneComplexType }\n" + 99 | " *\n" + 100 | " */\n" + 101 | " fun createStandAloneComplexType: StandAloneComplexType { return StandAloneComplexType() }\n" + 102 | "\n" + 103 | "\n" + 104 | "}\n" 105 | } 106 | -------------------------------------------------------------------------------- /src/main/kotlin/com/sixrq/kaxb/parsers/XmlParser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | import org.w3c.dom.Element 20 | import org.w3c.dom.Node 21 | import org.w3c.dom.NodeList 22 | import java.io.File 23 | import javax.xml.parsers.DocumentBuilderFactory 24 | 25 | class XmlParser(val filename: String, val packageName: String) { 26 | val root: Element by lazy { 27 | val resource = ClassLoader.getSystemClassLoader().getResource(filename) 28 | val xmlFile = if (resource == null) File(filename) else File(resource.toURI().schemeSpecificPart) 29 | val dbFactory = DocumentBuilderFactory.newInstance() 30 | val dBuilder = dbFactory.newDocumentBuilder() 31 | dBuilder.parse(xmlFile).documentElement 32 | } 33 | val xmlns: String by lazy { root.getAttribute("xmlns") } 34 | val primitiveTypeMapping: MutableMap = hashMapOf() 35 | 36 | 37 | fun generate() : Map { 38 | val elements = root.childNodes 39 | val schema = Schema(xmlns) 40 | val classes: MutableMap = hashMapOf() 41 | processElements(schema, elements) 42 | 43 | schema.includes.forEach { 44 | val xmlParser = XmlParser(it, packageName) 45 | classes.putAll(xmlParser.generate()) 46 | } 47 | primitiveTypeMapping.putAll(extractBasicTypes(schema)) 48 | classes.putAll(extractEnumerations(schema)) 49 | classes.putAll(extractClasses(schema)) 50 | classes.putAll(extractQNames(schema)) 51 | 52 | return classes 53 | } 54 | 55 | private fun extractEnumerations(schema: Schema) : Map { 56 | val enumerations: MutableMap = hashMapOf() 57 | schema.children.filter { 58 | it is SimpleType && 59 | it.children.filter { 60 | it is Restriction && 61 | it.children.filter { it is Enumeration }.isNotEmpty() 62 | }.isNotEmpty() 63 | }.forEach { 64 | enumerations.put(it.name, it) 65 | } 66 | return enumerations 67 | } 68 | 69 | private fun extractQNames(schema: Schema) : Map { 70 | val qNames: MutableMap = hashMapOf() 71 | schema.children.filter { it is com.sixrq.kaxb.parsers.Element }.forEach { 72 | qNames.put(it.name, it) 73 | } 74 | return qNames 75 | } 76 | 77 | private fun extractClasses(schema: Schema) : Map { 78 | val classes: MutableMap = hashMapOf() 79 | schema.children.filter { it is ComplexType }.forEach { 80 | classes.put(it.name, it) 81 | } 82 | return classes 83 | } 84 | 85 | private fun extractBasicTypes(schema: Schema) : Map { 86 | val basicTypes: MutableMap = hashMapOf() 87 | schema.children.filter { it is SimpleType && 88 | it.children.filter { it is Restriction && 89 | it.children.filter { it is Enumeration }.isEmpty()}.isNotEmpty()}.forEach { 90 | basicTypes.put(it.name, (it.children.filter { it is Restriction }[0] as Restriction).extractType()) 91 | } 92 | return basicTypes 93 | } 94 | 95 | private fun processElements(tag: Tag, elements: NodeList) { 96 | for (index in 0..(elements.length - 1)) { 97 | val item = elements.item(index) 98 | val childTag = { 99 | when (item.nodeName) { 100 | "xsd:complexType" -> ComplexType(xmlns, packageName) 101 | "xsd:simpleType" -> SimpleType(xmlns, packageName) 102 | "xsd:element" -> Element(xmlns, primitiveTypeMapping) 103 | "xsd:any" -> AnyElement(xmlns, primitiveTypeMapping) 104 | "xsd:extension" -> Extension(xmlns, primitiveTypeMapping) 105 | "xsd:annotation" -> Annotation(xmlns) 106 | "xsd:documentation" -> Documentation(xmlns) 107 | "xsd:sequence" -> Sequence(xmlns) 108 | "xsd:restriction" -> Restriction(xmlns) 109 | "xsd:enumeration" -> Enumeration(xmlns) 110 | "xsd:simpleContent" -> SimpleContent(xmlns) 111 | "xsd:attribute" -> Attribute(xmlns, primitiveTypeMapping) 112 | "xsd:include" -> Include(xmlns) 113 | else -> Tag(xmlns) 114 | } 115 | }.invoke() 116 | if (item.hasAttributes() || item.hasChildNodes()) { 117 | childTag.processAttributes(item) 118 | processElements(childTag, item.childNodes) 119 | if (childTag is Include) { 120 | tag.includes.add(childTag.schemaLocation) 121 | } else { 122 | tag.children.add(childTag) 123 | } 124 | } 125 | if (item.nodeType == Node.TEXT_NODE) { 126 | tag.processText(item) 127 | } 128 | } 129 | } 130 | } -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 165 | if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then 166 | cd "$(dirname "$0")" 167 | fi 168 | 169 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 170 | 171 | -------------------------------------------------------------------------------- /src/test/groovy/com/sixrq/kaxb/generators/ObjectFactoryGeneratorTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.generators 18 | 19 | import com.sixrq.kaxb.parsers.XmlParser 20 | import spock.lang.Specification 21 | 22 | class ObjectFactoryGeneratorTest extends Specification { 23 | def "An ObjectFactory is correctly generated for a single class"() { 24 | given: "a parsed schema with a single class and an ObjectFactoryGenerator" 25 | def parser = new XmlParser("StandAloneComplexType.xsd", "com.example") 26 | def classes = parser.generate() 27 | def objectFactoryGenerator = new ObjectFactoryGenerator("com.example") 28 | objectFactoryGenerator.addObject(classes.keySet()[0]) 29 | 30 | when: "the ObjectFactory is generated" 31 | def objectFactory = objectFactoryGenerator.gerenateObjectFactory() 32 | 33 | then: "the ObjectFactory is correctly formed" 34 | objectFactory == expectedSingleClassObjectFactory 35 | } 36 | 37 | def "An ObjectFactory is correctly generated for a single class and QName"() { 38 | given: "a parsed schema with a single class and an ObjectFactoryGenerator" 39 | def parser = new XmlParser("QName.xsd", "com.example") 40 | def classes = parser.generate() 41 | def objectFactoryGenerator = new ObjectFactoryGenerator("com.example") 42 | objectFactoryGenerator.addObject(classes.keySet()[0]) 43 | objectFactoryGenerator.addQName(classes.values()[1]) 44 | 45 | when: "the ObjectFactory is generated" 46 | def objectFactory = objectFactoryGenerator.gerenateObjectFactory() 47 | 48 | then: "the ObjectFactory is correctly formed" 49 | objectFactory == expectedQNameObjectFactory 50 | } 51 | 52 | def expectedQNameObjectFactory = "package com.example\n" + 53 | "\n" + 54 | "import javax.xml.bind.JAXBElement\n" + 55 | "import javax.xml.bind.annotation.XmlElementDecl\n" + 56 | "import javax.xml.bind.annotation.XmlRegistry\n" + 57 | "import javax.xml.namespace.QName\n" + 58 | "\n" + 59 | "/**\n" + 60 | " * This object contains factory methods for each\n" + 61 | " * Kotlin content interface and Kotlin element interface\n" + 62 | " * generated in the com.example package.\n" + 63 | " *

An ObjectFactory allows you to programatically\n" + 64 | " * construct new instances of the Kotlin representation\n" + 65 | " * for XML content. The Kotlin representation of XML\n" + 66 | " * content can consist of schema derived interfaces\n" + 67 | " * and classes representing the binding of schema\n" + 68 | " * type definitions, element declarations and model\n" + 69 | " * groups. Factory methods for each of these are\n" + 70 | " * provided in this class.\n" + 71 | " *\n" + 72 | " */\n" + 73 | "\n" + 74 | "@XmlRegistry\n" + 75 | "class ObjectFactory {\n" + 76 | "\n" + 77 | " private val _QNameEntry_QNAME = QName(\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\", \"QNameEntry\")\n" + 78 | "\n" + 79 | " /**\n" + 80 | " * Create an instance of {@link StandAloneComplexType }\n" + 81 | " *\n" + 82 | " */\n" + 83 | " fun createStandAloneComplexType: StandAloneComplexType { return StandAloneComplexType() }\n" + 84 | "\n" + 85 | " /**\n" + 86 | " * Create an instance of {@link JAXBElement }{@code <}{@link QNameEntry }{@code >}}\n" + 87 | " *\n" + 88 | " */\n" + 89 | " @XmlElementDecl(namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\", name = \"QNameEntry\")\n" + 90 | " public JAXBElement createQNameEntry(StandAloneComplexType value) {\n" + 91 | " return new JAXBElement(_QNameEntry_QNAME, StandAloneComplexType.class, null, value);\n" + 92 | " }\n" + 93 | "\n" + 94 | "\n" + 95 | "}\n" 96 | 97 | def expectedSingleClassObjectFactory = "package com.example\n" + 98 | "\n" + 99 | "import javax.xml.bind.JAXBElement\n" + 100 | "import javax.xml.bind.annotation.XmlElementDecl\n" + 101 | "import javax.xml.bind.annotation.XmlRegistry\n" + 102 | "import javax.xml.namespace.QName\n" + 103 | "\n" + 104 | "/**\n" + 105 | " * This object contains factory methods for each\n" + 106 | " * Kotlin content interface and Kotlin element interface\n" + 107 | " * generated in the com.example package.\n" + 108 | " *

An ObjectFactory allows you to programatically\n" + 109 | " * construct new instances of the Kotlin representation\n" + 110 | " * for XML content. The Kotlin representation of XML\n" + 111 | " * content can consist of schema derived interfaces\n" + 112 | " * and classes representing the binding of schema\n" + 113 | " * type definitions, element declarations and model\n" + 114 | " * groups. Factory methods for each of these are\n" + 115 | " * provided in this class.\n" + 116 | " *\n" + 117 | " */\n" + 118 | "\n" + 119 | "@XmlRegistry\n" + 120 | "class ObjectFactory {\n" + 121 | "\n" + 122 | "\n" + 123 | " /**\n" + 124 | " * Create an instance of {@link StandAloneComplexType }\n" + 125 | " *\n" + 126 | " */\n" + 127 | " fun createStandAloneComplexType: StandAloneComplexType { return StandAloneComplexType() }\n" + 128 | "\n" + 129 | "\n" + 130 | "}\n" 131 | } 132 | -------------------------------------------------------------------------------- /src/test/resources/GpxExtensionsv3.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | This schema defines the Garmin extensions to be used with the GPX 1.1 schema. 12 | The root elements defined by this schema are intended to be used as child 13 | elements of the "extensions" elements in the GPX 1.1 schema. The GPX 1.1 14 | schema is available at http://www.topografix.com/GPX/1/1/gpx.xsd. 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | This type contains data fields available in Garmin GDB waypoints that cannot 30 | be represented in waypoints in GPX 1.1 instances. 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | Category provides the ability to specify the type of a 61 | phone number. For example, a phone number can be categorized as 62 | "Home", "Work", "Mobile" e.t.c 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | This type contains data fields available in Garmin GDB routes that cannot 72 | be represented in routes in GPX 1.1 instances. 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | This type contains data fields available in Garmin GDB routes that cannot 84 | be represented in routes in GPX 1.1 instances. 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | This type contains data fields available in Garmin GDB tracks that cannot 96 | be represented in routes in GPX 1.1 instances. 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | This type contains data fields available in Garmin GDB track points that cannot 107 | be represented in track points in GPX 1.1 instances. 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | This type contains a temperature value measured in degrees Celsius. 119 | 120 | 121 | 122 | 123 | 124 | 125 | This type contains a distance value measured in meters. 126 | 127 | 128 | 129 | 130 | 131 | 132 | This type contains a string that specifies how a waypoint should be 133 | displayed on a map. 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | The latitude of the point. Decimal degrees, WGS84 datum. 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | The longitude of the point. Decimal degrees, WGS84 datum. 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | This type provides the ability to extend any data type that includes it. 201 | 202 | 203 | 204 | 205 | 206 | 207 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /src/test/groovy/com/sixrq/kaxb/parsers/SchemaParsingTests.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 SixRQ Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sixrq.kaxb.parsers 18 | 19 | import spock.lang.Specification 20 | 21 | class SchemaParsingTests extends Specification { 22 | def "A Complex Type with a String field correctly generates a class"() { 23 | given: "A schema file with a single complex type containing a token type" 24 | def parser = new XmlParser("StandAloneComplexType.xsd", "com.example") 25 | 26 | when: "the classes are generated" 27 | def classes = parser.generate() 28 | 29 | then: "the class is correctly generated" 30 | classes.get("StandAloneComplexType").toString() == expectedStandAloneComplexType 31 | } 32 | 33 | def "A Complex Type with a String field and QName correctly generates a class"() { 34 | given: "A schema file with a single complex type containing a token type" 35 | def parser = new XmlParser("QName.xsd", "com.example") 36 | 37 | when: "the classes are generated" 38 | def classes = parser.generate() 39 | 40 | then: "the class is correctly generated" 41 | classes.get("StandAloneComplexType").toString() == expectedStandAloneComplexType 42 | classes.get("QNameEntry").toString() == expectedQNameEntry 43 | } 44 | 45 | def "A Complex Type with Simple Type elements correctly generates a class"() { 46 | given: "A schema file with a single complex type containing a simple type" 47 | def parser = new XmlParser("SimpleType.xsd", "com.example") 48 | 49 | when: "the classes are generated" 50 | def classes = parser.generate() 51 | 52 | then: "the class is correctly generated" 53 | classes.get("ComplexType").toString() == expectedSimpleType 54 | } 55 | 56 | def "A Complex Type with Simple Type collection elements correctly generates a class"() { 57 | given: "A schema file with a single complex type containing a simple type" 58 | def parser = new XmlParser("SimpleTypeWithMaxOccurs.xsd", "com.example") 59 | 60 | when: "the classes are generated" 61 | def classes = parser.generate() 62 | 63 | then: "the class is correctly generated" 64 | classes.get("ComplexType").toString() == expectedSimpleTypeWithMaxOccurs 65 | } 66 | 67 | def "A Complex Type with an include and element of included type correctly generates a class"() { 68 | given: "A schema file with a single complex type containing a simple type" 69 | def parser = new XmlParser("ComplexTypeWithInclude.xsd", "com.example") 70 | 71 | when: "the classes are generated" 72 | def classes = parser.generate() 73 | 74 | then: "the class is correctly generated" 75 | classes.get("StandAloneComplexType").toString() == expectedStandAloneComplexType 76 | classes.get("IncludeComplexType").toString() == expectedIncludeComplexType 77 | } 78 | 79 | def "A Simple Enumerated Type correctly generates an enum"() { 80 | given: "A schema file with an enumerated simple type" 81 | def parser = new XmlParser("EnumeratedType.xsd", "com.example") 82 | 83 | when: "the classes are generated" 84 | def classes = parser.generate() 85 | 86 | then: "the class is correctly generated" 87 | classes.get("Enumeration").toString() == expectedEnumType 88 | } 89 | 90 | def "A Complex Type with an Any tag correctly generates an enum"() { 91 | given: "A schema file with an enumerated simple type" 92 | def parser = new XmlParser("ComplexTypeWithAny.xsd", "com.example") 93 | 94 | when: "the classes are generated" 95 | def classes = parser.generate() 96 | 97 | then: "the class is correctly generated" 98 | classes.get("AnyType").toString() == expectedAnyType 99 | } 100 | 101 | def "A Complex Type with SimpleContent correctly generates an class"() { 102 | given: "A schema file with an enumerated simple type" 103 | def parser = new XmlParser("ComplexTypeWithSimpleContent.xsd", "com.example") 104 | 105 | when: "the classes are generated" 106 | def classes = parser.generate() 107 | 108 | then: "the class is correctly generated" 109 | classes.get("Pair").toString() == expectedSimpleContent 110 | } 111 | 112 | 113 | 114 | def expectedAnyType = "package com.example\n" + 115 | "\n" + 116 | "import javax.xml.bind.annotation.XmlAccessType\n" + 117 | "import javax.xml.bind.annotation.XmlAccessorType\n" + 118 | "import javax.xml.bind.annotation.XmlType\n" + 119 | "import javax.xml.bind.annotation.XmlAnyElement\n" + 120 | "\n" + 121 | "/**\n" + 122 | "* This type provides the ability to extend any data type that includes it.\n" + 123 | "*/\n" + 124 | "\n" + 125 | "\n" + 126 | "@XmlAccessorType(XmlAccessType.FIELD)\n" + 127 | "@XmlType(name = \"AnyType\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\", propOrder = arrayOf(\n" + 128 | " \"any\"\n" + 129 | "))\n" + 130 | "class AnyType {\n" + 131 | " @XmlAnyElement(lax = true)\n" + 132 | " var any : MutableList = mutableListOf()\n" + 133 | "}\n" 134 | 135 | def expectedSimpleContent = "package com.example\n" + 136 | "\n" + 137 | "import javax.xml.bind.annotation.XmlAccessType\n" + 138 | "import javax.xml.bind.annotation.XmlAccessorType\n" + 139 | "import javax.xml.bind.annotation.XmlType\n" + 140 | "import javax.xml.bind.annotation.XmlValue\n" + 141 | "import javax.xml.bind.annotation.XmlJavaTypeAdapter\n" + 142 | "import javax.xml.bind.annotation.XmlSchemaType\n" + 143 | "\n" + 144 | "@XmlAccessorType(XmlAccessType.FIELD)\n" + 145 | "@XmlType(name = \"Pair\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\", propOrder = arrayOf(\n" + 146 | " \"value\"\n" + 147 | "))\n" + 148 | "class Pair {\n" + 149 | " @XmlValue\n" + 150 | " @XmlJavaTypeAdapter(CollapsedStringAdapter.class)\n" + 151 | " @XmlSchemaType(\"token\")\n" + 152 | " lateinit var value : String\n" + 153 | " @XmlValue\n" + 154 | " @XmlJavaTypeAdapter(CollapsedStringAdapter.class)\n" + 155 | " @XmlSchemaType(\"token\")\n" + 156 | " lateinit var name : String\n" + 157 | "\n" + 158 | "}\n" 159 | 160 | def expectedIncludeComplexType = "package com.example\n" + 161 | "\n" + 162 | "import javax.xml.bind.annotation.XmlAccessType\n" + 163 | "import javax.xml.bind.annotation.XmlAccessorType\n" + 164 | "import javax.xml.bind.annotation.XmlType\n" + 165 | "import javax.xml.bind.annotation.XmlElement\n" + 166 | "import javax.xml.bind.annotation.XmlSchemaType\n" + 167 | "\n" + 168 | "/**\n" + 169 | "* \n" + 170 | "* A sample complex type for testing\n" + 171 | "* \n" + 172 | "*/\n" + 173 | "\n" + 174 | "\n" + 175 | "@XmlAccessorType(XmlAccessType.FIELD)\n" + 176 | "@XmlType(name = \"IncludeComplexType\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\", propOrder = arrayOf(\n" + 177 | " \"stringToken\",\n" + 178 | " \"standAloneComplexType\"\n" + 179 | "))\n" + 180 | "class IncludeComplexType {\n" + 181 | " @XmlElement(name = \"StringToken\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\")\n" + 182 | " @XmlSchemaType(\"token\")\n" + 183 | " lateinit var stringToken : String\n" + 184 | " @XmlElement(name = \"StandAloneComplexType\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\")\n" + 185 | " lateinit var standAloneComplexType : StandAloneComplexType\n" + 186 | "}\n" 187 | 188 | def expectedEnumType = "package com.example\n" + 189 | "\n" + 190 | "import javax.xml.bind.annotation.XmlEnum\n" + 191 | "import javax.xml.bind.annotation.XmlEnumValue\n" + 192 | "import javax.xml.bind.annotation.XmlType\n" + 193 | "\n" + 194 | "/**\n" + 195 | "* \n" + 196 | "* A sample enumerated type for testing\n" + 197 | "* \n" + 198 | "*/\n" + 199 | "\n" + 200 | "\n" + 201 | "@XmlType(name = \"Enumeration\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\")\n" + 202 | "@XmlEnum\n" + 203 | "enum class Enumeration(val value : String ) {\n" + 204 | " @XmlEnumValue(\"Enum1\")\n" + 205 | " ENUM1(\"Enum1\"),\n" + 206 | " @XmlEnumValue(\"Enum2\")\n" + 207 | " ENUM2(\"Enum2\"),\n" + 208 | " @XmlEnumValue(\"Enum3\")\n" + 209 | " ENUM3(\"Enum3\");\n" + 210 | "\n" + 211 | " companion object {\n" + 212 | " fun fromValue(value : String ): Enumeration = Enumeration.values().first { it.value == value }\n" + 213 | " }\n" + 214 | "}\n" 215 | 216 | def expectedSimpleTypeWithMaxOccurs = "package com.example\n" + 217 | "\n" + 218 | "import javax.xml.bind.annotation.XmlAccessType\n" + 219 | "import javax.xml.bind.annotation.XmlAccessorType\n" + 220 | "import javax.xml.bind.annotation.XmlType\n" + 221 | "import javax.xml.bind.annotation.XmlElement\n" + 222 | "\n" + 223 | "@XmlAccessorType(XmlAccessType.FIELD)\n" + 224 | "@XmlType(name = \"ComplexType\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\", propOrder = arrayOf(\n" + 225 | " \"simpleDouble\"\n" + 226 | "))\n" + 227 | "class ComplexType {\n" + 228 | " @XmlElement(name = \"SimpleDouble\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\")\n" + 229 | " var simpleDouble : MutableList = mutableListOf()\n" + 230 | "}\n" 231 | 232 | def expectedSimpleType = "package com.example\n" + 233 | "\n" + 234 | "import javax.xml.bind.annotation.XmlAccessType\n" + 235 | "import javax.xml.bind.annotation.XmlAccessorType\n" + 236 | "import javax.xml.bind.annotation.XmlType\n" + 237 | "import javax.xml.bind.annotation.XmlElement\n" + 238 | "\n" + 239 | "@XmlAccessorType(XmlAccessType.FIELD)\n" + 240 | "@XmlType(name = \"ComplexType\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\", propOrder = arrayOf(\n" + 241 | " \"simpleDouble\"\n" + 242 | "))\n" + 243 | "class ComplexType {\n" + 244 | " @XmlElement(name = \"SimpleDouble\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\")\n" + 245 | " var simpleDouble : Double\n" + 246 | "}\n" 247 | 248 | def expectedStandAloneComplexType = "package com.example\n" + 249 | "\n" + 250 | "import javax.xml.bind.annotation.XmlAccessType\n" + 251 | "import javax.xml.bind.annotation.XmlAccessorType\n" + 252 | "import javax.xml.bind.annotation.XmlType\n" + 253 | "import javax.xml.bind.annotation.XmlElement\n" + 254 | "import javax.xml.bind.annotation.XmlSchemaType\n" + 255 | "\n" + 256 | "/**\n" + 257 | "* \n" + 258 | "* A sample complex type for testing\n" + 259 | "* \n" + 260 | "*/\n" + 261 | "\n" + 262 | "\n" + 263 | "@XmlAccessorType(XmlAccessType.FIELD)\n" + 264 | "@XmlType(name = \"StandAloneComplexType\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\", propOrder = arrayOf(\n" + 265 | " \"stringToken\"\n" + 266 | "))\n" + 267 | "class StandAloneComplexType {\n" + 268 | " @XmlElement(name = \"StringToken\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\")\n" + 269 | " @XmlSchemaType(\"token\")\n" + 270 | " lateinit var stringToken : String\n" + 271 | "}\n" 272 | 273 | def expectedQNameEntry = " @XmlElement(name = \"QNameEntry\", namespace = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\")\n" + 274 | " lateinit var qNameEntry : StandAloneComplexType" 275 | } --------------------------------------------------------------------------------