You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2018/02/21 15:36:34 UTC

[isis] 06/11: ISIS-1867: refactors JaxbService#jaxbContextFor so handles exception, similar to JaxbUtil

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 2da9f90fb5b127ca2029d7de45563af987de6080
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Feb 21 15:01:00 2018 +0000

    ISIS-1867: refactors JaxbService#jaxbContextFor so handles exception, similar to JaxbUtil
---
 .../isis/applib/services/jaxb/JaxbService.java     | 23 +++++++++++-----------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
index dae78d2..41cbcd0 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
@@ -131,22 +131,21 @@ public interface JaxbService {
         }
         @Override
         public <T> T fromXml(final Class<T> domainClass, final String xml, final Map<String, Object> unmarshallerProperties) {
-            try {
-                final JAXBContext context = jaxbContextFor(domainClass);
-                return _Casts.uncheckedCast(fromXml(context, xml, unmarshallerProperties));
-
-            } catch (final JAXBException ex) {
-                throw new NonRecoverableException("Error unmarshalling XML to class '" + domainClass.getName() + "'", ex);
-            }
+            final JAXBContext context = jaxbContextFor(domainClass);
+            return _Casts.uncheckedCast(fromXml(context, xml, unmarshallerProperties));
         }
 
         private Map<Class<?>, JAXBContext> jaxbContextByClass = new MapMaker().concurrencyLevel(10).makeMap();
 
-        private <T> JAXBContext jaxbContextFor(final Class<T> dtoClass) throws JAXBException {
-            JAXBContext jaxbContext = jaxbContextByClass.get(dtoClass);
+        private <T> JAXBContext jaxbContextFor(final Class<T> clazz)  {
+            JAXBContext jaxbContext = jaxbContextByClass.get(clazz);
             if(jaxbContext == null) {
-                jaxbContext = JAXBContext.newInstance(dtoClass);
-                jaxbContextByClass.put(dtoClass, jaxbContext);
+                try {
+                    jaxbContext = JAXBContext.newInstance(clazz);
+                } catch (JAXBException e) {
+                    throw new NonRecoverableException("Error obtaining JAXBContext for class '" + clazz + "'", e);
+                }
+                jaxbContextByClass.put(clazz, jaxbContext);
             }
             return jaxbContext;
         }
@@ -236,7 +235,7 @@ public interface JaxbService {
                 context.generateSchema(outputResolver);
 
                 return outputResolver.asMap();
-            } catch (final JAXBException | IOException ex) {
+            } catch (final IOException ex) {
                 throw new ApplicationException(ex);
             }
         }

-- 
To stop receiving notification emails like this one, please contact
danhaywood@apache.org.