You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/10/09 10:23:16 UTC

[isis] branch master updated (9f3110f -> b519372)

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

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


    from 9f3110f  Merge pull request #235 from apache/dependabot/maven/org.webjars-font-awesome-5.15.0
     new 8e2e0e8  ISIS-2446: Move JaxbService implementation applib -> runtimeservices
     new b519372  ISIS-2446: sync adoc and update sys overview

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../system/modules/ROOT/pages/about.adoc           |   2 +-
 .../conmap/ContentMappingServiceForCommandDto.java |  18 +-
 .../examples/services/jaxb/JaxbService.java        | 223 +++++++++------------
 .../examples/services/jaxb/JaxbServiceDefault.java | 134 -------------
 .../org/apache/isis/applib/IsisModuleApplib.java   |   3 -
 .../isis/applib/services/jaxb/JaxbService.java     | 223 +++++++++------------
 .../isis/commons/internal/resources/_Xml.java      |  49 ++++-
 .../IsisModuleCoreRuntimeServices.java             |   2 +
 .../runtimeservices}/jaxb/JaxbServiceDefault.java  |  89 ++++----
 .../commons/internal/reflection/ReflectTest.java   |  29 +--
 10 files changed, 300 insertions(+), 472 deletions(-)
 delete mode 100644 api/applib/src/main/adoc/modules/applib-svc/examples/services/jaxb/JaxbServiceDefault.java
 rename {api/applib/src/main/java/org/apache/isis/applib/services => core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices}/jaxb/JaxbServiceDefault.java (58%)


[isis] 01/02: ISIS-2446: Move JaxbService implementation applib -> runtimeservices

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8e2e0e86409a5594e2e4c8da4d1c29012172feb3
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Oct 9 12:18:09 2020 +0200

    ISIS-2446: Move JaxbService implementation applib -> runtimeservices
---
 .../org/apache/isis/applib/IsisModuleApplib.java   |   3 -
 .../isis/applib/services/jaxb/JaxbService.java     | 223 +++++++++------------
 .../isis/commons/internal/resources/_Xml.java      |  49 ++++-
 .../IsisModuleCoreRuntimeServices.java             |   2 +
 .../runtimeservices}/jaxb/JaxbServiceDefault.java  |  89 ++++----
 .../commons/internal/reflection/ReflectTest.java   |  29 +--
 6 files changed, 191 insertions(+), 204 deletions(-)

diff --git a/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java b/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java
index ab4e7be..f83eed3 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java
@@ -33,14 +33,12 @@ import org.apache.isis.applib.services.audit.AuditerServiceLogging;
 import org.apache.isis.applib.services.bookmark.BookmarkHolder_lookup;
 import org.apache.isis.applib.services.bookmark.BookmarkHolder_object;
 import org.apache.isis.applib.services.clock.ClockService;
-import org.apache.isis.applib.services.command.CommandServiceInternal;
 import org.apache.isis.applib.services.command.spi.CommandServiceListener;
 import org.apache.isis.applib.services.commanddto.conmap.ContentMappingServiceForCommandDto;
 import org.apache.isis.applib.services.commanddto.conmap.ContentMappingServiceForCommandsDto;
 import org.apache.isis.applib.services.commanddto.processor.spi.CommandDtoProcessorServiceIdentity;
 import org.apache.isis.applib.services.confview.ConfigurationMenu;
 import org.apache.isis.applib.services.iactn.InteractionContext;
-import org.apache.isis.applib.services.jaxb.JaxbServiceDefault;
 import org.apache.isis.applib.services.layout.LayoutServiceMenu;
 import org.apache.isis.applib.services.metamodel.MetaModelServiceMenu;
 import org.apache.isis.applib.services.publish.PublisherServiceLogging;
@@ -77,7 +75,6 @@ import org.apache.isis.schema.IsisModuleSchema;
         ContentMappingServiceForCommandDto.class,
         ContentMappingServiceForCommandsDto.class,
         InteractionContext.class,
-        JaxbServiceDefault.class,
         PublisherServiceLogging.class,
         SessionLoggingServiceLogging.class,
 
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java b/api/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
index 4148840..bf0344c 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
@@ -18,13 +18,9 @@
  */
 package org.apache.isis.applib.services.jaxb;
 
-import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
-import java.lang.reflect.Method;
-import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 import javax.annotation.Nullable;
 import javax.xml.bind.JAXBContext;
@@ -32,34 +28,37 @@ import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 
-import org.apache.isis.applib.ApplicationException;
-import org.apache.isis.applib.NonRecoverableException;
 import org.apache.isis.applib.mixins.dto.Dto_downloadXsd;
-import org.apache.isis.applib.util.JaxbUtil;
 import org.apache.isis.commons.internal.base._Casts;
 import org.apache.isis.commons.internal.base._NullSafe;
-import org.apache.isis.commons.internal.collections._Maps;
+import org.apache.isis.commons.internal.resources._Xml;
 
 import lombok.NonNull;
+import lombok.SneakyThrows;
+import lombok.val;
 
 // tag::refguide[]
 public interface JaxbService {
 
-    Object fromXml(                                     // <.>
+    default Object fromXml(                             // <.>
             JAXBContext jaxbContext,
-            String xml);
+            String xml) {
+        return fromXml(jaxbContext, xml, null);
+    }
 
     Object fromXml(                                     // <.>
             JAXBContext jaxbContext,
             String xml,
-            Map<String,Object> unmarshallerProperties);
+            @Nullable Map<String,Object> unmarshallerProperties);
 
     // end::refguide[]
     /**
      * As {@link #fromXml(JAXBContext, String)}, but downcast to a specific type.
      */
     // tag::refguide[]
