Skip to content

Commit

Permalink
Updates the MAL to the latest changes and adds backward compatibility…
Browse files Browse the repository at this point in the history
… to the code
  • Loading branch information
CesarCoelho committed Oct 10, 2024
1 parent 14c14e0 commit 5123cf7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@ public void execute() throws MojoExecutionException {

// run the specifications through each generator
// first process the list of languages to generate
if ((null != targetLanguages) && (0 < targetLanguages.length)) {
if ((targetLanguages != null) && (targetLanguages.length > 0)) {

if (forceGeneration || (outputDirectory.lastModified() < inputTimestamp)) {
if (forceGeneration) {
getLog().info("Generation being forced");
}
for (String targetLanguage : targetLanguages) {
final Generator gen = GENERATOR_MAP.get(targetLanguage.toLowerCase());
if (null != gen) {
if (gen != null) {
processWithGenerator(gen, refSpecs, refXsd, specs);
} else {
getLog().warn("Could not find generator for language: " + targetLanguage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
package esa.mo.xsd.util;

import esa.mo.xsd.SpecificationType;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
Expand Down Expand Up @@ -73,14 +78,51 @@ public SpecificationType getSpecType() {
return specType;
}

public synchronized static XmlSpecification loadSpecification(final File is) throws IOException, JAXBException {
/**
* Modifies the content from a XML file and returns it. Note that the file
* is not saved with these changes. This method is a hack to have the new
* "ServiceSchema-v003" specifications, to be compatible with the old code.
* This method will have to be removed after the mo-services-java codebase
* fully removes support for the old MAL.
*
* @param file The file with the specification.
* @return An input stream with the modified content.
* @throws IOException if something went while modifying the content.
*/
private static InputStream modifyFileToBeBackwardsCompatible(File file) throws IOException {
// Read the file content into a StringBuilder
StringBuilder fileContent = new StringBuilder();
try ( BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
fileContent.append(line).append(System.lineSeparator());
}
}

// Replace the text "ServiceSchema-v003" with "ServiceSchema"
String modifiedContent = fileContent.toString().replace("ServiceSchema-v003", "ServiceSchema");

// Convert the modified content to an InputStream
return new ByteArrayInputStream(modifiedContent.getBytes(StandardCharsets.UTF_8));
}

/**
* Loads an XML Specification.
*
* @param file The file with the specification.
* @return The representation of the XML specification.
* @throws IOException if something went while modifying the content.
* @throws JAXBException if the xml could not be parsed.
*/
public synchronized static XmlSpecification loadSpecification(final File file) throws IOException, JAXBException {
if (jc == null) {
jc = JAXBContext.newInstance("esa.mo.xsd");
}

final Unmarshaller unmarshaller = jc.createUnmarshaller();
final InputStream is = XmlSpecification.modifyFileToBeBackwardsCompatible(file);
final JAXBElement rootElement = (JAXBElement) unmarshaller.unmarshal(is);
SpecificationType specType = (SpecificationType) rootElement.getValue();
return new XmlSpecification(is, rootElement, specType);
return new XmlSpecification(file, rootElement, specType);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mal:specification xmlns:mal="http://www.ccsds.org/schema/ServiceSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mal:specification xmlns:mal="http://www.ccsds.org/schema/ServiceSchema-v003" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mal:area name="MAL" number="1" version="3">
<mal:dataTypes>
<mal:fundamental name="Attribute" comment="Attribute is the base type of all Attributes of the MAL data model. Attributes are contained within Composites and are used to build complex structures that make the data model.">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mal:specification xmlns:mal="http://www.ccsds.org/schema/ServiceSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mal:specification xmlns:mal="http://www.ccsds.org/schema/ServiceSchema-v003" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mal:area name="MAL" number="1" version="3">
<mal:dataTypes>
<mal:fundamental name="Attribute" comment="Attribute is the base type of all Attributes of the MAL data model. Attributes are contained within Composites and are used to build complex structures that make the data model.">
Expand Down

0 comments on commit 5123cf7

Please sign in to comment.