001/**
002 *  Licensed to the Apache Software Foundation (ASF) under one or more
003 *  contributor license agreements.  See the NOTICE file distributed with
004 *  this work for additional information regarding copyright ownership.
005 *  The ASF licenses this file to You under the Apache License, Version 2.0
006 *  (the "License"); you may not use this file except in compliance with
007 *  the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 *  Unless required by applicable law or agreed to in writing, software
012 *  distributed under the License is distributed on an "AS IS" BASIS,
013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 *  See the License for the specific language governing permissions and
015 *  limitations under the License.
016 */
017package org.apache.isis.core.metamodel.spec;
018
019import java.util.Collection;
020import java.util.List;
021
022/**
023 * Allows a {@link SpecificationLoader} to be provided even if the concrete
024 * implementation is only available later.
025 */
026public class SpecificationLoaderDelegator extends SpecificationLoaderAbstract {
027
028    private SpecificationLoader specificationLoaderDelegate;
029
030    public void setDelegate(final SpecificationLoader specificationLoaderDelegate) {
031        this.specificationLoaderDelegate = specificationLoaderDelegate;
032    }
033
034    @Override
035    public ObjectSpecification loadSpecification(final Class<?> cls) {
036        if (specificationLoaderDelegate == null) {
037            throw new IllegalStateException("No SpecificationLookup provided");
038        }
039        return specificationLoaderDelegate.loadSpecification(cls);
040    }
041
042    @Override
043    public Collection<ObjectSpecification> allSpecifications() {
044        return specificationLoaderDelegate.allSpecifications();
045    }
046
047    @Override
048    public ObjectSpecification lookupBySpecId(ObjectSpecId objectSpecId) {
049        return specificationLoaderDelegate.lookupBySpecId(objectSpecId);
050    }
051
052    @Override
053    public boolean loadSpecifications(List<Class<?>> typesToLoad, Class<?> typeToIgnore) {
054        return specificationLoaderDelegate.loadSpecifications(typesToLoad, typeToIgnore);
055    }
056
057    @Override
058    public ObjectSpecification loadSpecification(String fullyQualifiedClassName) {
059        return specificationLoaderDelegate.loadSpecification(fullyQualifiedClassName);
060    }
061
062    @Override
063    public boolean loaded(Class<?> cls) {
064        return specificationLoaderDelegate.loaded(cls);
065    }
066
067    @Override
068    public boolean loaded(String fullyQualifiedClassName) {
069        return specificationLoaderDelegate.loaded(fullyQualifiedClassName);
070    }
071
072    @Override
073    public boolean loadSpecifications(List<Class<?>> typesToLoad) {
074        return specificationLoaderDelegate.loadSpecifications(typesToLoad);
075    }
076
077    @Override
078    public ObjectSpecification introspectIfRequired(ObjectSpecification spec) {
079        return specificationLoaderDelegate.introspectIfRequired(spec);
080    }
081
082    
083    @Override
084    public List<Class<?>> getServiceClasses() {
085        return specificationLoaderDelegate.getServiceClasses();
086    }
087
088    @Override
089    public void invalidateCache(Class<?> domainClass) {
090        specificationLoaderDelegate.invalidateCache(domainClass);
091    }
092
093    @Override
094    public void injectInto(Object candidate) {
095        super.injectInto(candidate);
096        if(specificationLoaderDelegate != null) {
097            specificationLoaderDelegate.injectInto(candidate);
098        }
099    }
100
101
102
103}