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:12 UTC

[01/11] isis git commit: ISIS-915: recognize @XmlRootElement as a view model (ViewModelFacet)

Repository: isis
Updated Branches:
  refs/heads/master 2f5bd5273 -> 25ce73609


ISIS-915: recognize @XmlRootElement as a view model (ViewModelFacet)


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

Branch: refs/heads/master
Commit: b403a2c75ecc8b8cadddb72cf7dda5ad687c4223
Parents: 2f5bd52
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Nov 12 16:31:49 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Thu Nov 12 16:31:49 2015 +0000

----------------------------------------------------------------------
 .../RecreatableObjectFacetFactory.java          | 12 +++++-
 ...atableObjectFacetForViewModelAnnotation.java | 40 ++++++++++++++++++++
 ...eObjectFacetForXmlRootElementAnnotation.java | 40 ++++++++++++++++++++
 3 files changed, 91 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/b403a2c7/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
index b2f3120..fcda954 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
@@ -23,6 +23,7 @@ import java.lang.reflect.Method;
 import java.util.Map;
 
 import javax.annotation.PostConstruct;
+import javax.xml.bind.annotation.XmlRootElement;
 
 import com.google.common.collect.Maps;
 
@@ -77,6 +78,10 @@ public class RecreatableObjectFacetFactory extends FacetFactoryAbstract
         final org.apache.isis.applib.annotation.ViewModel annotation = Annotations.getAnnotation(processClassContext.getCls(), org.apache.isis.applib.annotation.ViewModel.class);
         FacetUtil.addFacet(create(annotation, processClassContext.getFacetHolder()));
 
