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

ahuber pushed a commit to branch ISIS-1976-rethink-object-adapters
in repository https://gitbox.apache.org/repos/asf/isis.git

commit ccb1571c3ced676860d25c9aa0eeec9c645c096a
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Mon Sep 3 07:39:50 2018 +0200

    ISIS-1976: decouple ObjectAdapter creation from PersistenceSession
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1976
---
 .../system/persistence/PersistenceSession4.java    | 124 ++----------------
 .../system/persistence/PersistenceSession5.java    | 138 +++------------------
 .../adaptermanager/ObjectAdapterContext.java       |  62 ++++++++-
 .../ObjectAdapterContext_Factories.java            | 103 +++++++++++++++
 .../adaptermanager/ObjectAdapterLegacy.java        |  12 +-
 5 files changed, 204 insertions(+), 235 deletions(-)

diff --git 
a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
 
b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
index ea9e07c..7475e3f 100644
--- 
a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
+++ 
b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
@@ -161,7 +161,7 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
             LOG.debug("opening {}", this);
         }
 
-        objectAdapterContext = 
ObjectAdapterLegacy.openContext(servicesInjector);
+        objectAdapterContext = 
ObjectAdapterLegacy.openContext(servicesInjector, authenticationSession, 
specificationLoader, this);
 
         persistenceManager = 
jdoPersistenceManagerFactory.getPersistenceManager();
 
@@ -914,7 +914,7 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
      * Makes an {@link ObjectAdapter} persistent. The specified object should 
be
      * stored away via this object store's persistence mechanism, and have a
      * new and unique OID assigned to it. The object, should also be added to
-     * the {@link PersistenceSession4} as the object is implicitly 'in use'.
+     * the {@link PersistenceSession} as the object is implicitly 'in use'.
      *
      * <p>
      * If the object has any associations then each of these, where they aren't
@@ -987,18 +987,6 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
         return adapter.isParentedCollection();
     }
 