-    <T> T fromXml(Class<T> domainClass, String xml);    // <.>
+    default <T> T fromXml(Class<T> domainClass, String xml) { // <.>
+        return fromXml(domainClass, xml, null);
+    }
 
     // end::refguide[]
     /**
@@ -69,13 +68,15 @@ public interface JaxbService {
     <T> T fromXml(                                      // <.>
             Class<T> domainClass,
             String xml,
-            Map<String,Object> unmarshallerProperties);
-
-    String toXml(final Object domainObject);            // <.>
+            @Nullable Map<String,Object> unmarshallerProperties);
 
+    default String toXml(Object domainObject) {         // <.>
+        return toXml(domainObject, null);
+    }
+        
     String toXml(                                       // <.>
-            final Object domainObject,
-            Map<String,Object> marshallerProperties);
+            Object domainObject,
+            @Nullable Map<String,Object> marshallerProperties);
 
     // end::refguide[]
     /**
@@ -110,137 +111,83 @@ public interface JaxbService {
         // tag::refguide[]
     }
 
-    Map<String, String> toXsd(                          // <.>
-            final Object domainObject,
-            final IsisSchemas isisSchemas);
+    Map<String, String> toXsd(                 // <.>
+            Object domainObject, 
+            IsisSchemas isisSchemas);
 
     // end::refguide[]
     class Simple implements JaxbService {
 
-        @Override
-        public Object fromXml(final JAXBContext jaxbContext, final String xml) {
-            return fromXml(jaxbContext, xml, _Maps.newHashMap());
-        }
-
-        @Override
-        public Object fromXml(final JAXBContext jaxbContext, final String xml, final Map<String, Object> unmarshallerProperties) {
+        @Override @SneakyThrows @Nullable
+        public Object fromXml(
+                final @NonNull JAXBContext jaxbContext, 
+                final @Nullable String xml, 
+                final @Nullable Map<String, Object> unmarshallerProperties) {
             try {
-
                 return internalFromXml(jaxbContext, xml, unmarshallerProperties);
-
-            } catch (final JAXBException ex) {
-                throw new NonRecoverableException("Error unmarshalling XML", ex);
+            } catch (Exception e) {
+                throw _Xml.verbose("unmarshalling XML", null, e);
             }
         }
 
-        protected Object internalFromXml(
-                @NonNull final JAXBContext jaxbContext,
-                @Nullable final String xml,
-                @Nullable final Map<String, Object> unmarshallerProperties) throws JAXBException {
-            
-            if(xml==null) {
-                return null;
-            }
+        @Override @SneakyThrows @Nullable
+        public <T> T fromXml(
+                final @NonNull Class<T> domainClass, 
+                final @Nullable String xml, 
+                final @Nullable Map<String, Object> unmarshallerProperties) {
             
-            final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
-
-            if(unmarshallerProperties!=null) {
-                for (Map.Entry<String, Object> entry : unmarshallerProperties.entrySet()) {
-                    unmarshaller.setProperty(entry.getKey(), entry.getValue());
-                }
-            }
-
-            configure(unmarshaller);
-
-            return unmarshaller.unmarshal(new StringReader(xml));
-        }
-
-        @Override
-        public <T> T fromXml(final Class<T> domainClass, final String xml) {
-            return fromXml(domainClass, xml, _Maps.newHashMap());
-        }
-
-        @Override
-        public <T> T fromXml(final Class<T> domainClass, final String xml, final Map<String, Object> unmarshallerProperties) {
-            final JAXBContext context = jaxbContextFor(domainClass);
-            return _Casts.uncheckedCast(fromXml(context, xml, unmarshallerProperties));
-        }
-
-        private static <T> JAXBContext jaxbContextFor(final Class<T> clazz)  {
             try {
-                return JaxbUtil.jaxbContextFor(clazz);
-            } catch (RuntimeException e) {
-                throw new NonRecoverableException("Error obtaining JAXBContext for class '" + clazz + "'", e.getCause());
+                val jaxbContext = jaxbContextForClass(domainClass);
+                return _Casts.uncheckedCast(internalFromXml(jaxbContext, xml, unmarshallerProperties));
+            } catch (Exception e) {
+                throw _Xml.verbose("unmarshalling XML", domainClass, e);
             }
         }
 
-        @Override
-        public String toXml(final Object domainObject) {
-            return toXml(domainObject, _Maps.newHashMap());
-        }
-
-        @Override
-        public String toXml(final Object domainObject, final Map<String, Object> marshallerProperties)  {
+        @Override @SneakyThrows
+        public String toXml(
+                final @NonNull Object domainObject, 
+                final @Nullable Map<String, Object> marshallerProperties)  {
 
-            final Class<?> domainClass = domainObject.getClass();
-            final JAXBContext context = jaxbContextFor(domainObject);
+            val domainClass = domainObject.getClass();
+            val jaxbContext = jaxbContextForObject(domainObject);
             try {
-                final Marshaller marshaller = context.createMarshaller();
+                val marshaller = jaxbContext.createMarshaller();
 
                 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
-                for (Map.Entry<String, Object> entry : marshallerProperties.entrySet()) {
-                    marshaller.setProperty(entry.getKey(), entry.getValue());
+                if(!_NullSafe.isEmpty(marshallerProperties)) {
+                    for (val entry : marshallerProperties.entrySet()) {
+                        marshaller.setProperty(entry.getKey(), entry.getValue());
+                    }
                 }
 
                 configure(marshaller);
 
-                final StringWriter sw = new StringWriter();
-                marshaller.marshal(domainObject, sw);
-                final String xml = sw.toString();
+                val writer = new StringWriter();
+                marshaller.marshal(domainObject, writer);
+                val xml = writer.toString();
 
                 return xml;
 
-            } catch (final JAXBException ex) {
-                final Class<? extends JAXBException> exClass = ex.getClass();
-
-                final String name = exClass.getName();
-                if(name.equals("com.sun.xml.bind.v2.runtime.IllegalAnnotationsException")) {
-                    // report a better error if possible
-                    // this is done reflectively so as to not have to bring in a new Maven dependency
-                    List<? extends Exception> errors = null;
-                    String annotationExceptionMessages = null;
-                    try {
-                        final Method getErrorsMethod = exClass.getMethod("getErrors");
-                        errors = _Casts.uncheckedCast(getErrorsMethod.invoke(ex));
-
-                        annotationExceptionMessages = ": " +
-                                _NullSafe.stream(errors)
-                        .map(Exception::getMessage)
-                        .collect(Collectors.joining("; "));
-
-                    } catch (Exception e) {
-                        // fall through if we hit any snags, and instead throw the more generic error message.
-                    }
-                    if(errors != null) {
-                        throw new NonRecoverableException(
-                                "Error marshalling domain object to XML, due to illegal annotations on domain object class '"
-                                        + domainClass.getName() + "'; " + errors.size() + " error"
-                                        + (errors.size() == 1? "": "s")
-                                        + " reported" + (!errors
-                                                .isEmpty() ? annotationExceptionMessages : ""), ex);
-                    }
-                }
-
-                throw new NonRecoverableException("Error marshalling domain object to XML; domain object class is '" + domainClass.getName() + "'", ex);
+            } catch (Exception e) {
+                throw _Xml.verbose("marshalling domain object to XML", domainClass, e);
             }
         }
 
         /**
          * Optional hook
          */
