001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020package org.apache.isis.core.progmodel.facets.object.value; 021 022import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider; 023import org.apache.isis.core.commons.authentication.AuthenticationSessionProviderAware; 024import org.apache.isis.core.commons.config.IsisConfiguration; 025import org.apache.isis.core.commons.config.IsisConfigurationAware; 026import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager; 027import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAware; 028import org.apache.isis.core.metamodel.deployment.DeploymentCategory; 029import org.apache.isis.core.metamodel.facetapi.FacetUtil; 030import org.apache.isis.core.metamodel.facetapi.FeatureType; 031import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract; 032import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext; 033import org.apache.isis.core.metamodel.runtimecontext.RuntimeContextAware; 034import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector; 035import org.apache.isis.core.metamodel.runtimecontext.ServicesInjectorAware; 036 037public abstract class ValueUsingValueSemanticsProviderFacetFactory<T> extends FacetFactoryAbstract implements IsisConfigurationAware, AuthenticationSessionProviderAware, AdapterManagerAware, ServicesInjectorAware, RuntimeContextAware { 038 039 private IsisConfiguration configuration; 040 private RuntimeContext runtimeContext; 041 private AuthenticationSessionProvider authenticationSessionProvider; 042 private AdapterManager adapterManager; 043 private ServicesInjector servicesInjector; 044 045 /** 046 * Lazily created. 047 */ 048 private ValueSemanticsProviderContext context; 049 050 protected ValueUsingValueSemanticsProviderFacetFactory() { 051 super(FeatureType.OBJECTS_ONLY); 052 } 053 054 protected void addFacets(final ValueSemanticsProviderAndFacetAbstract<T> adapter) { 055 final ValueFacetUsingSemanticsProvider facet = new ValueFacetUsingSemanticsProvider(adapter, adapter, getContext()); 056 FacetUtil.addFacet(facet); 057 } 058 059 // //////////////////////////////////////////////////// 060 // Dependencies (injected via setter) 061 // //////////////////////////////////////////////////// 062 063 /** 064 * Derived from {@link #setRuntimeContext(RuntimeContext)} (since {@link RuntimeContextAware}). 065 */ 066 private DeploymentCategory getDeploymentCategory() { 067 return runtimeContext.getDeploymentCategory(); 068 } 069 070 071 public IsisConfiguration getConfiguration() { 072 return configuration; 073 } 074 075 public ValueSemanticsProviderContext getContext() { 076 if (context == null) { 077 context = new ValueSemanticsProviderContext(getDeploymentCategory(), authenticationSessionProvider, getSpecificationLoader(), adapterManager, servicesInjector); 078 } 079 return context; 080 } 081 082 @Override 083 public void setConfiguration(final IsisConfiguration configuration) { 084 this.configuration = configuration; 085 } 086 087 @Override 088 public void setAuthenticationSessionProvider(final AuthenticationSessionProvider authenticationSessionProvider) { 089 this.authenticationSessionProvider = authenticationSessionProvider; 090 } 091 092 @Override 093 public void setAdapterManager(final AdapterManager adapterManager) { 094 this.adapterManager = adapterManager; 095 } 096 097 @Override 098 public void setServicesInjector(final ServicesInjector dependencyInjector) { 099 this.servicesInjector = dependencyInjector; 100 } 101 102 @Override 103 public void setRuntimeContext(RuntimeContext runtimeContext) { 104 this.runtimeContext = runtimeContext; 105 } 106 107}