-
-    // -- ObjectPersistor impl
-
-    private void makePersistent(final ObjectAdapter adapter) {
-        makePersistentInTransaction(adapter);
-    }
-
-
-    private void remove(final ObjectAdapter adapter) {
-        destroyObjectInTransaction(adapter);
-    }
-
     // -- destroyObjectInTransaction
 
     /**
@@ -1153,7 +1141,7 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
 
         // we create value facets as standalone (so not added to maps)
         if (objSpec.containsFacet(ValueFacet.class)) {
-            adapter = createStandaloneAdapter(pojo);
+            adapter = 
objectAdapterContext.getFactories().createStandaloneAdapter(pojo);
             return adapter;
         }
 
@@ -1463,9 +1451,6 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
         return pojo;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public ObjectAdapter adapterFor(final Object pojo) {
 
@@ -1477,14 +1462,14 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
             return existingOrValueAdapter;
         }
 
-        final ObjectAdapter newAdapter = 
createTransientOrViewModelRootAdapter(pojo);
+
+        // Creates a new transient root {@link ObjectAdapter adapter} for the 
supplied domain
+        final RootOid rootOid = createTransientOrViewModelOid(pojo);
+        final ObjectAdapter newAdapter = 
objectAdapterContext.getFactories().createRootAdapter(pojo, rootOid);
 
         return mapAndInjectServices(newAdapter);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public ObjectAdapter adapterFor(final Object pojo, final ObjectAdapter 
parentAdapter, final OneToManyAssociation collection) {
 
@@ -1496,47 +1481,16 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
             return existingOrValueAdapter;
         }
 
+        ensureMapsConsistent(parentAdapter);
+        
         // the List, Set etc. instance gets wrapped in its own adapter
-        final ObjectAdapter newAdapter = createCollectionAdapter(pojo, 
parentAdapter, collection);
+        final ObjectAdapter newAdapter = objectAdapterContext.getFactories()
+                .createCollectionAdapter(pojo, parentAdapter, collection);
 
         return mapAndInjectServices(newAdapter);
     }
 
-    /**
-     * Creates an {@link ObjectAdapter adapter} to represent a collection
-     * of the parent.
-     *
-     * <p>
-     * The returned adapter will have a {@link ParentedCollectionOid}; its 
version
-     * and its persistence are the same as its owning parent.
-     *
-     * <p>
-     * Should only be called if the pojo is known not to be
-     * {@link #getAdapterFor(Object) mapped}.
-     */
-    private ObjectAdapter createCollectionAdapter(
-            final Object pojo,
-            final ObjectAdapter parentAdapter,
-            final OneToManyAssociation otma) {
-
-        ensureMapsConsistent(parentAdapter);
-        Assert.assertNotNull(pojo);
-
-        final Oid parentOid = parentAdapter.getOid();
 
-        // persistence of collection follows the parent
-        final ParentedCollectionOid collectionOid = new 
ParentedCollectionOid((RootOid) parentOid, otma);
-        final ObjectAdapter collectionAdapter = createCollectionAdapter(pojo, 
collectionOid);
-
-        // we copy over the type onto the adapter itself
-        // [not sure why this is really needed, surely we have enough info in
-        // the adapter
-        // to look this up on the fly?]
-        final TypeOfFacet facet = otma.getFacet(TypeOfFacet.class);
-        
collectionAdapter.setElementSpecificationProvider(ElementSpecificationProviderFromTypeOfFacet.createFrom(facet));
-
-        return collectionAdapter;
-    }
 
 
     /**
@@ -1620,66 +1574,14 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
         final ObjectAdapter createdAdapter;
         if(oid instanceof RootOid) {
             final RootOid rootOid = (RootOid) oid;
-            createdAdapter = createRootAdapter(pojo, rootOid);
+            createdAdapter = 
objectAdapterContext.getFactories().createRootAdapter(pojo, rootOid);
         } else /*if (oid instanceof CollectionOid)*/ {
             final ParentedCollectionOid collectionOid = 
(ParentedCollectionOid) oid;
-            createdAdapter = createCollectionAdapter(pojo, collectionOid);
+            createdAdapter = 
objectAdapterContext.getFactories().createCollectionAdapter(pojo, 
collectionOid);
         }
         return createdAdapter;
     }
 
-    /**
-     * Creates a new transient root {@link ObjectAdapter adapter} for the 
supplied domain
-     * object.
-     */
-    private ObjectAdapter createTransientOrViewModelRootAdapter(final Object 
pojo) {
-        final RootOid rootOid = createTransientOrViewModelOid(pojo);
-        return createRootAdapter(pojo, rootOid);
-    }
-
-    /**
-     * Creates a {@link ObjectAdapter adapter} with no {@link Oid}.
-     *
-     * <p>
-     * Standalone adapters are never {@link 
#mapAndInjectServices(ObjectAdapter) mapped}
-     * (they have no {@link Oid}, after all).
-     *
-     * <p>
-     * Should only be called if the pojo is known not to be
-     * {@link #getAdapterFor(Object) mapped}, and for immutable value types
-     * referenced.
-     */
-    private ObjectAdapter createStandaloneAdapter(final Object pojo) {
-        return createAdapter(pojo, null);
-    }
-
-    /**
-     * Creates (but does not {@link #mapAndInjectServices(ObjectAdapter) map}) 
a new
-     * root {@link ObjectAdapter adapter} for the supplied domain object.
-     *
-     * @see #createStandaloneAdapter(Object)
-     * @see #createCollectionAdapter(Object, ParentedCollectionOid)
-     */
-    private ObjectAdapter createRootAdapter(final Object pojo, RootOid 
rootOid) {
-        assert rootOid != null;
-        return createAdapter(pojo, rootOid);
-    }
-
-    private ObjectAdapter createCollectionAdapter(
-            final Object pojo,
-            ParentedCollectionOid collectionOid) {
-        assert collectionOid != null;
-        return createAdapter(pojo, collectionOid);
-    }
-
-    private PojoAdapter createAdapter(
-            final Object pojo,
-            final Oid oid) {
-        return new PojoAdapter(
-                pojo, oid,
-                authenticationSession,
-                specificationLoader, this);
-    }
 
 
     private ObjectAdapter mapAndInjectServices(final ObjectAdapter adapter) {
diff --git 
a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
 
b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
index f17d8f0..461e8e4 100644
--- 
a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
+++ 
b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
@@ -103,7 +103,6 @@ import 
org.apache.isis.core.runtime.persistence.ObjectNotFoundException;
 import org.apache.isis.core.runtime.persistence.PojoRecreationException;
 import org.apache.isis.core.runtime.persistence.PojoRefreshException;
 import org.apache.isis.core.runtime.persistence.UnsupportedFindException;
-import org.apache.isis.core.runtime.persistence.adapter.PojoAdapter;
 import 
org.apache.isis.core.runtime.persistence.objectstore.transaction.CreateObjectCommand;
 import 
org.apache.isis.core.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
 import 
org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
@@ -161,7 +160,7 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
             LOG.debug("opening {}", this);
         }
 
