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 2017/10/16 16:01:28 UTC

[isis] 06/09: ISIS-1742: removes DomainObjectContainer#newTransientInstance, #newPersistenceInstance, #newInstance, #newAggregatedInstance, #mixin ... either use FactoryService or no replacement provided.

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

danhaywood pushed a commit to branch dev/2.0.0/ISIS-1742-remove-deprecations
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 2518c8fc088781e82200eb6ee6b9932b311a7523
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Mon Oct 16 16:12:57 2017 +0100

    ISIS-1742: removes DomainObjectContainer#newTransientInstance, #newPersistenceInstance, #newInstance, #newAggregatedInstance, #mixin ... either use FactoryService or no replacement provided.
---
 ..._DomainObjectContainer_object-creation-api.adoc | 34 +++---------
 .../_rgsvc_core-domain-api_FactoryService.adoc     |  4 --
 .../apache/isis/applib/DomainObjectContainer.java  | 60 +---------------------
 .../container/DomainObjectContainerDefault.java    | 60 ++--------------------
 todo-deprecation-list.txt                          |  7 ++-
 5 files changed, 16 insertions(+), 149 deletions(-)

diff --git a/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_core-domain-api_DomainObjectContainer_object-creation-api.adoc b/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_core-domain-api_DomainObjectContainer_object-creation-api.adoc
index a7b100a..a4e5413 100644
--- a/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_core-domain-api_DomainObjectContainer_object-creation-api.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_core-domain-api_DomainObjectContainer_object-creation-api.adoc
@@ -5,43 +5,21 @@
 :_imagesdir: images/
 
 
-
-The object creation APIs are used to instantiate new domain objects or view models.
+The (deprecated) object creation APIs is used to instantiate a view model, specifying its memento.
 
 [source,java]
 ----
 public interface DomainObjectContainer {
 
-    <T> T newTransientInstance(final Class<T> ofType);                              // <1>
-    <T> T newViewModelInstance(final Class<T> ofType, final String memento);        // <2>
-    <T> T mixin();                                                                  // <3>
+    <T> T newViewModelInstance(final Class<T> ofType, final String memento);        // <1>
     ...
 }
 ----
