Kotlin enum クラスの XML スキーマ ファイルをいくつか使用したいと思います。
xml スキーマからクラスを生成すると、次のような出力が得られます。
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for LogLevelType.
*
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* <simpleType name="LogLevelType">
* <restriction base="{http://www.w3.org/2001/XMLSchema}string">
* <enumeration value="ERROR"/>
* <enumeration value="WARNING"/>
* <enumeration value="INFO"/>
* <enumeration value="DEBUG"/>
* </restriction>
* </simpleType>
* </pre>
*
*/
@XmlType(name = "LogLevelType", namespace = "http://www.brabantia.com/XMLSchema/Logging")
@XmlEnum
public enum LogLevelType {
ERROR,
WARNING,
INFO,
DEBUG;
public String value() {
return name();
}
public static LogLevelType fromValue(String v) {
return valueOf(v);
}
}
そのため、列挙型クラスを作成して同じ注釈を追加すると、逆に同じことができると考えました。
import javax.xml.bind.annotation.XmlEnum
import javax.xml.bind.annotation.XmlType
@XmlType(name = "ErrorCategoryType", namespace = "http://www.brabantia.com/XMLSchema/Enum")
@XmlEnum
enum class ErrorCategoryType {
FUNCTIONAL,
TECHNICAL;
fun value(): String = name
fun fromValue(v: String) = valueOf(v)
}
私のpomファイルには、次の構成があります。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/jaxb</outputDirectory>
<!-- The package of your generated sources -->
<packageName>com.brabantia.common.schema</packageName>
<sources>
<source>${project.basedir}/src/main/resources/BrabantiaMain.xsd</source>
</sources>
</configuration>
</execution>
<execution>
<id>schemagen</id>
<goals>
<goal>schemagen</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/src/main/resources/Generated</outputDirectory>
<sources>
<source>${project.basedir}/src/main/kotlin/com/brabantia/common/xmlschemas/enums</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Java クラスは xjc を使用して生成されますが、schemagen を使用して xml スキーマを生成しようとすると、次のエラーが表示されます。
Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.3.1:schemagen (default-cli) on project xml-schemas: Execution default-cli of goal org.codehaus.mojo:jaxb2-maven-plugin:2.3.1:schemagen failed: syntax error @[1,41] in file:/C:/projects/INTEGRATION_FACTORY/XML_SCHEMAS/src/main/kotlin/com/brabantia/common/xmlschemas/enum/ErrorCategoryType.kt -> [Help 1]
Kotlin enum クラスから XML スキーマを生成するにはどうすればよいですか?