-        objectAdapterContext = 
ObjectAdapterLegacy.openContext(servicesInjector);
+        objectAdapterContext = 
ObjectAdapterLegacy.openContext(servicesInjector, authenticationSession, 
specificationLoader, this);
 
         persistenceManager = 
jdoPersistenceManagerFactory.getPersistenceManager();
 
@@ -237,13 +236,11 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
         final List<Object> registeredServices = 
servicesInjector.getRegisteredServices();
         for (final Object service : registeredServices) {
             final ObjectAdapter serviceAdapter = adapterFor(service);
-            remapAsPersistentIfRequired(serviceAdapter);
-        }
-    }
-
-    private void remapAsPersistentIfRequired(final ObjectAdapter 
serviceAdapter) {
-        if (serviceAdapter.getOid().isTransient()) {
-            objectAdapterContext.remapAsPersistent(serviceAdapter, null, this);
+            
+            // remap as Persistent if required
+            if (serviceAdapter.getOid().isTransient()) {
+                objectAdapterContext.remapAsPersistent(serviceAdapter, null, 
this);
+            }
         }
     }
 
@@ -912,7 +909,7 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
      * Makes an {@link ObjectAdapter} persistent. The specified object should 
be
      * stored away via this object store's persistence mechanism, and have a
      * new and unique OID assigned to it. The object, should also be added to
-     * the {@link PersistenceSession5} as the object is implicitly 'in use'.
+     * the {@link PersistenceSession} as the object is implicitly 'in use'.
      *
      * <p>
      * If the object has any associations then each of these, where they aren't
@@ -1137,7 +1134,7 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
 
         // we create value facets as standalone (so not added to maps)
         if (objSpec.containsFacet(ValueFacet.class)) {
-            adapter = createStandaloneAdapter(pojo);
+            adapter = 
objectAdapterContext.getFactories().createStandaloneAdapter(pojo);
             return adapter;
         }
 
@@ -1221,10 +1218,6 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
                         + "but map's adapter's OID was: " + 
adapterAccordingToMap.getOid());
     }
 
-
-    /**
-     * foreign refs: 1
-     */
     @Override
     public ObjectAdapter adapterForAny(RootOid rootOid) {
 
@@ -1261,9 +1254,6 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
         }
     }
 
