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 2015/11/13 18:57:18 UTC

[07/11] isis git commit: ISIS-1250: boolean property to include/ignore the isis schemas for the toXsd(...) method.

ISIS-1250: boolean property to include/ignore the isis schemas for the toXsd(...) method.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/b17dc0e1
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/b17dc0e1
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/b17dc0e1

Branch: refs/heads/master
Commit: b17dc0e1a9a5ff6267ab1d6a051b66f62627cf41
Parents: 0e9d1b2
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Nov 13 12:18:41 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Nov 13 12:18:41 2015 +0000

----------------------------------------------------------------------
 .../services/jaxb/JaxbServiceDefault.java       | 26 +++++++++++++++++++-
 .../util/CatalogingSchemaOutputResolver.java    | 13 ++++++++--
 2 files changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/b17dc0e1/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/JaxbServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/JaxbServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/JaxbServiceDefault.java
index 6d86f4f..caeb11e 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/JaxbServiceDefault.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/JaxbServiceDefault.java
@@ -23,6 +23,7 @@ import java.lang.reflect.Method;
 import java.util.List;
 import java.util.Map;
 
+import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
@@ -47,6 +48,29 @@ import org.apache.isis.schema.utils.jaxbadapters.PersistentEntityAdapter;
 )
 public class JaxbServiceDefault implements JaxbService {
 
+    /**
+     * This boolean flag controls whether, when generating {@link #toXsd(Object) XML schemas},
+     * any of the common Isis schemas (in the namespace <code>http://org.apache.isis.schema</code>) should be included or just ignored (and therefore don't appear in the ZIP file).
+     *
+     * <p>
+     *     The practical benefit of this is that for many DTOs there will only be one other
+     *     schema, that of the DTO itself.  Rather than generating a ZIP of two schemas (the Isis
+     *     schema and the one for the DTO), the {@link #toXsd(Object) toXsd} method will instead
+     *     return a single XSD file; far more convenient when debugging and so on.
+     *     The Isis schemas meanwhile can always be <a href="http://isis.apache.org/schema">downloaded from the website </a>.
+     * </p>
+     */
+    public static final String INCLUDE_ISIS_SCHEMA = "isis.services.jaxb.includeIsisSchema";
+
+    private boolean includeIsisSchema;
+
+    @PostConstruct
+    public void init(Map<String,String> props) {
+        final String prop = props.get(INCLUDE_ISIS_SCHEMA);
+        this.includeIsisSchema = prop != null && Boolean.parseBoolean(prop);
+
+    }
+
     @Override
     public <T> T fromXml(final Class<T> domainClass, final String xml) {
         try {
@@ -127,7 +151,7 @@ public class JaxbServiceDefault implements JaxbService {
             final Class<?> domainClass = domainObject.getClass();
             final JAXBContext context = JAXBContext.newInstance(domainClass);
 
-            final CatalogingSchemaOutputResolver outputResolver = new CatalogingSchemaOutputResolver();
+            final CatalogingSchemaOutputResolver outputResolver = new CatalogingSchemaOutputResolver(includeIsisSchema);
             context.generateSchema(outputResolver);
 
             return outputResolver.asMap();

http://git-wip-us.apache.org/repos/asf/isis/blob/b17dc0e1/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/CatalogingSchemaOutputResolver.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/CatalogingSchemaOutputResolver.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/CatalogingSchemaOutputResolver.java
index 460c97f..b267284 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/CatalogingSchemaOutputResolver.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/CatalogingSchemaOutputResolver.java
@@ -34,8 +34,13 @@ import com.google.common.collect.Maps;
  */
 public class CatalogingSchemaOutputResolver extends SchemaOutputResolver
 {
+    private final boolean includeIsisSchema;
     private List<String> namespaceUris = Lists.newArrayList();
 
+    public CatalogingSchemaOutputResolver(final boolean includeIsisSchema) {
+        this.includeIsisSchema = includeIsisSchema;
+    }
+
     public List<String> getNamespaceUris() {
         return namespaceUris;
     }
@@ -55,8 +60,12 @@ public class CatalogingSchemaOutputResolver extends SchemaOutputResolver
 
         result.setSystemId(namespaceUri);
 
-        namespaceUris.add(namespaceUri);
-        schemaResultByNamespaceUri.put(namespaceUri, result);
+        if (namespaceUri.matches(".*isis\\.apache\\.org.*") && !includeIsisSchema) {
+            // ignore
+        } else {
+            namespaceUris.add(namespaceUri);
+            schemaResultByNamespaceUri.put(namespaceUri, result);
+        }
 
         return result;
     }