-<1> create a new non-persisted domain entity.  Any services will be automatically injected into the service.
-<2> create a new view model, with the specified memento (as per xref:../rgcms/rgcms.adoc#_rgcms_classes_super_AbstractViewModel[ViewModel#viewModelMemento()].  In general it is easier to just annotate with xref:../rgant/rgant.adoc#_rgant-ViewModel[`@ViewModel`] and let Apache Isis manage the memento automatically.
-<3> programmatically instantiate a mixin, as annotated with
-xref:../rgant/rgant.adoc#_rgant-Mixin[`@Mixin`] or xref:../rgant/rgant.adoc#_rgant-DomainObject_nature[`@DomainObject#nature()`].
-
-For example:
-
-[source,java]
-----
-Customer cust = container.newTransientInstance(Customer.class);
-cust.setFirstName("Freddie");
-cust.setLastName("Mercury");
-container.persist(cust);
-----
+<1> create a new view model, with the specified memento (as per xref:../rgcms/rgcms.adoc#_rgcms_classes_super_AbstractViewModel[ViewModel#viewModelMemento()].
 
-As an alternative to using `newTransientInstance(...)` or `mixin(...)`, you could also simply `new()` up the object.
-Doing this will not inject any domain services, but they can be injected manually using the xref:rgsvc.adoc#_rgsvc_metadata-api_ServiceRegistry[`ServiceRegistry`].
-
-[NOTE]
+[TIP]
 ====
-Calling `new(...)` also this circumvents Apache Isis' xref:../rgcms/rgcms.adoc#_rgcms_methods_reserved_created[`created()`]
-callback, and in addition any default values for properties (either explicitly set by
-xref:../rgcms/rgcms.adoc#_rgcms_methods_prefixes_default[`default...()`] or defaulted implicitly according to Apache Isis'
-own conventions) will not be called either.  If you don't intend to use these features, though, the net effect is code
-that has less coupling to Isis and is arguably easier to understand (has "less magic" happening).
+In general it is easier to just annotate with xref:../rgant/rgant.adoc#_rgant-ViewModel[`@ViewModel`], or as a JAXB view model, and let Apache Isis manage the memento automatically.
 ====
 
+
diff --git a/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_core-domain-api_FactoryService.adoc b/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_core-domain-api_FactoryService.adoc
index 41554c6..b79fda8 100644
--- a/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_core-domain-api_FactoryService.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_core-domain-api_FactoryService.adoc
@@ -7,10 +7,6 @@
 
 The `FactoryService` collects together methods for instantiating domain objects.
 
-[NOTE]
-====
-The methods in this service replace similar methods (now deprecated) in xref:../rgsvc/rgsvc.adoc#_rgsvc_core-domain-api_DomainObjectContainer[`DomainObjectContainer`].
-====
 
 
 == API
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 18e59dd..e45a9f8 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
@@ -19,12 +19,8 @@
 
 package org.apache.isis.applib;
 
-import java.util.List;
-
 import org.apache.isis.applib.annotation.Programmatic;
-import org.apache.isis.applib.security.UserMemento;
 import org.apache.isis.applib.services.factory.FactoryService;
-import org.apache.isis.applib.services.i18n.TranslatableString;
 import org.apache.isis.applib.services.message.MessageService;
 import org.apache.isis.applib.services.metamodel.MetaModelService3;
 import org.apache.isis.applib.services.repository.RepositoryService;
@@ -109,70 +105,16 @@ public interface DomainObjectContainer {
 
     //endregion
 
-    //region > new{Transient/Persistent}Instance
+    //region > newViewModelInstance
 
-    /**
-    * @deprecated - use {@link org.apache.isis.applib.services.factory.FactoryService#instantiate(Class)} instead.
-     */
-    @Deprecated
-    @Programmatic
-    <T> T newTransientInstance(final Class<T> ofType);
 
     /**
      * Create a new {@link ViewModel} instance of the specified type, initializing with the specified memento.
      *
-     * <p>
-     *     Rather than use this constructor it is generally preferable to simply instantiate a
-     *     class annotated with {@link org.apache.isis.applib.annotation.ViewModel annotation}.
-     *     If services need injecting into it, use {@link #injectServicesInto(Object)}.
-     * </p>
      */
     @Programmatic
     <T> T newViewModelInstance(final Class<T> ofType, final String memento);
 
-    /**
-     * @deprecated - not supported, will throw a RuntimeException
-     */
-    @Deprecated
-    @Programmatic
-    <T> T newAggregatedInstance(Object parent, Class<T> ofType);
-
-    /**
-     * (Deprecated) returns a new instance of the specified class that will have been
-     * persisted.
-     *
-     * @deprecated - in almost all cases the workflow is to {@link #newTransientInstance(Class)}, populate the object
-     * (eg with the arguments to an action) and then to
-     * {@link #persist(Object) persist) the object.  It is exceptionally rare for
-     * an object to be created, and with no further data required - be in a state
-     * to be persisted immediately.
-     */
-    @Programmatic
-    @Deprecated
-    <T> T newPersistentInstance(final Class<T> ofType);
-
-    /**
-     * Returns a new instance of the specified class that has the same persisted
-     * state (either transient or persisted) as the provided object.
-     * 
-     * <p>
-     * This method has been deprecated because it is a rare use case, causing
-     * unnecessary interface bloat for very little gain.
-     * <p></p>
-     * 
-     * @deprecated
-     */
-    @Programmatic
-    @Deprecated
-    <T> T newInstance(final Class<T> ofType, final Object object);
-
-    /**
-     * @deprecated - use {@link org.apache.isis.applib.services.factory.FactoryService#mixin(Class, Object)} instead.
-     */
-    @Deprecated
-    @Programmatic
-    <T> T mixin( Class<T> mixinClass, Object mixedIn);
-
     //endregion
 
 
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 e8cbdd9..7a041f8 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
@@ -56,16 +56,7 @@ public class DomainObjectContainerDefault
         implements DomainObjectContainer, ExceptionRecognizer {
 
 
-
-    //region > newXxxInstance, remove
-
-    @Deprecated
-    @Programmatic
-    @Override
-    @SuppressWarnings("unchecked")
-    public <T> T newTransientInstance(final Class<T> ofClass) {
-        return factoryService.instantiate(ofClass);
-    }
+    //region > newViewModelInstance
 
     @Programmatic
     @SuppressWarnings("unchecked")
@@ -83,54 +74,9 @@ public class DomainObjectContainerDefault
         }
     }
 
-    /**
-     * @deprecated - Aggregated objects are no longer supported
-     */
-    @Deprecated
-    @Programmatic
-    @Override
-    @SuppressWarnings("unchecked")
-    public <T> T newAggregatedInstance(final Object parent, final Class<T> ofClass) {
-        throw new RuntimeException("Aggregated objects are no longer supported");
-    }
-
-    /**
-     * Returns a new instance of the specified class that will have been
-     * persisted.
-     */
-    @Deprecated
-    @Programmatic
-    @Override
-    public <T> T newPersistentInstance(final Class<T> ofClass) {
-        final T newInstance = newTransientInstance(ofClass);
-        persist(newInstance);
-        return newInstance;
-    }
-
-    /**
-     * Returns a new instance of the specified class that has the same persisted
-     * state as the specified object.
-     *
-     * @deprecated - use {@link FactoryService#instantiate(Class)}.
-     */
-    @Programmatic
-    @Override
-    @Deprecated
-    public <T> T newInstance(final Class<T> ofClass, final Object object) {
-        if (isPersistent(object)) {
-            return newPersistentInstance(ofClass);
-        } else {
-            return newTransientInstance(ofClass);
-        }
-    }
-
+    //endregion
 
-    @Deprecated
-    @Programmatic
-    @Override
-    public <T> T mixin(final Class<T> mixinClass, final Object mixedIn) {
-        return factoryService.mixin(mixinClass, mixedIn);
-    }
+    //region >  remove
 
     @Programmatic
     @Override
diff --git a/todo-deprecation-list.txt b/todo-deprecation-list.txt
index 7bba042..3cc8760 100644
--- a/todo-deprecation-list.txt
+++ b/todo-deprecation-list.txt
@@ -465,4 +465,9 @@ org.apache.isis.applib
     - informUser, warnUser, raiseError ... use MessageService
     - getUser                          ... use UserService
     - getProperty, getPropertyNames    ... use ConfigurationService
-    - injectServicesInto, lookupService, lookupServices   ... use ServicesRegistry
\ No newline at end of file
+    - injectServicesInto, lookupService, lookupServices   ... use ServicesRegistry
+    - newTransientInstance - use FactoryService#instantiate
+    - newAggregatedInstance - no replacement
+    - newPersistentInstance - no replacement
+    - newInstance - no replacement
+    - mixin - use FactoryService#mixin
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.