-    /**
-     * foreign refs: 1
-     */
     @Override
     public Map<RootOid, ObjectAdapter> adaptersFor(final List<RootOid> 
rootOids) {
         return adaptersFor(rootOids, ConcurrencyChecking.NO_CHECK);
@@ -1328,8 +1318,6 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
      * This method  will <i>always</i> return an object, possibly indicating 
it is persistent; so make sure that you
      * know that the oid does indeed represent an object you know exists.
      * </p>
-     * 
-     * foreign refs: 4
      */
     @Override
     public ObjectAdapter adapterFor(final RootOid rootOid) {
@@ -1363,9 +1351,6 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
      * value.  This allows the client to retry if they wish.
      *
      * @throws {@link 
org.apache.isis.core.runtime.persistence.ObjectNotFoundException} if the object 
does not exist.
-     * 
-     * foreign refs: 0
-     * 
      */
     @Override
     public ObjectAdapter adapterFor(
@@ -1460,10 +1445,6 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
         return pojo;
     }
 
-    /**
-     * {@inheritDoc}
-     * foreign refs: ~90
-     */
     @Override
     public ObjectAdapter adapterFor(final Object pojo) {
 
@@ -1475,15 +1456,13 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
             return existingOrValueAdapter;
         }
 
-        final ObjectAdapter newAdapter = 
createTransientOrViewModelRootAdapter(pojo);
+        // Creates a new transient root {@link ObjectAdapter adapter} for the 
supplied domain
+        final RootOid rootOid = createTransientOrViewModelOid(pojo);
+        final ObjectAdapter newAdapter = 
objectAdapterContext.getFactories().createRootAdapter(pojo, rootOid);
 
         return mapAndInjectServices(newAdapter);
     }
 
-    /**
-     * {@inheritDoc}
-     * foreign refs: 2
-     */
     @Override
     public ObjectAdapter adapterFor(final Object pojo, final ObjectAdapter 
parentAdapter, final OneToManyAssociation collection) {
 
@@ -1495,47 +1474,16 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
             return existingOrValueAdapter;
         }
 
+        ensureMapsConsistent(parentAdapter);
+        
         // the List, Set etc. instance gets wrapped in its own adapter
-        final ObjectAdapter newAdapter = createCollectionAdapter(pojo, 
parentAdapter, collection);
+        final ObjectAdapter newAdapter = objectAdapterContext.getFactories()
+                .createCollectionAdapter(pojo, parentAdapter, collection);
 
         return mapAndInjectServices(newAdapter);
     }
 
-    /**
-     * Creates an {@link ObjectAdapter adapter} to represent a collection
-     * of the parent.
-     *
-     * <p>
-     * The returned adapter will have a {@link ParentedCollectionOid}; its 
version
-     * and its persistence are the same as its owning parent.
-     *
-     * <p>
-     * Should only be called if the pojo is known not to be
-     * {@link #getAdapterFor(Object) mapped}.
-     */
-    private ObjectAdapter createCollectionAdapter(
-            final Object pojo,
-            final ObjectAdapter parentAdapter,
-            final OneToManyAssociation otma) {
-
-        ensureMapsConsistent(parentAdapter);
-        Assert.assertNotNull(pojo);
 
-        final Oid parentOid = parentAdapter.getOid();
-
-        // persistence of collection follows the parent
-        final ParentedCollectionOid collectionOid = new 
ParentedCollectionOid((RootOid) parentOid, otma);
-        final ObjectAdapter collectionAdapter = createCollectionAdapter(pojo, 
collectionOid);
-
-        // we copy over the type onto the adapter itself
-        // [not sure why this is really needed, surely we have enough info in
-        // the adapter
-        // to look this up on the fly?]
-        final TypeOfFacet facet = otma.getFacet(TypeOfFacet.class);
-        
collectionAdapter.setElementSpecificationProvider(ElementSpecificationProviderFromTypeOfFacet.createFrom(facet));
-
-        return collectionAdapter;
-    }
 
     /**
      * Either returns an existing {@link ObjectAdapter adapter} (as per
@@ -1618,66 +1566,14 @@ implements 
IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
         final ObjectAdapter createdAdapter;
         if(oid instanceof RootOid) {
             final RootOid rootOid = (RootOid) oid;
-            createdAdapter = createRootAdapter(pojo, rootOid);
+            createdAdapter = 
objectAdapterContext.getFactories().createRootAdapter(pojo, rootOid);
         } else /*if (oid instanceof CollectionOid)*/ {
             final ParentedCollectionOid collectionOid = 
(ParentedCollectionOid) oid;
-            createdAdapter = createCollectionAdapter(pojo, collectionOid);
+            createdAdapter = 
objectAdapterContext.getFactories().createCollectionAdapter(pojo, 
collectionOid);
         }
         return createdAdapter;
     }
 
