From d924ba0e1551299aa5054c342b768042226511b9 Mon Sep 17 00:00:00 2001 From: Oliver Bertuch Date: Wed, 11 May 2022 19:07:00 +0200 Subject: [PATCH] style(service): fix code smells in Context See https://sonarcloud.io/organizations/gdcc/rules?open=java%3AS3252&rule_key=java%3AS3252 --- .../io/gdcc/xoai/serviceprovider/model/Context.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xoai-service-provider/src/main/java/io/gdcc/xoai/serviceprovider/model/Context.java b/xoai-service-provider/src/main/java/io/gdcc/xoai/serviceprovider/model/Context.java index 83d734ed..ef26b893 100644 --- a/xoai-service-provider/src/main/java/io/gdcc/xoai/serviceprovider/model/Context.java +++ b/xoai-service-provider/src/main/java/io/gdcc/xoai/serviceprovider/model/Context.java @@ -22,16 +22,16 @@ public class Context { private static final TransformerFactory factory = TransformerFactory.newInstance(); private Transformer transformer; - private Map metadataTransformers = new HashMap(); + private final Map metadataTransformers = new HashMap<>(); private String baseUrl; private Granularity granularity; private OAIClient client; public Context() { try { - this.withMetadataTransformer("xoai", factory.newTransformer()); + this.withMetadataTransformer("xoai", Context.factory.newTransformer()); } catch (TransformerConfigurationException e) { - throw new RuntimeException("Unable to initialize identity transformer"); + throw new IllegalStateException("Unable to initialize identity transformer", e); } } @@ -95,7 +95,7 @@ public OAIClient getClient () { public enum KnownTransformer { OAI_DC("to_xoai/oai_dc.xsl"); - private String location; + private final String location; KnownTransformer(String location) { this.location = location; @@ -103,9 +103,9 @@ public enum KnownTransformer { public Transformer transformer () { try { - return factory.newTransformer(new StreamSource(this.getClass().getClassLoader().getResourceAsStream(location))); + return Context.factory.newTransformer(new StreamSource(this.getClass().getClassLoader().getResourceAsStream(location))); } catch (TransformerConfigurationException e) { - throw new RuntimeException("Unable to load resource file '"+location+"'", e); + throw new IllegalStateException("Unable to load resource file '" + location + "'", e); } } }