Skip to content

Commit

Permalink
XML config generator patch (finos#658)
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

* Made more robust

* Fixed
  • Loading branch information
SimonCockx authored Sep 26, 2023
1 parent 68e322c commit 8a16e5d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.ConstructorDetector;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.google.inject.Injector;
import com.regnosys.rosetta.RosettaStandaloneSetup;
Expand Down Expand Up @@ -54,15 +53,16 @@ public static void main(String[] args) throws IOException, ParseException {
XsdImport xsdImport = injector.getInstance(XsdImport.class);
xsdImport.generateRosetta(schema, properties);
RosettaXMLConfiguration xmlConfig = xsdImport.generateXMLConfiguration(schema, properties);
getObjectMapper().writerWithDefaultPrettyPrinter().writeValue(new File(xmlConfigOutputPath), xmlConfig);
File xmlConfigOutputFile = new File(xmlConfigOutputPath);
xmlConfigOutputFile.getParentFile().mkdirs();
getObjectMapper().writerWithDefaultPrettyPrinter().writeValue(xmlConfigOutputFile, xmlConfig);
xsdImport.saveResources(rosettaOutputPath);
}

public static ObjectMapper getObjectMapper() {
return new ObjectMapper()
.registerModule(new Jdk8Module())
.setSerializationInclusion(Include.NON_ABSENT)
.setConstructorDetector(ConstructorDetector.USE_PROPERTIES_BASED);
.setSerializationInclusion(Include.NON_ABSENT);
}

private static GenerationProperties getGenerationProperties(String propertiesPath) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.xmlet.xsdparser.xsdelements.enums.UsageEnum;
import org.xmlet.xsdparser.xsdelements.visitors.AttributesVisitor;

import com.google.common.collect.ImmutableMap;
import com.regnosys.rosetta.builtin.RosettaBuiltinsService;
import com.regnosys.rosetta.rosetta.RosettaCardinality;
import com.regnosys.rosetta.rosetta.RosettaFactory;
Expand Down Expand Up @@ -180,10 +179,15 @@ public Optional<TypeXMLConfiguration> getXMLConfiguration(XsdComplexType xsdType
));
}
}
Map<String, String> xmlAttributes = new LinkedHashMap<>();
if (schemaTargetNamespace != null) {
xmlAttributes.put("xmlns", schemaTargetNamespace);
}
xmlAttributes.put("xmlns:xsi", util.XSI_NAMESPACE);
return Optional.of(
new TypeXMLConfiguration(
Optional.of(rootTypeName),
Optional.of(ImmutableMap.of("xmlns", schemaTargetNamespace, "xmlns:xsi", util.XSI_NAMESPACE)),
Optional.of(xmlAttributes),
attributeConfig.isEmpty() ? Optional.empty() : Optional.of(attributeConfig)
));
}
Expand Down

0 comments on commit 8a16e5d

Please sign in to comment.