-    /**
-     * Creates a new transient root {@link ObjectAdapter adapter} for the 
supplied domain
-     * object.
-     */
-    private ObjectAdapter createTransientOrViewModelRootAdapter(final Object 
pojo) {
-        final RootOid rootOid = createTransientOrViewModelOid(pojo);
-        return createRootAdapter(pojo, rootOid);
-    }
-
-    /**
-     * Creates a {@link ObjectAdapter adapter} with no {@link Oid}.
-     *
-     * <p>
-     * Standalone adapters are never {@link 
#mapAndInjectServices(ObjectAdapter) mapped}
-     * (they have no {@link Oid}, after all).
-     *
-     * <p>
-     * Should only be called if the pojo is known not to be
-     * {@link #getAdapterFor(Object) mapped}, and for immutable value types
-     * referenced.
-     */
-    private ObjectAdapter createStandaloneAdapter(final Object pojo) {
-        return createAdapter(pojo, null);
-    }
-
-    /**
-     * Creates (but does not {@link #mapAndInjectServices(ObjectAdapter) map}) 
a new
-     * root {@link ObjectAdapter adapter} for the supplied domain object.
-     *
-     * @see #createStandaloneAdapter(Object)
-     * @see #createCollectionAdapter(Object, ParentedCollectionOid)
-     */
-    private ObjectAdapter createRootAdapter(final Object pojo, RootOid 
rootOid) {
-        assert rootOid != null;
-        return createAdapter(pojo, rootOid);
-    }
-
-    private ObjectAdapter createCollectionAdapter(
-            final Object pojo,
-            ParentedCollectionOid collectionOid) {
-        assert collectionOid != null;
-        return createAdapter(pojo, collectionOid);
-    }
-
-    private PojoAdapter createAdapter(
-            final Object pojo,
-            final Oid oid) {
-        return new PojoAdapter(
-                pojo, oid,
-                authenticationSession,
-                specificationLoader, this);
-    }
 
 
     private ObjectAdapter mapAndInjectServices(final ObjectAdapter adapter) {
diff --git 
a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext.java
 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext.java
index f661b37..268d821 100644
--- 
a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext.java
+++ 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext.java
@@ -18,6 +18,7 @@
  */
 package org.apache.isis.core.runtime.system.persistence.adaptermanager;
 
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
 import org.apache.isis.core.commons.ensure.IsisAssertException;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.oid.Oid;
@@ -30,6 +31,7 @@ import 
org.apache.isis.core.metamodel.services.ServicesInjector;
 import org.apache.isis.core.metamodel.spec.ObjectSpecId;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
+import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
 import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
 
 /**
@@ -41,8 +43,16 @@ public class ObjectAdapterContext {
     private final OidAdapterHashMap oidAdapterMap = new OidAdapterHashMap();
     private final ServicesInjector servicesInjector;
     
-    ObjectAdapterContext(ServicesInjector servicesInjector) {
+    ObjectAdapterContext(
+            ServicesInjector servicesInjector, 
+            AuthenticationSession authenticationSession, 
+            SpecificationLoader specificationLoader, 
+            PersistenceSession persistenceSession) {
         this.servicesInjector = servicesInjector;
+        this.objectAdapterFactories = new ObjectAdapterContext_Factories(
+                authenticationSession, 
+                specificationLoader, 
+                persistenceSession);
     }
 
     // -- LIFE-CYCLING
@@ -112,10 +122,57 @@ public class ObjectAdapterContext {
     
     // -- FACTORIES
     
+    public static interface ObjectAdapterFactories {
+        
+        /**
+         * Creates (but does not {@link #mapAndInjectServices(ObjectAdapter) 
map}) a new
+         * root {@link ObjectAdapter adapter} for the supplied domain object.
+         *
+         * @see #createStandaloneAdapter(Object)
+         * @see #createCollectionAdapter(Object, ParentedCollectionOid)
+         */
+        ObjectAdapter createRootAdapter(Object pojo, RootOid rootOid);
+        
+        /**
+         * Creates a {@link ObjectAdapter adapter} with no {@link Oid}.
+         *
+         * <p>
+         * Standalone adapters are never {@link 
#mapAndInjectServices(ObjectAdapter) mapped}
+         * (they have no {@link Oid}, after all).
+         *
+         * <p>
+         * Should only be called if the pojo is known not to be
+         * {@link #getAdapterFor(Object) mapped}, and for immutable value types
+         * referenced.
+         */
+        ObjectAdapter createStandaloneAdapter(Object pojo);
+
+        ObjectAdapter createCollectionAdapter(Object pojo, 
ParentedCollectionOid collectionOid);
+
+        /**
+         * Creates an {@link ObjectAdapter adapter} to represent a collection
+         * of the parent.
+         *
+         * <p>
+         * The returned adapter will have a {@link ParentedCollectionOid}; its 
version
+         * and its persistence are the same as its owning parent.
+         *
+         * <p>
+         * Should only be called if the pojo is known not to be
+         * {@link #getAdapterFor(Object) mapped}.
+         */
+        ObjectAdapter createCollectionAdapter(Object pojo, ObjectAdapter 
parentAdapter, OneToManyAssociation otma);
+    }
     
