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/08/05 08:51:38 UTC
[2/2] isis git commit: ISIS-1188: removed
IsisSystemFixturesHookAbstract (collapsed down into IsisSystemAbstract).
ISIS-1188: removed IsisSystemFixturesHookAbstract (collapsed down into IsisSystemAbstract).
Also deprecated DebugSelection interface; no longer used.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/a930c1da
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/a930c1da
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/a930c1da
Branch: refs/heads/master
Commit: a930c1da1e3ec9e9d6aadf58856524d0a8a420a0
Parents: 6549e1e
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Wed Aug 5 07:38:20 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Wed Aug 5 07:39:34 2015 +0100
----------------------------------------------------------------------
.../integtestsupport/IsisSystemDefault.java | 16 -
.../core/runtime/system/DebugSelection.java | 3 +
.../system/IsisSystemFixturesHookAbstract.java | 469 -------------------
.../IsisSystemAbstract.java | 366 ++++++++++++---
.../IsisSystemUsingInstallers.java | 64 +--
5 files changed, 311 insertions(+), 607 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/a930c1da/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemDefault.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemDefault.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemDefault.java
index 7a1bae9..4c7b875 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemDefault.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemDefault.java
@@ -61,28 +61,12 @@ public class IsisSystemDefault extends IsisSystemAbstract {
private final IsisConfigurationDefault configuration;
private final List<Object> servicesIfAny;
- public IsisSystemDefault(Object... servicesIfAny) {
- this(DeploymentType.SERVER, servicesIfAny);
- }
-
- public IsisSystemDefault(List<Object> services) {
- this(DeploymentType.SERVER, services);
- }
-
- public IsisSystemDefault(DeploymentType deploymentType, Object... servicesIfAny) {
- this(deploymentType, asList(servicesIfAny));
- }
-
public IsisSystemDefault(DeploymentType deploymentType, List<Object> services) {
super(deploymentType);
this.configuration = new IsisConfigurationDefault(ResourceStreamSourceContextLoaderClassPath.create("config"));
this.servicesIfAny = services;
}
- private static List<Object> asList(Object... objects) {
- return objects != null? Collections.unmodifiableList(Lists.newArrayList(objects)): null;
- }
-
/**
* Reads <tt>isis.properties</tt> (and other optional property files) from the "config" package on the current classpath.
*/
http://git-wip-us.apache.org/repos/asf/isis/blob/a930c1da/core/runtime/src/main/java/org/apache/isis/core/runtime/system/DebugSelection.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/DebugSelection.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/DebugSelection.java
index 153a9d5..543592b 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/DebugSelection.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/DebugSelection.java
@@ -24,7 +24,10 @@ import org.apache.isis.core.commons.debug.DebuggableWithTitle;
/**
* Provides a mechanism for providing a series of DebugInfo objects, keyed on
* name.
+ *
+ * @deprecated
*/
+@Deprecated
public interface DebugSelection {
DebuggableWithTitle debugSection(String sectionName);
http://git-wip-us.apache.org/repos/asf/isis/blob/a930c1da/core/runtime/src/main/java/org/apache/isis/core/runtime/system/IsisSystemFixturesHookAbstract.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/IsisSystemFixturesHookAbstract.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/IsisSystemFixturesHookAbstract.java
deleted file mode 100644
index 799bc96..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/IsisSystemFixturesHookAbstract.java
+++ /dev/null
@@ -1,469 +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.system;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.List;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.isis.applib.DomainObjectContainer;
-import org.apache.isis.applib.fixtures.LogonFixture;
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.commons.debug.DebuggableWithTitle;
-import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
-import org.apache.isis.core.metamodel.facetapi.MetaModelRefiner;
-import org.apache.isis.core.metamodel.services.ServicesInjectorSpi;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
-import org.apache.isis.core.metamodel.specloader.ServiceInitializer;
-import org.apache.isis.core.runtime.about.AboutIsis;
-import org.apache.isis.core.runtime.authentication.AuthenticationManager;
-import org.apache.isis.core.runtime.authentication.exploration.ExplorationSession;
-import org.apache.isis.core.runtime.authorization.AuthorizationManager;
-import org.apache.isis.core.runtime.installerregistry.InstallerLookup;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.internal.InitialisationSession;
-import org.apache.isis.core.runtime.system.internal.IsisLocaleInitializer;
-import org.apache.isis.core.runtime.system.internal.IsisTimeZoneInitializer;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory;
-import org.apache.isis.core.runtime.system.session.IsisSession;
-import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
-import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
-import org.apache.isis.core.runtime.system.transaction.IsisTransactionManagerException;
-
-/**
- * An implementation of {@link IsisSystem} that has a hook for installing
- * fixtures but does not install them itself.
- */
-public abstract class IsisSystemFixturesHookAbstract implements IsisSystem {
-
- public static final Logger LOG = LoggerFactory.getLogger(IsisSystemFixturesHookAbstract.class);
-
- private final IsisLocaleInitializer localeInitializer;
- private final IsisTimeZoneInitializer timeZoneInitializer;
- private final DeploymentType deploymentType;
-
- private boolean initialized = false;
-
- private IsisSessionFactory sessionFactory;
-
- private ServiceInitializer serviceInitializer;
-
- // ///////////////////////////////////////////
- // Constructors
- // ///////////////////////////////////////////
-
- public IsisSystemFixturesHookAbstract(final DeploymentType deploymentType) {
- this(deploymentType, new IsisLocaleInitializer(), new IsisTimeZoneInitializer());
- }
-
- public IsisSystemFixturesHookAbstract(final DeploymentType deploymentType, final IsisLocaleInitializer localeInitializer, final IsisTimeZoneInitializer timeZoneInitializer) {
- this.deploymentType = deploymentType;
- this.localeInitializer = localeInitializer;
- this.timeZoneInitializer = timeZoneInitializer;
- }
-
- // ///////////////////////////////////////////
- // DeploymentType
- // ///////////////////////////////////////////
-
- @Override
- public DeploymentType getDeploymentType() {
- return deploymentType;
- }
-
- // ///////////////////////////////////////////
- // init, shutdown
- // ///////////////////////////////////////////
-
- @Override
- public void init() {
-
- if (initialized) {
- throw new IllegalStateException("Already initialized");
- } else {
- initialized = true;
- }
-
- LOG.info("initialising Isis System");
- LOG.info("working directory: " + new File(".").getAbsolutePath());
- LOG.info("resource stream source: " + getConfiguration().getResourceStreamSource());
-
- localeInitializer.initLocale(getConfiguration());
- timeZoneInitializer.initTimeZone(getConfiguration());
-
- try {
- sessionFactory = doCreateSessionFactory(deploymentType);
-
- // temporarily make a configuration available
- // REVIEW: would rather inject this, or perhaps even the
- // ConfigurationBuilder
- IsisContext.setConfiguration(getConfiguration());
-
- initContext(sessionFactory);
- sessionFactory.init();
-
- // validate here after all entities have been registered in the persistence session factory
- final SpecificationLoaderSpi specificationLoader = sessionFactory.getSpecificationLoader();
- specificationLoader.validateAndAssert();
-
- serviceInitializer = initializeServices();
-
- installFixturesIfRequired();
-
- translateServicesAndEnumConstants();
-
- } catch (final IsisSystemException ex) {
- LOG.error("failed to initialise", ex);
- throw new RuntimeException(ex);
- }
- }
-
- private void initContext(final IsisSessionFactory sessionFactory) {
- getDeploymentType().initContext(sessionFactory);
- }
-
- /**
- * @see #shutdownServices(ServiceInitializer)
- */
- private ServiceInitializer initializeServices() {
-
- final List<Object> services = sessionFactory.getServices();
-
- // validate
- final ServiceInitializer serviceInitializer = new ServiceInitializer();
- serviceInitializer.validate(getConfiguration(), services);
-
- // call @PostConstruct (in a session)
- IsisContext.openSession(new InitialisationSession());
- try {
- getTransactionManager().startTransaction();
- try {
- serviceInitializer.postConstruct();
-
- return serviceInitializer;
- } catch(RuntimeException ex) {
- getTransactionManager().getTransaction().setAbortCause(new IsisTransactionManagerException(ex));
- return serviceInitializer;
- } finally {
- // will commit or abort
- getTransactionManager().endTransaction();
- }
- } finally {
- IsisContext.closeSession();
- }
- }
-
- /**
- * The act of invoking titleOf(...) will cause translations to be requested.
- */
- private void translateServicesAndEnumConstants() {
- IsisContext.openSession(new InitialisationSession());
- try {
- final List<Object> services = sessionFactory.getServices();
- final DomainObjectContainer container = lookupService(DomainObjectContainer.class);
- for (Object service : services) {
- final String unused = container.titleOf(service);
- }
- for (final ObjectSpecification objSpec : allSpecifications()) {
- final Class<?> correspondingClass = objSpec.getCorrespondingClass();
- if(correspondingClass.isEnum()) {
- final Object[] enumConstants = correspondingClass.getEnumConstants();
- for (Object enumConstant : enumConstants) {
- final String unused = container.titleOf(enumConstant);
- }
- }
- }
- } finally {
- IsisContext.closeSession();
- }
-
- }
-
- private <T> T lookupService(final Class<T> serviceClass) {
- return getServicesInjector().lookupService(serviceClass);
- }
-
- private ServicesInjectorSpi getServicesInjector() {
- return getPersistenceSession().getServicesInjector();
- }
-
- private PersistenceSession getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
- Collection<ObjectSpecification> allSpecifications() {
- return IsisContext.getSpecificationLoader().allSpecifications();
- }
-
- @Override
- public void shutdown() {
- LOG.info("shutting down system");
-
- shutdownServices(this.serviceInitializer);
-
- IsisContext.closeAllSessions();
- }
-
- /**
- * @see #initializeServices()
- */
- private void shutdownServices(final ServiceInitializer serviceInitializer) {
-
- // call @PostDestroy (in a session)
- IsisContext.openSession(new InitialisationSession());
- try {
- getTransactionManager().startTransaction();
- try {
- serviceInitializer.preDestroy();
-
- } catch(RuntimeException ex) {
- getTransactionManager().getTransaction().setAbortCause(new IsisTransactionManagerException(ex));
- } finally {
- // will commit or abort
- getTransactionManager().endTransaction();
- }
- } finally {
- IsisContext.closeSession();
- }
- }
-
- // ///////////////////////////////////////////
- // Hook:
- // ///////////////////////////////////////////
-
- /**
- * Hook method; the returned implementation is expected to use the same
- * general approach as the subclass itself.
- *
- * <p>
- * So, for example, <tt>IsisSystemUsingInstallers</tt> uses the
- * {@link InstallerLookup} mechanism to find its components. The
- * corresponding <tt>ExecutionContextFactoryUsingInstallers</tt> object
- * returned by this method should use {@link InstallerLookup} likewise.
- */
- protected abstract IsisSessionFactory doCreateSessionFactory(final DeploymentType deploymentType) throws IsisSystemException;
-
-
- // ///////////////////////////////////////////
- // Configuration
- // ///////////////////////////////////////////
-
- /**
- * Populated after {@link #init()}.
- */
- @Override
- public IsisSessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- // ///////////////////////////////////////////
- // Configuration
- // ///////////////////////////////////////////
-
- @Override
- public abstract IsisConfiguration getConfiguration();
-
-
- // ///////////////////////////////////////////
- // OidMarshaller
- // ///////////////////////////////////////////
-
- /**
- * Just returns a {@link OidMarshaller}; subclasses may override if
- * required.
- */
- protected OidMarshaller obtainOidMarshaller() {
- return new OidMarshaller();
- }
-
- // ///////////////////////////////////////////
- // Reflector
- // ///////////////////////////////////////////
-
- protected abstract SpecificationLoaderSpi obtainSpecificationLoaderSpi(DeploymentType deploymentType, Collection<MetaModelRefiner> metaModelRefiners) throws IsisSystemException;
-
- // ///////////////////////////////////////////
- // PersistenceSessionFactory
- // ///////////////////////////////////////////
-
- protected abstract PersistenceSessionFactory obtainPersistenceSessionFactory(DeploymentType deploymentType, final List<Object> services) throws IsisSystemException;
-
- // ///////////////////////////////////////////
- // Fixtures (hooks)
- // ///////////////////////////////////////////
-
- /**
- * Optional hook for appending debug information pertaining to fixtures
- * installer if required.
- */
- protected void appendFixturesInstallerDebug(final DebugBuilder debug) {
- }
-
- /**
- * The {@link LogonFixture}, if any, obtained by running fixtures.
- *
- * <p>
- * Intended to be used when for {@link DeploymentType#SERVER_EXPLORATION
- * exploration} (instead of an {@link ExplorationSession}) or
- * {@link DeploymentType#SERVER_PROTOTYPE prototype} deployments (saves logging
- * in). Should be <i>ignored</i> in other {@link DeploymentType}s.
- *
- * <p>
- * This implementation always returns <tt>null</tt>.
- */
- @Override
- public LogonFixture getLogonFixture() {
- return null;
- }
-
- /**
- * Optional hook for installing fixtures.
- *
- * <p>
- * This implementation does nothing.
- */
- protected void installFixturesIfRequired() throws IsisSystemException {
- }
-
- // ///////////////////////////////////////////
- // Authentication & Authorization Manager
- // ///////////////////////////////////////////
-
- protected abstract AuthenticationManager obtainAuthenticationManager(DeploymentType deploymentType) throws IsisSystemException;
-
- protected abstract AuthorizationManager obtainAuthorizationManager(final DeploymentType deploymentType);
-
- // ///////////////////////////////////////////
- // Services
- // ///////////////////////////////////////////
-
- protected abstract List<Object> obtainServices();
-
-
- // ///////////////////////////////////////////
- // debugging
- // ///////////////////////////////////////////
-
- private void debug(final DebugBuilder debug, final Object object) {
- if (object instanceof DebuggableWithTitle) {
- final DebuggableWithTitle d = (DebuggableWithTitle) object;
- debug.appendTitle(d.debugTitle());
- d.debugData(debug);
- } else {
- debug.appendln(object.toString());
- debug.appendln("... no further debug information");
- }
- }
-
- @Override
- public DebuggableWithTitle debugSection(final String selectionName) {
- // DebugInfo deb;
- if (selectionName.equals("Configuration")) {
- return getConfiguration();
- } /*
- * else if (selectionName.equals("Overview")) { debugOverview(debug);
- * } else if (selectionName.equals("Authenticator")) { deb =
- * IsisContext.getAuthenticationManager(); } else if
- * (selectionName.equals("Reflector")) { deb =
- * IsisContext.getSpecificationLoader(); } else if
- * (selectionName.equals("Contexts")) { deb =
- * debugListContexts(debug); } else { deb =
- * debugDisplayContext(selectionName, debug); }
- */
- return null;
- }
-
- private void debugDisplayContext(final String selector, final DebugBuilder debug) {
- final IsisSession d = IsisContext.getSession(selector);
- if (d != null) {
- d.debugAll(debug);
- } else {
- debug.appendln("No context: " + selector);
- }
- }
-
- private void debugListContexts(final DebugBuilder debug) {
- final String[] contextIds = IsisContext.getInstance().allSessionIds();
- for (final String contextId : contextIds) {
- debug.appendln(contextId);
- debug.appendln("-----");
- final IsisSession d = IsisContext.getSession(contextId);
- d.debug(debug);
- debug.appendln();
- }
- }
-
- @Override
- public String[] debugSectionNames() {
- final String[] general = new String[] { "Overview", "Authenticator", "Configuration", "Reflector", "Requests", "Contexts" };
- final String[] contextIds = IsisContext.getInstance().allSessionIds();
- final String[] combined = new String[general.length + contextIds.length];
- System.arraycopy(general, 0, combined, 0, general.length);
- System.arraycopy(contextIds, 0, combined, general.length, contextIds.length);
- return combined;
- }
-
- private void debugOverview(final DebugBuilder debug) {
- try {
- debug.appendln(AboutIsis.getFrameworkName());
- debug.appendln(AboutIsis.getFrameworkVersion());
- if (AboutIsis.getApplicationName() != null) {
- debug.appendln("application: " + AboutIsis.getApplicationName());
- }
- if (AboutIsis.getApplicationVersion() != null) {
- debug.appendln("version" + AboutIsis.getApplicationVersion());
- }
-
- final String user = System.getProperty("user.name");
- final String system = System.getProperty("os.name") + " (" + System.getProperty("os.arch") + ") " + System.getProperty("os.version");
- final String java = System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version");
- debug.appendln("user: " + user);
- debug.appendln("os: " + system);
- debug.appendln("java: " + java);
- debug.appendln("working directory: " + new File(".").getAbsolutePath());
-
- debug.appendTitle("System Installer");
- appendFixturesInstallerDebug(debug);
-
- debug.appendTitle("System Components");
- debug.appendln("Authentication manager", IsisContext.getAuthenticationManager().getClass().getName());
- debug.appendln("Configuration", getConfiguration().getClass().getName());
-
- final DebuggableWithTitle[] inf = IsisContext.debugSystem();
- for (final DebuggableWithTitle element : inf) {
- if (element != null) {
- element.debugData(debug);
- }
- }
- } catch (final RuntimeException e) {
- debug.appendException(e);
- }
- }
-
- IsisTransactionManager getTransactionManager() {
- return IsisContext.getTransactionManager();
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a930c1da/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisSystemAbstract.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisSystemAbstract.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisSystemAbstract.java
index 9341c50..73e27bf 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisSystemAbstract.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisSystemAbstract.java
@@ -19,6 +19,7 @@
package org.apache.isis.core.runtime.systemusinginstallers;
+import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -26,6 +27,7 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.apache.isis.applib.DomainObjectContainer;
import org.apache.isis.applib.fixtures.LogonFixture;
import org.apache.isis.applib.fixturescripts.FixtureScripts;
import org.apache.isis.applib.services.fixturespec.FixtureScriptsDefault;
@@ -33,11 +35,14 @@ import org.apache.isis.core.commons.components.Installer;
import org.apache.isis.core.commons.components.Noop;
import org.apache.isis.core.commons.config.IsisConfiguration;
import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.commons.debug.DebuggableWithTitle;
import org.apache.isis.core.commons.lang.ListExtensions;
import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
import org.apache.isis.core.metamodel.facetapi.MetaModelRefiner;
import org.apache.isis.core.metamodel.services.ServicesInjectorSpi;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.metamodel.specloader.ServiceInitializer;
import org.apache.isis.core.runtime.authentication.AuthenticationManager;
import org.apache.isis.core.runtime.authentication.exploration.ExplorationSession;
import org.apache.isis.core.runtime.authorization.AuthorizationManager;
@@ -45,41 +50,184 @@ import org.apache.isis.core.runtime.fixtures.FixturesInstaller;
import org.apache.isis.core.runtime.installerregistry.InstallerLookup;
import org.apache.isis.core.runtime.persistence.internal.RuntimeContextFromSession;
import org.apache.isis.core.runtime.system.DeploymentType;
+import org.apache.isis.core.runtime.system.IsisSystem;
import org.apache.isis.core.runtime.system.IsisSystemException;
-import org.apache.isis.core.runtime.system.IsisSystemFixturesHookAbstract;
import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.internal.InitialisationSession;
import org.apache.isis.core.runtime.system.internal.IsisLocaleInitializer;
import org.apache.isis.core.runtime.system.internal.IsisTimeZoneInitializer;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
import org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory;
import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
import org.apache.isis.core.runtime.system.session.IsisSessionFactoryDefault;
+import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
+import org.apache.isis.core.runtime.system.transaction.IsisTransactionManagerException;
/**
*
*/
-public abstract class IsisSystemAbstract extends IsisSystemFixturesHookAbstract {
+public abstract class IsisSystemAbstract implements IsisSystem {
public static final Logger LOG = LoggerFactory.getLogger(IsisSystemAbstract.class);
- private FixturesInstaller fixtureInstaller;
- private LogonFixture logonFixture;
+ private final IsisLocaleInitializer localeInitializer;
+ private final IsisTimeZoneInitializer timeZoneInitializer;
+ private final DeploymentType deploymentType;
+
+ private boolean initialized = false;
- // ///////////////////////////////////////////
- // Constructors
- // ///////////////////////////////////////////
+ private ServiceInitializer serviceInitializer;
+ private FixturesInstaller fixtureInstaller;
+
+ //region > constructors
public IsisSystemAbstract(final DeploymentType deploymentType) {
this(deploymentType, new IsisLocaleInitializer(), new IsisTimeZoneInitializer());
}
public IsisSystemAbstract(final DeploymentType deploymentType, final IsisLocaleInitializer localeInitializer, final IsisTimeZoneInitializer timeZoneInitializer) {
- super(deploymentType, localeInitializer, timeZoneInitializer);
+ this.deploymentType = deploymentType;
+ this.localeInitializer = localeInitializer;
+ this.timeZoneInitializer = timeZoneInitializer;
}
+ //endregion
+ //region > deploymentType
@Override
- protected void installFixturesIfRequired() throws IsisSystemException {
+ public DeploymentType getDeploymentType() {
+ return deploymentType;
+ }
+
+ //endregion
+
+ //region > init
+
+ @Override
+ public void init() {
+
+ if (initialized) {
+ throw new IllegalStateException("Already initialized");
+ } else {
+ initialized = true;
+ }
+
+ LOG.info("initialising Isis System");
+ LOG.info("working directory: " + new File(".").getAbsolutePath());
+ LOG.info("resource stream source: " + getConfiguration().getResourceStreamSource());
+
+ localeInitializer.initLocale(getConfiguration());
+ timeZoneInitializer.initTimeZone(getConfiguration());
+
+ try {
+ sessionFactory = createSessionFactory(deploymentType);
+
+ // temporarily make a configuration available
+ // REVIEW: would rather inject this, or perhaps even the
+ // ConfigurationBuilder
+ IsisContext.setConfiguration(getConfiguration());
+
+ initContext(sessionFactory);
+ sessionFactory.init();
+
+ // validate here after all entities have been registered in the persistence session factory
+ final SpecificationLoaderSpi specificationLoader = sessionFactory.getSpecificationLoader();
+ specificationLoader.validateAndAssert();
+
+ serviceInitializer = initializeServices();
+
+ installFixturesIfRequired();
+
+ translateServicesAndEnumConstants();
+
+ } catch (final IsisSystemException ex) {
+ LOG.error("failed to initialise", ex);
+ throw new RuntimeException(ex);
+ }
+ }
+
+ //region > createSessionFactory
+
+ private IsisSessionFactory sessionFactory;
+
+ /**
+ * Populated after {@link #init()}.
+ */
+ @Override
+ public IsisSessionFactory getSessionFactory() {
+ return sessionFactory;
+ }
+
+ private IsisSessionFactory createSessionFactory(final DeploymentType deploymentType) throws IsisSystemException {
+ final List<Object> services = obtainServices();
+ final PersistenceSessionFactory persistenceSessionFactory =
+ obtainPersistenceSessionFactory(deploymentType, services);
+
+ final IsisConfiguration configuration = getConfiguration();
+ final AuthenticationManager authenticationManager = obtainAuthenticationManager(deploymentType);
+ final AuthorizationManager authorizationManager = obtainAuthorizationManager(deploymentType);
+ final OidMarshaller oidMarshaller = obtainOidMarshaller();
+
+ final Collection<MetaModelRefiner> metaModelRefiners =
+ refiners(authenticationManager, authorizationManager, persistenceSessionFactory);
+ final SpecificationLoaderSpi reflector = obtainSpecificationLoaderSpi(deploymentType, metaModelRefiners);
+
+ ServicesInjectorSpi servicesInjector = persistenceSessionFactory.getServicesInjector();
+ servicesInjector.addFallbackIfRequired(FixtureScripts.class, new FixtureScriptsDefault());
+ servicesInjector.validateServices();
+
+ // bind metamodel to the (runtime) framework
+ final RuntimeContextFromSession runtimeContext = obtainRuntimeContextFromSession();
+ runtimeContext.injectInto(reflector);
+
+ return new IsisSessionFactoryDefault(
+ deploymentType, configuration, reflector,
+ authenticationManager, authorizationManager,
+ persistenceSessionFactory, oidMarshaller);
+ }
+
+ private static Collection<MetaModelRefiner> refiners(Object... possibleRefiners ) {
+ return ListExtensions.filtered(Arrays.asList(possibleRefiners), MetaModelRefiner.class);
+ }
+ //endregion
+
+
+ private void initContext(final IsisSessionFactory sessionFactory) {
+ getDeploymentType().initContext(sessionFactory);
+ }
+
+ /**
+ * @see #shutdownServices(ServiceInitializer)
+ */
+ private ServiceInitializer initializeServices() {
+
+ final List<Object> services = sessionFactory.getServices();
+
+ // validate
+ final ServiceInitializer serviceInitializer = new ServiceInitializer();
+ serviceInitializer.validate(getConfiguration(), services);
+
+ // call @PostConstruct (in a session)
+ IsisContext.openSession(new InitialisationSession());
+ try {
+ getTransactionManager().startTransaction();
+ try {
+ serviceInitializer.postConstruct();
+
+ return serviceInitializer;
+ } catch(RuntimeException ex) {
+ getTransactionManager().getTransaction().setAbortCause(new IsisTransactionManagerException(ex));
+ return serviceInitializer;
+ } finally {
+ // will commit or abort
+ getTransactionManager().endTransaction();
+ }
+ } finally {
+ IsisContext.closeSession();
+ }
+ }
+
+ private void installFixturesIfRequired() throws IsisSystemException {
fixtureInstaller = obtainFixturesInstaller();
if (isNoop(fixtureInstaller)) {
@@ -103,15 +251,75 @@ public abstract class IsisSystemAbstract extends IsisSystemFixturesHookAbstract
return candidate == null || (fixtureInstaller instanceof Noop);
}
- // ///////////////////////////////////////////
- // Fixtures
- // ///////////////////////////////////////////
+ /**
+ * The act of invoking titleOf(...) will cause translations to be requested.
+ */
+ private void translateServicesAndEnumConstants() {
+ IsisContext.openSession(new InitialisationSession());
+ try {
+ final List<Object> services = sessionFactory.getServices();
+ final DomainObjectContainer container = lookupService(DomainObjectContainer.class);
+ for (Object service : services) {
+ final String unused = container.titleOf(service);
+ }
+ for (final ObjectSpecification objSpec : allSpecifications()) {
+ final Class<?> correspondingClass = objSpec.getCorrespondingClass();
+ if(correspondingClass.isEnum()) {
+ final Object[] enumConstants = correspondingClass.getEnumConstants();
+ for (Object enumConstant : enumConstants) {
+ final String unused = container.titleOf(enumConstant);
+ }
+ }
+ }
+ } finally {
+ IsisContext.closeSession();
+ }
+
+ }
+
+ private <T> T lookupService(final Class<T> serviceClass) {
+ return getServicesInjector().lookupService(serviceClass);
+ }
+
+ private ServicesInjectorSpi getServicesInjector() {
+ return getPersistenceSession().getServicesInjector();
+ }
+
+ private PersistenceSession getPersistenceSession() {
+ return IsisContext.getPersistenceSession();
+ }
+
+ Collection<ObjectSpecification> allSpecifications() {
+ return IsisContext.getSpecificationLoader().allSpecifications();
+ }
+
+ //endregion
+
+ //region > obtainXxx: specificationLoaderSpi, persistenceSessionFactory, oidMarshaller, runtimeContextFromSession, authenticationManager authorizationManager, services, fixturesInstaller
+
+ protected abstract SpecificationLoaderSpi obtainSpecificationLoaderSpi(DeploymentType deploymentType, Collection<MetaModelRefiner> metaModelRefiners) throws IsisSystemException;
+
+ protected abstract PersistenceSessionFactory obtainPersistenceSessionFactory(DeploymentType deploymentType, final List<Object> services) throws IsisSystemException;
+
+ protected OidMarshaller obtainOidMarshaller() {
+ return new OidMarshaller();
+ }
+
+ protected RuntimeContextFromSession obtainRuntimeContextFromSession() {
+ return new RuntimeContextFromSession();
+ }
+
+ protected abstract AuthenticationManager obtainAuthenticationManager(DeploymentType deploymentType) throws IsisSystemException;
+
+ protected abstract AuthorizationManager obtainAuthorizationManager(final DeploymentType deploymentType);
+
+ protected abstract List<Object> obtainServices();
/**
* This is the only {@link Installer} that is used by any (all) subclass
* implementations, because it effectively <i>is</i> the component we need
* (as opposed to a builder/factory of the component we need).
- *
+ *
* <p>
* The fact that the component <i>is</i> an installer (and therefore can be
* {@link InstallerLookup} looked up} is at this level really just an
@@ -120,17 +328,56 @@ public abstract class IsisSystemAbstract extends IsisSystemFixturesHookAbstract
*/
protected abstract FixturesInstaller obtainFixturesInstaller() throws IsisSystemException;
- // ///////////////////////////////////////////
- // Fixtures Installer
- // ///////////////////////////////////////////
- public FixturesInstaller getFixturesInstaller() {
- return fixtureInstaller;
+ //endregion
+
+ //region > shutdown
+
+ @Override
+ public void shutdown() {
+ LOG.info("shutting down system");
+
+ shutdownServices(this.serviceInitializer);
+
+ IsisContext.closeAllSessions();
}
/**
+ * @see #initializeServices()
+ */
+ private void shutdownServices(final ServiceInitializer serviceInitializer) {
+
+ // call @PostDestroy (in a session)
+ IsisContext.openSession(new InitialisationSession());
+ try {
+ getTransactionManager().startTransaction();
+ try {
+ serviceInitializer.preDestroy();
+
+ } catch(RuntimeException ex) {
+ getTransactionManager().getTransaction().setAbortCause(new IsisTransactionManagerException(ex));
+ } finally {
+ // will commit or abort
+ getTransactionManager().endTransaction();
+ }
+ } finally {
+ IsisContext.closeSession();
+ }
+ }
+
+ //endregion
+
+ //region > configuration
+ @Override
+ public abstract IsisConfiguration getConfiguration();
+ //endregion
+
+ //region > logonFixture
+ private LogonFixture logonFixture;
+
+ /**
* The {@link LogonFixture}, if any, obtained by running fixtures.
- *
+ *
* <p>
* Intended to be used when for {@link DeploymentType#SERVER_EXPLORATION
* exploration} (instead of an {@link ExplorationSession}) or
@@ -141,68 +388,45 @@ public abstract class IsisSystemAbstract extends IsisSystemFixturesHookAbstract
public LogonFixture getLogonFixture() {
return logonFixture;
}
+ //endregion
- @Override
- protected void appendFixturesInstallerDebug(final DebugBuilder debug) {
- debug.appendln("Fixture Installer", fixtureInstaller == null ? "none" : fixtureInstaller.getClass().getName());
- }
-
+ //region > debugging
- // ///////////////////////////////////////////
- // Session Factory
- // ///////////////////////////////////////////
+ private void debug(final DebugBuilder debug, final Object object) {
+ if (object instanceof DebuggableWithTitle) {
+ final DebuggableWithTitle d = (DebuggableWithTitle) object;
+ debug.appendTitle(d.debugTitle());
+ d.debugData(debug);
+ } else {
+ debug.appendln(object.toString());
+ debug.appendln("... no further debug information");
+ }
+ }
@Override
- public IsisSessionFactory doCreateSessionFactory(final DeploymentType deploymentType) throws IsisSystemException {
- final List<Object> services = obtainServices();
- final PersistenceSessionFactory persistenceSessionFactory = obtainPersistenceSessionFactory(deploymentType, services);
- return createSessionFactory(deploymentType, persistenceSessionFactory);
+ public DebuggableWithTitle debugSection(final String selectionName) {
+ // DebugInfo deb;
+ if (selectionName.equals("Configuration")) {
+ return getConfiguration();
+ }
+ return null;
}
- /**
- * Overloaded version designed to be called by subclasses that need to
- * explicitly specify different persistence mechanisms.
- *
- * <p>
- * This is <i>not</i> a hook method, rather it is designed to be called
- * <i>from</i> the {@link #doCreateSessionFactory(DeploymentType) hook
- * method}.
- */
- protected final IsisSessionFactory createSessionFactory(
- final DeploymentType deploymentType,
- final PersistenceSessionFactory persistenceSessionFactory) throws IsisSystemException {
-
- final IsisConfiguration configuration = getConfiguration();
- final AuthenticationManager authenticationManager = obtainAuthenticationManager(deploymentType);
- final AuthorizationManager authorizationManager = obtainAuthorizationManager(deploymentType);
- final OidMarshaller oidMarshaller = obtainOidMarshaller();
-
- final Collection<MetaModelRefiner> metaModelRefiners =
- refiners(authenticationManager, authorizationManager, persistenceSessionFactory);
- final SpecificationLoaderSpi reflector = obtainSpecificationLoaderSpi(deploymentType, metaModelRefiners);
-
- ServicesInjectorSpi servicesInjector = persistenceSessionFactory.getServicesInjector();
- servicesInjector.addFallbackIfRequired(FixtureScripts.class, new FixtureScriptsDefault());
- servicesInjector.validateServices();
-
- // bind metamodel to the (runtime) framework
- final RuntimeContextFromSession runtimeContext = obtainRuntimeContextFromSession();
- runtimeContext.injectInto(reflector);
-
- return new IsisSessionFactoryDefault(
- deploymentType, configuration, reflector,
- authenticationManager, authorizationManager,
- persistenceSessionFactory, oidMarshaller);
+ @Override
+ public String[] debugSectionNames() {
+ final String[] general = new String[] { "Overview", "Authenticator", "Configuration", "Reflector", "Requests", "Contexts" };
+ final String[] contextIds = IsisContext.getInstance().allSessionIds();
+ final String[] combined = new String[general.length + contextIds.length];
+ System.arraycopy(general, 0, combined, 0, general.length);
+ System.arraycopy(contextIds, 0, combined, general.length, contextIds.length);
+ return combined;
}
- protected RuntimeContextFromSession obtainRuntimeContextFromSession() {
- return new RuntimeContextFromSession();
+ IsisTransactionManager getTransactionManager() {
+ return IsisContext.getTransactionManager();
}
- private static Collection<MetaModelRefiner> refiners(Object... possibleRefiners ) {
- return ListExtensions.filtered(Arrays.asList(possibleRefiners), MetaModelRefiner.class);
- }
+ //endregion
-
}
http://git-wip-us.apache.org/repos/asf/isis/blob/a930c1da/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisSystemUsingInstallers.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisSystemUsingInstallers.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisSystemUsingInstallers.java
index 46a046e..fa96621 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisSystemUsingInstallers.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisSystemUsingInstallers.java
@@ -21,8 +21,10 @@ package org.apache.isis.core.runtime.systemusinginstallers;
import java.util.Collection;
import java.util.List;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.apache.isis.core.commons.config.IsisConfiguration;
import org.apache.isis.core.metamodel.facetapi.MetaModelRefiner;
import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
@@ -34,17 +36,18 @@ import org.apache.isis.core.runtime.authorization.AuthorizationManagerInstaller;
import org.apache.isis.core.runtime.fixtures.FixturesInstaller;
import org.apache.isis.core.runtime.installerregistry.InstallerLookup;
import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory;
import org.apache.isis.core.runtime.services.ServicesInstaller;
import org.apache.isis.core.runtime.system.DeploymentType;
import org.apache.isis.core.runtime.system.IsisSystemException;
import org.apache.isis.core.runtime.system.SystemConstants;
-import org.apache.isis.core.runtime.systemdependencyinjector.SystemDependencyInjector;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory;
import org.apache.isis.core.runtime.transaction.facetdecorator.standard.TransactionFacetDecoratorInstaller;
import static org.apache.isis.core.commons.ensure.Ensure.ensureThatArg;
import static org.apache.isis.core.commons.ensure.Ensure.ensureThatState;
-import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.nullValue;
public class IsisSystemUsingInstallers extends IsisSystemAbstract {
@@ -59,6 +62,7 @@ public class IsisSystemUsingInstallers extends IsisSystemAbstract {
private PersistenceMechanismInstaller persistenceMechanismInstaller;
private FixturesInstaller fixtureInstaller;
+
// ///////////////////////////////////////////
// Constructors
// ///////////////////////////////////////////
@@ -69,32 +73,18 @@ public class IsisSystemUsingInstallers extends IsisSystemAbstract {
this.installerLookup = installerLookup;
}
- // ///////////////////////////////////////////
- // InstallerLookup
- // ///////////////////////////////////////////
-
- /**
- * As per
- * {@link #IsisSystemUsingInstallers(DeploymentType, InstallerLookup)
- * constructor}.
- */
- public SystemDependencyInjector getInstallerLookup() {
- return installerLookup;
- }
-
- // ///////////////////////////////////////////
- // Create context hooks
- // ///////////////////////////////////////////
-
// ///////////////////////////////////////////
// Configuration
// ///////////////////////////////////////////
/**
- * Returns a <i>snapshot</i> of the {@link IsisConfiguration configuration}
- * held by the {@link #getInstallerLookup() installer lookup}.
- *
+ * Returns a <i>snapshot</i> of the {@link IsisConfiguration configuration}.
+ *
+ * <p>
+ * ... as held by the internal {@link InstallerLookup}.
+ * </p>
+ *
* @see InstallerLookup#getConfiguration()
*/
@Override
@@ -143,10 +133,6 @@ public class IsisSystemUsingInstallers extends IsisSystemAbstract {
return authorizationInstaller.createAuthorizationManager();
}
- // ///////////////////////////////////////////
- // Fixtures
- // ///////////////////////////////////////////
-
public void lookupAndSetFixturesInstaller() {
final IsisConfiguration configuration = installerLookup.getConfiguration();
final String fixture = configuration.getString(SystemConstants.FIXTURES_INSTALLER_KEY);
@@ -157,10 +143,6 @@ public class IsisSystemUsingInstallers extends IsisSystemAbstract {
}
}
- public void setFixtureInstaller(final FixturesInstaller fixtureInstaller) {
- this.fixtureInstaller = fixtureInstaller;
- }
-
@Override
protected FixturesInstaller obtainFixturesInstaller() throws IsisSystemException {
return fixtureInstaller;
@@ -170,10 +152,6 @@ public class IsisSystemUsingInstallers extends IsisSystemAbstract {
// Reflector
// ///////////////////////////////////////////
- public void setReflectorInstaller(final ObjectReflectorInstaller reflectorInstaller) {
- this.reflectorInstaller = reflectorInstaller;
- }
-
@Override
protected SpecificationLoaderSpi obtainSpecificationLoaderSpi(final DeploymentType deploymentType, final Collection<MetaModelRefiner> metaModelRefiners) throws IsisSystemException {
if (reflectorInstaller == null) {
@@ -188,14 +166,6 @@ public class IsisSystemUsingInstallers extends IsisSystemAbstract {
return reflectorInstaller.createReflector(metaModelRefiners);
}
- // ///////////////////////////////////////////
- // Container and Services
- // ///////////////////////////////////////////
-
- public void setServicesInstaller(final ServicesInstaller servicesInstaller) {
- this.servicesInstaller = servicesInstaller;
- }
-
@Override
protected List<Object> obtainServices() {
if (servicesInstaller == null) {
@@ -207,14 +177,6 @@ public class IsisSystemUsingInstallers extends IsisSystemAbstract {
}
- // ///////////////////////////////////////////
- // PersistenceSessionFactory
- // ///////////////////////////////////////////
-
- public void setPersistenceMechanismInstaller(final PersistenceMechanismInstaller persistenceMechanismInstaller) {
- this.persistenceMechanismInstaller = persistenceMechanismInstaller;
- }
-
@Override
protected PersistenceSessionFactory obtainPersistenceSessionFactory(final DeploymentType deploymentType, final List<Object> services) throws IsisSystemException {