Skip to content

Commit

Permalink
XML config generator (#657)
Browse files Browse the repository at this point in the history
* Added support to xsd import tool for extensions of simple types and XSD attributes

* Cleaned

* Cleaned

* Added xml config generator

* Fixed null handling

* Added rootType annotation
  • Loading branch information
SimonCockx authored Sep 26, 2023
1 parent 05217f5 commit 68e322c
Show file tree
Hide file tree
Showing 35 changed files with 844 additions and 204 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<slf4j.version>2.0.9</slf4j.version>
<logback.version>1.4.11</logback.version>
<InMemoryJavaCompiler.version>1.3.0</InMemoryJavaCompiler.version>
<jackson.version>2.15.2</jackson.version>

<!-- test -->
<junit.version>5.10.0</junit.version>
Expand Down Expand Up @@ -259,6 +260,16 @@
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>org.mdkt.compiler</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class ExpressionGenerator extends RosettaExpressionSwitch<StringConcatenationCli
«expr.childElseThen.genElseIf(scope)»
«ELSE»
else {
return «expr.elsethen.ensureMapperJavaCode(typeProvider.getRType(expr.ifthen).toJavaReferenceType, cardinalityProvider.isMulti(expr.ifthen), scope)»;
return «expr.elsethen.javaCode(scope)»;
}
«ENDIF»
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,23 @@ class ModelObjectGenerator {
return «javaType».class;
}

«FOR pt :interfaces.filter(JavaParameterizedType).filter[getBaseType.simpleName=="ReferenceWithMeta" || getBaseType.simpleName=="FieldWithMeta"
«FOR pt :interfaces.filter(JavaParameterizedType).filter[getBaseType.simpleName=="ReferenceWithMeta" || getBaseType.simpleName=="FieldWithMeta"
@Override
default Class<«pt.getArguments.head»> getValueType() {
return «pt.getArguments.head».class;
}
default Class<«pt.getArguments.head»> getValueType() {
return «pt.getArguments.head».class;
}
«ENDFOR»

«d.processMethod»'''
«d.processMethod»
'''
protected def StringConcatenationClient pojoInterfaceGetterMethods(JavaClass javaType, JavaClass metaType, GeneratedIdentifier metaDataIdentifier, Data d) '''
«FOR attribute : d.expandedAttributes»
«javadoc(attribute.definition, attribute.docReferences, null
«attribute.toMultiMetaOrRegularJavaType» get«attribute.name.toFirstUpper»();
«ENDFOR»'''
«ENDFOR»
'''
protected def StringConcatenationClient pojoInterfaceBuilderMethods(JavaClass javaType, Data d) '''
«d.name» build();
Expand Down
94 changes: 50 additions & 44 deletions rosetta-runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -1,52 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.regnosys.rosetta</groupId>
<artifactId>com.regnosys.rosetta.parent</artifactId>
<version>0.0.0.master</version>
</parent>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.regnosys.rosetta</groupId>
<artifactId>com.regnosys.rosetta.parent</artifactId>
<version>0.0.0.master</version>
</parent>

<artifactId>com.regnosys.rosetta.lib</artifactId>
<artifactId>com.regnosys.rosetta.lib</artifactId>

<description>
Responsibilities: defining the Java runtime necessary for running generated Java code.
</description>
<description>
Responsibilities: defining the Java runtime necessary for running
generated Java code.
</description>

<properties>
<maven.compiler.release>8</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<properties>
<maven.compiler.release>8</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.xtend</groupId>
<artifactId>org.eclipse.xtend.lib</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependencies>
<dependency>
<groupId>org.eclipse.xtend</groupId>
<artifactId>org.eclipse.xtend.lib</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.xtend</groupId>
<artifactId>xtend-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!-- Test dependencies -->
<dependency>
<groupId>
org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.xtend</groupId>
<artifactId>xtend-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import org.apache.commons.lang3.Validate;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.rosetta.util.DottedPath;

public class ModelSymbolId {
public class ModelSymbolId implements Comparable<ModelSymbolId> {
private DottedPath namespace;
private String name;

Expand All @@ -19,6 +21,11 @@ public ModelSymbolId(DottedPath namespace, String name) {
this.name = name;
}

@JsonCreator
public static ModelSymbolId splitOnDots(String str) {
DottedPath qualifiedName = DottedPath.splitOnDots(str);
return new ModelSymbolId(qualifiedName.parent(), qualifiedName.last());
}
public static ModelSymbolId fromRegulatoryReference(DottedPath namespace, String body, String... corpusList) {
Objects.requireNonNull(namespace);
Objects.requireNonNull(body);
Expand All @@ -32,6 +39,7 @@ public DottedPath getNamespace() {
public String getName() {
return name;
}
@JsonValue
public DottedPath getQualifiedName() {
return namespace.child(name);
}
Expand Down Expand Up @@ -82,6 +90,8 @@ public boolean equals(Object obj) {
return Objects.equals(name, other.name) && Objects.equals(namespace, other.namespace);
}



@Override
public int compareTo(ModelSymbolId o) {
return this.getQualifiedName().compareTo(o.getQualifiedName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class MapperUtils {
*/
public static <T> Mapper<T> runSingle(Supplier<Mapper<T>> supplier) {
Mapper<T> result = supplier.get();
if (result == null) {
return MapperS.ofNull();
}
if (result instanceof MapperS<?> || result instanceof ComparisonResult) {
return result;
}
Expand All @@ -18,6 +21,9 @@ public static <T> Mapper<T> runSingle(Supplier<Mapper<T>> supplier) {
// Note: below method is only necessary for JavaC, as the Eclipse compiler manages to solve type boundaries just fine.
public static <T> Mapper<? extends T> runSinglePolymorphic(Supplier<Mapper<? extends T>> supplier) {
Mapper<? extends T> result = supplier.get();
if (result == null) {
return MapperS.ofNull();
}
if (result instanceof MapperS<?> || result instanceof ComparisonResult) {
return result;
}
Expand All @@ -29,6 +35,9 @@ public static <T> Mapper<? extends T> runSinglePolymorphic(Supplier<Mapper<? ext
*/
public static <T> MapperC<T> runMulti(Supplier<Mapper<T>> supplier) {
Mapper<T> result = supplier.get();
if (result == null) {
return MapperC.ofNull();
}
if (result instanceof MapperC<?>) {
return (MapperC<T>) result;
}
Expand All @@ -37,6 +46,9 @@ public static <T> MapperC<T> runMulti(Supplier<Mapper<T>> supplier) {
// Note: below method is only necessary for JavaC, as the Eclipse compiler manages to solve type boundaries just fine.
public static <T> MapperC<? extends T> runMultiPolymorphic(Supplier<Mapper<? extends T>> supplier) {
Mapper<? extends T> result = supplier.get();
if (result == null) {
return MapperC.ofNull();
}
if (result instanceof MapperC<?>) {
return (MapperC<? extends T>) result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import org.apache.commons.lang3.ArrayUtils;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public class DottedPath implements Comparable<DottedPath> {
protected final String[] segments;

Expand All @@ -32,6 +35,7 @@ public static DottedPath of(String... segments) {
public static DottedPath split(String str, String separator) {
return new DottedPath(str.split(Pattern.quote(separator)));
}
@JsonCreator
public static DottedPath splitOnDots(String str) {
return split(str, ".");
}
Expand All @@ -56,6 +60,7 @@ public DottedPath concat(DottedPath second) {
public String withSeparator(CharSequence separator) {
return String.join(separator, segments);
}
@JsonValue
public String withDots() {
return withSeparator(".");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.rosetta.util.serialisation;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class AttributeXMLConfiguration {
private final Optional<String> xmlName;
private final Optional<Map<String, String>> xmlAttributes;
private final Optional<AttributeXMLRepresentation> xmlRepresentation;

@JsonCreator
public AttributeXMLConfiguration(
@JsonProperty("xmlName") Optional<String> xmlName,
@JsonProperty("xmlAttributes") Optional<Map<String, String>> xmlAttributes,
@JsonProperty("xmlRepresentation") Optional<AttributeXMLRepresentation> xmlRepresentation) {
this.xmlName = xmlName;
this.xmlAttributes = xmlAttributes;
this.xmlRepresentation = xmlRepresentation;
}

public Optional<String> getXmlName() {
return xmlName;
}

public Optional<Map<String, String>> getXmlAttributes() {
return xmlAttributes;
}

public Optional<AttributeXMLRepresentation> getXmlRepresentation() {
return xmlRepresentation;
}

@Override
public int hashCode() {
return Objects.hash(xmlAttributes, xmlName, xmlRepresentation);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AttributeXMLConfiguration other = (AttributeXMLConfiguration) obj;
return Objects.equals(xmlAttributes, other.xmlAttributes)
&& Objects.equals(xmlName, other.xmlName) && Objects.equals(xmlRepresentation, other.xmlRepresentation);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.rosetta.util.serialisation;

public enum AttributeXMLRepresentation {
ELEMENT,
ATTRIBUTE,
VALUE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.rosetta.util.serialisation;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.SortedMap;
import java.util.TreeMap;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.rosetta.model.lib.ModelSymbolId;

public class RosettaXMLConfiguration {
@JsonAnyGetter
private final SortedMap<ModelSymbolId, TypeXMLConfiguration> typeConfigMap;

@JsonCreator
private RosettaXMLConfiguration() {
this(Collections.emptyMap());
}
public RosettaXMLConfiguration(Map<ModelSymbolId, TypeXMLConfiguration> typeConfigMap) {
this.typeConfigMap = new TreeMap<>(typeConfigMap);
}

public Optional<TypeXMLConfiguration> getConfigurationForType(ModelSymbolId symbolId) {
return Optional.ofNullable(typeConfigMap.get(symbolId));
}

@JsonAnySetter
private void add(String symbolId, TypeXMLConfiguration config) {
typeConfigMap.put(ModelSymbolId.splitOnDots(symbolId), config);
}
@Override
public int hashCode() {
return Objects.hash(typeConfigMap);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
RosettaXMLConfiguration other = (RosettaXMLConfiguration) obj;
return Objects.equals(typeConfigMap, other.typeConfigMap);
}
}
Loading

0 comments on commit 68e322c

Please sign in to comment.