+        // XmlRootElement annotation
+        final XmlRootElement xmlRootElement = Annotations.getAnnotation(processClassContext.getCls(), XmlRootElement.class);
+        FacetUtil.addFacet(create(xmlRootElement, processClassContext.getFacetHolder()));
+
         // RecreatableDomainObject interface
         if (RecreatableDomainObject.class.isAssignableFrom(processClassContext.getCls())) {
             final PostConstructMethodCache postConstructMethodCache = this;
@@ -89,7 +94,12 @@ public class RecreatableObjectFacetFactory extends FacetFactoryAbstract
 
     private ViewModelFacet create(final org.apache.isis.applib.annotation.ViewModel annotation, final FacetHolder holder) {
         final PostConstructMethodCache postConstructMethodCache = this;
-        return annotation != null ? new RecreatableObjectFacetForRecreatableObjectAnnotation(holder, getSpecificationLoader(), adapterManager, servicesInjector, postConstructMethodCache) : null;
+        return annotation != null ? new RecreatableObjectFacetForViewModelAnnotation(holder, getSpecificationLoader(), adapterManager, servicesInjector, postConstructMethodCache) : null;
+    }
+
+    private ViewModelFacet create(final XmlRootElement annotation, final FacetHolder holder) {
+        final PostConstructMethodCache postConstructMethodCache = this;
+        return annotation != null ? new RecreatableObjectFacetForXmlRootElementAnnotation(holder, getSpecificationLoader(), adapterManager, servicesInjector, postConstructMethodCache) : null;
     }
 
     // //////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/isis/blob/b403a2c7/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForViewModelAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForViewModelAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForViewModelAnnotation.java
new file mode 100644
index 0000000..dec2264
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForViewModelAnnotation.java
@@ -0,0 +1,40 @@
+/*
+ *  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.core.metamodel.facets.object.recreatable;
+
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.PostConstructMethodCache;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
+
+public class RecreatableObjectFacetForViewModelAnnotation extends RecreatableObjectFacetDeclarativeAbstract {
+
+    public RecreatableObjectFacetForViewModelAnnotation(
+            final FacetHolder holder,
+            final SpecificationLoader specificationLoader,
+            final AdapterManager adapterManager,
+            final ServicesInjector servicesInjector,
+            final PostConstructMethodCache postConstructMethodCache) {
+        super(holder, ArchitecturalLayer.APPLICATION,
+                specificationLoader, adapterManager, servicesInjector, postConstructMethodCache);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b403a2c7/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java
new file mode 100644
index 0000000..e416416
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java
@@ -0,0 +1,40 @@
+/*
+ *  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.core.metamodel.facets.object.recreatable;
+
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.PostConstructMethodCache;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
+
+public class RecreatableObjectFacetForXmlRootElementAnnotation extends RecreatableObjectFacetDeclarativeAbstract {
+
+    public RecreatableObjectFacetForXmlRootElementAnnotation(
+            final FacetHolder holder,
+            final SpecificationLoader specificationLoader,
+            final AdapterManager adapterManager,
+            final ServicesInjector servicesInjector,
+            final PostConstructMethodCache postConstructMethodCache) {
+        super(holder, ArchitecturalLayer.APPLICATION,
+                specificationLoader, adapterManager, servicesInjector, postConstructMethodCache);
+    }
+
+}


[04/11] isis git commit: ISIS-915 and ISIS-1251: use JAXB to create memento for the RecreatableObjectFacetForXmlRootElementAnnotation implementation of ViewModelFacet. Also factored out UrlEncodingService.

Posted by da...@apache.org.
ISIS-915 and ISIS-1251: use JAXB to create memento for the RecreatableObjectFacetForXmlRootElementAnnotation implementation of ViewModelFacet.  Also factored out UrlEncodingService.


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

Branch: refs/heads/master
Commit: 9163f6db4fd5214057ee3562e0fae2c52ce0df36
Parents: b599436
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Nov 13 09:59:11 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Nov 13 09:59:11 2015 +0000

----------------------------------------------------------------------
 .../isis/applib/services/jaxb/JaxbService.java  |   6 +-
 .../urlencoding/UrlEncodingService.java         |  44 +++++
 ...bleObjectFacetForDomainObjectAnnotation.java |   7 +-
 .../RecreatableObjectFacetAbstract.java         |  45 ++++-
 ...creatableObjectFacetDeclarativeAbstract.java | 166 -------------------
 ...ectFacetDeclarativeInitializingAbstract.java | 165 ++++++++++++++++++
 .../RecreatableObjectFacetFactory.java          |   4 +-
 ...acetForRecreatableDomainObjectInterface.java |   6 +-
 ...jectFacetForRecreatableObjectAnnotation.java |   5 +-
 ...bjectFacetForRecreatableObjectInterface.java |   6 +-
 ...atableObjectFacetForViewModelAnnotation.java |   5 +-
 ...eObjectFacetForXmlRootElementAnnotation.java |  39 ++++-
 .../facets/object/viewmodel/ViewModelFacet.java |  49 ++++++
 .../services/jaxb/JaxbServiceDefault.java       |  49 ++++--
 .../jaxb/util/PersistentEntityAdapter.java      |  51 ------
 .../services/memento/MementoServiceDefault.java |  38 ++---
 .../system/persistence/PersistenceSession.java  |  46 +++--
 ...odaLocalTimeXMLGregorianCalendarAdapter.java |   4 -
 .../jaxbadapters/PersistentEntityAdapter.java   |  51 ++++++
 19 files changed, 493 insertions(+), 293 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
----------------------------------------------------------------------
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 61c0ecb..4c7c03b 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
@@ -23,9 +23,11 @@ import org.apache.isis.applib.annotation.Programmatic;
 public interface JaxbService {
 
     @Programmatic
-    public String toXml(final Dto dto);
+    <T> T fromXml(Class<T> domainClass, String memento);
 
     @Programmatic
-    public Map<String, String> toXsd(final Dto dto);
+    public String toXml(final Object domainObject);
 
+    @Programmatic
+    public Map<String, String> toXsd(final Object domainObject);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/applib/src/main/java/org/apache/isis/applib/services/urlencoding/UrlEncodingService.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/urlencoding/UrlEncodingService.java b/core/applib/src/main/java/org/apache/isis/applib/services/urlencoding/UrlEncodingService.java
new file mode 100644
index 0000000..9c8c25f
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/urlencoding/UrlEncodingService.java
@@ -0,0 +1,44 @@
+/**
+ *  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.urlencoding;
+
+import java.nio.charset.Charset;
+
+import com.google.common.io.BaseEncoding;
+
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.annotation.Programmatic;
+
+@DomainService(
+        nature = NatureOfService.DOMAIN
+)
+public class UrlEncodingService {
+
+    @Programmatic
+    public String decode(String str) {
+        final byte[] bytes = BaseEncoding.base64Url().decode(str);
+        return new String(bytes, Charset.forName("UTF-8"));
+    }
+
+    @Programmatic
+    public String encode(final String xmlStr) {
+        byte[] bytes = xmlStr.getBytes(Charset.forName("UTF-8"));
+        return BaseEncoding.base64Url().encode(bytes);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/recreatable/RecreatableObjectFacetForDomainObjectAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/recreatable/RecreatableObjectFacetForDomainObjectAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/recreatable/RecreatableObjectFacetForDomainObjectAnnotation.java
index 5c5eb13..7ea9baa 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/recreatable/RecreatableObjectFacetForDomainObjectAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/recreatable/RecreatableObjectFacetForDomainObjectAnnotation.java
@@ -25,11 +25,12 @@ import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
 import org.apache.isis.core.metamodel.facets.PostConstructMethodCache;
 import org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet;
-import org.apache.isis.core.metamodel.facets.object.recreatable.RecreatableObjectFacetDeclarativeAbstract;
+import org.apache.isis.core.metamodel.facets.object.recreatable.RecreatableObjectFacetDeclarativeInitializingAbstract;
 import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
 import org.apache.isis.core.metamodel.spec.SpecificationLoader;
 
-public class RecreatableObjectFacetForDomainObjectAnnotation extends RecreatableObjectFacetDeclarativeAbstract {
+public class RecreatableObjectFacetForDomainObjectAnnotation extends
+        RecreatableObjectFacetDeclarativeInitializingAbstract {
 
     public static ViewModelFacet create(
             final DomainObject domainObject,
@@ -92,7 +93,7 @@ public class RecreatableObjectFacetForDomainObjectAnnotation extends Recreatable
             final AdapterManager adapterManager,
             final ServicesInjector servicesInjector,
             final PostConstructMethodCache postConstructMethodCache) {
-        super(holder, architecturalLayer, specificationLoader, adapterManager, servicesInjector,
+        super(holder, architecturalLayer, RecreationMechanism.INITIALIZES, specificationLoader, adapterManager, servicesInjector,
                 postConstructMethodCache);
     }
 

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetAbstract.java
index a117e37..969d007 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetAbstract.java
@@ -28,11 +28,14 @@ import org.apache.isis.core.metamodel.facetapi.FacetHolder;
 import org.apache.isis.core.metamodel.facets.MarkerFacetAbstract;
 import org.apache.isis.core.metamodel.facets.PostConstructMethodCache;
 import org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
 
 public abstract class RecreatableObjectFacetAbstract extends MarkerFacetAbstract implements ViewModelFacet {
 
     private final ArchitecturalLayer architecturalLayer;
     private final PostConstructMethodCache postConstructMethodCache;
+    private final ViewModelFacet.RecreationMechanism recreationMechanism;
+    protected final ServicesInjector servicesInjector;
 
     public static Class<? extends Facet> type() {
         return ViewModelFacet.class;
@@ -41,10 +44,14 @@ public abstract class RecreatableObjectFacetAbstract extends MarkerFacetAbstract
     public RecreatableObjectFacetAbstract(
             final FacetHolder holder,
             final ArchitecturalLayer architecturalLayer,
-            final PostConstructMethodCache postConstructMethodCache) {
+            final RecreationMechanism recreationMechanism,
+            final PostConstructMethodCache postConstructMethodCache,
+            final ServicesInjector servicesInjector) {
         super(type(), holder);
         this.architecturalLayer = architecturalLayer;
         this.postConstructMethodCache = postConstructMethodCache;
+        this.recreationMechanism = recreationMechanism;
+        this.servicesInjector = servicesInjector;
     }
 
     @Override
@@ -64,19 +71,49 @@ public abstract class RecreatableObjectFacetAbstract extends MarkerFacetAbstract
     }
 
     @Override
+    public RecreationMechanism getRecreationMechanism() {
+        return recreationMechanism;
+    }
+
+    @Override
+    public final Object instantiate(
+            final Class<?> viewModelClass,
+            final String mementoStr) {
+        if(getRecreationMechanism() == RecreationMechanism.INITIALIZES) {
+            throw new IllegalStateException("This view model instantiates rather than initializes");
+        }
+        final Object viewModelPojo = doInstantiate(viewModelClass, mementoStr);
+        servicesInjector.injectInto(viewModelPojo);
+        invokePostConstructMethod(viewModelPojo);
+        return viewModelPojo;
+    }
+
+    /**
+     * Hook for subclass; must be overridden if {@link #getRecreationMechanism()} is {@link RecreationMechanism#INSTANTIATES} (ignored otherwise).
+     */
+    protected Object doInstantiate(final Class<?> viewModelClass, final String mementoStr) {
+        throw new IllegalStateException("doInstantiate() must be overridden if RecreationMechanism is INSTANTIATES");
+    }
+
+    @Override
     public final void initialize(
             final Object viewModelPojo,
             final String mementoStr) {
+        if(getRecreationMechanism() == RecreationMechanism.INSTANTIATES) {
+            throw new IllegalStateException("This view model instantiates rather than initializes");
+        }
         doInitialize(viewModelPojo, mementoStr);
         invokePostConstructMethod(viewModelPojo);
     }
 
     /**
-     * Mandatory hook for subclasses.
+     * Hook for subclass; must be overridden if {@link #getRecreationMechanism()} is {@link RecreationMechanism#INITIALIZES} (ignored otherwise).
      */
-    protected abstract void doInitialize(
+    protected void doInitialize(
             final Object viewModelPojo,
-            final String mementoStr);
+            final String mementoStr) {
+        throw new IllegalStateException("doInitialize() must be overridden if RecreationMechanism is INITIALIZE");
+    }
 
     private void invokePostConstructMethod(final Object viewModel) {
         final Method postConstructMethod = postConstructMethodCache.postConstructMethodFor(viewModel);

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetDeclarativeAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetDeclarativeAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetDeclarativeAbstract.java
deleted file mode 100644
index 0c8cf64..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetDeclarativeAbstract.java
+++ /dev/null
@@ -1,166 +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.core.metamodel.facets.object.recreatable;
-
-import java.util.List;
-import java.util.Set;
-import java.util.UUID;
-
-import org.apache.isis.applib.services.bookmark.Bookmark;
-import org.apache.isis.applib.services.bookmark.BookmarkService;
-import org.apache.isis.applib.services.memento.MementoService;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-import org.apache.isis.core.metamodel.facets.PostConstructMethodCache;
-import org.apache.isis.core.metamodel.facets.properties.update.modify.PropertySetterFacet;
-import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.SpecificationLoader;
-import org.apache.isis.core.metamodel.spec.feature.Contributed;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-
-public abstract class RecreatableObjectFacetDeclarativeAbstract extends RecreatableObjectFacetAbstract {
-
-    private final SpecificationLoader specificationLoader;
-    private final ServicesInjector servicesInjector;
-    private final AdapterManager adapterManager;
-
-    public RecreatableObjectFacetDeclarativeAbstract(
-            final FacetHolder holder,
-            final ArchitecturalLayer architecturalLayer,
-            final SpecificationLoader specificationLoader,
-            final AdapterManager adapterManager,
-            final ServicesInjector servicesInjector,
-            final PostConstructMethodCache postConstructMethodCache) {
-        super(holder, architecturalLayer, postConstructMethodCache);
-        this.specificationLoader = specificationLoader;
-        this.servicesInjector = servicesInjector;
-        this.adapterManager = adapterManager;
-    }
-
-    @Override
-    protected void doInitialize(
-            final Object viewModelPojo,
-            final String mementoStr) {
-
-        final MementoService mementoService = servicesInjector.lookupService(MementoService.class);
-        final BookmarkService bookmarkService = servicesInjector.lookupService(BookmarkService.class);
-
-        final MementoService.Memento memento = mementoService.parse(mementoStr);
-
-        final Set<String> mementoKeys = memento.keySet();
-
-        // manually recreate the adapter in order to be able to query state via the metamodel
-        ObjectAdapter viewModelAdapter = adapterManager.getAdapterFor(viewModelPojo);
-        if(viewModelAdapter == null) {
-            final ObjectSpecification objectSpecification = specificationLoader.loadSpecification(viewModelPojo.getClass());
-            final ObjectSpecId objectSpecId = objectSpecification.getSpecId();
-            viewModelAdapter = adapterManager.mapRecreatedPojo(new RootOid(objectSpecId, mementoStr, Oid.State.VIEWMODEL), viewModelPojo);
-        }
-
-        final ObjectSpecification spec = viewModelAdapter.getSpecification();
-        final List<OneToOneAssociation> properties = spec.getProperties(Contributed.EXCLUDED);
-        for (OneToOneAssociation property : properties) {
-            final String propertyId = property.getId();
-
-            Object propertyValue = null;
-
-            if(mementoKeys.contains(propertyId)) {
-                final Class<?> propertyType = property.getSpecification().getCorrespondingClass();
-                propertyValue = memento.get(propertyId, propertyType);
-            } else if(mementoKeys.contains(propertyId + ".bookmark")) {
-                final Bookmark propertyValueBookmark = memento.get(propertyId + ".bookmark", Bookmark.class);
-                propertyValue = bookmarkService.lookup(propertyValueBookmark);
-            }
-
-            if(propertyValue != null) {
-                property.set(viewModelAdapter, adapterManager.adapterFor(propertyValue), InteractionInitiatedBy.FRAMEWORK);
-            }
-        }
-    }
-    
-    @Override
-    public String memento(Object viewModelPojo) {
-
-        final MementoService mementoService = servicesInjector.lookupService(MementoService.class);
-        final BookmarkService bookmarkService = servicesInjector.lookupService(BookmarkService.class);
-
-        final MementoService.Memento memento = mementoService.create();
-
-        // this is horrible, but there's a catch-22 here...
-        // we need an adapter in order to query the state of the object via the metamodel, on the other hand
-        // we can't create an adapter without the identifier, which is what we're trying to derive
-        // so... we create a temporary transient adapter, use it to wrap this adapter and interrogate this pojo,
-        // then throw away that adapter (remove from the adapter map)
-        boolean createdTemporaryAdapter = false;
-        ObjectAdapter viewModelAdapter = adapterManager.getAdapterFor(viewModelPojo);
-        if(viewModelAdapter == null) {
-            final ObjectSpecification objectSpecification = specificationLoader.loadSpecification(viewModelPojo.getClass());
-            final ObjectSpecId objectSpecId = objectSpecification.getSpecId();
-            viewModelAdapter = adapterManager.mapRecreatedPojo(RootOid.create(objectSpecId, UUID.randomUUID().toString()), viewModelPojo);
-
-            createdTemporaryAdapter = true;
-        }
-
-        try {
-            final ObjectSpecification spec = viewModelAdapter.getSpecification();
-            final List<OneToOneAssociation> properties = spec.getProperties(Contributed.EXCLUDED);
-            for (OneToOneAssociation property : properties) {
-                // ignore read-only
-                if(!property.containsDoOpFacet(PropertySetterFacet.class)) {
-                    continue;
-                }
-                // ignore those explicitly annotated as @NotPersisted
-                if(property.isNotPersisted()) {
-                    continue;
-                }
-
-                // otherwise, include
-
-                // REVIEW: this look to be the same as viewModelAdapter, above?
-                final ObjectAdapter ownerAdapter = adapterManager.adapterFor(viewModelPojo);
-
-                final ObjectAdapter propertyValueAdapter = property.get(ownerAdapter,
-                        InteractionInitiatedBy.FRAMEWORK);
-                if(propertyValueAdapter != null) {
-                    final Object propertyValue = propertyValueAdapter.getObject();
-                    if(mementoService.canSet(propertyValue)) {
-                        memento.set(property.getId(), propertyValue);
-                    } else {
-                        final Bookmark propertyValueBookmark = bookmarkService.bookmarkFor(propertyValue);
-                        memento.set(property.getId() + ".bookmark", propertyValueBookmark);
-                    }
-                }
-            }
-            return memento.asString();
-        } finally {
-            if(createdTemporaryAdapter) {
-                adapterManager.removeAdapter(viewModelAdapter);
-            }
-        }
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetDeclarativeInitializingAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetDeclarativeInitializingAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetDeclarativeInitializingAbstract.java
new file mode 100644
index 0000000..205f21d
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetDeclarativeInitializingAbstract.java
@@ -0,0 +1,165 @@
+/*
+ *  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.core.metamodel.facets.object.recreatable;
+
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.applib.services.bookmark.BookmarkService;
+import org.apache.isis.applib.services.memento.MementoService;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.PostConstructMethodCache;
+import org.apache.isis.core.metamodel.facets.properties.update.modify.PropertySetterFacet;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
+import org.apache.isis.core.metamodel.spec.feature.Contributed;
+import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
+
+public abstract class RecreatableObjectFacetDeclarativeInitializingAbstract extends RecreatableObjectFacetAbstract {
+
+    private final SpecificationLoader specificationLoader;
+    private final AdapterManager adapterManager;
+
+    public RecreatableObjectFacetDeclarativeInitializingAbstract(
+            final FacetHolder holder,
+            final ArchitecturalLayer architecturalLayer,
+            final RecreationMechanism recreationMechanism,
+            final SpecificationLoader specificationLoader,
+            final AdapterManager adapterManager,
+            final ServicesInjector servicesInjector,
+            final PostConstructMethodCache postConstructMethodCache) {
+        super(holder, architecturalLayer, recreationMechanism, postConstructMethodCache, servicesInjector);
+        this.specificationLoader = specificationLoader;
+        this.adapterManager = adapterManager;
+    }
+
+    @Override
+    protected void doInitialize(
+            final Object viewModelPojo,
+            final String mementoStr) {
+
+        final MementoService mementoService = servicesInjector.lookupService(MementoService.class);
+        final BookmarkService bookmarkService = servicesInjector.lookupService(BookmarkService.class);
+
+        final MementoService.Memento memento = mementoService.parse(mementoStr);
+
+        final Set<String> mementoKeys = memento.keySet();
+
+        // manually recreate the adapter in order to be able to query state via the metamodel
+        ObjectAdapter viewModelAdapter = adapterManager.getAdapterFor(viewModelPojo);
+        if(viewModelAdapter == null) {
+            final ObjectSpecification objectSpecification = specificationLoader.loadSpecification(viewModelPojo.getClass());
+            final ObjectSpecId objectSpecId = objectSpecification.getSpecId();
+            viewModelAdapter = adapterManager.mapRecreatedPojo(new RootOid(objectSpecId, mementoStr, Oid.State.VIEWMODEL), viewModelPojo);
+        }
+
+        final ObjectSpecification spec = viewModelAdapter.getSpecification();
+        final List<OneToOneAssociation> properties = spec.getProperties(Contributed.EXCLUDED);
+        for (OneToOneAssociation property : properties) {
+            final String propertyId = property.getId();
+
+            Object propertyValue = null;
+
+            if(mementoKeys.contains(propertyId)) {
+                final Class<?> propertyType = property.getSpecification().getCorrespondingClass();
+                propertyValue = memento.get(propertyId, propertyType);
+            } else if(mementoKeys.contains(propertyId + ".bookmark")) {
+                final Bookmark propertyValueBookmark = memento.get(propertyId + ".bookmark", Bookmark.class);
+                propertyValue = bookmarkService.lookup(propertyValueBookmark);
+            }
+
+            if(propertyValue != null) {
+                property.set(viewModelAdapter, adapterManager.adapterFor(propertyValue), InteractionInitiatedBy.FRAMEWORK);
+            }
+        }
+    }
+    
+    @Override
+    public String memento(Object viewModelPojo) {
+
+        final MementoService mementoService = servicesInjector.lookupService(MementoService.class);
+        final BookmarkService bookmarkService = servicesInjector.lookupService(BookmarkService.class);
+
+        final MementoService.Memento memento = mementoService.create();
+
+        // this is horrible, but there's a catch-22 here...
+        // we need an adapter in order to query the state of the object via the metamodel, on the other hand
+        // we can't create an adapter without the identifier, which is what we're trying to derive
+        // so... we create a temporary transient adapter, use it to wrap this adapter and interrogate this pojo,
+        // then throw away that adapter (remove from the adapter map)
+        boolean createdTemporaryAdapter = false;
+        ObjectAdapter viewModelAdapter = adapterManager.getAdapterFor(viewModelPojo);
+        if(viewModelAdapter == null) {
+            final ObjectSpecification objectSpecification = specificationLoader.loadSpecification(viewModelPojo.getClass());
+            final ObjectSpecId objectSpecId = objectSpecification.getSpecId();
+            viewModelAdapter = adapterManager.mapRecreatedPojo(RootOid.create(objectSpecId, UUID.randomUUID().toString()), viewModelPojo);
+
+            createdTemporaryAdapter = true;
+        }
+
+        try {
+            final ObjectSpecification spec = viewModelAdapter.getSpecification();
+            final List<OneToOneAssociation> properties = spec.getProperties(Contributed.EXCLUDED);
+            for (OneToOneAssociation property : properties) {
+                // ignore read-only
+                if(!property.containsDoOpFacet(PropertySetterFacet.class)) {
+                    continue;
+                }
+                // ignore those explicitly annotated as @NotPersisted
+                if(property.isNotPersisted()) {
+                    continue;
+                }
+
+                // otherwise, include
+
+                // REVIEW: this look to be the same as viewModelAdapter, above?
+                final ObjectAdapter ownerAdapter = adapterManager.adapterFor(viewModelPojo);
+
+                final ObjectAdapter propertyValueAdapter = property.get(ownerAdapter,
+                        InteractionInitiatedBy.FRAMEWORK);
+                if(propertyValueAdapter != null) {
+                    final Object propertyValue = propertyValueAdapter.getObject();
+                    if(mementoService.canSet(propertyValue)) {
+                        memento.set(property.getId(), propertyValue);
+                    } else {
+                        final Bookmark propertyValueBookmark = bookmarkService.bookmarkFor(propertyValue);
+                        memento.set(property.getId() + ".bookmark", propertyValueBookmark);
+                    }
+                }
+            }
+            return memento.asString();
+        } finally {
+            if(createdTemporaryAdapter) {
+                adapterManager.removeAdapter(viewModelAdapter);
+            }
+        }
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
index fcda954..ec03ff4 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
@@ -71,7 +71,7 @@ public class RecreatableObjectFacetFactory extends FacetFactoryAbstract
         if (ViewModel.class.isAssignableFrom(processClassContext.getCls())) {
             final PostConstructMethodCache postConstructMethodCache = this;
             FacetUtil.addFacet(new RecreatableObjectFacetForRecreatableObjectInterface(
-                    processClassContext.getFacetHolder(), postConstructMethodCache));
+                    processClassContext.getFacetHolder(), postConstructMethodCache, servicesInjector));
         }
 
         // ViewModel annotation
@@ -86,7 +86,7 @@ public class RecreatableObjectFacetFactory extends FacetFactoryAbstract
         if (RecreatableDomainObject.class.isAssignableFrom(processClassContext.getCls())) {
             final PostConstructMethodCache postConstructMethodCache = this;
             FacetUtil.addFacet(new RecreatableObjectFacetForRecreatableDomainObjectInterface(
-                    processClassContext.getFacetHolder(), postConstructMethodCache));
+                    processClassContext.getFacetHolder(), postConstructMethodCache, servicesInjector));
         }
 
         // DomainObject(nature=VIEW_MODEL) is managed by the DomainObjectFacetFactory

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableDomainObjectInterface.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableDomainObjectInterface.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableDomainObjectInterface.java
index c59ef86..bc638e6 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableDomainObjectInterface.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableDomainObjectInterface.java
@@ -22,13 +22,15 @@ package org.apache.isis.core.metamodel.facets.object.recreatable;
 import org.apache.isis.applib.RecreatableDomainObject;
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
 import org.apache.isis.core.metamodel.facets.PostConstructMethodCache;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
 
 public class RecreatableObjectFacetForRecreatableDomainObjectInterface extends RecreatableObjectFacetAbstract {
 
     public RecreatableObjectFacetForRecreatableDomainObjectInterface(
             final FacetHolder holder,
-            final PostConstructMethodCache postConstructMethodCache) {
-        super(holder, ArchitecturalLayer.DOMAIN, postConstructMethodCache);
+            final PostConstructMethodCache postConstructMethodCache,
+            final ServicesInjector servicesInjector) {
+        super(holder, ArchitecturalLayer.DOMAIN, RecreationMechanism.INITIALIZES, postConstructMethodCache, servicesInjector);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableObjectAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableObjectAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableObjectAnnotation.java
index 30af377..f7c3fa6 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableObjectAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableObjectAnnotation.java
@@ -25,7 +25,8 @@ import org.apache.isis.core.metamodel.facets.PostConstructMethodCache;
 import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
 import org.apache.isis.core.metamodel.spec.SpecificationLoader;
 
-public class RecreatableObjectFacetForRecreatableObjectAnnotation extends RecreatableObjectFacetDeclarativeAbstract {
+public class RecreatableObjectFacetForRecreatableObjectAnnotation extends
+        RecreatableObjectFacetDeclarativeInitializingAbstract {
 
     public RecreatableObjectFacetForRecreatableObjectAnnotation(
             final FacetHolder holder,
@@ -33,7 +34,7 @@ public class RecreatableObjectFacetForRecreatableObjectAnnotation extends Recrea
             final AdapterManager adapterManager,
             final ServicesInjector servicesInjector,
             final PostConstructMethodCache postConstructMethodCache) {
-        super(holder, ArchitecturalLayer.APPLICATION,
+        super(holder, ArchitecturalLayer.APPLICATION, RecreationMechanism.INITIALIZES,
                 specificationLoader, adapterManager, servicesInjector, postConstructMethodCache);
     }
 

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableObjectInterface.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableObjectInterface.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableObjectInterface.java
index 67cd85d..3765f8c 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableObjectInterface.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForRecreatableObjectInterface.java
@@ -22,13 +22,15 @@ package org.apache.isis.core.metamodel.facets.object.recreatable;
 import org.apache.isis.applib.ViewModel;
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
 import org.apache.isis.core.metamodel.facets.PostConstructMethodCache;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
 
 public class RecreatableObjectFacetForRecreatableObjectInterface extends RecreatableObjectFacetAbstract {
 
     public RecreatableObjectFacetForRecreatableObjectInterface(
             final FacetHolder holder,
-            final PostConstructMethodCache postConstructMethodCache) {
-        super(holder, ArchitecturalLayer.APPLICATION, postConstructMethodCache);
+            final PostConstructMethodCache postConstructMethodCache,
+            final ServicesInjector servicesInjector) {
+        super(holder, ArchitecturalLayer.APPLICATION, RecreationMechanism.INITIALIZES, postConstructMethodCache, servicesInjector);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForViewModelAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForViewModelAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForViewModelAnnotation.java
index dec2264..41da143 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForViewModelAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForViewModelAnnotation.java
@@ -25,7 +25,8 @@ import org.apache.isis.core.metamodel.facets.PostConstructMethodCache;
 import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
 import org.apache.isis.core.metamodel.spec.SpecificationLoader;
 
-public class RecreatableObjectFacetForViewModelAnnotation extends RecreatableObjectFacetDeclarativeAbstract {
+public class RecreatableObjectFacetForViewModelAnnotation extends
+        RecreatableObjectFacetDeclarativeInitializingAbstract {
 
     public RecreatableObjectFacetForViewModelAnnotation(
             final FacetHolder holder,
@@ -33,7 +34,7 @@ public class RecreatableObjectFacetForViewModelAnnotation extends RecreatableObj
             final AdapterManager adapterManager,
             final ServicesInjector servicesInjector,
             final PostConstructMethodCache postConstructMethodCache) {
-        super(holder, ArchitecturalLayer.APPLICATION,
+        super(holder, ArchitecturalLayer.APPLICATION, RecreationMechanism.INITIALIZES,
                 specificationLoader, adapterManager, servicesInjector, postConstructMethodCache);
     }
 

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java
index e416416..06581c3 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java
@@ -19,13 +19,19 @@
 
 package org.apache.isis.core.metamodel.facets.object.recreatable;
 
+import org.apache.isis.applib.services.jaxb.JaxbService;
+import org.apache.isis.applib.services.urlencoding.UrlEncodingService;
 import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
 import org.apache.isis.core.metamodel.facets.PostConstructMethodCache;
 import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
 import org.apache.isis.core.metamodel.spec.SpecificationLoader;
 
-public class RecreatableObjectFacetForXmlRootElementAnnotation extends RecreatableObjectFacetDeclarativeAbstract {
+public class RecreatableObjectFacetForXmlRootElementAnnotation extends RecreatableObjectFacetAbstract {
+
+    private final SpecificationLoader specificationLoader;
+    private final AdapterManager adapterManager;
+    private final ServicesInjector servicesInjector;
 
     public RecreatableObjectFacetForXmlRootElementAnnotation(
             final FacetHolder holder,
@@ -33,8 +39,35 @@ public class RecreatableObjectFacetForXmlRootElementAnnotation extends Recreatab
             final AdapterManager adapterManager,
             final ServicesInjector servicesInjector,
             final PostConstructMethodCache postConstructMethodCache) {
-        super(holder, ArchitecturalLayer.APPLICATION,
-                specificationLoader, adapterManager, servicesInjector, postConstructMethodCache);
+        super(holder, ArchitecturalLayer.APPLICATION, RecreationMechanism.INSTANTIATES,
+                postConstructMethodCache, servicesInjector);
+
+        this.specificationLoader = specificationLoader;
+        this.adapterManager = adapterManager;
+        this.servicesInjector = servicesInjector;
     }
 
+    @Override
+    protected Object doInstantiate(final Class<?> viewModelClass, final String mementoStr) {
+
+        final JaxbService jaxbService = servicesInjector.lookupService(JaxbService.class);
+        final UrlEncodingService urlEncodingService =
+                servicesInjector.lookupService(UrlEncodingService.class);
+
+        final String xmlStr = urlEncodingService.decode(mementoStr);
+        final Object viewModelPojo = jaxbService.fromXml(viewModelClass, xmlStr);
+        return viewModelPojo;
+    }
+
+    @Override
+    public String memento(final Object pojo) {
+
+        final JaxbService jaxbService = servicesInjector.lookupService(JaxbService.class);
+        final UrlEncodingService urlEncodingService =
+                servicesInjector.lookupService(UrlEncodingService.class);
+
+        final String xml = jaxbService.toXml(pojo);
+        final String encoded = urlEncodingService.encode(xml);
+        return encoded;
+    }
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/viewmodel/ViewModelFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/viewmodel/ViewModelFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/viewmodel/ViewModelFacet.java
index 78fbb3b..355895e 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/viewmodel/ViewModelFacet.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/viewmodel/ViewModelFacet.java
@@ -19,6 +19,7 @@
 
 package org.apache.isis.core.metamodel.facets.object.viewmodel;
 
+import org.apache.isis.applib.annotation.Nature;
 import org.apache.isis.core.metamodel.facetapi.Facet;
 
 /**
@@ -38,13 +39,52 @@ import org.apache.isis.core.metamodel.facetapi.Facet;
  */
 public interface ViewModelFacet extends Facet {
 
+
     public enum ArchitecturalLayer {
         APPLICATION,
         DOMAIN
     }
 
+    public enum RecreationMechanism {
+        /**
+         * Instantiates a new instance and then populates
+         */
+        INSTANTIATES,
+        /**
+         * Initializes an instance already created by the framework
+         */
+        INITIALIZES;
+
+        public boolean isInstantiates() {
+            return this == INSTANTIATES;
+        }
+        public boolean isInitializes() {
+            return this == INITIALIZES;
+        }
+    }
+
+    /**
+     * Whether this implementation supports the recreation of objects by {@link RecreationMechanism#INSTANTIATES instantiating} (and implicitly also initializing) a new pojo, or by {@link RecreationMechanism#INITIALIZES initializing} a pojo created and passed to it by the framework.
+     *
+     * <p>
+     *     Determines whether the framework then calls {@link #instantiate(Class, String)} or if it calls {@link #initialize(Object, String)}.
+     * </p>
+     */
+    RecreationMechanism getRecreationMechanism();
+
+    /**
+     * Will be called if {@link #getRecreationMechanism()} is {@link RecreationMechanism#INITIALIZES}.
+     */
     void initialize(Object pojo, String memento);
 
+    /**
+     * Will be called only call if {@link #getRecreationMechanism()} is {@link RecreationMechanism#INSTANTIATES}.
+     */
+    Object instantiate(final Class<?> viewModelClass, String memento);
+
+    /**
+     * Obtain a memento of the pojo, which can then be used to reinstantiate (either by {@link #instantiate(Class, String)} or {@link #initialize(Object, String)}) subsequently.
+     */
     String memento(Object pojo);
 
     /**
@@ -52,7 +92,16 @@ public interface ViewModelFacet extends Facet {
      */
     boolean isCloneable(Object pojo);
 
+    /**
+     * View models are implicitly immutable (their state is determined by their {@link #memento(Object)}), so this
+     * method allows the framework to clone an existing view model to mutate it, thereby simulating editable
+     * view models.
+     */
     Object clone(Object pojo);
 
+    /**
+     * Currently metadata only, capturing the nature of the view model, eg {@link Nature#EXTERNAL_ENTITY} is a {@link ArchitecturalLayer#DOMAIN domain} layer where as {@link Nature#VIEW_MODEL} is {@link ArchitecturalLayer#APPLICATION application} layer.
+     * @return
+     */
     ArchitecturalLayer getArchitecturalLayer();
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/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 4fd19aa..562a666 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
@@ -17,6 +17,7 @@
 package org.apache.isis.core.runtime.services.jaxb;
 
 import java.io.IOException;
+import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.Map;
 
@@ -24,41 +25,46 @@ import javax.inject.Inject;
 import javax.xml.bind.JAXBContext;
 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.DomainObjectContainer;
 import org.apache.isis.applib.annotation.DomainService;
 import org.apache.isis.applib.annotation.NatureOfService;
-import org.apache.isis.applib.services.jaxb.Dto;
 import org.apache.isis.applib.services.jaxb.JaxbService;
 import org.apache.isis.core.runtime.services.jaxb.util.CatalogingSchemaOutputResolver;
-import org.apache.isis.core.runtime.services.jaxb.util.PersistentEntityAdapter;
+import org.apache.isis.schema.utils.jaxbadapters.PersistentEntityAdapter;
 
 @DomainService(
         nature = NatureOfService.DOMAIN
 )
 public class JaxbServiceDefault implements JaxbService {
 
-    public Map<String,String> toXsd(final Dto dto) {
-
+    @Override
+    public <T> T fromXml(final Class<T> domainClass, final String memento) {
         try {
-            final Class<? extends Dto> dtoClass = dto.getClass();
-            final JAXBContext context = JAXBContext.newInstance(dtoClass);
+            final JAXBContext context = JAXBContext.newInstance(domainClass);
 
-            final CatalogingSchemaOutputResolver outputResolver = new CatalogingSchemaOutputResolver();
-            context.generateSchema(outputResolver);
+            final PersistentEntityAdapter adapter = new PersistentEntityAdapter();
+            container.injectServicesInto(adapter);
 
-            return outputResolver.asMap();
-        } catch (final JAXBException | IOException ex) {
+            final Unmarshaller unmarshaller = context.createUnmarshaller();
+            unmarshaller.setAdapter(PersistentEntityAdapter.class, adapter);
+
+            final Object unmarshal = unmarshaller.unmarshal(new StringReader(memento));
+            return (T) unmarshal;
+
+        } catch (final JAXBException ex) {
             throw new ApplicationException(ex);
         }
     }
 
-    public String toXml(final Dto dto)  {
+    @Override
+    public String toXml(final Object domainObject)  {
 
         try {
-            final Class<? extends Dto> dtoClass = dto.getClass();
-            final JAXBContext context = JAXBContext.newInstance(dtoClass);
+            final Class<?> domainClass = domainObject.getClass();
+            final JAXBContext context = JAXBContext.newInstance(domainClass);
 
             final PersistentEntityAdapter adapter = new PersistentEntityAdapter();
             container.injectServicesInto(adapter);
@@ -68,15 +74,30 @@ public class JaxbServiceDefault implements JaxbService {
             marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
 
             final StringWriter sw = new StringWriter();
-            marshaller.marshal(dto, sw);
+            marshaller.marshal(domainObject, sw);
             return sw.toString();
 
         } catch (final JAXBException ex) {
             throw new ApplicationException(ex);
         }
+    }
 
+    public Map<String,String> toXsd(final Object domainObject) {
+
+        try {
+            final Class<?> domainClass = domainObject.getClass();
+            final JAXBContext context = JAXBContext.newInstance(domainClass);
+
+            final CatalogingSchemaOutputResolver outputResolver = new CatalogingSchemaOutputResolver();
+            context.generateSchema(outputResolver);
+
+            return outputResolver.asMap();
+        } catch (final JAXBException | IOException ex) {
+            throw new ApplicationException(ex);
+        }
     }
 
+
     @Inject
     DomainObjectContainer container;
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/PersistentEntityAdapter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/PersistentEntityAdapter.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/PersistentEntityAdapter.java
deleted file mode 100644
index 6987129..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/PersistentEntityAdapter.java
+++ /dev/null
@@ -1,51 +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.core.runtime.services.jaxb.util;
-
-import javax.inject.Inject;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
-
-import org.apache.isis.applib.services.bookmark.Bookmark;
-import org.apache.isis.applib.services.bookmark.BookmarkService;
-import org.apache.isis.schema.common.v1.BookmarkObjectState;
-import org.apache.isis.schema.common.v1.OidDto;
-
-public class PersistentEntityAdapter extends XmlAdapter<OidDto, Object> {
-
-    @Override
-    public Object unmarshal(final OidDto oidDto) throws Exception {
-
-        final String objectType = oidDto.getObjectType();
-        final String identifier = oidDto.getObjectIdentifier();
-        final Bookmark bookmark = new Bookmark(objectType, identifier);
-
-        return bookmarkService.lookup(bookmark);
-    }
-
-    @Override
-    public OidDto marshal(final Object domainObject) throws Exception {
-        final Bookmark bookmark = bookmarkService.bookmarkFor(domainObject);
-        final OidDto oidDto = new OidDto();
-        oidDto.setObjectIdentifier(bookmark.getIdentifier());
-        oidDto.setObjectState(BookmarkObjectState.PERSISTENT);
-        oidDto.setObjectType(bookmark.getObjectType());
-        return oidDto;
-    }
-
-    @Inject
-    BookmarkService bookmarkService;
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/runtime/src/main/java/org/apache/isis/core/runtime/services/memento/MementoServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/memento/MementoServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/memento/MementoServiceDefault.java
index ee39527..bfe7372 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/memento/MementoServiceDefault.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/memento/MementoServiceDefault.java
@@ -16,14 +16,14 @@
  */
 package org.apache.isis.core.runtime.services.memento;
 
-import java.nio.charset.Charset;
 import java.util.List;
 import java.util.Set;
 
+import javax.inject.Inject;
+
 import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
-import com.google.common.io.BaseEncoding;
 
 import org.dom4j.Document;
 import org.dom4j.DocumentHelper;
@@ -33,6 +33,7 @@ import org.apache.isis.applib.annotation.DomainService;
 import org.apache.isis.applib.annotation.NatureOfService;
 import org.apache.isis.applib.annotation.Programmatic;
 import org.apache.isis.applib.services.memento.MementoService;
+import org.apache.isis.applib.services.urlencoding.UrlEncodingService;
 
 /**
  * This service provides a mechanism by which a serializable memento of arbitrary state can be created.  Most
@@ -53,14 +54,20 @@ public class MementoServiceDefault implements MementoService {
         private final boolean noEncoding;
         private final Document doc;
 
-        MementoDefault(boolean noEncoding) {
-            this(DocumentHelper.createDocument(), noEncoding);
+        private final UrlEncodingService urlEncodingService;
+
+        MementoDefault(boolean noEncoding, final UrlEncodingService urlEncodingService) {
+            this(DocumentHelper.createDocument(), noEncoding, urlEncodingService);
             doc.addElement("memento");
         }
 
-        MementoDefault(Document doc, boolean noEncoding) {
+        MementoDefault(
+                Document doc,
+                boolean noEncoding,
+                final UrlEncodingService urlEncodingService) {
             this.doc = doc;
             this.noEncoding = noEncoding;
+            this.urlEncodingService = urlEncodingService;
         }
         
         @Override
@@ -83,7 +90,7 @@ public class MementoServiceDefault implements MementoService {
         }
 
         protected String encode(final String xmlStr) {
-            return noEncoding ? xmlStr : base64UrlEncode(xmlStr);
+            return noEncoding ? xmlStr : urlEncodingService.encode(xmlStr);
         }
 
         private static final Function<Element, String> ELEMENT_NAME = new Function<Element, String>(){
@@ -132,7 +139,7 @@ public class MementoServiceDefault implements MementoService {
     @Programmatic
     @Override
     public Memento create() {
-        return new MementoDefault(noEncoding);
+        return new MementoDefault(noEncoding, urlEncodingService);
     }
 
 
@@ -143,28 +150,21 @@ public class MementoServiceDefault implements MementoService {
         if (noEncoding) {
             xmlStr = str;
         } else {
-            xmlStr = base64UrlDecode(str);
+            xmlStr = urlEncodingService.decode(str);
         }
         final Document doc = Dom4jUtil.parse(xmlStr);
-        return new MementoDefault(doc, noEncoding);
+        return new MementoDefault(doc, noEncoding, urlEncodingService);
     }
 
     @Programmatic
     @Override
     public boolean canSet(final Object input) {
-        return input != null ? Dom4jUtil.isSupportedClass(input.getClass()) : true;
+        return input == null || Dom4jUtil.isSupportedClass(input.getClass());
     }
 
     // //////////////////////////////////////
 
-    private static String base64UrlDecode(String str) {
-        final byte[] bytes = BaseEncoding.base64Url().decode(str);
-        return new String(bytes, Charset.forName("UTF-8"));
-    }
-    
-    private static String base64UrlEncode(final String xmlStr) {
-        byte[] bytes = xmlStr.getBytes(Charset.forName("UTF-8"));
-        return BaseEncoding.base64Url().encode(bytes);
-    }
+    @Inject
+    UrlEncodingService urlEncodingService;
 
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
index 0e72141..f561705 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
@@ -579,23 +579,40 @@ public class PersistenceSession implements
     }
 
     private ObjectAdapter createInstance(
-            final ObjectSpecification objectSpec,
+            final ObjectSpecification spec,
             final Variant variant,
             final String memento) {
         if (LOG.isDebugEnabled()) {
-            LOG.debug("creating " + variant + " instance of " + objectSpec);
+            LOG.debug("creating " + variant + " instance of " + spec);
         }
-        final Object pojo = instantiateAndInjectServices(objectSpec);
+        final Object pojo;
 
         if(variant == Variant.VIEW_MODEL) {
-            final ViewModelFacet facet = objectSpec.getFacet(ViewModelFacet.class);
-            initialize(facet, pojo, memento);
+            pojo = recreateViewModel(spec, memento);
+        } else {
+            pojo = instantiateAndInjectServices(spec);
+
         }
 
         final ObjectAdapter adapter = adapterFor(pojo);
         return initializePropertiesAndDoCallback(adapter);
     }
 
+    private Object recreateViewModel(final ObjectSpecification spec, final String memento) {
+        final ViewModelFacet facet = spec.getFacet(ViewModelFacet.class);
+        if(facet == null) {
+            throw new IllegalArgumentException("spec does not have ViewModelFacet; spec is " + spec.getFullIdentifier());
+        }
+
+        final Object viewModelPojo;
+        if(facet.getRecreationMechanism().isInitializes()) {
+            viewModelPojo = instantiateAndInjectServices(spec);
+            facet.initialize(viewModelPojo, memento);
+        } else {
+            viewModelPojo = facet.instantiate(spec.getCorrespondingClass(), memento);
+        }
+        return viewModelPojo;
+    }
 
     public Object instantiateAndInjectServices(final ObjectSpecification objectSpec) {
 
@@ -1596,25 +1613,20 @@ public class PersistenceSession implements
     private Object recreatePojoDefault(final RootOid rootOid) {
         final ObjectSpecification spec =
                 specificationLoader.lookupBySpecId(rootOid.getObjectSpecId());
-        final Object pojo = instantiateAndInjectServices(spec);
-        if(rootOid.isViewModel()) {
-            // initialize the view model pojo from the oid's identifier
+        final Object pojo;
 
-            final ViewModelFacet facet = spec.getFacet(ViewModelFacet.class);
-            if(facet == null) {
-                throw new IllegalArgumentException("spec does not have RecreatableObjectFacet; " + rootOid.toString() + "; spec is " + spec.getFullIdentifier());
-            }
+        if(rootOid.isViewModel()) {
 
             final String memento = rootOid.getIdentifier();
-            initialize(facet, pojo, memento);
+            pojo = recreateViewModel(spec, memento);
+
+        } else {
+            pojo = instantiateAndInjectServices(spec);
+
         }
         return pojo;
     }
 
-    private void initialize(final ViewModelFacet facet, final Object pojo, final String memento) {
-        facet.initialize(pojo, memento);
-    }
-
     /**
      * {@inheritDoc}
      */

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/JodaLocalTimeXMLGregorianCalendarAdapter.java
----------------------------------------------------------------------
diff --git a/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/JodaLocalTimeXMLGregorianCalendarAdapter.java b/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/JodaLocalTimeXMLGregorianCalendarAdapter.java
index 3410ded..9648929 100644
--- a/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/JodaLocalTimeXMLGregorianCalendarAdapter.java
+++ b/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/JodaLocalTimeXMLGregorianCalendarAdapter.java
@@ -23,8 +23,6 @@ import javax.xml.datatype.XMLGregorianCalendar;
 import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl;
 
 import org.joda.time.LocalTime;
-import org.joda.time.format.DateTimeFormatter;
-import org.joda.time.format.ISODateTimeFormat;
 
 /**
  * Not registered in the XSD schema (as a JAXB binding, because can only map xs:dateTime once (and have chosen to map to LocalDateTime).
@@ -33,8 +31,6 @@ public final class JodaLocalTimeXMLGregorianCalendarAdapter {
     private JodaLocalTimeXMLGregorianCalendarAdapter() {
     }
 
-    private static DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
-
     public static LocalTime parse(final XMLGregorianCalendar xgc) {
         if(xgc == null) return null;
 

http://git-wip-us.apache.org/repos/asf/isis/blob/9163f6db/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
----------------------------------------------------------------------
diff --git a/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java b/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
new file mode 100644
index 0000000..0ff29b3
--- /dev/null
+++ b/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
@@ -0,0 +1,51 @@
+/**
+ *  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.schema.utils.jaxbadapters;
+
+import javax.inject.Inject;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.applib.services.bookmark.BookmarkService;
+import org.apache.isis.schema.common.v1.BookmarkObjectState;
+import org.apache.isis.schema.common.v1.OidDto;
+
+public class PersistentEntityAdapter extends XmlAdapter<OidDto, Object> {
+
+    @Override
+    public Object unmarshal(final OidDto oidDto) throws Exception {
+
+        final String objectType = oidDto.getObjectType();
+        final String identifier = oidDto.getObjectIdentifier();
+        final Bookmark bookmark = new Bookmark(objectType, identifier);
+
+        return bookmarkService.lookup(bookmark);
+    }
+
+    @Override
+    public OidDto marshal(final Object domainObject) throws Exception {
+        final Bookmark bookmark = bookmarkService.bookmarkFor(domainObject);
+        final OidDto oidDto = new OidDto();
+        oidDto.setObjectIdentifier(bookmark.getIdentifier());
+        oidDto.setObjectState(BookmarkObjectState.PERSISTENT);
+        oidDto.setObjectType(bookmark.getObjectType());
+        return oidDto;
+    }
+
+    @Inject
+    BookmarkService bookmarkService;
+}


[06/11] isis git commit: ISIS-915: improving the error handling.

Posted by da...@apache.org.
ISIS-915: improving the error handling.


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

Branch: refs/heads/master
Commit: 0e9d1b2be4cd513685fe4f0999c43fedb7e78f5a
Parents: d654fc8
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Nov 13 11:58:52 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Nov 13 11:58:52 2015 +0000

----------------------------------------------------------------------
 .../isis/applib/services/jaxb/JaxbService.java  |  2 +-
 .../services/jaxb/JaxbServiceDefault.java       | 51 +++++++++++++++++---
 .../jaxbadapters/PersistentEntityAdapter.java   | 14 +++++-
 3 files changed, 59 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/0e9d1b2b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
----------------------------------------------------------------------
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 4c7c03b..0cdd9e5 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
@@ -23,7 +23,7 @@ import org.apache.isis.applib.annotation.Programmatic;
 public interface JaxbService {
 
     @Programmatic
-    <T> T fromXml(Class<T> domainClass, String memento);
+    <T> T fromXml(Class<T> domainClass, String xml);
 
     @Programmatic
     public String toXml(final Object domainObject);

http://git-wip-us.apache.org/repos/asf/isis/blob/0e9d1b2b/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 562a666..6d86f4f 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
@@ -19,6 +19,8 @@ package org.apache.isis.core.runtime.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 javax.inject.Inject;
@@ -27,8 +29,13 @@ import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import com.google.common.collect.Iterables;
+
 import org.apache.isis.applib.ApplicationException;
 import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.applib.NonRecoverableException;
 import org.apache.isis.applib.annotation.DomainService;
 import org.apache.isis.applib.annotation.NatureOfService;
 import org.apache.isis.applib.services.jaxb.JaxbService;
@@ -41,7 +48,7 @@ import org.apache.isis.schema.utils.jaxbadapters.PersistentEntityAdapter;
 public class JaxbServiceDefault implements JaxbService {
 
     @Override
-    public <T> T fromXml(final Class<T> domainClass, final String memento) {
+    public <T> T fromXml(final Class<T> domainClass, final String xml) {
         try {
             final JAXBContext context = JAXBContext.newInstance(domainClass);
 
@@ -51,19 +58,19 @@ public class JaxbServiceDefault implements JaxbService {
             final Unmarshaller unmarshaller = context.createUnmarshaller();
             unmarshaller.setAdapter(PersistentEntityAdapter.class, adapter);
 
-            final Object unmarshal = unmarshaller.unmarshal(new StringReader(memento));
+            final Object unmarshal = unmarshaller.unmarshal(new StringReader(xml));
             return (T) unmarshal;
 
         } catch (final JAXBException ex) {
-            throw new ApplicationException(ex);
+            throw new NonRecoverableException("Error unmarshalling domain object from XML; domain object class is '" + domainClass.getName() + "'", ex);
         }
     }
 
     @Override
     public String toXml(final Object domainObject)  {
 
+        final Class<?> domainClass = domainObject.getClass();
         try {
-            final Class<?> domainClass = domainObject.getClass();
             final JAXBContext context = JAXBContext.newInstance(domainClass);
 
             final PersistentEntityAdapter adapter = new PersistentEntityAdapter();
@@ -75,10 +82,42 @@ public class JaxbServiceDefault implements JaxbService {
 
             final StringWriter sw = new StringWriter();
             marshaller.marshal(domainObject, sw);
-            return sw.toString();
+            final String xml = sw.toString();
+
+            return xml;
 
         } catch (final JAXBException ex) {
-            throw new ApplicationException(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 = (List<? extends Exception>) getErrorsMethod.invoke(ex);
+                    annotationExceptionMessages = ": " + Joiner.on("; ").join(
+                            Iterables.transform(errors, new Function<Exception, String>() {
+                                @Override public String apply(final Exception e) {
+                                    return e.getMessage();
+                                }
+                            }));
+                } 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);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/isis/blob/0e9d1b2b/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
----------------------------------------------------------------------
diff --git a/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java b/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
index 0ff29b3..612205b 100644
--- a/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
+++ b/core/schema/src/main/java/org/apache/isis/schema/utils/jaxbadapters/PersistentEntityAdapter.java
@@ -38,14 +38,26 @@ public class PersistentEntityAdapter extends XmlAdapter<OidDto, Object> {
 
     @Override
     public OidDto marshal(final Object domainObject) throws Exception {
+        if(domainObject == null) {
+            return null;
+        }
         final Bookmark bookmark = bookmarkService.bookmarkFor(domainObject);
         final OidDto oidDto = new OidDto();
         oidDto.setObjectIdentifier(bookmark.getIdentifier());
-        oidDto.setObjectState(BookmarkObjectState.PERSISTENT);
+        oidDto.setObjectState(convert(bookmark.getObjectState()));
         oidDto.setObjectType(bookmark.getObjectType());
         return oidDto;
     }
 
+    private BookmarkObjectState convert(final Bookmark.ObjectState objectState) {
+        switch (objectState) {
+            case VIEW_MODEL:return BookmarkObjectState.VIEW_MODEL;
+            case TRANSIENT:return BookmarkObjectState.TRANSIENT;
+            case PERSISTENT:return BookmarkObjectState.PERSISTENT;
+        }
+        throw new IllegalArgumentException("Not recognized: " + objectState.name());
+    }
+
     @Inject
     BookmarkService bookmarkService;
 }


[08/11] isis git commit: ISIS-1252: new abstract UiEvent hierarchy, updates to @DomainObjectLayout annotation, support for title facet.

Posted by da...@apache.org.
ISIS-1252: new abstract UiEvent hierarchy, updates to @DomainObjectLayout annotation, support for title facet.


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

Branch: refs/heads/master
Commit: ffb62e9a0f4f153fe8c72b0f26da03b7e4269ad9
Parents: b17dc0e
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Nov 13 13:40:09 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Nov 13 13:40:09 2015 +0000

----------------------------------------------------------------------
 .../applib/annotation/DomainObjectLayout.java   |  48 ++++++++-
 .../services/eventbus/AbstractUiEvent.java      |  97 +++++++++++++++++
 .../services/eventbus/CssClassFaUiEvent.java    | 108 +++++++++++++++++++
 .../services/eventbus/CssClassUiEvent.java      |  79 ++++++++++++++
 .../applib/services/eventbus/IconUiEvent.java   |  77 +++++++++++++
 .../applib/services/eventbus/TitleUiEvent.java  | 106 ++++++++++++++++++
 .../DomainObjectLayoutFacetFactory.java         |  16 ++-
 ...ObjectLayoutAnnotationUsingTitleUiEvent.java | 108 +++++++++++++++++++
 .../dflt/ProgrammingModelFacetsJava5.java       |   6 +-
 9 files changed, 640 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/ffb62e9a/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObjectLayout.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObjectLayout.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObjectLayout.java
index d4e8789..535248d 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObjectLayout.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObjectLayout.java
@@ -25,6 +25,11 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+import org.apache.isis.applib.services.eventbus.CssClassFaUiEvent;
+import org.apache.isis.applib.services.eventbus.CssClassUiEvent;
+import org.apache.isis.applib.services.eventbus.IconUiEvent;
+import org.apache.isis.applib.services.eventbus.TitleUiEvent;
+
 /**
  * Layout hints for domain objects.
  */
@@ -33,6 +38,38 @@ import java.lang.annotation.Target;
 @Retention(RetentionPolicy.RUNTIME)
 public @interface DomainObjectLayout {
 
+
+    /**
+     * Which subclass of {@link TitleUiEvent} should be used to obtain a title.
+     *
+     * <p>
+     * This subclass must provide a no-arg constructor; the fields are set reflectively.
+     * </p>
+     */
+    Class<? extends TitleUiEvent<?>> titleUiEvent() default TitleUiEvent.Default.class;
+
+    // //////////////////////////////////////
+
+    /**
+     * Which subclass of {@link IconUiEvent} should be used to obtain an icon.
+     *
+     * <p>
+     * This subclass must provide a no-arg constructor; the fields are set reflectively.
+     * </p>
+     */
+    Class<? extends IconUiEvent<?>> iconUiEvent() default IconUiEvent.Default.class;
+
+    // //////////////////////////////////////
+
+    /**
+     * Which subclass of {@link CssClassUiEvent} should be used to obtain a CSS class.
+     *
+     * <p>
+     * This subclass must provide a no-arg constructor; the fields are set reflectively.
+     * </p>
+     */
+    Class<? extends CssClassUiEvent<?>> cssClassUiEvent() default CssClassUiEvent.Default.class;
+
     /**
      * Indicates the css class that a domain class (type) should have.
      */
@@ -41,13 +78,20 @@ public @interface DomainObjectLayout {
     // //////////////////////////////////////
 
     /**
+     * Which subclass of {@link CssClassFaUiEvent} should be used to obtain a CSS font-awesome class and position.
+     *
+     * <p>
+     * This subclass must provide a no-arg constructor; the fields are set reflectively.
+     * </p>
+     */
+    Class<? extends CssClassFaUiEvent<?>> cssClassFaUiEvent() default CssClassFaUiEvent.Default.class;
+
+    /**
      * Indicates the <a href="http://fortawesome.github.io/Font-Awesome/">Font Awesome</a> CSS class to decorate an
      * domain object.
      */
     String cssClassFa() default "";
 
-    // //////////////////////////////////////
-
     /**
      * Indicates the position of the <a href="http://fortawesome.github.io/Font-Awesome/">Font Awesome</a>
      * icon. The icon could be rendered on the left or the right of the object's title.

http://git-wip-us.apache.org/repos/asf/isis/blob/ffb62e9a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AbstractUiEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AbstractUiEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AbstractUiEvent.java
new file mode 100644
index 0000000..c0f74af
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AbstractUiEvent.java
@@ -0,0 +1,97 @@
+/*
+ *  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.eventbus;
+
+import java.util.EventObject;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.apache.isis.applib.util.ObjectContracts;
+
+public abstract class AbstractUiEvent<S> extends EventObject {
+
+    private static final long serialVersionUID = 1L;
+
+    //region > constructors
+    /**
+     * If used then the framework will set state via (non-API) setters.
+     *
+     * <p>
+     *     Because the {@link EventObject} superclass prohibits a null source, a dummy value is temporarily used.
+     * </p>
+     */
+    public AbstractUiEvent() {
+        this(null);
+    }
+
+    public AbstractUiEvent(final S source) {
+        super(sourceElseDummy(source));
+    }
+
+    private static Object sourceElseDummy(final Object source) {
+        return source != null ? source : new Object();
+    }
+    //endregion
+
+    //region > source
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public S getSource() {
+        return (S)source;
+    }
+
+    /**
+     * Not API, set by the framework if the no-arg constructor is used.
+     */
+    public void setSource(S source) {
+        this.source = source;
+    }
+
+    //endregion
+
+    //region > userData
+    /**
+     * Provides a mechanism to pass data around.
+     */
+    private final Map<Object, Object> userData = Maps.newHashMap();
+
+    /**
+     * Obtain user-data, as set by any other subscribers.
+     */
+    public Object get(Object key) {
+        return userData.get(key);
+    }
+    /**
+     * Set user-data, for the use of other subscribers.
+     */
+    public void put(Object key, Object value) {
+        userData.put(key, value);
+    }
+    //endregion
+
+    //region > toString
+    @Override
+    public String toString() {
+        return ObjectContracts.toString(this, "source");
+    }
+    //endregion
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/ffb62e9a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassFaUiEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassFaUiEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassFaUiEvent.java
new file mode 100644
index 0000000..54cf2b7
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassFaUiEvent.java
@@ -0,0 +1,108 @@
+/*
+ *  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.eventbus;
+
+import java.util.EventObject;
+
+import org.apache.isis.applib.annotation.DomainObjectLayout;
+
+/**
+ * Emitted for subscribers to obtain a cssClassFa hint (equivalent to the {@link DomainObjectLayout#cssClassFa()} attribute), providing the CSS class for a font-awesome
+ * icon for this domain object.
+ */
+public abstract class CssClassFaUiEvent<S> extends AbstractUiEvent<S> {
+
+    private static final long serialVersionUID = 1L;
+
+    //region > constructors
+    /**
+     * If used then the framework will set state via (non-API) setters.
+     *
+     * <p>
+     *     Because the {@link EventObject} superclass prohibits a null source, a dummy value is temporarily used.
+     * </p>
+     */
+    public CssClassFaUiEvent() {
+        this(null);
+    }
+
+    public CssClassFaUiEvent(final S source) {
+        super(source);
+    }
+
+    //endregion
+
+    //region > Default class
+
+    /**
+     * Propagated if no custom subclass was specified using
+     * {@link org.apache.isis.applib.annotation.DomainObjectLayout#iconUiEvent()} annotation attribute.
+     */
+    public static class Default extends CssClassFaUiEvent<Object> {
+        private static final long serialVersionUID = 1L;
+    }
+    //endregion
+
+    //region > cssClassFa
+    private String cssClassFa;
+
+    /**
+     * The CSS class for a font-awesome icon for this domain object, as provided by a subscriber using {@link #setCssClassFa(String)}.
+     */
+    public String getCssClassFa() {
+        return cssClassFa;
+    }
+
+
+    /**
+     * For subscribers to call to provide a CSS class for a font-awesome icon for this object.
+     */
+    public void setCssClassFa(final String cssClass) {
+        this.cssClassFa = cssClass;
+    }
+    //endregion
+
+    //region > cssClassFaPosition
+    private DomainObjectLayout.CssClassFaPosition cssClassFaPosition;
+
+    /**
+     * The {@link DomainObjectLayout.CssClassFaPosition position} as provided by a subscriber using {@link #setCssClassFaPosition(org.apache.isis.applib.annotation.DomainObjectLayout.CssClassFaPosition)}.
+     *
+     * <p>
+     *     This attribute is currently ignored by Isis viewers.
+     * </p>
+     */
+    public DomainObjectLayout.CssClassFaPosition getCssClassFaPosition() {
+        return cssClassFaPosition;
+    }
+
+    /**
+     * For subscribers to call to provide the positioning of the font-awesome icon for this object.
+     *
+     * <p>
+     *     This attribute is currently ignored by Isis viewers.
+     * </p>
+     */
+    public void setCssClassFaPosition(
+            final DomainObjectLayout.CssClassFaPosition cssClassFaPosition) {
+        this.cssClassFaPosition = cssClassFaPosition;
+    }
+    //endregion
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/ffb62e9a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassUiEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassUiEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassUiEvent.java
new file mode 100644
index 0000000..f43c603
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassUiEvent.java
@@ -0,0 +1,79 @@
+/*
+ *  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.eventbus;
+
+import java.util.EventObject;
+
+import org.apache.isis.applib.annotation.DomainObjectLayout;
+
+/**
+ * Emitted for subscribers to obtain a cssClass hint (equivalent to the <tt>cssClass()</tt> supporting method or the {@link DomainObjectLayout#cssClass()} attribute).
+ */
+public abstract class CssClassUiEvent<S> extends AbstractUiEvent<S> {
+
+    private static final long serialVersionUID = 1L;
+
+    //region > constructors
+    /**
+     * If used then the framework will set state via (non-API) setters.
+     *
+     * <p>
+     *     Because the {@link EventObject} superclass prohibits a null source, a dummy value is temporarily used.
+     * </p>
+     */
+    public CssClassUiEvent() {
+        this(null);
+    }
+
+    public CssClassUiEvent(final S source) {
+        super(source);
+    }
+
+    //endregion
+
+    //region > Default class
+
+    /**
+     * Propagated if no custom subclass was specified using
+     * {@link org.apache.isis.applib.annotation.DomainObjectLayout#iconUiEvent()} annotation attribute.
+     */
+    public static class Default extends CssClassUiEvent<Object> {
+        private static final long serialVersionUID = 1L;
+    }
+    //endregion
+
+    //region > cssClass
+    private String cssClass;
+
+    /**
+     * The CSS class as provided by a subscriber using {@link #setCssClass(String)}.
+     */
+    public String getCssClass() {
+        return cssClass;
+    }
+
+    /**
+     * For subscribers to call to provide a CSS class for this object.
+     */
+    public void setCssClass(final String cssClass) {
+        this.cssClass = cssClass;
+    }
+    //endregion
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/ffb62e9a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/IconUiEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/IconUiEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/IconUiEvent.java
new file mode 100644
index 0000000..5924a95
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/IconUiEvent.java
@@ -0,0 +1,77 @@
+/*
+ *  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.eventbus;
+
+import java.util.EventObject;
+
+/**
+ * Emitted for subscribers to obtain a cssClass hint (equivalent to the <tt>iconName()</tt> supporting method).
+ */
+public abstract class IconUiEvent<S> extends AbstractUiEvent<S> {
+
+    private static final long serialVersionUID = 1L;
+
+    //region > constructors
+    /**
+     * If used then the framework will set state via (non-API) setters.
+     *
+     * <p>
+     *     Because the {@link EventObject} superclass prohibits a null source, a dummy value is temporarily used.
+     * </p>
+     */
+    public IconUiEvent() {
+        this(null);
+    }
+
+    public IconUiEvent(final S source) {
+        super(source);
+    }
+
+    //endregion
+
+    //region > Default class
+
+    /**
+     * Propagated if no custom subclass was specified using
+     * {@link org.apache.isis.applib.annotation.DomainObjectLayout#iconUiEvent()} annotation attribute.
+     */
+    public static class Default extends IconUiEvent<Object> {
+        private static final long serialVersionUID = 1L;
+    }
+    //endregion
+
+    //region > iconName
+    private String iconName;
+
+    /**
+     * The icon name as provided by a subscriber using {@link #setIconName(String)}.
+     */
+    public String getIconName() {
+        return iconName;
+    }
+
+    /**
+     * For subscribers to call to provide an icon name for this object.
+     */
+    public void setIconName(final String iconName) {
+        this.iconName = iconName;
+    }
+    //endregion
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/ffb62e9a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/TitleUiEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/TitleUiEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/TitleUiEvent.java
new file mode 100644
index 0000000..181015d
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/TitleUiEvent.java
@@ -0,0 +1,106 @@
+/*
+ *  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.eventbus;
+
+import java.util.EventObject;
+
+import org.apache.isis.applib.services.i18n.TranslatableString;
+
+/**
+ * Emitted for subscribers to obtain a cssClass hint (equivalent to the <tt>title()</tt> supporting method).
+ */
+public abstract class TitleUiEvent<S> extends AbstractUiEvent<S> {
+
+    private static final long serialVersionUID = 1L;
+
+    //region > Default class
+
+    /**
+     * Propagated if no custom subclass was specified using
+     * {@link org.apache.isis.applib.annotation.DomainObjectLayout#titleUiEvent()} annotation attribute.
+     */
+    public static class Default extends TitleUiEvent<Object> {
+        private static final long serialVersionUID = 1L;
+    }
+    //endregion
+
+    //region > constructors
+    /**
+     * If used then the framework will set state via (non-API) setters.
+     *
+     * <p>
+     *     Because the {@link EventObject} superclass prohibits a null source, a dummy value is temporarily used.
+     * </p>
+     */
+    public TitleUiEvent() {
+        this(null);
+    }
+
+    public TitleUiEvent(final S source) {
+        super(source);
+    }
+
+    //endregion
+
+    //region > title
+    private String title;
+
+    /**
+     * The title as provided by a subscriber using {@link #setTitle(String)}.
+     *
+     * <p>
+     *     Note that a {@link #getTranslatedTitle()} will be used in preference, if available.
+     * </p>
+     */
+    public String getTitle() {
+        return title;
+    }
+
+    /**
+     * For subscribers to call to provide a (non-translated) title for this object.
+     */
+    public void setTitle(final String title) {
+        this.title = title;
+    }
+    //endregion
+
+    //region > translatedTitle
+    private TranslatableString translatedTitle;
+
+    /**
+     * The translatable (i18n) title as provided by a subscriber using {@link #setTranslatedTitle(TranslatableString)}.
+     *
+     * <p>
+     *     If a translatable title has been provided then this will be used in preference to any
+     *     {@link #getTitle() non-translatable title}.
+     * </p>
+     */
+    public TranslatableString getTranslatedTitle() {
+        return translatedTitle;
+    }
+
+    /**
+     * For subscribers to call to provide a translatable (i18n) title for this object.
+     */
+    public void setTranslatedTitle(final TranslatableString translatedTitle) {
+        this.translatedTitle = translatedTitle;
+    }
+    //endregion
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/ffb62e9a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java
index 8a7c834..088b7b3 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java
@@ -23,8 +23,11 @@ import org.apache.isis.core.metamodel.facetapi.FacetUtil;
 import org.apache.isis.core.metamodel.facetapi.FeatureType;
 import org.apache.isis.core.metamodel.facets.Annotations;
 import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjectorAware;
+
+public class DomainObjectLayoutFacetFactory extends FacetFactoryAbstract implements ServicesInjectorAware {
 
-public class DomainObjectLayoutFacetFactory extends FacetFactoryAbstract {
 
     public DomainObjectLayoutFacetFactory() {
         super(FeatureType.OBJECTS_ONLY);
@@ -40,6 +43,10 @@ public class DomainObjectLayoutFacetFactory extends FacetFactoryAbstract {
         final ViewModelLayout viewModelLayout = Annotations.getAnnotation(cls, ViewModelLayout.class);
 
         FacetUtil.addFacet(
+                TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent.create(
+                        domainObjectLayout, servicesInjector, facetHolder));
+
+        FacetUtil.addFacet(
                 CssClassFacetForDomainObjectLayoutAnnotation.create(domainObjectLayout, facetHolder));
         FacetUtil.addFacet(
                 CssClassFacetForViewModelLayoutAnnotation.create(viewModelLayout, facetHolder));
@@ -77,4 +84,11 @@ public class DomainObjectLayoutFacetFactory extends FacetFactoryAbstract {
         return;
     }
 
+
+    private ServicesInjector servicesInjector;
+
+    @Override
+    public void setServicesInjector(final ServicesInjector servicesInjector) {
+        this.servicesInjector = servicesInjector;
+    }
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/ffb62e9a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent.java
new file mode 100644
index 0000000..55f0b0d
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent.java
@@ -0,0 +1,108 @@
+/*
+ *  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.core.metamodel.facets.object.domainobjectlayout;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.applib.NonRecoverableException;
+import org.apache.isis.applib.annotation.DomainObjectLayout;
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.applib.services.eventbus.TitleUiEvent;
+import org.apache.isis.applib.services.i18n.TranslatableString;
+import org.apache.isis.applib.services.i18n.TranslationService;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.title.TitleFacetAbstract;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+public class TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent extends TitleFacetAbstract {
+
+    private static final Logger LOG = LoggerFactory.getLogger(TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent.class);
+
+    public static Facet create(
+            final DomainObjectLayout domainObjectLayout,
+            final ServicesInjector servicesInjector,
+            final FacetHolder facetHolder) {
+        if(domainObjectLayout == null) {
+            return null;
+        }
+        final Class<? extends TitleUiEvent<?>> titleUiEventClass = domainObjectLayout.titleUiEvent();
+
+        final TranslationService translationService = servicesInjector.lookupService(TranslationService.class);
+        final ObjectSpecification facetHolderAsSpec = (ObjectSpecification) facetHolder; // bit naughty...
+        final String translationContext = facetHolderAsSpec.getCorrespondingClass().getCanonicalName();
+        final EventBusService eventBusService = servicesInjector.lookupService(EventBusService.class);
+
+        return new TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent(
+                titleUiEventClass, translationService, translationContext, eventBusService, facetHolder);
+    }
+
+    private final Class<? extends TitleUiEvent<?>> titleUiEventClass;
+    private final TranslationService translationService;
+    private final String translationContext;
+    private final EventBusService eventBusService;
+
+    public TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent(
+            final Class<? extends TitleUiEvent<?>> titleUiEventClass,
+            final TranslationService translationService,
+            final String translationContext,
+            final EventBusService eventBusService,
+            final FacetHolder holder) {
+        super(holder);
+        this.titleUiEventClass = titleUiEventClass;
+        this.translationService = translationService;
+        this.translationContext = translationContext;
+        this.eventBusService = eventBusService;
+    }
+
+    @Override
+    public String title(final ObjectAdapter owningAdapter, final Localization localization) {
+
+        final TitleUiEvent<Object> titleUiEvent = newTitleUiEvent(owningAdapter);
+
+        eventBusService.post(titleUiEvent);
+
+        final TranslatableString translatedTitle = titleUiEvent.getTranslatedTitle();
+        if(translatedTitle != null) {
+            return translatedTitle.translate(translationService, translationContext);
+        }
+        final String title = titleUiEvent.getTitle();
+        return title; // could be null
+    }
+
+    private TitleUiEvent<Object> newTitleUiEvent(final ObjectAdapter owningAdapter) {
+        final Object domainObject = owningAdapter.getObject();
+        return newTitleUiEvent(domainObject);
+    }
+
+    private TitleUiEvent<Object> newTitleUiEvent(final Object domainObject) {
+        try {
+            final TitleUiEvent<Object> titleUiEvent = (TitleUiEvent<Object>) titleUiEventClass.newInstance();
+            titleUiEvent.setSource(domainObject);
+            return titleUiEvent;
+        } catch (InstantiationException | IllegalAccessException ex) {
+            throw new NonRecoverableException(ex);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/ffb62e9a/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java b/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
index 4b9c4b7..37b50d2 100644
--- a/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
+++ b/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
@@ -310,8 +310,6 @@ public final class ProgrammingModelFacetsJava5 extends ProgrammingModelAbstract
         addFactory(ObjectValidPropertiesFacetImplFactory.class);
         addFactory(PluralFacetStaticMethodFactory.class);
         addFactory(org.apache.isis.core.metamodel.facets.object.named.staticmethod.NamedFacetStaticMethodFactory.class);
-        addFactory(TitleAnnotationFacetFactory.class);
-        addFactory(TitleFacetViaMethodsFactory.class);
 
         addFactory(MemberOrderFacetFactory.class);
         addFactory(ActionOrderFacetAnnotationFactory.class);
@@ -402,6 +400,10 @@ public final class ProgrammingModelFacetsJava5 extends ProgrammingModelAbstract
         addFactory(ActionLayoutFacetFactory.class);
         addFactory(CollectionLayoutFacetFactory.class);
 
+        // must come after DomainObjectLayoutFacetFactory
+        addFactory(TitleAnnotationFacetFactory.class);
+        addFactory(TitleFacetViaMethodsFactory.class);
+
         addFactory(NamedFacetOnTypeAnnotationFactory.class);
         addFactory(NamedFacetOnMemberFactory.class);
         addFactory(NamedFacetOnParameterAnnotationFactory.class);


[02/11] isis git commit: ISIS-1249: annotate with @DomainServiceLayout. Remove some comments and unnecessary @Programmatic annotation for the @PostConstruct and @PreDestroy.

Posted by da...@apache.org.
ISIS-1249: annotate with @DomainServiceLayout.  Remove some comments and unnecessary @Programmatic annotation for the @PostConstruct and @PreDestroy.


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

Branch: refs/heads/master
Commit: 01aeb7746e7eec8bc7a6c8551e4c25199728e298
Parents: b403a2c
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Nov 12 16:34:01 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Thu Nov 12 16:34:01 2015 +0000

----------------------------------------------------------------------
 .../org/apache/isis/applib/AbstractSubscriber.java    | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/01aeb774/core/applib/src/main/java/org/apache/isis/applib/AbstractSubscriber.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/AbstractSubscriber.java b/core/applib/src/main/java/org/apache/isis/applib/AbstractSubscriber.java
index 78703ca..23d681f 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/AbstractSubscriber.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/AbstractSubscriber.java
@@ -19,36 +19,34 @@
 package org.apache.isis.applib;
 
 import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
+
+import org.apache.isis.applib.annotation.DomainServiceLayout;
 import org.apache.isis.applib.annotation.Programmatic;
 import org.apache.isis.applib.services.eventbus.EventBusService;
 
 /**
  * Convenience class for services that act as subscribers.
  */
+@DomainServiceLayout(
+        menuOrder = "1"
+)
 public abstract class AbstractSubscriber {
 
-    //region > postConstruct, preDestroy
-
-    @Programmatic
     @PostConstruct
     public void postConstruct() {
         eventBusService.register(this);
     }
 
     @Programmatic
-    @PreDestroy
     public void preDestroy() {
         eventBusService.unregister(this);
     }
-    //endregion
 
-    //region > injected services
+
     @javax.inject.Inject
     protected DomainObjectContainer container;
 
     @javax.inject.Inject
     protected EventBusService eventBusService;
-    //endregion
 
 }


[05/11] isis git commit: ISIS-915: minor tidy-up.

Posted by da...@apache.org.
ISIS-915: minor tidy-up.


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

Branch: refs/heads/master
Commit: d654fc8ef3f386f76fa48145fe0881e269a7a41a
Parents: 9163f6d
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Nov 13 10:06:48 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Nov 13 10:06:48 2015 +0000

----------------------------------------------------------------------
 .../RecreatableObjectFacetAbstract.java         |  3 ++
 .../RecreatableObjectFacetFactory.java          |  4 ++-
 ...eObjectFacetForXmlRootElementAnnotation.java | 34 ++++++++------------
 3 files changed, 19 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/d654fc8e/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetAbstract.java
index 969d007..63de997 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetAbstract.java
@@ -22,6 +22,7 @@ package org.apache.isis.core.metamodel.facets.object.recreatable;
 import java.lang.reflect.Method;
 
 import org.apache.isis.applib.ViewModel;
+import org.apache.isis.applib.services.urlencoding.UrlEncodingService;
 import org.apache.isis.core.commons.lang.MethodExtensions;
 import org.apache.isis.core.metamodel.facetapi.Facet;
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
@@ -122,4 +123,6 @@ public abstract class RecreatableObjectFacetAbstract extends MarkerFacetAbstract
         }
     }
 
+
+
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/d654fc8e/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
index ec03ff4..939e9bf 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
@@ -99,7 +99,9 @@ public class RecreatableObjectFacetFactory extends FacetFactoryAbstract
 
     private ViewModelFacet create(final XmlRootElement annotation, final FacetHolder holder) {
         final PostConstructMethodCache postConstructMethodCache = this;
-        return annotation != null ? new RecreatableObjectFacetForXmlRootElementAnnotation(holder, getSpecificationLoader(), adapterManager, servicesInjector, postConstructMethodCache) : null;
+        return annotation != null
+                ? new RecreatableObjectFacetForXmlRootElementAnnotation(holder, servicesInjector, postConstructMethodCache)
+                : null;
     }
 
     // //////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/isis/blob/d654fc8e/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java
index 06581c3..5c167af 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetForXmlRootElementAnnotation.java
@@ -21,53 +21,45 @@ package org.apache.isis.core.metamodel.facets.object.recreatable;
 
 import org.apache.isis.applib.services.jaxb.JaxbService;
 import org.apache.isis.applib.services.urlencoding.UrlEncodingService;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
 import org.apache.isis.core.metamodel.facets.PostConstructMethodCache;
 import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
-import org.apache.isis.core.metamodel.spec.SpecificationLoader;
 
 public class RecreatableObjectFacetForXmlRootElementAnnotation extends RecreatableObjectFacetAbstract {
 
-    private final SpecificationLoader specificationLoader;
-    private final AdapterManager adapterManager;
-    private final ServicesInjector servicesInjector;
 
     public RecreatableObjectFacetForXmlRootElementAnnotation(
             final FacetHolder holder,
-            final SpecificationLoader specificationLoader,
-            final AdapterManager adapterManager,
             final ServicesInjector servicesInjector,
             final PostConstructMethodCache postConstructMethodCache) {
         super(holder, ArchitecturalLayer.APPLICATION, RecreationMechanism.INSTANTIATES,
                 postConstructMethodCache, servicesInjector);
-
-        this.specificationLoader = specificationLoader;
-        this.adapterManager = adapterManager;
-        this.servicesInjector = servicesInjector;
     }
 
     @Override
     protected Object doInstantiate(final Class<?> viewModelClass, final String mementoStr) {
 
-        final JaxbService jaxbService = servicesInjector.lookupService(JaxbService.class);
-        final UrlEncodingService urlEncodingService =
-                servicesInjector.lookupService(UrlEncodingService.class);
+        final String xmlStr = getUrlEncodingService().decode(mementoStr);
+        final Object viewModelPojo = getJaxbService().fromXml(viewModelClass, xmlStr);
 
-        final String xmlStr = urlEncodingService.decode(mementoStr);
-        final Object viewModelPojo = jaxbService.fromXml(viewModelClass, xmlStr);
         return viewModelPojo;
     }
 
     @Override
     public String memento(final Object pojo) {
 
-        final JaxbService jaxbService = servicesInjector.lookupService(JaxbService.class);
-        final UrlEncodingService urlEncodingService =
-                servicesInjector.lookupService(UrlEncodingService.class);
+        final String xml = getJaxbService().toXml(pojo);
+        final String encoded = getUrlEncodingService().encode(xml);
 
-        final String xml = jaxbService.toXml(pojo);
-        final String encoded = urlEncodingService.encode(xml);
         return encoded;
     }
+
+    private JaxbService getJaxbService() {
+        return servicesInjector.lookupService(JaxbService.class);
+    }
+
+    private UrlEncodingService getUrlEncodingService() {
+        return servicesInjector.lookupService(UrlEncodingService.class);
+    }
+
 }


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

Posted by da...@apache.org.
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;
     }


[09/11] isis git commit: ISIS-1252: adding support for icons via UI event.

Posted by da...@apache.org.
ISIS-1252: adding support for icons via UI event.


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

Branch: refs/heads/master
Commit: d556d519e83581224153395789aa550c1810812b
Parents: ffb62e9
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Nov 13 13:53:42 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Nov 13 13:53:42 2015 +0000

----------------------------------------------------------------------
 .../isis/applib/DomainObjectContainer.java      |  11 ++
 .../DomainObjectLayoutFacetFactory.java         |   3 +
 ...nObjectLayoutAnnotationUsingIconUiEvent.java | 103 +++++++++++++++++++
 .../container/DomainObjectContainerDefault.java |  11 ++
 .../dflt/ProgrammingModelFacetsJava5.java       |   7 +-
 5 files changed, 131 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/d556d519/core/applib/src/main/java/org/apache/isis/applib/DomainObjectContainer.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/DomainObjectContainer.java b/core/applib/src/main/java/org/apache/isis/applib/DomainObjectContainer.java
index d26c8b7..e97df0c 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/DomainObjectContainer.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/DomainObjectContainer.java
@@ -48,6 +48,17 @@ public interface DomainObjectContainer {
 
     //endregion
 
+    //region > iconNameOf
+
+    /**
+     * Return the icon name of the object, as rendered in the UI by the
+     * Isis viewers.
+     */
+    @Programmatic
+    String iconNameOf(Object domainObject);
+
+    //endregion
+
     //region > resolve, objectChanged
 
     /**

http://git-wip-us.apache.org/repos/asf/isis/blob/d556d519/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java
index 088b7b3..7bb700e 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java
@@ -45,6 +45,9 @@ public class DomainObjectLayoutFacetFactory extends FacetFactoryAbstract impleme
         FacetUtil.addFacet(
                 TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent.create(
                         domainObjectLayout, servicesInjector, facetHolder));
+        FacetUtil.addFacet(
+                IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent.create(
+                        domainObjectLayout, servicesInjector, facetHolder));
 
         FacetUtil.addFacet(
                 CssClassFacetForDomainObjectLayoutAnnotation.create(domainObjectLayout, facetHolder));

http://git-wip-us.apache.org/repos/asf/isis/blob/d556d519/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent.java
new file mode 100644
index 0000000..ffe01b9
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent.java
@@ -0,0 +1,103 @@
+/*
+ *  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.core.metamodel.facets.object.domainobjectlayout;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.applib.NonRecoverableException;
+import org.apache.isis.applib.annotation.DomainObjectLayout;
+import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.applib.services.eventbus.IconUiEvent;
+import org.apache.isis.applib.services.i18n.TranslationService;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.icon.IconFacetAbstract;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+public class IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent extends IconFacetAbstract {
+
+    private static final Logger LOG = LoggerFactory.getLogger(IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent.class);
+
+    public static Facet create(
+            final DomainObjectLayout domainObjectLayout,
+            final ServicesInjector servicesInjector,
+            final FacetHolder facetHolder) {
+        if(domainObjectLayout == null) {
+            return null;
+        }
+        final Class<? extends IconUiEvent<?>> iconUiEventClass = domainObjectLayout.iconUiEvent();
+
+        final TranslationService translationService = servicesInjector.lookupService(TranslationService.class);
+        final ObjectSpecification facetHolderAsSpec = (ObjectSpecification) facetHolder; // bit naughty...
+        final String translationContext = facetHolderAsSpec.getCorrespondingClass().getCanonicalName();
+        final EventBusService eventBusService = servicesInjector.lookupService(EventBusService.class);
+
+        return new IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent(
+                iconUiEventClass, translationService, translationContext, eventBusService, facetHolder);
+    }
+
+    private final Class<? extends IconUiEvent<?>> iconUiEventClass;
+    private final TranslationService translationService;
+    private final String translationContext;
+    private final EventBusService eventBusService;
+
+    public IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent(
+            final Class<? extends IconUiEvent<?>> iconUiEventClass,
+            final TranslationService translationService,
+            final String translationContext,
+            final EventBusService eventBusService,
+            final FacetHolder holder) {
+        super(holder);
+        this.iconUiEventClass = iconUiEventClass;
+        this.translationService = translationService;
+        this.translationContext = translationContext;
+        this.eventBusService = eventBusService;
+    }
+
+    @Override
+    public String iconName(final ObjectAdapter owningAdapter) {
+
+        final IconUiEvent<Object> iconUiEvent = newIconUiEvent(owningAdapter);
+
+        eventBusService.post(iconUiEvent);
+
+        final String iconName = iconUiEvent.getIconName();
+        return iconName; // could be null
+    }
+
+    private IconUiEvent<Object> newIconUiEvent(final ObjectAdapter owningAdapter) {
+        final Object domainObject = owningAdapter.getObject();
+        return newIconUiEvent(domainObject);
+    }
+
+    private IconUiEvent<Object> newIconUiEvent(final Object domainObject) {
+        try {
+            final IconUiEvent<Object> iconUiEvent = (IconUiEvent<Object>) iconUiEventClass.newInstance();
+            iconUiEvent.setSource(domainObject);
+            return iconUiEvent;
+        } catch (InstantiationException | IllegalAccessException ex) {
+            throw new NonRecoverableException(ex);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/d556d519/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
index ea6b4ff..2040475 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
@@ -105,6 +105,17 @@ public class DomainObjectContainerDefault
 
     //endregion
 
+    //region > iconNameOf
+
+    @Programmatic
+    @Override
+    public String iconNameOf(final Object domainObject) {
+        final ObjectAdapter objectAdapter = adapterManager.adapterFor(unwrapped(domainObject));
+        return objectAdapter.getSpecification().getIconName(objectAdapter);
+    }
+
+    //endregion
+
     //region > newXxxInstance, remove
 
     @Programmatic

http://git-wip-us.apache.org/repos/asf/isis/blob/d556d519/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java b/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
index 37b50d2..417297f 100644
--- a/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
+++ b/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
@@ -295,10 +295,6 @@ public final class ProgrammingModelFacetsJava5 extends ProgrammingModelAbstract
         addFactory(HideForContextFacetViaMethodFactory.class);
         addFactory(RenderFacetOrResolveFactory.class);
 
-        // objects
-        addFactory(IconFacetMethodFactory.class);
-        addFactory(CssClassFacetMethodFactory.class);
-
         addFactory(CreatedCallbackFacetFactory.class);
         addFactory(LoadCallbackFacetFactory.class);
         addFactory(PersistCallbackViaSaveMethodFacetFactory.class);
@@ -404,6 +400,9 @@ public final class ProgrammingModelFacetsJava5 extends ProgrammingModelAbstract
         addFactory(TitleAnnotationFacetFactory.class);
         addFactory(TitleFacetViaMethodsFactory.class);
 
+        addFactory(IconFacetMethodFactory.class);
+        addFactory(CssClassFacetMethodFactory.class);
+
         addFactory(NamedFacetOnTypeAnnotationFactory.class);
         addFactory(NamedFacetOnMemberFactory.class);
         addFactory(NamedFacetOnParameterAnnotationFactory.class);


[10/11] isis git commit: ISIS-1252: adding support for CssClassUiEvent. Also adding in concept of Noop events to suppress (and making these the default); also...

Posted by da...@apache.org.
ISIS-1252: adding support for CssClassUiEvent.  Also adding in concept of Noop events to suppress (and making these the default); also...

... some cosmetic UI changes for the downloadXml and downloadXsd mixin actions.


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

Branch: refs/heads/master
Commit: 99c55b8c343f77baa796c59128d89c6fdd1f0d78
Parents: d556d51
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Nov 13 17:56:05 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Nov 13 17:56:05 2015 +0000

----------------------------------------------------------------------
 .../applib/annotation/DomainObjectLayout.java   |  16 +--
 .../services/eventbus/CssClassFaUiEvent.java    | 108 -------------------
 .../services/eventbus/CssClassUiEvent.java      |  15 ++-
 .../applib/services/eventbus/IconUiEvent.java   |  15 ++-
 .../applib/services/eventbus/TitleUiEvent.java  |  15 ++-
 .../applib/services/jaxb/Dto_downloadXml.java   |   8 +-
 .../applib/services/jaxb/Dto_downloadXsd.java   |   8 +-
 ...ectLayoutAnnotationUsingCssClassUiEvent.java |  99 +++++++++++++++++
 .../DomainObjectLayoutFacetFactory.java         |   3 +
 ...nObjectLayoutAnnotationUsingIconUiEvent.java |  16 +--
 ...ObjectLayoutAnnotationUsingTitleUiEvent.java |   3 +
 .../dflt/ProgrammingModelFacetsJava5.java       |   1 -
 12 files changed, 165 insertions(+), 142 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/99c55b8c/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObjectLayout.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObjectLayout.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObjectLayout.java
index 535248d..d65dc2f 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObjectLayout.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/DomainObjectLayout.java
@@ -25,7 +25,6 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-import org.apache.isis.applib.services.eventbus.CssClassFaUiEvent;
 import org.apache.isis.applib.services.eventbus.CssClassUiEvent;
 import org.apache.isis.applib.services.eventbus.IconUiEvent;
 import org.apache.isis.applib.services.eventbus.TitleUiEvent;
@@ -46,7 +45,7 @@ public @interface DomainObjectLayout {
      * This subclass must provide a no-arg constructor; the fields are set reflectively.
      * </p>
      */
-    Class<? extends TitleUiEvent<?>> titleUiEvent() default TitleUiEvent.Default.class;
+    Class<? extends TitleUiEvent<?>> titleUiEvent() default TitleUiEvent.Noop.class;
 
     // //////////////////////////////////////
 
@@ -57,7 +56,7 @@ public @interface DomainObjectLayout {
      * This subclass must provide a no-arg constructor; the fields are set reflectively.
      * </p>
      */
-    Class<? extends IconUiEvent<?>> iconUiEvent() default IconUiEvent.Default.class;
+    Class<? extends IconUiEvent<?>> iconUiEvent() default IconUiEvent.Noop.class;
 
     // //////////////////////////////////////
 
@@ -68,7 +67,7 @@ public @interface DomainObjectLayout {
      * This subclass must provide a no-arg constructor; the fields are set reflectively.
      * </p>
      */
-    Class<? extends CssClassUiEvent<?>> cssClassUiEvent() default CssClassUiEvent.Default.class;
+    Class<? extends CssClassUiEvent<?>> cssClassUiEvent() default CssClassUiEvent.Noop.class;
 
     /**
      * Indicates the css class that a domain class (type) should have.
@@ -78,15 +77,6 @@ public @interface DomainObjectLayout {
     // //////////////////////////////////////
 
     /**
-     * Which subclass of {@link CssClassFaUiEvent} should be used to obtain a CSS font-awesome class and position.
-     *
-     * <p>
-     * This subclass must provide a no-arg constructor; the fields are set reflectively.
-     * </p>
-     */
-    Class<? extends CssClassFaUiEvent<?>> cssClassFaUiEvent() default CssClassFaUiEvent.Default.class;
-
-    /**
      * Indicates the <a href="http://fortawesome.github.io/Font-Awesome/">Font Awesome</a> CSS class to decorate an
      * domain object.
      */

http://git-wip-us.apache.org/repos/asf/isis/blob/99c55b8c/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassFaUiEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassFaUiEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassFaUiEvent.java
deleted file mode 100644
index 54cf2b7..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassFaUiEvent.java
+++ /dev/null
@@ -1,108 +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.eventbus;
-
-import java.util.EventObject;
-
-import org.apache.isis.applib.annotation.DomainObjectLayout;
-
-/**
- * Emitted for subscribers to obtain a cssClassFa hint (equivalent to the {@link DomainObjectLayout#cssClassFa()} attribute), providing the CSS class for a font-awesome
- * icon for this domain object.
- */
-public abstract class CssClassFaUiEvent<S> extends AbstractUiEvent<S> {
-
-    private static final long serialVersionUID = 1L;
-
-    //region > constructors
-    /**
-     * If used then the framework will set state via (non-API) setters.
-     *
-     * <p>
-     *     Because the {@link EventObject} superclass prohibits a null source, a dummy value is temporarily used.
-     * </p>
-     */
-    public CssClassFaUiEvent() {
-        this(null);
-    }
-
-    public CssClassFaUiEvent(final S source) {
-        super(source);
-    }
-
-    //endregion
-
-    //region > Default class
-
-    /**
-     * Propagated if no custom subclass was specified using
-     * {@link org.apache.isis.applib.annotation.DomainObjectLayout#iconUiEvent()} annotation attribute.
-     */
-    public static class Default extends CssClassFaUiEvent<Object> {
-        private static final long serialVersionUID = 1L;
-    }
-    //endregion
-
-    //region > cssClassFa
-    private String cssClassFa;
-
-    /**
-     * The CSS class for a font-awesome icon for this domain object, as provided by a subscriber using {@link #setCssClassFa(String)}.
-     */
-    public String getCssClassFa() {
-        return cssClassFa;
-    }
-
-
-    /**
-     * For subscribers to call to provide a CSS class for a font-awesome icon for this object.
-     */
-    public void setCssClassFa(final String cssClass) {
-        this.cssClassFa = cssClass;
-    }
-    //endregion
-
-    //region > cssClassFaPosition
-    private DomainObjectLayout.CssClassFaPosition cssClassFaPosition;
-
-    /**
-     * The {@link DomainObjectLayout.CssClassFaPosition position} as provided by a subscriber using {@link #setCssClassFaPosition(org.apache.isis.applib.annotation.DomainObjectLayout.CssClassFaPosition)}.
-     *
-     * <p>
-     *     This attribute is currently ignored by Isis viewers.
-     * </p>
-     */
-    public DomainObjectLayout.CssClassFaPosition getCssClassFaPosition() {
-        return cssClassFaPosition;
-    }
-
-    /**
-     * For subscribers to call to provide the positioning of the font-awesome icon for this object.
-     *
-     * <p>
-     *     This attribute is currently ignored by Isis viewers.
-     * </p>
-     */
-    public void setCssClassFaPosition(
-            final DomainObjectLayout.CssClassFaPosition cssClassFaPosition) {
-        this.cssClassFaPosition = cssClassFaPosition;
-    }
-    //endregion
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/99c55b8c/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassUiEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassUiEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassUiEvent.java
index f43c603..49c41ec 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassUiEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CssClassUiEvent.java
@@ -50,14 +50,25 @@ public abstract class CssClassUiEvent<S> extends AbstractUiEvent<S> {
     //region > Default class
 
     /**
-     * Propagated if no custom subclass was specified using
-     * {@link org.apache.isis.applib.annotation.DomainObjectLayout#iconUiEvent()} annotation attribute.
+     * Implementation provided as a convenience for domain objects that have no custom subclass.
      */
     public static class Default extends CssClassUiEvent<Object> {
         private static final long serialVersionUID = 1L;
     }
     //endregion
 
+    //region > Noop class
+
+    /**
+     * Marker class that is the default for
+     * {@link org.apache.isis.applib.annotation.DomainObjectLayout#cssClassUiEvent()} annotation attribute, meaning that
+     * an event should <i>not</i> be emitted by default.
+     */
+    public static class Noop extends CssClassUiEvent<Object> {
+        private static final long serialVersionUID = 1L;
+    }
+    //endregion
+
     //region > cssClass
     private String cssClass;
 

http://git-wip-us.apache.org/repos/asf/isis/blob/99c55b8c/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/IconUiEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/IconUiEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/IconUiEvent.java
index 5924a95..2a777e2 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/IconUiEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/IconUiEvent.java
@@ -48,14 +48,25 @@ public abstract class IconUiEvent<S> extends AbstractUiEvent<S> {
     //region > Default class
 
     /**
-     * Propagated if no custom subclass was specified using
-     * {@link org.apache.isis.applib.annotation.DomainObjectLayout#iconUiEvent()} annotation attribute.
+     * Implementation provided as a convenience for domain objects that have no custom subclass.
      */
     public static class Default extends IconUiEvent<Object> {
         private static final long serialVersionUID = 1L;
     }
     //endregion
 
+    //region > Noop class
+
+    /**
+     * Marker class that is the default for
+     * {@link org.apache.isis.applib.annotation.DomainObjectLayout#iconUiEvent()} annotation attribute, meaning that
+     * an event should <i>not</i> be emitted by default.
+     */
+    public static class Noop extends IconUiEvent<Object> {
+        private static final long serialVersionUID = 1L;
+    }
+    //endregion
+
     //region > iconName
     private String iconName;
 

http://git-wip-us.apache.org/repos/asf/isis/blob/99c55b8c/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/TitleUiEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/TitleUiEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/TitleUiEvent.java
index 181015d..0bb9b91 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/TitleUiEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/TitleUiEvent.java
@@ -32,14 +32,25 @@ public abstract class TitleUiEvent<S> extends AbstractUiEvent<S> {
     //region > Default class
 
     /**
-     * Propagated if no custom subclass was specified using
-     * {@link org.apache.isis.applib.annotation.DomainObjectLayout#titleUiEvent()} annotation attribute.
+     * Implementation provided as a convenience for domain objects that have no custom subclass.
      */
     public static class Default extends TitleUiEvent<Object> {
         private static final long serialVersionUID = 1L;
     }
     //endregion
 
+    //region > Noop class
+
+    /**
+     * Marker class that is the default for
+     * {@link org.apache.isis.applib.annotation.DomainObjectLayout#titleUiEvent()} annotation attribute, meaning that
+     * an event should <i>not</i> be emitted by default.
+     */
+    public static class Noop extends TitleUiEvent<Object> {
+        private static final long serialVersionUID = 1L;
+    }
+    //endregion
+
     //region > constructors
     /**
      * If used then the framework will set state via (non-API) setters.

http://git-wip-us.apache.org/repos/asf/isis/blob/99c55b8c/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java
index 91332b3..79c4006 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java
@@ -25,8 +25,10 @@ import javax.xml.bind.JAXBException;
 
 import org.apache.isis.applib.FatalException;
 import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.ActionLayout;
 import org.apache.isis.applib.annotation.MemberOrder;
 import org.apache.isis.applib.annotation.Mixin;
+import org.apache.isis.applib.annotation.RestrictTo;
 import org.apache.isis.applib.annotation.SemanticsOf;
 import org.apache.isis.applib.value.Clob;
 
@@ -50,7 +52,11 @@ public class Dto_downloadXml {
 
     @Action(
             domainEvent = ActionDomainEvent.class,
-            semantics = SemanticsOf.SAFE
+            semantics = SemanticsOf.SAFE,
+            restrictTo = RestrictTo.PROTOTYPING
+    )
+    @ActionLayout(
+            cssClassFa = "fa-download"
     )
     @MemberOrder(sequence = "500.1")
     public Object $$(final String fileName) throws JAXBException, IOException {

http://git-wip-us.apache.org/repos/asf/isis/blob/99c55b8c/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java
index ce10bb1..dfb4c90 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java
@@ -30,8 +30,10 @@ import javax.inject.Inject;
 import org.apache.isis.applib.DomainObjectContainer;
 import org.apache.isis.applib.FatalException;
 import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.ActionLayout;
 import org.apache.isis.applib.annotation.MemberOrder;
 import org.apache.isis.applib.annotation.Mixin;
+import org.apache.isis.applib.annotation.RestrictTo;
 import org.apache.isis.applib.annotation.SemanticsOf;
 import org.apache.isis.applib.value.Blob;
 import org.apache.isis.applib.value.Clob;
@@ -56,7 +58,11 @@ public class Dto_downloadXsd {
 
     @Action(
             domainEvent = ActionDomainEvent.class,
-            semantics = SemanticsOf.SAFE
+            semantics = SemanticsOf.SAFE,
+            restrictTo = RestrictTo.PROTOTYPING
+    )
+    @ActionLayout(
+            cssClassFa = "fa-download"
     )
     @MemberOrder(sequence = "500.2")
     public Object $$(final String fileName) {

http://git-wip-us.apache.org/repos/asf/isis/blob/99c55b8c/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/CssClassFacetViaDomainObjectLayoutAnnotationUsingCssClassUiEvent.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/CssClassFacetViaDomainObjectLayoutAnnotationUsingCssClassUiEvent.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/CssClassFacetViaDomainObjectLayoutAnnotationUsingCssClassUiEvent.java
new file mode 100644
index 0000000..9f21e51
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/CssClassFacetViaDomainObjectLayoutAnnotationUsingCssClassUiEvent.java
@@ -0,0 +1,99 @@
+/*
+ *  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.core.metamodel.facets.object.domainobjectlayout;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.applib.NonRecoverableException;
+import org.apache.isis.applib.annotation.DomainObjectLayout;
+import org.apache.isis.applib.services.eventbus.CssClassUiEvent;
+import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.members.cssclass.CssClassFacet;
+import org.apache.isis.core.metamodel.facets.members.cssclass.CssClassFacetAbstract;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+public class CssClassFacetViaDomainObjectLayoutAnnotationUsingCssClassUiEvent extends FacetAbstract implements
+        CssClassFacet {
+
+    private static final Logger LOG = LoggerFactory.getLogger(CssClassFacetViaDomainObjectLayoutAnnotationUsingCssClassUiEvent.class);
+
+    public static Facet create(
+            final DomainObjectLayout domainObjectLayout,
+            final ServicesInjector servicesInjector,
+            final FacetHolder facetHolder) {
+        if(domainObjectLayout == null) {
+            return null;
+        }
+        final Class<? extends CssClassUiEvent<?>> cssClassUiEventClass = domainObjectLayout.cssClassUiEvent();
+        if(CssClassUiEvent.Noop.class.isAssignableFrom(cssClassUiEventClass)) {
+            return null;
+        }
+
+        final EventBusService eventBusService = servicesInjector.lookupService(EventBusService.class);
+
+        return new CssClassFacetViaDomainObjectLayoutAnnotationUsingCssClassUiEvent(
+                cssClassUiEventClass, eventBusService, facetHolder);
+    }
+
+    private final Class<? extends CssClassUiEvent<?>> cssClassUiEventClass;
+    private final EventBusService eventBusService;
+
+    public CssClassFacetViaDomainObjectLayoutAnnotationUsingCssClassUiEvent(
+            final Class<? extends CssClassUiEvent<?>> cssClassUiEventClass,
+            final EventBusService eventBusService,
+            final FacetHolder holder) {
+        super(CssClassFacetAbstract.type(), holder, Derivation.NOT_DERIVED);
+        this.cssClassUiEventClass = cssClassUiEventClass;
+        this.eventBusService = eventBusService;
+    }
+
+    @Override
+    public String cssClass(final ObjectAdapter objectAdapter) {
+
+        final CssClassUiEvent<Object> cssClassUiEvent = newCssClassUiEvent(objectAdapter);
+
+        eventBusService.post(cssClassUiEvent);
+
+        final String cssClass = cssClassUiEvent.getCssClass();
+        return cssClass; // could be null
+    }
+
+    private CssClassUiEvent<Object> newCssClassUiEvent(final ObjectAdapter owningAdapter) {
+        final Object domainObject = owningAdapter.getObject();
+        return newCssClassUiEvent(domainObject);
+    }
+
+    private CssClassUiEvent<Object> newCssClassUiEvent(final Object domainObject) {
+        try {
+            final CssClassUiEvent<Object> cssClassUiEvent = (CssClassUiEvent<Object>) cssClassUiEventClass.newInstance();
+            cssClassUiEvent.setSource(domainObject);
+            return cssClassUiEvent;
+        } catch (InstantiationException | IllegalAccessException ex) {
+            throw new NonRecoverableException(ex);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/99c55b8c/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java
index 7bb700e..51e952d 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/DomainObjectLayoutFacetFactory.java
@@ -48,6 +48,9 @@ public class DomainObjectLayoutFacetFactory extends FacetFactoryAbstract impleme
         FacetUtil.addFacet(
                 IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent.create(
                         domainObjectLayout, servicesInjector, facetHolder));
+        FacetUtil.addFacet(
+                CssClassFacetViaDomainObjectLayoutAnnotationUsingCssClassUiEvent.create(
+                        domainObjectLayout, servicesInjector, facetHolder));
 
         FacetUtil.addFacet(
                 CssClassFacetForDomainObjectLayoutAnnotation.create(domainObjectLayout, facetHolder));

http://git-wip-us.apache.org/repos/asf/isis/blob/99c55b8c/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent.java
index ffe01b9..4036892 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent.java
@@ -26,13 +26,11 @@ import org.apache.isis.applib.NonRecoverableException;
 import org.apache.isis.applib.annotation.DomainObjectLayout;
 import org.apache.isis.applib.services.eventbus.EventBusService;
 import org.apache.isis.applib.services.eventbus.IconUiEvent;
-import org.apache.isis.applib.services.i18n.TranslationService;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.facetapi.Facet;
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
 import org.apache.isis.core.metamodel.facets.object.icon.IconFacetAbstract;
 import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 
 public class IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent extends IconFacetAbstract {
 
@@ -46,31 +44,25 @@ public class IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent extends Ic
             return null;
         }
         final Class<? extends IconUiEvent<?>> iconUiEventClass = domainObjectLayout.iconUiEvent();
+        if(IconUiEvent.Noop.class.isAssignableFrom(iconUiEventClass)) {
+            return null;
+        }
 
-        final TranslationService translationService = servicesInjector.lookupService(TranslationService.class);
-        final ObjectSpecification facetHolderAsSpec = (ObjectSpecification) facetHolder; // bit naughty...
-        final String translationContext = facetHolderAsSpec.getCorrespondingClass().getCanonicalName();
         final EventBusService eventBusService = servicesInjector.lookupService(EventBusService.class);
 
         return new IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent(
-                iconUiEventClass, translationService, translationContext, eventBusService, facetHolder);
+                iconUiEventClass, eventBusService, facetHolder);
     }
 
     private final Class<? extends IconUiEvent<?>> iconUiEventClass;
-    private final TranslationService translationService;
-    private final String translationContext;
     private final EventBusService eventBusService;
 
     public IconFacetViaDomainObjectLayoutAnnotationUsingIconUiEvent(
             final Class<? extends IconUiEvent<?>> iconUiEventClass,
-            final TranslationService translationService,
-            final String translationContext,
             final EventBusService eventBusService,
             final FacetHolder holder) {
         super(holder);
         this.iconUiEventClass = iconUiEventClass;
-        this.translationService = translationService;
-        this.translationContext = translationContext;
         this.eventBusService = eventBusService;
     }
 

http://git-wip-us.apache.org/repos/asf/isis/blob/99c55b8c/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent.java
index 55f0b0d..dd8c457 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobjectlayout/TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent.java
@@ -49,6 +49,9 @@ public class TitleFacetViaDomainObjectLayoutAnnotationUsingTitleUiEvent extends
         }
         final Class<? extends TitleUiEvent<?>> titleUiEventClass = domainObjectLayout.titleUiEvent();
 
+        if(TitleUiEvent.Noop.class.isAssignableFrom(titleUiEventClass)) {
+            return null;
+        }
         final TranslationService translationService = servicesInjector.lookupService(TranslationService.class);
         final ObjectSpecification facetHolderAsSpec = (ObjectSpecification) facetHolder; // bit naughty...
         final String translationContext = facetHolderAsSpec.getCorrespondingClass().getCanonicalName();

http://git-wip-us.apache.org/repos/asf/isis/blob/99c55b8c/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java b/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
index 417297f..3ce5e46 100644
--- a/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
+++ b/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
@@ -399,7 +399,6 @@ public final class ProgrammingModelFacetsJava5 extends ProgrammingModelAbstract
         // must come after DomainObjectLayoutFacetFactory
         addFactory(TitleAnnotationFacetFactory.class);
         addFactory(TitleFacetViaMethodsFactory.class);
-
         addFactory(IconFacetMethodFactory.class);
         addFactory(CssClassFacetMethodFactory.class);
 


Re: [03/11] isis git commit: ISIS-1250: take-on of the JaxbService...

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
That might be a copy N paste from the downloadXsd which generates multiple
files, zipped together.

I'll double check.

Thx for the review.

Cheers, Dan.
On 14 Nov 2015 19:21, "Martin Grigorov" <mg...@apache.org> wrote:

> Hi Dan,
>
> On Fri, Nov 13, 2015 at 6:57 PM, <da...@apache.org> wrote:
>
> > public Dto_downloadXml(final Dto dto) {
> > +        this.dto = dto;
> > +        try {
> > +            mimeTypeApplicationZip = new MimeType("application", "zip");
> >
>
> What is the magic here that it is a "zip"?
> The methods below deal with "xml" (as I'd expect).
>
>
> > +        } catch (final MimeTypeParseException ex) {
> > +            throw new FatalException(ex);
> > +        }
> > +    }
> > +
> > +    public static class ActionDomainEvent extends
> > org.apache.isis.applib.IsisApplibModule.ActionDomainEvent<Dto> {}
> > +
> > +    @Action(
> > +            domainEvent = ActionDomainEvent.class,
> > +            semantics = SemanticsOf.SAFE
> > +    )
> > +    @MemberOrder(sequence = "500.1")
> > +    public Object $(final String fileName) throws JAXBException,
> > IOException {
> > +
> > +        final String xml = jaxbService.toXml(dto);
> > +        return new Clob(Util.withSuffix(fileName, "xml"), "text/xml",
> > xml);
> > +    }
> > +
> > +    public String default0$() {
> > +        return Util.withSuffix(dto.getClass().getName(), "xml");
> > +    }
> >
>
>
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>

Re: [03/11] isis git commit: ISIS-1250: take-on of the JaxbService...

Posted by Martin Grigorov <mg...@apache.org>.
Hi Dan,

On Fri, Nov 13, 2015 at 6:57 PM, <da...@apache.org> wrote:

> public Dto_downloadXml(final Dto dto) {
> +        this.dto = dto;
> +        try {
> +            mimeTypeApplicationZip = new MimeType("application", "zip");
>

What is the magic here that it is a "zip"?
The methods below deal with "xml" (as I'd expect).


> +        } catch (final MimeTypeParseException ex) {
> +            throw new FatalException(ex);
> +        }
> +    }
> +
> +    public static class ActionDomainEvent extends
> org.apache.isis.applib.IsisApplibModule.ActionDomainEvent<Dto> {}
> +
> +    @Action(
> +            domainEvent = ActionDomainEvent.class,
> +            semantics = SemanticsOf.SAFE
> +    )
> +    @MemberOrder(sequence = "500.1")
> +    public Object $(final String fileName) throws JAXBException,
> IOException {
> +
> +        final String xml = jaxbService.toXml(dto);
> +        return new Clob(Util.withSuffix(fileName, "xml"), "text/xml",
> xml);
> +    }
> +
> +    public String default0$() {
> +        return Util.withSuffix(dto.getClass().getName(), "xml");
> +    }
>



Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

[03/11] isis git commit: ISIS-1250: take-on of the JaxbService...

Posted by da...@apache.org.
ISIS-1250: take-on of the JaxbService...

... providing toXml() and toXsd(), along with supporting mixins.


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

Branch: refs/heads/master
Commit: b59943674b6029eb9d5c52172a3d3e79ed35a60a
Parents: 01aeb77
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Nov 12 23:26:39 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Thu Nov 12 23:26:39 2015 +0000

----------------------------------------------------------------------
 .../apache/isis/applib/services/jaxb/Dto.java   |  21 ++++
 .../applib/services/jaxb/Dto_downloadXml.java   |  70 ++++++++++++
 .../applib/services/jaxb/Dto_downloadXsd.java   | 112 +++++++++++++++++++
 .../isis/applib/services/jaxb/JaxbService.java  |  31 +++++
 .../apache/isis/applib/services/jaxb/Util.java  |  33 ++++++
 core/runtime/pom.xml                            |   5 +
 .../services/jaxb/JaxbServiceDefault.java       |  83 ++++++++++++++
 .../util/CatalogingSchemaOutputResolver.java    |  74 ++++++++++++
 .../jaxb/util/PersistentEntityAdapter.java      |  51 +++++++++
 .../jaxb/util/StreamResultWithWriter.java       |  45 ++++++++
 .../persistence/spi/JdoObjectIdSerializer.java  |   2 +-
 11 files changed, 526 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto.java b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto.java
new file mode 100644
index 0000000..84a6999
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto.java
@@ -0,0 +1,21 @@
+/**
+ *  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;
+
+public interface Dto {
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java
new file mode 100644
index 0000000..91332b3
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXml.java
@@ -0,0 +1,70 @@
+/**
+ *  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.io.IOException;
+
+import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
+import javax.inject.Inject;
+import javax.xml.bind.JAXBException;
+
+import org.apache.isis.applib.FatalException;
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.MemberOrder;
+import org.apache.isis.applib.annotation.Mixin;
+import org.apache.isis.applib.annotation.SemanticsOf;
+import org.apache.isis.applib.value.Clob;
+
+@Mixin
+public class Dto_downloadXml {
+
+    private final Dto dto;
+
+    final MimeType mimeTypeApplicationZip;
+
+    public Dto_downloadXml(final Dto dto) {
+        this.dto = dto;
+        try {
+            mimeTypeApplicationZip = new MimeType("application", "zip");
+        } catch (final MimeTypeParseException ex) {
+            throw new FatalException(ex);
+        }
+    }
+
+    public static class ActionDomainEvent extends org.apache.isis.applib.IsisApplibModule.ActionDomainEvent<Dto> {}
+
+    @Action(
+            domainEvent = ActionDomainEvent.class,
+            semantics = SemanticsOf.SAFE
+    )
+    @MemberOrder(sequence = "500.1")
+    public Object $$(final String fileName) throws JAXBException, IOException {
+
+        final String xml = jaxbService.toXml(dto);
+        return new Clob(Util.withSuffix(fileName, "xml"), "text/xml", xml);
+    }
+
+    public String default0$$() {
+        return Util.withSuffix(dto.getClass().getName(), "xml");
+    }
+
+
+    @Inject
+    JaxbService jaxbService;
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java
new file mode 100644
index 0000000..ce10bb1
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Dto_downloadXsd.java
@@ -0,0 +1,112 @@
+/**
+ *  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.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
+import javax.inject.Inject;
+
+import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.applib.FatalException;
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.MemberOrder;
+import org.apache.isis.applib.annotation.Mixin;
+import org.apache.isis.applib.annotation.SemanticsOf;
+import org.apache.isis.applib.value.Blob;
+import org.apache.isis.applib.value.Clob;
+
+@Mixin
+public class Dto_downloadXsd {
+
+    private final Dto dto;
+
+    final MimeType mimeTypeApplicationZip;
+
+    public Dto_downloadXsd(final Dto dto) {
+        this.dto = dto;
+        try {
+            mimeTypeApplicationZip = new MimeType("application", "zip");
+        } catch (final MimeTypeParseException ex) {
+            throw new FatalException(ex);
+        }
+    }
+
+    public static class ActionDomainEvent extends org.apache.isis.applib.IsisApplibModule.ActionDomainEvent<Dto> {}
+
+    @Action(
+            domainEvent = ActionDomainEvent.class,
+            semantics = SemanticsOf.SAFE
+    )
+    @MemberOrder(sequence = "500.2")
+    public Object $$(final String fileName) {
+
+        final Map<String, String> map = jaxbService.toXsd(dto);
+
+        if(map.isEmpty()) {
+            container.warnUser("No schemas were generated for " + dto.getClass().getName() + "; programming error?");
+            return null;
+        }
+
+        if(map.size() == 1) {
+            final Map.Entry<String, String> entry = map.entrySet().iterator().next();
+            return new Clob(Util.withSuffix(fileName, "xsd"), "text/xml", entry.getValue());
+        }
+
+        try {
+            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            final ZipOutputStream zos = new ZipOutputStream(baos);
+            final OutputStreamWriter writer = new OutputStreamWriter(zos);
+
+            for (Map.Entry<String, String> entry : map.entrySet()) {
+                final String namespaceUri = entry.getKey();
+                final String schemaText = entry.getValue();
+                zos.putNextEntry(new ZipEntry(zipEntryNameFor(namespaceUri)));
+                writer.write(schemaText);
+                writer.flush();
+                zos.closeEntry();
+            }
+
+            writer.close();
+            return new Blob(Util.withSuffix(fileName, "zip"), mimeTypeApplicationZip, baos.toByteArray());
+        } catch (final IOException ex) {
+            throw new FatalException("Unable to create zip", ex);
+        }
+    }
+
+    public String default0$$() {
+        return Util.withSuffix(dto.getClass().getName(), "xsd");
+    }
+
+    private static String zipEntryNameFor(final String namespaceUri) {
+        return Util.withSuffix(namespaceUri, "xsd");
+    }
+
+
+    @Inject
+    DomainObjectContainer container;
+
+    @Inject
+    JaxbService jaxbService;
+}
+

http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..61c0ecb
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/JaxbService.java
@@ -0,0 +1,31 @@
+/**
+ *  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 org.apache.isis.applib.annotation.Programmatic;
+
+public interface JaxbService {
+
+    @Programmatic
+    public String toXml(final Dto dto);
+
+    @Programmatic
+    public Map<String, String> toXsd(final Dto dto);
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Util.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Util.java b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Util.java
new file mode 100644
index 0000000..0859d07
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/jaxb/Util.java
@@ -0,0 +1,33 @@
+/**
+ *  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;
+
+class Util {
+
+    private Util(){}
+
+    static String withSuffix(String fileName, String suffix) {
+        if(!suffix.startsWith(".")) {
+            suffix = "." + suffix;
+        }
+        if(!fileName.endsWith(suffix)) {
+            fileName += suffix;
+        }
+        return fileName;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/runtime/pom.xml
----------------------------------------------------------------------
diff --git a/core/runtime/pom.xml b/core/runtime/pom.xml
index c50a2ec..6d41a7f 100644
--- a/core/runtime/pom.xml
+++ b/core/runtime/pom.xml
@@ -105,6 +105,11 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.isis.core</groupId>
+            <artifactId>isis-core-schema</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>dom4j</groupId>
             <artifactId>dom4j</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/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
new file mode 100644
index 0000000..4fd19aa
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/JaxbServiceDefault.java
@@ -0,0 +1,83 @@
+/**
+ *  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.core.runtime.services.jaxb;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+
+import org.apache.isis.applib.ApplicationException;
+import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.services.jaxb.Dto;
+import org.apache.isis.applib.services.jaxb.JaxbService;
+import org.apache.isis.core.runtime.services.jaxb.util.CatalogingSchemaOutputResolver;
+import org.apache.isis.core.runtime.services.jaxb.util.PersistentEntityAdapter;
+
+@DomainService(
+        nature = NatureOfService.DOMAIN
+)
+public class JaxbServiceDefault implements JaxbService {
+
+    public Map<String,String> toXsd(final Dto dto) {
+
+        try {
+            final Class<? extends Dto> dtoClass = dto.getClass();
+            final JAXBContext context = JAXBContext.newInstance(dtoClass);
+
+            final CatalogingSchemaOutputResolver outputResolver = new CatalogingSchemaOutputResolver();
+            context.generateSchema(outputResolver);
+
+            return outputResolver.asMap();
+        } catch (final JAXBException | IOException ex) {
+            throw new ApplicationException(ex);
+        }
+    }
+
+    public String toXml(final Dto dto)  {
+
+        try {
+            final Class<? extends Dto> dtoClass = dto.getClass();
+            final JAXBContext context = JAXBContext.newInstance(dtoClass);
+
+            final PersistentEntityAdapter adapter = new PersistentEntityAdapter();
+            container.injectServicesInto(adapter);
+
+            final Marshaller marshaller = context.createMarshaller();
+            marshaller.setAdapter(PersistentEntityAdapter.class, adapter);
+            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+
+            final StringWriter sw = new StringWriter();
+            marshaller.marshal(dto, sw);
+            return sw.toString();
+
+        } catch (final JAXBException ex) {
+            throw new ApplicationException(ex);
+        }
+
+    }
+
+    @Inject
+    DomainObjectContainer container;
+}
+

http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/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
new file mode 100644
index 0000000..460c97f
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/CatalogingSchemaOutputResolver.java
@@ -0,0 +1,74 @@
+/**
+ *  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.core.runtime.services.jaxb.util;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.SchemaOutputResolver;
+import javax.xml.transform.Result;
+import javax.xml.transform.stream.StreamResult;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+/**
+ * An implementation of {@link SchemaOutputResolver} that keeps track of all the schemas for which it has
+ * {@link #createOutput(String, String) created} an output {@link StreamResult} containing the content of the schema.
+ */
+public class CatalogingSchemaOutputResolver extends SchemaOutputResolver
+{
+    private List<String> namespaceUris = Lists.newArrayList();
+
+    public List<String> getNamespaceUris() {
+        return namespaceUris;
+    }
+
+    private Map<String, StreamResultWithWriter> schemaResultByNamespaceUri = Maps.newLinkedHashMap();
+
+    public String getSchemaTextFor(final String namespaceUri) {
+        final StreamResultWithWriter streamResult = schemaResultByNamespaceUri.get(namespaceUri);
+        return streamResult != null? streamResult.asString(): null;
+    }
+
+    @Override
+    public Result createOutput(
+            final String namespaceUri, final String suggestedFileName) throws IOException {
+
+        final StreamResultWithWriter result = new StreamResultWithWriter();
+
+        result.setSystemId(namespaceUri);
+
+        namespaceUris.add(namespaceUri);
+        schemaResultByNamespaceUri.put(namespaceUri, result);
+
+        return result;
+    }
+
+    public Map<String, String> asMap() {
+        final Map<String,String> map = Maps.newLinkedHashMap();
+        final List<String> namespaceUris = getNamespaceUris();
+
+        for (String namespaceUri : namespaceUris) {
+            map.put(namespaceUri, getSchemaTextFor(namespaceUri));
+        }
+
+        return Collections.unmodifiableMap(map);
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/PersistentEntityAdapter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/PersistentEntityAdapter.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/PersistentEntityAdapter.java
new file mode 100644
index 0000000..6987129
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/PersistentEntityAdapter.java
@@ -0,0 +1,51 @@
+/**
+ *  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.core.runtime.services.jaxb.util;
+
+import javax.inject.Inject;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.applib.services.bookmark.BookmarkService;
+import org.apache.isis.schema.common.v1.BookmarkObjectState;
+import org.apache.isis.schema.common.v1.OidDto;
+
+public class PersistentEntityAdapter extends XmlAdapter<OidDto, Object> {
+
+    @Override
+    public Object unmarshal(final OidDto oidDto) throws Exception {
+
+        final String objectType = oidDto.getObjectType();
+        final String identifier = oidDto.getObjectIdentifier();
+        final Bookmark bookmark = new Bookmark(objectType, identifier);
+
+        return bookmarkService.lookup(bookmark);
+    }
+
+    @Override
+    public OidDto marshal(final Object domainObject) throws Exception {
+        final Bookmark bookmark = bookmarkService.bookmarkFor(domainObject);
+        final OidDto oidDto = new OidDto();
+        oidDto.setObjectIdentifier(bookmark.getIdentifier());
+        oidDto.setObjectState(BookmarkObjectState.PERSISTENT);
+        oidDto.setObjectType(bookmark.getObjectType());
+        return oidDto;
+    }
+
+    @Inject
+    BookmarkService bookmarkService;
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/StreamResultWithWriter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/StreamResultWithWriter.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/StreamResultWithWriter.java
new file mode 100644
index 0000000..99884be
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/jaxb/util/StreamResultWithWriter.java
@@ -0,0 +1,45 @@
+/**
+ *  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.core.runtime.services.jaxb.util;
+
+import java.io.StringWriter;
+
+import javax.xml.transform.stream.StreamResult;
+
+/**
+ * A {@link StreamResult} that contains its own writer.
+ *
+ * <p>
+ *     The point is that the writer is only ever queried lazily AFTER the result has been generated.
+ * </p>
+ */
+public class StreamResultWithWriter extends StreamResult {
+    private final StringWriter writer;
+
+    public StreamResultWithWriter() {
+        this(new StringWriter());
+    }
+
+    private StreamResultWithWriter(StringWriter writer) {
+        super(writer);
+        this.writer = writer;
+    }
+
+    public String asString() {
+        return writer.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b5994367/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java
index ff662eb..1df7289 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java
@@ -125,7 +125,7 @@ public final class JdoObjectIdSerializer {
 
         // the JDO spec (5.4.3) requires that OIDs are serializable toString and 
         // recreatable through the constructor
-        return jdoOid.getClass().getName().toString() + SEPARATOR + jdoOid.toString();
+        return jdoOid.getClass().getName() + SEPARATOR + jdoOid.toString();
     }
 
     private static List<String> dnPrefixes = Arrays.asList("S", "I", "L", "M", "B");


[11/11] isis git commit: ISIS-1254: adding Noop subclasses for the domain events so that the programmer can explicitly disable event propogation if required.

Posted by da...@apache.org.
ISIS-1254: adding Noop subclasses for the domain events  so that the programmer can explicitly disable event propogation if required.


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

Branch: refs/heads/master
Commit: 25ce7360983c20b7760bb5064a103bc813e91bdc
Parents: 99c55b8
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Nov 13 17:56:46 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Nov 13 17:56:46 2015 +0000

----------------------------------------------------------------------
 .../applib/services/eventbus/ActionDomainEvent.java | 16 ++++++++++++++--
 .../services/eventbus/CollectionDomainEvent.java    | 16 ++++++++++++++--
 .../services/eventbus/PropertyDomainEvent.java      | 16 ++++++++++++++--
 .../action/ActionAnnotationFacetFactory.java        |  4 +++-
 .../CollectionAnnotationFacetFactory.java           |  4 +++-
 .../property/PropertyAnnotationFacetFactory.java    |  5 ++++-
 6 files changed, 52 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/25ce7360/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/ActionDomainEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/ActionDomainEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/ActionDomainEvent.java
index 17d6f7c..93ca053 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/ActionDomainEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/ActionDomainEvent.java
@@ -34,8 +34,9 @@ public abstract class ActionDomainEvent<S> extends AbstractInteractionEvent<S> {
     //region > Default class
 
     /**
-     * Propagated if no custom subclass was specified using
-     * {@link org.apache.isis.applib.annotation.Action#domainEvent()} annotation attribute.
+     * The default for {@link org.apache.isis.applib.annotation.Action#domainEvent()} annotation attribute, will be
+     * used as the event class to be posted if some other subclass wasn't specified (though setting to
+     * {@link org.apache.isis.applib.services.eventbus.ActionDomainEvent.Noop} will disable).
      */
     public static class Default extends ActionInteractionEvent<Object> {
         private static final long serialVersionUID = 1L;
@@ -45,6 +46,17 @@ public abstract class ActionDomainEvent<S> extends AbstractInteractionEvent<S> {
     }
     //endregion
 
+    //region > Noop class
+
+    /**
+     * Disables event propogation if explicitly set as the value of
+     * {@link org.apache.isis.applib.annotation.Action#domainEvent()} annotation attribute.
+     */
+    public static class Noop extends ActionDomainEvent<Object> {
+        private static final long serialVersionUID = 1L;
+    }
+    //endregion
+
     //region > constructors
 
     /**

http://git-wip-us.apache.org/repos/asf/isis/blob/25ce7360/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionDomainEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionDomainEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionDomainEvent.java
index c91daa7..2fef767 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionDomainEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionDomainEvent.java
@@ -27,8 +27,9 @@ public abstract class CollectionDomainEvent<S,T> extends AbstractInteractionEven
 
     //region > Default class
     /**
-     * Propagated if no custom subclass was specified using
-     * {@link org.apache.isis.applib.annotation.Collection#domainEvent()} annotation attribute.
+     * The default for {@link org.apache.isis.applib.annotation.Collection#domainEvent()} annotation attribute, will be
+     * used as the event class to be posted if some other subclass wasn't specified (though setting to
+     * {@link org.apache.isis.applib.services.eventbus.CollectionDomainEvent.Noop} will disable).
      */
     public static class Default extends CollectionInteractionEvent<Object, Object> {
         private static final long serialVersionUID = 1L;
@@ -42,6 +43,17 @@ public abstract class CollectionDomainEvent<S,T> extends AbstractInteractionEven
     }
     //endregion
 
+    //region > Noop class
+
+    /**
+     * Disables event propogation if explicitly set as the value of
+     * {@link org.apache.isis.applib.annotation.Collection#domainEvent()} annotation attribute.
+     */
+    public static class Noop extends CollectionDomainEvent<Object,Object> {
+        private static final long serialVersionUID = 1L;
+    }
+    //endregion
+
     //region > constructors
 
     /**

http://git-wip-us.apache.org/repos/asf/isis/blob/25ce7360/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/PropertyDomainEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/PropertyDomainEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/PropertyDomainEvent.java
index b641276..1114f34 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/PropertyDomainEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/PropertyDomainEvent.java
@@ -27,8 +27,9 @@ public abstract class PropertyDomainEvent<S,T> extends AbstractInteractionEvent<
 
     //region > Default class
     /**
-     * Propagated if no custom subclass was specified using
-     * {@link org.apache.isis.applib.annotation.Property#domainEvent()} annotation attribute.
+     * The default for {@link org.apache.isis.applib.annotation.Property#domainEvent()} annotation attribute, will be
+     * used as the event class to be posted if some other subclass wasn't specified (though setting to
+     * {@link org.apache.isis.applib.services.eventbus.PropertyDomainEvent.Noop} will disable).
      */
     public static class Default extends PropertyInteractionEvent<Object, Object> {
         private static final long serialVersionUID = 1L;
@@ -38,6 +39,17 @@ public abstract class PropertyDomainEvent<S,T> extends AbstractInteractionEvent<
     }
     //endregion
 
+    //region > Noop class
+
+    /**
+     * Disables event propogation if explicitly set as the value of
+     * {@link org.apache.isis.applib.annotation.Property#domainEvent()} annotation attribute.
+     */
+    public static class Noop extends PropertyDomainEvent<Object,Object> {
+        private static final long serialVersionUID = 1L;
+    }
+    //endregion
+
     //region > constructors
 
     /**

http://git-wip-us.apache.org/repos/asf/isis/blob/25ce7360/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/actions/action/ActionAnnotationFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/actions/action/ActionAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/actions/action/ActionAnnotationFacetFactory.java
index 8f9da41..cca21b9 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/actions/action/ActionAnnotationFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/actions/action/ActionAnnotationFacetFactory.java
@@ -199,7 +199,9 @@ public class ActionAnnotationFacetFactory extends FacetFactoryAbstract implement
                 actionDomainEventFacet = new ActionDomainEventFacetDefault(
                         actionDomainEventType, servicesInjector, getSpecificationLoader(), holder);
             }
-            FacetUtil.addFacet(actionDomainEventFacet);
+            if(!ActionDomainEvent.Noop.class.isAssignableFrom(actionDomainEventFacet.getEventType())) {
+                FacetUtil.addFacet(actionDomainEventFacet);
+            }
 
 
             // replace the current actionInvocationFacet with one that will

http://git-wip-us.apache.org/repos/asf/isis/blob/25ce7360/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/CollectionAnnotationFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/CollectionAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/CollectionAnnotationFacetFactory.java
index e4ccfb9..ef1022b 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/CollectionAnnotationFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/CollectionAnnotationFacetFactory.java
@@ -166,7 +166,9 @@ public class CollectionAnnotationFacetFactory extends FacetFactoryAbstract imple
             collectionDomainEventFacet = new CollectionDomainEventFacetDefault(
                     collectionDomainEventType, servicesInjector, getSpecificationLoader(), holder);
         }
-        FacetUtil.addFacet(collectionDomainEventFacet);
+        if(!CollectionDomainEvent.Noop.class.isAssignableFrom(collectionDomainEventFacet.getEventType())) {
+            FacetUtil.addFacet(collectionDomainEventFacet);
+        }
 
 
         //

http://git-wip-us.apache.org/repos/asf/isis/blob/25ce7360/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/property/PropertyAnnotationFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/property/PropertyAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/property/PropertyAnnotationFacetFactory.java
index 6ec1109..7dfb0d5 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/property/PropertyAnnotationFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/property/PropertyAnnotationFacetFactory.java
@@ -167,7 +167,10 @@ public class PropertyAnnotationFacetFactory extends FacetFactoryAbstract impleme
             propertyDomainEventFacet = new PropertyDomainEventFacetDefault(
                     propertyDomainEventType, getterFacet, servicesInjector, getSpecificationLoader(), holder);
         }
-        FacetUtil.addFacet(propertyDomainEventFacet);
+        if(!PropertyDomainEvent.Noop.class.isAssignableFrom(propertyDomainEventFacet.getEventType())) {
+            FacetUtil.addFacet(propertyDomainEventFacet);
+        }
+
 
 
         //