Skip to content

Commit

Permalink
Merge pull request #709 from focus-shift/rename-xml-utils
Browse files Browse the repository at this point in the history
Rename xmlUtils to (Jackson/Jaxb)XMLMapper
  • Loading branch information
derTobsch authored Dec 26, 2024
2 parents d76d870 + 7315d7c commit a4dd7e8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
public class JacksonConfigurationService implements ConfigurationService {

private static final XMLUtil xmlUtil = new XMLUtil();
private static final JacksonXMLMapper xmlUtil = new JacksonXMLMapper();

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package de.focus_shift.jollyday.jackson;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import de.focus_shift.jollyday.jackson.mapping.Configuration;

import java.io.InputStream;

public class XMLUtil {
import static com.fasterxml.jackson.databind.PropertyNamingStrategies.UPPER_CAMEL_CASE;

public class JacksonXMLMapper {

private static final XmlMapper mapper = new JacksonMapperCreator().create();

Expand All @@ -28,7 +29,7 @@ public Configuration unmarshallConfiguration(InputStream stream) {
private static class JacksonMapperCreator {
private XmlMapper create() {
final XmlMapper mapper = new XmlMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE);
mapper.setPropertyNamingStrategy(UPPER_CAMEL_CASE);
return mapper;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.focus_shift.jollyday.jackson.test;

import de.focus_shift.jollyday.jackson.XMLUtil;
import de.focus_shift.jollyday.jackson.JacksonXMLMapper;
import de.focus_shift.jollyday.jackson.mapping.Configuration;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand All @@ -14,7 +14,7 @@ class XMLUtilTest {
@ParameterizedTest
@ValueSource(strings = {"Holidays_at.xml", "Holidays_de.xml", "Holidays_gb.xml", "Holidays_ua.xml", "Holidays_tr.xml", "Holidays_za.xml"})
void unmarshalRealResource(String holidayFileName) {
final XMLUtil sut = new XMLUtil();
final JacksonXMLMapper sut = new JacksonXMLMapper();
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream("holidays/" + holidayFileName);
final Configuration configuration = sut.unmarshallConfiguration(inputStream);
assertThat(configuration.getHolidays()).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
public class JaxbConfigurationService implements ConfigurationService {

private static final XMLUtil xmlUtil = new XMLUtil();
private static final JaxbXMLMapper xmlUtil = new JaxbXMLMapper();

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

import java.io.InputStream;

public class XMLUtil {
public class JaxbXMLMapper {

/**
* the package name to search for the generated java classes.
*/
private static final String PACKAGE = "de.focus_shift.jollyday.jaxb.mapping";

private static final Logger LOG = LoggerFactory.getLogger(XMLUtil.class);
private static final Logger LOG = LoggerFactory.getLogger(JaxbXMLMapper.class);

private static final JAXBContext jaxbContext = new JAXBContextCreator().create();

Expand Down Expand Up @@ -52,14 +52,14 @@ private JAXBContext create() {
private static JAXBContext createJAXBContext() {
JAXBContext ctx = null;
try {
ctx = JAXBContext.newInstance(XMLUtil.PACKAGE, ClassLoadingUtil.getClassloader());
ctx = JAXBContext.newInstance(JaxbXMLMapper.PACKAGE, ClassLoadingUtil.getClassloader());
} catch (JAXBException e) {
LOG.warn("Could not create JAXB context using the current classloader from ClassLoadingUtil. Falling back to ObjectFactory class classloader.");
}

if (ctx == null) {
try {
ctx = JAXBContext.newInstance(XMLUtil.PACKAGE, ObjectFactory.class.getClassLoader());
ctx = JAXBContext.newInstance(JaxbXMLMapper.PACKAGE, ObjectFactory.class.getClassLoader());
} catch (JAXBException exception) {
throw new IllegalStateException("Could not create JAXB context using ObjectFactory classloader.", exception);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.focus_shift.jollyday.jaxb.test;

import de.focus_shift.jollyday.jaxb.XMLUtil;
import de.focus_shift.jollyday.jaxb.JaxbXMLMapper;
import de.focus_shift.jollyday.jaxb.mapping.Configuration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -13,7 +13,7 @@

class XMLUtilTest {

private final XMLUtil sut = new XMLUtil();
private final JaxbXMLMapper sut = new JaxbXMLMapper();

@Test
void testUnmarshallConfigurationNullCheck() {
Expand Down

0 comments on commit a4dd7e8

Please sign in to comment.