-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing update to Jakarta XML 4.0 (#1358)
* Experimenting * Tests * Fix compile issues * Fixed test errors * Fix failing tests --------- Co-authored-by: Bryn Rhodes <bryn@databaseconsultinggroup.com>
- Loading branch information
1 parent
70722a1
commit 662ff61
Showing
11 changed files
with
139 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...java/elm-jaxb/src/main/resources/org/cqframework/cql/elm/serializing/jaxb/jaxb.properties
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
...jaxb/src/test/java/org/cqframework/cql/elm/serializing/jaxb/ElmJsonLibraryReaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.cqframework.cql.elm.serializing.jaxb; | ||
|
||
import static org.testng.Assert.assertNotNull; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import org.hl7.elm.r1.Library; | ||
import org.testng.annotations.Test; | ||
|
||
public class ElmJsonLibraryReaderTest { | ||
|
||
@Test | ||
public void testRead() throws IOException { | ||
var reader = new ElmJsonLibraryReader(); | ||
Library library = reader.read(new ByteArrayInputStream("{\"library\" : { \"type\" : \"Library\"}}".getBytes())); | ||
assertNotNull(library); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...-jaxb/src/test/java/org/cqframework/cql/elm/serializing/jaxb/ElmXmlLibraryReaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.cqframework.cql.elm.serializing.jaxb; | ||
|
||
import static org.testng.Assert.assertNotNull; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import org.hl7.elm.r1.Library; | ||
import org.testng.annotations.Test; | ||
|
||
public class ElmXmlLibraryReaderTest { | ||
|
||
@Test | ||
public void testRead() throws IOException { | ||
var reader = new ElmXmlLibraryReader(); | ||
Library library = | ||
reader.read(new ByteArrayInputStream("<library xmlns=\"urn:hl7-org:elm:r1\"></library>".getBytes())); | ||
assertNotNull(library); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 60 additions & 7 deletions
67
...odel-jaxb/src/main/java/org/hl7/elm_modelinfo/r1/serializing/jaxb/XmlModelInfoReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,88 @@ | ||
package org.hl7.elm_modelinfo.r1.serializing.jaxb; | ||
|
||
import jakarta.xml.bind.JAXB; | ||
import jakarta.xml.bind.JAXBContext; | ||
import jakarta.xml.bind.JAXBElement; | ||
import jakarta.xml.bind.JAXBException; | ||
import jakarta.xml.bind.Unmarshaller; | ||
import java.io.*; | ||
import java.net.URI; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.hl7.elm_modelinfo.r1.ModelInfo; | ||
import org.hl7.elm_modelinfo.r1.ObjectFactory; | ||
import org.hl7.elm_modelinfo.r1.serializing.ModelInfoReader; | ||
|
||
public class XmlModelInfoReader implements ModelInfoReader { | ||
|
||
private final Map<String, String> properties = new HashMap<>(); | ||
private final Unmarshaller unmarshaller; | ||
|
||
public XmlModelInfoReader() { | ||
properties.put(JAXBContext.JAXB_CONTEXT_FACTORY, "org.eclipse.persistence.jaxb.JAXBContextFactory"); | ||
|
||
try { | ||
this.unmarshaller = JAXBContext.newInstance(new Class<?>[] {ObjectFactory.class}, properties) | ||
.createUnmarshaller(); | ||
} catch (JAXBException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private Unmarshaller getUnmarshaller() { | ||
return unmarshaller; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private ModelInfo toModelInfo(Object obj) { | ||
return ((JAXBElement<ModelInfo>) obj).getValue(); | ||
} | ||
|
||
public ModelInfo read(File src) throws IOException { | ||
return JAXB.unmarshal(src, ModelInfo.class); | ||
try { | ||
return toModelInfo(getUnmarshaller().unmarshal(src)); | ||
} catch (JAXBException e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
|
||
public ModelInfo read(Reader src) throws IOException { | ||
return JAXB.unmarshal(src, ModelInfo.class); | ||
try { | ||
return toModelInfo(getUnmarshaller().unmarshal(src)); | ||
} catch (JAXBException e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
|
||
public ModelInfo read(InputStream src) throws IOException { | ||
return JAXB.unmarshal(src, ModelInfo.class); | ||
try { | ||
return toModelInfo(getUnmarshaller().unmarshal(src)); | ||
} catch (JAXBException e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
|
||
public ModelInfo read(URL url) throws IOException { | ||
return JAXB.unmarshal(url, ModelInfo.class); | ||
try { | ||
return toModelInfo(getUnmarshaller().unmarshal(url)); | ||
} catch (JAXBException e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
|
||
public ModelInfo read(URI uri) throws IOException { | ||
return JAXB.unmarshal(uri, ModelInfo.class); | ||
try { | ||
return toModelInfo(getUnmarshaller().unmarshal(uri.toURL())); | ||
} catch (JAXBException e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
|
||
public ModelInfo read(String string) throws IOException { | ||
return JAXB.unmarshal(string, ModelInfo.class); | ||
try { | ||
return toModelInfo(getUnmarshaller().unmarshal(new ByteArrayInputStream(string.getBytes()))); | ||
} catch (JAXBException e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
...el-jaxb/src/main/resources/java/org/hl7/elm_modelinfo/r1/serializing/jaxb/jaxb.properties
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
...-jaxb/src/test/java/org/hl7/elm_modelinfo/r1/serializing/jaxb/XmlModelInfoReaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.hl7.elm_modelinfo.r1.serializing.jaxb; | ||
|
||
import static org.testng.Assert.assertNotNull; | ||
|
||
import java.io.IOException; | ||
import org.hl7.elm_modelinfo.r1.ModelInfo; | ||
import org.testng.annotations.Test; | ||
|
||
public class XmlModelInfoReaderTest { | ||
|
||
@Test | ||
public void testRead() throws IOException { | ||
var reader = new XmlModelInfoReader(); | ||
ModelInfo mi = reader.read( | ||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ns4:modelInfo xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:ns4=\"urn:hl7-org:elm-modelinfo:r1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"></ns4:modelInfo>"); | ||
assertNotNull(mi); | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
Src/java/model/src/main/resources/org/hl7/elm_modelinfo/r1/jaxb.properties
This file was deleted.
Oops, something went wrong.