+    private final ObjectAdapterFactories objectAdapterFactories;
+    
+    public ObjectAdapterFactories getFactories() {
+        return objectAdapterFactories;
+    }
     
     // 
------------------------------------------------------------------------------------------------
     
+    @Deprecated // don't expose caching
     public void addAdapterHonoringSpecImmutability(Object pojo, ObjectAdapter 
adapter) {
         // add all aggregated collections
         final ObjectSpecification objSpec = adapter.getSpecification();
@@ -137,6 +194,7 @@ public class ObjectAdapterContext {
      * @param hintRootOid - allow a different persistent root oid to be 
provided.
      * @param session 
      */
+    @Deprecated // expected to be moved
     public void remapAsPersistent(final ObjectAdapter adapter, RootOid 
hintRootOid, PersistenceSession session) {
 
         final ObjectAdapter rootAdapter = adapter.getAggregateRoot();  // 
TODO: REVIEW: think this is redundant; would seem this method is only ever 
called for roots anyway.
@@ -253,4 +311,6 @@ public class ObjectAdapterContext {
 
 
 
+
+
 }
\ No newline at end of file
diff --git 
a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext_Factories.java
 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext_Factories.java
new file mode 100644
index 0000000..4256a02
--- /dev/null
+++ 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext_Factories.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.runtime.system.persistence.adaptermanager;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.commons.ensure.Assert;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.ParentedCollectionOid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import 
org.apache.isis.core.metamodel.facets.actcoll.typeof.ElementSpecificationProviderFromTypeOfFacet;
+import org.apache.isis.core.metamodel.facets.actcoll.typeof.TypeOfFacet;
+import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
+import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
+import org.apache.isis.core.runtime.persistence.adapter.PojoAdapter;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
+import 
org.apache.isis.core.runtime.system.persistence.adaptermanager.ObjectAdapterContext.ObjectAdapterFactories;
+
+/**
+ *  
+ * @since 2.0.0-M2
+ */
+class ObjectAdapterContext_Factories implements ObjectAdapterFactories {
+
+    private final AuthenticationSession authenticationSession;
+    private final SpecificationLoader specificationLoader;
+    private final PersistenceSession session;
+
+    ObjectAdapterContext_Factories(AuthenticationSession authenticationSession,
+            SpecificationLoader specificationLoader, PersistenceSession 
session) {
+        this.authenticationSession = authenticationSession;
+        this.specificationLoader = specificationLoader;
+        this.session = session;
+    }
+
+    @Override
+    public ObjectAdapter createStandaloneAdapter(final Object pojo) {
+        return createAdapter(pojo, null);
+    }
+
+    @Override
+    public ObjectAdapter createRootAdapter(final Object pojo, RootOid rootOid) 
{
+        assert rootOid != null;
+        return createAdapter(pojo, rootOid);
+    }
+
+    @Override
+    public ObjectAdapter createCollectionAdapter(
+            final Object pojo,
+            ParentedCollectionOid collectionOid) {
+        assert collectionOid != null;
+        return createAdapter(pojo, collectionOid);
+    }
+
+    @Override
+    public ObjectAdapter createCollectionAdapter(
+            final Object pojo,
+            final ObjectAdapter parentAdapter,
+            final OneToManyAssociation otma) {
+
+        Assert.assertNotNull(pojo);
+
+        final Oid parentOid = parentAdapter.getOid();
+
+        // persistence of collection follows the parent
+        final ParentedCollectionOid collectionOid = new 
ParentedCollectionOid((RootOid) parentOid, otma);
+        final ObjectAdapter collectionAdapter = createCollectionAdapter(pojo, 
collectionOid);
+
+        // we copy over the type onto the adapter itself
+        // [not sure why this is really needed, surely we have enough info in
+        // the adapter
+        // to look this up on the fly?]
+        final TypeOfFacet facet = otma.getFacet(TypeOfFacet.class);
+        
collectionAdapter.setElementSpecificationProvider(ElementSpecificationProviderFromTypeOfFacet.createFrom(facet));
+
+        return collectionAdapter;
+    }
+
+    private ObjectAdapter createAdapter(
+            final Object pojo,
+            final Oid oid) {
+        return new PojoAdapter(
+                pojo, oid,
+                authenticationSession,
+                specificationLoader, session);
+    }
+}
\ No newline at end of file
diff --git 
a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterLegacy.java
 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterLegacy.java
index 77b8ed1..3469dfc 100644
--- 
a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterLegacy.java
+++ 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterLegacy.java
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
 import org.apache.isis.applib.services.bookmark.Bookmark;
 import org.apache.isis.commons.internal.collections._Lists;
 import org.apache.isis.commons.internal.exceptions._Exceptions;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
 import org.apache.isis.core.commons.ensure.Assert;
 import org.apache.isis.core.commons.exceptions.IsisException;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
@@ -46,6 +47,7 @@ import 
org.apache.isis.core.metamodel.spec.feature.Contributed;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
 import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
 import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
+import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
 import org.apache.isis.core.runtime.memento.CollectionData;
 import org.apache.isis.core.runtime.memento.Data;
 import org.apache.isis.core.runtime.memento.ObjectData;
@@ -65,8 +67,14 @@ public class ObjectAdapterLegacy {
     
     static final Logger LOG = 
LoggerFactory.getLogger(ObjectAdapterLegacy.class);
     
-    public static ObjectAdapterContext openContext(ServicesInjector 
servicesInjector) {
-        final ObjectAdapterContext objectAdapterContext = new 
ObjectAdapterContext(servicesInjector);
+    public static ObjectAdapterContext openContext(
+            ServicesInjector servicesInjector, 
+            AuthenticationSession authenticationSession, 
+            SpecificationLoader specificationLoader, 
+            PersistenceSession persistenceSession) {
+        final ObjectAdapterContext objectAdapterContext = 
+                new ObjectAdapterContext(servicesInjector, 
authenticationSession, 
+                        specificationLoader, persistenceSession);
         objectAdapterContext.open();
         return objectAdapterContext;
     }

Reply via email to