You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/05/04 12:24:53 UTC
[isis] 02/03: ISIS-1841: IsisContext: adds shortcuts for convenience
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 5b92468d60dbdfe6c9c3a837b10f50484642d75f
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri May 4 12:34:51 2018 +0200
ISIS-1841: IsisContext: adds shortcuts for convenience
also removes deprecated testReset()
---
.../core/integtestsupport/IsisSystemForTest.java | 2 +-
.../runtime/headless/IsisSystemBootstrapper.java | 2 +-
.../core/runtime/system/context/IsisContext.java | 45 ++++++++++++++++++----
3 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java
index 1149542..c2fef4d 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java
@@ -327,7 +327,7 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
// for subsequent tests; the attempt to bootstrap the framework will leave
// the IsisContext singleton as set.
- IsisContext.testReset();
+ IsisContext.clear();
final Set<String> validationErrors = ex.getValidationErrors();
final StringBuilder buf = new StringBuilder();
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystemBootstrapper.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystemBootstrapper.java
index b167b51..e587ec5 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystemBootstrapper.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystemBootstrapper.java
@@ -187,7 +187,7 @@ public class IsisSystemBootstrapper {
isisSessionFactory.destroyServicesAndShutdown();
pmf.close();
- IsisContext.testReset();
+ IsisContext.clear();
}
public void tearDownAllModules() {
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
index 9763ff5..3e4bf99 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
@@ -19,8 +19,15 @@
package org.apache.isis.core.runtime.system.context;
+import java.util.Optional;
+
import org.apache.isis.applib.internal.context._Context;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.services.ServicesInjector;
+import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
import org.apache.isis.core.metamodel.specloader.validator.MetaModelInvalidException;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.core.runtime.system.session.IsisSession;
import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
/**
@@ -40,6 +47,7 @@ public interface IsisContext {
/**
*
* @return Isis's session factory
+ * @throws IllegalStateException if IsisSessionFactory not initialized
*/
// Implementation Note: Populated only by {@link IsisSessionFactoryBuilder}.
public static IsisSessionFactory getSessionFactory() {
@@ -68,16 +76,39 @@ public interface IsisContext {
resetLogging();
}
- // -- DEPRECATIONS
+ // -- CONVENIENT SHORTCUTS
/**
- * Resets
- * @deprecated replaced by {@link #clear()}
- *
+ * @return framework's current PersistenceSession (if any)
+ * @throws IllegalStateException if IsisSessionFactory not initialized
+ */
+ public static Optional<PersistenceSession> getPersistenceSession() {
+ return Optional.ofNullable(getSessionFactory().getCurrentSession())
+ .map(IsisSession::getPersistenceSession);
+ }
+
+ /**
+ * @return framework's IsisConfiguration
+ * @throws IllegalStateException if IsisSessionFactory not initialized
+ */
+ public static IsisConfiguration getConfiguration() {
+ return getSessionFactory().getConfiguration();
+ }
+
+ /**
+ * @return framework's SpecificationLoader
+ * @throws IllegalStateException if IsisSessionFactory not initialized
+ */
+ public static SpecificationLoader getSpecificationLoader() {
+ return getSessionFactory().getSpecificationLoader();
+ }
+
+ /**
+ * @return framework's ServicesInjector
+ * @throws IllegalStateException if IsisSessionFactory not initialized
*/
- @Deprecated
- public static void testReset() {
- clear();
+ public static ServicesInjector getServicesInjector() {
+ return getSessionFactory().getServicesInjector();
}
// -- HELPER
--
To stop receiving notification emails like this one, please contact
ahuber@apache.org.