-        protected JAXBContext jaxbContextFor(final Object domainObject) {
-            final Class<?> domainClass = domainObject.getClass();
-            return jaxbContextFor(domainClass);
+        protected JAXBContext jaxbContextForObject(final @NonNull Object domainObject) {
+            val useCache = true;
+            return _Xml.jaxbContextFor(domainObject.getClass(), useCache);
+        }
+        
+        /**
+         * Optional hook
+         */
+        protected JAXBContext jaxbContextForClass(final @NonNull Class<?> domainObjectClass) {
+            val useCache = true;
+            return _Xml.jaxbContextFor(domainObjectClass, useCache);
         }
 
         /**
@@ -255,21 +202,41 @@ public interface JaxbService {
         protected void configure(final Marshaller marshaller) {
         }
 
-        @Override
-        public Map<String,String> toXsd(final Object domainObject, final IsisSchemas isisSchemas) {
+        @Nullable
+        protected Object internalFromXml(
+                final @NonNull JAXBContext jaxbContext,
+                final @Nullable String xml,
+                final @Nullable Map<String, Object> unmarshallerProperties) throws JAXBException {
+            
+            if(xml==null) {
+                return null;
+            }
+            
+            val unmarshaller = jaxbContext.createUnmarshaller();
+            if(!_NullSafe.isEmpty(unmarshallerProperties)) {
+                for (val entry : unmarshallerProperties.entrySet()) {
+                    unmarshaller.setProperty(entry.getKey(), entry.getValue());
+                }
+            }
+            configure(unmarshaller);
+
+            val pojo = unmarshaller.unmarshal(new StringReader(xml));
+            return pojo;
+        }
+        
+        @Override @SneakyThrows
+        public Map<String,String> toXsd(
+                final @NonNull Object domainObject, 
+                final @NonNull IsisSchemas isisSchemas) {
 
-            try {
-                final Class<?> domainClass = domainObject.getClass();
-                final JAXBContext context = jaxbContextFor(domainClass);
+            val jaxbContext = jaxbContextForObject(domainObject);
 
-                final CatalogingSchemaOutputResolver outputResolver = new CatalogingSchemaOutputResolver(isisSchemas);
-                context.generateSchema(outputResolver);
+            val outputResolver = new CatalogingSchemaOutputResolver(isisSchemas);
+            jaxbContext.generateSchema(outputResolver);
 
-                return outputResolver.asMap();
-            } catch (final IOException ex) {
-                throw new ApplicationException(ex);
-            }
+            return outputResolver.asMap();
         }
+        
     }
 
     // tag::refguide[]
diff --git a/commons/src/main/java/org/apache/isis/commons/internal/resources/_Xml.java b/commons/src/main/java/org/apache/isis/commons/internal/resources/_Xml.java
index 685ba0a..d1b63f0 100644
--- a/commons/src/main/java/org/apache/isis/commons/internal/resources/_Xml.java
+++ b/commons/src/main/java/org/apache/isis/commons/internal/resources/_Xml.java
@@ -23,6 +23,8 @@ import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
 
 import javax.annotation.Nullable;
 import javax.xml.bind.JAXBContext;
@@ -33,6 +35,7 @@ import javax.xml.namespace.QName;
 import com.sun.xml.bind.v2.runtime.IllegalAnnotationsException;
 
 import org.apache.isis.commons.internal.base._Casts;
+import org.apache.isis.commons.internal.base._NullSafe;
 import org.apache.isis.commons.internal.collections._Maps;
 import org.apache.isis.commons.internal.exceptions._Exceptions;
 
@@ -80,11 +83,11 @@ public final class _Xml {
 
     @SneakyThrows
     public static <T> T readXml(
-            final @NonNull Class<T> type,
+            final @NonNull Class<T> dtoClass,
             final @NonNull Reader reader,
             final @NonNull ReadOptions readOptions) {
         
-        val unmarshaller = jaxbContextFor(type, readOptions.isUseContextCache()).createUnmarshaller();
+        val unmarshaller = jaxbContextFor(dtoClass, readOptions.isUseContextCache()).createUnmarshaller();
         return _Casts.uncheckedCast(unmarshaller.unmarshal(reader));
     }
 
@@ -137,22 +140,50 @@ public final class _Xml {
     }
     
     
+    // -- 
+    
+    public static Exception verbose(String doingWhat, @Nullable Class<?> dtoClass, Exception e) {
+        
+        val dtoClassName = Optional.ofNullable(dtoClass).map(Class::getName).orElse("unknown");
+        
+        if(e instanceof IllegalAnnotationsException) {
+            // report a better error if possible
+            val errors = ((IllegalAnnotationsException) e).getErrors();
+            if(_NullSafe.size(errors)>0) {
+            
+                return _Exceptions.unrecoverable(String.format("Error %s, "
+                        + "due to illegal annotations on object class '%s'; "
+                        + "%d error(s) reported: %s",
+                        doingWhat,
+                        dtoClassName,
+                        errors.size(),
+                        errors.stream()
+                            .map(Exception::getMessage)
+                            .collect(Collectors.joining("; "))),
+                        e);
+            }                    
+        }
+
+        return _Exceptions.unrecoverable(String.format("Error %s; "
+                + "object class is '%s'", doingWhat, dtoClassName), e);
+    }
+    
     // -- JAXB CONTEXT CACHE
 
     private static Map<Class<?>, JAXBContext> jaxbContextByClass = _Maps.newConcurrentHashMap();
 
-    public static <T> JAXBContext jaxbContextFor(final Class<T> type, final boolean useCache)  {
+    public static <T> JAXBContext jaxbContextFor(final Class<T> dtoClass, final boolean useCache)  {
         return useCache
-                ? jaxbContextByClass.computeIfAbsent(type, _Xml::contextOf)
-                : contextOf(type);
+                ? jaxbContextByClass.computeIfAbsent(dtoClass, _Xml::contextOf)
+                : contextOf(dtoClass);
     }
 
     @SneakyThrows
-    private static <T> JAXBContext contextOf(final Class<T> type) {
+    private static <T> JAXBContext contextOf(final Class<T> dtoClass) {
         try {
-            return JAXBContext.newInstance(type);
-        } catch (IllegalAnnotationsException e) {
-            throw _Exceptions.unrecoverableFormatted("%s", e.getErrors(), e);
+            return JAXBContext.newInstance(dtoClass);
+        } catch (Exception e) {
+            throw verbose("obtaining JAXBContext for class", dtoClass, e);
         }
     }
 
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/IsisModuleCoreRuntimeServices.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/IsisModuleCoreRuntimeServices.java
index 5fa6705..50e5143 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/IsisModuleCoreRuntimeServices.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/IsisModuleCoreRuntimeServices.java
@@ -41,6 +41,7 @@ import org.apache.isis.core.runtimeservices.homepage.HomePageResolverServiceDefa
 import org.apache.isis.core.runtimeservices.i18n.po.TranslationServicePo;
 import org.apache.isis.core.runtimeservices.i18n.po.TranslationServicePoMenu;
 import org.apache.isis.core.runtimeservices.ixn.InteractionDtoServiceInternalDefault;
+import org.apache.isis.core.runtimeservices.jaxb.JaxbServiceDefault;
 import org.apache.isis.core.runtimeservices.menubars.MenuBarsLoaderServiceDefault;
 import org.apache.isis.core.runtimeservices.menubars.bootstrap3.MenuBarsServiceBS3;
 import org.apache.isis.core.runtimeservices.message.MessageServiceDefault;
@@ -80,6 +81,7 @@ import org.apache.isis.core.runtimeservices.xmlsnapshot.XmlSnapshotServiceDefaul
         HomePageResolverServiceDefault.class,
         InteractionDtoServiceInternalDefault.class,
         IsisInteractionFactoryDefault.class,
+        JaxbServiceDefault.class,
         TranslationServicePo.class,
         MenuBarsLoaderServiceDefault.class,
         MenuBarsServiceBS3.class,
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbServiceDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/jaxb/JaxbServiceDefault.java
similarity index 58%
rename from api/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbServiceDefault.java
rename to core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/jaxb/JaxbServiceDefault.java
index e990777..a053ab1 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbServiceDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/jaxb/JaxbServiceDefault.java
@@ -16,13 +16,13 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.isis.applib.services.jaxb;
+package org.apache.isis.core.runtimeservices.jaxb;
 
 import java.util.Map;
 
-import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Named;
+import javax.inject.Provider;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
@@ -34,70 +34,40 @@ import org.springframework.context.annotation.Primary;
 import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Service;
 
-import org.apache.isis.applib.NonRecoverableException;
 import org.apache.isis.applib.annotation.OrderPrecedence;
 import org.apache.isis.applib.domain.DomainObjectList;
 import org.apache.isis.applib.jaxb.PersistentEntitiesAdapter;
 import org.apache.isis.applib.jaxb.PersistentEntityAdapter;
 import org.apache.isis.applib.services.inject.ServiceInjector;
+import org.apache.isis.applib.services.jaxb.JaxbService;
 import org.apache.isis.applib.services.metamodel.MetaModelService;
-import org.apache.isis.applib.services.registry.ServiceRegistry;
+import org.apache.isis.commons.internal.resources._Xml;
 
-import lombok.AllArgsConstructor;
-import lombok.NoArgsConstructor;
+import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+import lombok.SneakyThrows;
+import lombok.val;
 
 @Service
-@Named("isisApplib.JaxbServiceDefault")
+@Named("isisRuntimeServices.JaxbServiceDefault")
 @Order(OrderPrecedence.MIDPOINT)
 @Primary
 @Qualifier("Default")
-@NoArgsConstructor @AllArgsConstructor
+@RequiredArgsConstructor(onConstructor_ = {@Inject})
 public class JaxbServiceDefault extends JaxbService.Simple {
 
-    @Inject private ServiceRegistry serviceRegistry;
-    @Inject private ServiceInjector serviceInjector;
-    /*@Inject circular dependency*/private MetaModelService metaModelService;
+    private final ServiceInjector serviceInjector;
+    /*circular dependency, so use provider*/
+    private final Provider<MetaModelService> metaModelServiceProvider;
 
-    /*@Inject circular dependency*/
-    public JaxbServiceDefault(ServiceInjector serviceInjector, MetaModelService metaModelService) {
-        this.serviceInjector = serviceInjector;
-        this.metaModelService = metaModelService;
-    }
-    
-    @PostConstruct
-    public void init(){
-        this.metaModelService = serviceRegistry.lookupServiceElseFail(MetaModelService.class);
-    }
-
-    @Override
-    public Object fromXml(final JAXBContext jaxbContext, final String xml, final Map<String, Object> unmarshallerProperties) {
-        try {
-            Object pojo = internalFromXml(jaxbContext, xml, unmarshallerProperties);
-
-            if(pojo instanceof DomainObjectList) {
-
-                // go around the loop again, so can properly deserialize the contents
-                DomainObjectList list = (DomainObjectList) pojo;
-                JAXBContext jaxbContextForList = jaxbContextFor(list);
-
-                return internalFromXml(jaxbContextForList, xml, unmarshallerProperties);
-            }
-
-            return pojo;
-
-        } catch (final JAXBException ex) {
-            throw new NonRecoverableException("Error unmarshalling XML", ex);
-        }
-    }
-
-    @Override
-    protected JAXBContext jaxbContextFor(final Object domainObject) {
-        final Class<?> domainClass = domainObject.getClass();
+    @Override @SneakyThrows
+    protected JAXBContext jaxbContextForObject(final @NonNull Object domainObject) {
         if(domainObject instanceof DomainObjectList) {
-            DomainObjectList list = (DomainObjectList) domainObject;
+            val domainClass = domainObject.getClass();
+            val domainObjectList = (DomainObjectList) domainObject;
             try {
-                final String elementObjectType = list.getElementObjectType();
-                final Class<?> elementType = metaModelService.fromObjectType(elementObjectType);
+                val elementType = metaModelServiceProvider.get()
+                        .fromObjectType(domainObjectList.getElementObjectType());
                 if (elementType!=null 
                         && elementType.getAnnotation(XmlJavaTypeAdapter.class) == null) {
                     
@@ -105,13 +75,28 @@ public class JaxbServiceDefault extends JaxbService.Simple {
                 } else {
                     return JAXBContext.newInstance(domainClass);
                 }
-            } catch (JAXBException e) {
-                throw new RuntimeException(e);
+            } catch (Exception e) {
+                throw _Xml.verbose("obtaining JAXBContext for a DomainObjectList", domainClass, e);
             }
         }
-        return super.jaxbContextFor(domainObject);
+        return super.jaxbContextForObject(domainObject);
     }
 
+    @Override
+    protected Object internalFromXml(@NonNull JAXBContext jaxbContext, String xml,
+            Map<String, Object> unmarshallerProperties) throws JAXBException {
+     
+        val pojo = super.internalFromXml(jaxbContext, xml, unmarshallerProperties);
+        if(pojo instanceof DomainObjectList) {
+
+            // go around the loop again, so can properly deserialize the contents
+            val domainObjectList = (DomainObjectList) pojo;
+            val jaxbContextForList = jaxbContextForObject(domainObjectList);
+
+            return internalFromXml(jaxbContextForList, xml, unmarshallerProperties);
+        }
+        return pojo;
+    }
 
     @Override
     protected void configure(final Unmarshaller unmarshaller) {
diff --git a/core/runtimeservices/src/test/java/org/apache/isis/core/metamodel/commons/internal/reflection/ReflectTest.java b/core/runtimeservices/src/test/java/org/apache/isis/core/metamodel/commons/internal/reflection/ReflectTest.java
index 505f2df..5bb62c2 100644
--- a/core/runtimeservices/src/test/java/org/apache/isis/core/metamodel/commons/internal/reflection/ReflectTest.java
+++ b/core/runtimeservices/src/test/java/org/apache/isis/core/metamodel/commons/internal/reflection/ReflectTest.java
@@ -22,16 +22,16 @@ package org.apache.isis.core.metamodel.commons.internal.reflection;
 import java.lang.reflect.Method;
 import java.util.List;
 import java.util.Set;
+import java.util.TreeSet;
 import java.util.stream.Collectors;
 
 import org.junit.jupiter.api.Test;
 
 import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 import org.apache.isis.applib.annotation.Programmatic;
-import org.apache.isis.applib.services.jaxb.JaxbServiceDefault;
-import org.apache.isis.commons.collections.Can;
 import org.apache.isis.commons.internal.collections._Sets;
 import org.apache.isis.commons.internal.reflection._Reflect.InterfacePolicy;
 import org.apache.isis.core.runtimeservices.user.UserServiceDefault;
@@ -114,21 +114,26 @@ class ReflectTest {
         assertNotNull(annot);
     }
 
+    static class A extends I.B {}
+    static interface I {
+        static class B implements I {}
+    }
+    
+    
     @Test
     void typeHierarchyAndInterfaces2() {
 
-        Class<?> type = JaxbServiceDefault.class;
+        Class<?> type = A.class;
 
         val typeSet = streamTypeHierarchy(type, InterfacePolicy.INCLUDE)
-                .map(t->t.getName())
-                .collect(Collectors.toSet());
-
-        assertSetContainsAll(_Sets.<String>of(
-                "org.apache.isis.applib.services.jaxb.JaxbServiceDefault",
-                "org.apache.isis.applib.services.jaxb.JaxbService$Simple",
-                "org.apache.isis.applib.services.jaxb.JaxbService",
-                "java.lang.Object"),
-            typeSet);
+                .map(t->t.getSimpleName())
+                .collect(Collectors.toCollection(TreeSet::new));
+
+        assertEquals(_Sets.<String>ofSorted(
+                "A",
+                "B",
+                "I",
+                "Object"), typeSet);
 
     }
 


[isis] 02/02: ISIS-2446: sync adoc and update sys overview

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b51937212e52f4358ca495e87393533078a5de16
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Oct 9 12:20:35 2020 +0200

    ISIS-2446: sync adoc and update sys overview
---
 .../system/modules/ROOT/pages/about.adoc           |   2 +-
 .../conmap/ContentMappingServiceForCommandDto.java |  18 +-
 .../examples/services/jaxb/JaxbService.java        | 223 +++++++++------------
 .../examples/services/jaxb/JaxbServiceDefault.java | 134 -------------
 4 files changed, 109 insertions(+), 268 deletions(-)

diff --git a/antora/components/system/modules/ROOT/pages/about.adoc b/antora/components/system/modules/ROOT/pages/about.adoc
index 165678c..37b8492 100644
--- a/antora/components/system/modules/ROOT/pages/about.adoc
+++ b/antora/components/system/modules/ROOT/pages/about.adoc
@@ -1750,7 +1750,7 @@ _Dependencies_
 
 * org.apache.isis.core:isis-core-internaltestsupport:jar:<managed>
 * org.apache.isis.core:isis-core-runtime:jar:<managed>
-* org.webjars:font-awesome:jar:5.13.0
+* org.webjars:font-awesome:jar:5.15.0
 
 
 
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/commanddto/conmap/ContentMappingServiceForCommandDto.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/commanddto/conmap/ContentMappingServiceForCommandDto.java
index 9fd3a67..2651643 100644
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/commanddto/conmap/ContentMappingServiceForCommandDto.java
+++ b/api/applib/src/main/adoc/modules/applib-svc/examples/services/commanddto/conmap/ContentMappingServiceForCommandDto.java
@@ -20,6 +20,7 @@ package org.apache.isis.applib.services.commanddto.conmap;
 
 import java.util.List;
 
+import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.ws.rs.core.MediaType;
@@ -46,8 +47,8 @@ import lombok.val;
 @Qualifier("CommandDto")
 public class ContentMappingServiceForCommandDto implements ContentMappingService {
 
-    @Override
-    public Object map(Object object, final List<MediaType> acceptableMediaTypes) {
+    @Override @Nullable
+    public Object map(final Object object, final List<MediaType> acceptableMediaTypes) {
         final boolean supported = Util.isSupported(CommandDto.class, acceptableMediaTypes);
         if(!supported) {
             return null;
@@ -56,12 +57,14 @@ public class ContentMappingServiceForCommandDto implements ContentMappingService
         return asProcessedDto(object);
     }
 
+    @Nullable
     CommandDto asProcessedDto(final Object object) {
         val commandDto = asCommandDto(object);
         return asProcessedDto(object, commandDto);
     }
 
-    private CommandDto asCommandDto(Object object) {
+    @Nullable
+    private CommandDto asCommandDto(final Object object) {
         if(object instanceof CommandDto) {
             return (CommandDto) object;
         }
@@ -71,10 +74,15 @@ public class ContentMappingServiceForCommandDto implements ContentMappingService
         return null;
     }
 
-    private CommandDto asProcessedDto(final Object domainObject, CommandDto commandDto) {
+    @Nullable
+    private CommandDto asProcessedDto(final Object domainObject, @Nullable CommandDto commandDto) {
 
+        if(commandDto == null) {
+            return null;
+        }
+        
         // global processors
-        for (final CommandDtoProcessorService commandDtoProcessorService : commandDtoProcessorServices) {
+        for (val commandDtoProcessorService : commandDtoProcessorServices) {
             commandDto = commandDtoProcessorService.process(domainObject, commandDto);
             if(commandDto == null) {
                 // any processor could return null, effectively breaking the chain.
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/jaxb/JaxbService.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/jaxb/JaxbService.java
index 4148840..bf0344c 100644
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/jaxb/JaxbService.java
+++ b/api/applib/src/main/adoc/modules/applib-svc/examples/services/jaxb/JaxbService.java
@@ -18,13 +18,9 @@
  */
 package org.apache.isis.applib.services.jaxb;
 
-import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
-import java.lang.reflect.Method;
-import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 import javax.annotation.Nullable;
 import javax.xml.bind.JAXBContext;
@@ -32,34 +28,37 @@ import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 
-import org.apache.isis.applib.ApplicationException;
-import org.apache.isis.applib.NonRecoverableException;
 import org.apache.isis.applib.mixins.dto.Dto_downloadXsd;
-import org.apache.isis.applib.util.JaxbUtil;
 import org.apache.isis.commons.internal.base._Casts;
 import org.apache.isis.commons.internal.base._NullSafe;
-import org.apache.isis.commons.internal.collections._Maps;
+import org.apache.isis.commons.internal.resources._Xml;
 
 import lombok.NonNull;
+import lombok.SneakyThrows;
+import lombok.val;
 
 // tag::refguide[]
 public interface JaxbService {
 
-    Object fromXml(                                     // <.>
+    default Object fromXml(                             // <.>
             JAXBContext jaxbContext,
-            String xml);
+            String xml) {
+        return fromXml(jaxbContext, xml, null);
+    }
 
     Object fromXml(                                     // <.>
             JAXBContext jaxbContext,
             String xml,
-            Map<String,Object> unmarshallerProperties);
+            @Nullable Map<String,Object> unmarshallerProperties);
 
     // end::refguide[]
     /**
      * As {@link #fromXml(JAXBContext, String)}, but downcast to a specific type.
      */
     // tag::refguide[]
-    <T> T fromXml(Class<T> domainClass, String xml);    // <.>
+    default <T> T fromXml(Class<T> domainClass, String xml) { // <.>
+        return fromXml(domainClass, xml, null);
+    }
 
     // end::refguide[]
     /**
@@ -69,13 +68,15 @@ public interface JaxbService {
     <T> T fromXml(                                      // <.>
             Class<T> domainClass,
             String xml,
-            Map<String,Object> unmarshallerProperties);
-
-    String toXml(final Object domainObject);            // <.>
+            @Nullable Map<String,Object> unmarshallerProperties);
 
+    default String toXml(Object domainObject) {         // <.>
+        return toXml(domainObject, null);
+    }
+        
     String toXml(                                       // <.>
-            final Object domainObject,
-            Map<String,Object> marshallerProperties);
+            Object domainObject,
+            @Nullable Map<String,Object> marshallerProperties);
 
     // end::refguide[]
     /**
@@ -110,137 +111,83 @@ public interface JaxbService {
         // tag::refguide[]
     }
 
-    Map<String, String> toXsd(                          // <.>
-            final Object domainObject,
-            final IsisSchemas isisSchemas);
+    Map<String, String> toXsd(                 // <.>
+            Object domainObject, 
+            IsisSchemas isisSchemas);
 
     // end::refguide[]
     class Simple implements JaxbService {
 
-        @Override
-        public Object fromXml(final JAXBContext jaxbContext, final String xml) {
-            return fromXml(jaxbContext, xml, _Maps.newHashMap());
-        }
-
-        @Override
-        public Object fromXml(final JAXBContext jaxbContext, final String xml, final Map<String, Object> unmarshallerProperties) {
+        @Override @SneakyThrows @Nullable
+        public Object fromXml(
+                final @NonNull JAXBContext jaxbContext, 
+                final @Nullable String xml, 
+                final @Nullable Map<String, Object> unmarshallerProperties) {
             try {
-
                 return internalFromXml(jaxbContext, xml, unmarshallerProperties);
-
-            } catch (final JAXBException ex) {
-                throw new NonRecoverableException("Error unmarshalling XML", ex);
+            } catch (Exception e) {
+                throw _Xml.verbose("unmarshalling XML", null, e);
             }
         }
 
-        protected Object internalFromXml(
-                @NonNull final JAXBContext jaxbContext,
-                @Nullable final String xml,
-                @Nullable final Map<String, Object> unmarshallerProperties) throws JAXBException {
-            
-            if(xml==null) {
-                return null;
-            }
+        @Override @SneakyThrows @Nullable
+        public <T> T fromXml(
+                final @NonNull Class<T> domainClass, 
+                final @Nullable String xml, 
+                final @Nullable Map<String, Object> unmarshallerProperties) {
             
-            final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
-
-            if(unmarshallerProperties!=null) {
-                for (Map.Entry<String, Object> entry : unmarshallerProperties.entrySet()) {
-                    unmarshaller.setProperty(entry.getKey(), entry.getValue());
-                }
-            }
-
-            configure(unmarshaller);
-
-            return unmarshaller.unmarshal(new StringReader(xml));
-        }
-
-        @Override
-        public <T> T fromXml(final Class<T> domainClass, final String xml) {
-            return fromXml(domainClass, xml, _Maps.newHashMap());
-        }
-
-        @Override
-        public <T> T fromXml(final Class<T> domainClass, final String xml, final Map<String, Object> unmarshallerProperties) {
-            final JAXBContext context = jaxbContextFor(domainClass);
-            return _Casts.uncheckedCast(fromXml(context, xml, unmarshallerProperties));
-        }
-
-        private static <T> JAXBContext jaxbContextFor(final Class<T> clazz)  {
             try {
-                return JaxbUtil.jaxbContextFor(clazz);
-            } catch (RuntimeException e) {
-                throw new NonRecoverableException("Error obtaining JAXBContext for class '" + clazz + "'", e.getCause());
+                val jaxbContext = jaxbContextForClass(domainClass);
+                return _Casts.uncheckedCast(internalFromXml(jaxbContext, xml, unmarshallerProperties));
+            } catch (Exception e) {
+                throw _Xml.verbose("unmarshalling XML", domainClass, e);
             }
         }
 
-        @Override
-        public String toXml(final Object domainObject) {
-            return toXml(domainObject, _Maps.newHashMap());
-        }
-
-        @Override
-        public String toXml(final Object domainObject, final Map<String, Object> marshallerProperties)  {
+        @Override @SneakyThrows
+        public String toXml(
+                final @NonNull Object domainObject, 
+                final @Nullable Map<String, Object> marshallerProperties)  {
 
-            final Class<?> domainClass = domainObject.getClass();
-            final JAXBContext context = jaxbContextFor(domainObject);
+            val domainClass = domainObject.getClass();
+            val jaxbContext = jaxbContextForObject(domainObject);
             try {
-                final Marshaller marshaller = context.createMarshaller();
+                val marshaller = jaxbContext.createMarshaller();
 
                 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
-                for (Map.Entry<String, Object> entry : marshallerProperties.entrySet()) {
-                    marshaller.setProperty(entry.getKey(), entry.getValue());
+                if(!_NullSafe.isEmpty(marshallerProperties)) {
+                    for (val entry : marshallerProperties.entrySet()) {
+                        marshaller.setProperty(entry.getKey(), entry.getValue());
+                    }
                 }
 
                 configure(marshaller);
 
-                final StringWriter sw = new StringWriter();
-                marshaller.marshal(domainObject, sw);
-                final String xml = sw.toString();
+                val writer = new StringWriter();
+                marshaller.marshal(domainObject, writer);
+                val xml = writer.toString();
 
                 return xml;
 
-            } catch (final JAXBException ex) {
-                final Class<? extends JAXBException> exClass = ex.getClass();
-
-                final String name = exClass.getName();
-                if(name.equals("com.sun.xml.bind.v2.runtime.IllegalAnnotationsException")) {
-                    // report a better error if possible
-                    // this is done reflectively so as to not have to bring in a new Maven dependency
-                    List<? extends Exception> errors = null;
-                    String annotationExceptionMessages = null;
-                    try {
-                        final Method getErrorsMethod = exClass.getMethod("getErrors");
-                        errors = _Casts.uncheckedCast(getErrorsMethod.invoke(ex));
-
-                        annotationExceptionMessages = ": " +
-                                _NullSafe.stream(errors)
-                        .map(Exception::getMessage)
-                        .collect(Collectors.joining("; "));
-
-                    } catch (Exception e) {
-                        // fall through if we hit any snags, and instead throw the more generic error message.
-                    }
-                    if(errors != null) {
-                        throw new NonRecoverableException(
-                                "Error marshalling domain object to XML, due to illegal annotations on domain object class '"
-                                        + domainClass.getName() + "'; " + errors.size() + " error"
-                                        + (errors.size() == 1? "": "s")
-                                        + " reported" + (!errors
-                                                .isEmpty() ? annotationExceptionMessages : ""), ex);
-                    }
-                }
-
-                throw new NonRecoverableException("Error marshalling domain object to XML; domain object class is '" + domainClass.getName() + "'", ex);
+            } catch (Exception e) {
+                throw _Xml.verbose("marshalling domain object to XML", domainClass, e);
             }
         }
 
         /**
          * Optional hook
          */
-        protected JAXBContext jaxbContextFor(final Object domainObject) {
-            final Class<?> domainClass = domainObject.getClass();
-            return jaxbContextFor(domainClass);
+        protected JAXBContext jaxbContextForObject(final @NonNull Object domainObject) {
+            val useCache = true;
+            return _Xml.jaxbContextFor(domainObject.getClass(), useCache);
+        }
+        
+        /**
+         * Optional hook
+         */
+        protected JAXBContext jaxbContextForClass(final @NonNull Class<?> domainObjectClass) {
+            val useCache = true;
+            return _Xml.jaxbContextFor(domainObjectClass, useCache);
         }
 
         /**
@@ -255,21 +202,41 @@ public interface JaxbService {
         protected void configure(final Marshaller marshaller) {
         }
 
-        @Override
-        public Map<String,String> toXsd(final Object domainObject, final IsisSchemas isisSchemas) {
+        @Nullable
+        protected Object internalFromXml(
+                final @NonNull JAXBContext jaxbContext,
+                final @Nullable String xml,
+                final @Nullable Map<String, Object> unmarshallerProperties) throws JAXBException {
+            
+            if(xml==null) {
+                return null;
+            }
+            
+            val unmarshaller = jaxbContext.createUnmarshaller();
+            if(!_NullSafe.isEmpty(unmarshallerProperties)) {
+                for (val entry : unmarshallerProperties.entrySet()) {
+                    unmarshaller.setProperty(entry.getKey(), entry.getValue());
+                }
+            }
+            configure(unmarshaller);
+
+            val pojo = unmarshaller.unmarshal(new StringReader(xml));
+            return pojo;
+        }
+        
+        @Override @SneakyThrows
+        public Map<String,String> toXsd(
+                final @NonNull Object domainObject, 
+                final @NonNull IsisSchemas isisSchemas) {
 
-            try {
-                final Class<?> domainClass = domainObject.getClass();
-                final JAXBContext context = jaxbContextFor(domainClass);
+            val jaxbContext = jaxbContextForObject(domainObject);
 
-                final CatalogingSchemaOutputResolver outputResolver = new CatalogingSchemaOutputResolver(isisSchemas);
-                context.generateSchema(outputResolver);
+            val outputResolver = new CatalogingSchemaOutputResolver(isisSchemas);
+            jaxbContext.generateSchema(outputResolver);
 
-                return outputResolver.asMap();
-            } catch (final IOException ex) {
-                throw new ApplicationException(ex);
-            }
+            return outputResolver.asMap();
         }
+        
     }
 
     // tag::refguide[]
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/jaxb/JaxbServiceDefault.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/jaxb/JaxbServiceDefault.java
deleted file mode 100644
index e990777..0000000
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/jaxb/JaxbServiceDefault.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.apache.isis.applib.services.jaxb;
-
-import java.util.Map;
-
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.context.annotation.Primary;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Service;
-
-import org.apache.isis.applib.NonRecoverableException;
-import org.apache.isis.applib.annotation.OrderPrecedence;
-import org.apache.isis.applib.domain.DomainObjectList;
-import org.apache.isis.applib.jaxb.PersistentEntitiesAdapter;
-import org.apache.isis.applib.jaxb.PersistentEntityAdapter;
-import org.apache.isis.applib.services.inject.ServiceInjector;
-import org.apache.isis.applib.services.metamodel.MetaModelService;
-import org.apache.isis.applib.services.registry.ServiceRegistry;
-
-import lombok.AllArgsConstructor;
-import lombok.NoArgsConstructor;
-
-@Service
-@Named("isisApplib.JaxbServiceDefault")
-@Order(OrderPrecedence.MIDPOINT)
-@Primary
-@Qualifier("Default")
-@NoArgsConstructor @AllArgsConstructor
-public class JaxbServiceDefault extends JaxbService.Simple {
-
-    @Inject private ServiceRegistry serviceRegistry;
-    @Inject private ServiceInjector serviceInjector;
-    /*@Inject circular dependency*/private MetaModelService metaModelService;
-
-    /*@Inject circular dependency*/
-    public JaxbServiceDefault(ServiceInjector serviceInjector, MetaModelService metaModelService) {
-        this.serviceInjector = serviceInjector;
-        this.metaModelService = metaModelService;
-    }
-    
-    @PostConstruct
-    public void init(){
-        this.metaModelService = serviceRegistry.lookupServiceElseFail(MetaModelService.class);
-    }
-
-    @Override
-    public Object fromXml(final JAXBContext jaxbContext, final String xml, final Map<String, Object> unmarshallerProperties) {
-        try {
-            Object pojo = internalFromXml(jaxbContext, xml, unmarshallerProperties);
-
-            if(pojo instanceof DomainObjectList) {
-
-                // go around the loop again, so can properly deserialize the contents
-                DomainObjectList list = (DomainObjectList) pojo;
-                JAXBContext jaxbContextForList = jaxbContextFor(list);
-
-                return internalFromXml(jaxbContextForList, xml, unmarshallerProperties);
-            }
-
-            return pojo;
-
-        } catch (final JAXBException ex) {
-            throw new NonRecoverableException("Error unmarshalling XML", ex);
-        }
-    }
-
-    @Override
-    protected JAXBContext jaxbContextFor(final Object domainObject) {
-        final Class<?> domainClass = domainObject.getClass();
-        if(domainObject instanceof DomainObjectList) {
-            DomainObjectList list = (DomainObjectList) domainObject;
-            try {
-                final String elementObjectType = list.getElementObjectType();
-                final Class<?> elementType = metaModelService.fromObjectType(elementObjectType);
-                if (elementType!=null 
-                        && elementType.getAnnotation(XmlJavaTypeAdapter.class) == null) {
-                    
-                    return JAXBContext.newInstance(domainClass, elementType);
-                } else {
-                    return JAXBContext.newInstance(domainClass);
-                }
-            } catch (JAXBException e) {
-                throw new RuntimeException(e);
-            }
-        }
-        return super.jaxbContextFor(domainObject);
-    }
-
-
-    @Override
-    protected void configure(final Unmarshaller unmarshaller) {
-        unmarshaller.setAdapter(PersistentEntityAdapter.class,
-                serviceInjector.injectServicesInto(new PersistentEntityAdapter()));
-        unmarshaller.setAdapter(PersistentEntitiesAdapter.class,
-                serviceInjector.injectServicesInto(new PersistentEntitiesAdapter()));
-    }
-
-    @Override
-    protected void configure(final Marshaller marshaller) {
-        marshaller.setAdapter(PersistentEntityAdapter.class,
-                serviceInjector.injectServicesInto(new PersistentEntityAdapter()));
-        marshaller.setAdapter(PersistentEntitiesAdapter.class,
-                serviceInjector.injectServicesInto(new PersistentEntitiesAdapter()));
-    }
-
-
-}
-