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    
020    package org.apache.isis.core.progmodel.facets.object.value;
021    
022    import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider;
023    import org.apache.isis.core.commons.authentication.AuthenticationSessionProviderAware;
024    import org.apache.isis.core.commons.config.IsisConfiguration;
025    import org.apache.isis.core.commons.config.IsisConfigurationAware;
026    import org.apache.isis.core.metamodel.adapter.map.AdapterMap;
027    import org.apache.isis.core.metamodel.adapter.map.AdapterMapAware;
028    import org.apache.isis.core.metamodel.facetapi.Facet;
029    import org.apache.isis.core.metamodel.facetapi.FacetUtil;
030    import org.apache.isis.core.metamodel.facetapi.FeatureType;
031    import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
032    import org.apache.isis.core.metamodel.runtimecontext.DependencyInjector;
033    import org.apache.isis.core.metamodel.runtimecontext.DependencyInjectorAware;
034    
035    public abstract class ValueUsingValueSemanticsProviderFacetFactory<T> extends FacetFactoryAbstract implements
036        IsisConfigurationAware, AuthenticationSessionProviderAware, AdapterMapAware, DependencyInjectorAware {
037    
038        private IsisConfiguration configuration;
039        private AuthenticationSessionProvider authenticationSessionProvider;
040        private AdapterMap adapterManager;
041        private DependencyInjector dependencyInjector;
042        /**
043         * Lazily created.
044         */
045        private ValueSemanticsProviderContext context;
046    
047        protected ValueUsingValueSemanticsProviderFacetFactory(final Class<? extends Facet> adapterFacetType) {
048            super(FeatureType.OBJECTS_ONLY);
049        }
050    
051        protected void addFacets(final ValueSemanticsProviderAndFacetAbstract<T> adapter) {
052            final ValueFacetUsingSemanticsProvider facet =
053                new ValueFacetUsingSemanticsProvider(adapter, adapter, getContext());
054            FacetUtil.addFacet(facet);
055        }
056    
057        // ////////////////////////////////////////////////////
058        // Dependencies (injected via setter)
059        // ////////////////////////////////////////////////////
060    
061        public IsisConfiguration getConfiguration() {
062            return configuration;
063        }
064    
065        public ValueSemanticsProviderContext getContext() {
066            if (context == null) {
067                context =
068                    new ValueSemanticsProviderContext(authenticationSessionProvider, getSpecificationLookup(),
069                        adapterManager, dependencyInjector);
070            }
071            return context;
072        }
073    
074        @Override
075        public void setIsisConfiguration(final IsisConfiguration configuration) {
076            this.configuration = configuration;
077        }
078    
079        @Override
080        public void setAuthenticationSessionProvider(final AuthenticationSessionProvider authenticationSessionProvider) {
081            this.authenticationSessionProvider = authenticationSessionProvider;
082        }
083    
084        @Override
085        public void setAdapterMap(final AdapterMap adapterManager) {
086            this.adapterManager = adapterManager;
087        }
088    
089        @Override
090        public void setDependencyInjector(final DependencyInjector dependencyInjector) {
091            this.dependencyInjector = dependencyInjector;
092        }
093    
094    }