001// Copyright 2006, 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007//     http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.tapestry5.ioc.internal;
016
017import org.apache.tapestry5.ioc.AnnotationProvider;
018import org.apache.tapestry5.ioc.ObjectLocator;
019
020import java.lang.annotation.Annotation;
021
022/**
023 * Base service locator class used when only the module is known (i.e., when instantiating a module
024 * class).
025 */
026public class ObjectLocatorImpl implements ObjectLocator
027{
028    private final InternalRegistry registry;
029
030    private final Module module;
031
032    public ObjectLocatorImpl(InternalRegistry registry, Module module)
033    {
034        this.registry = registry;
035        this.module = module;
036    }
037
038    @Override
039    public <T> T getService(String serviceId, Class<T> serviceInterface)
040    {
041        String expandedServiceId = registry.expandSymbols(serviceId);
042
043        return registry.getService(expandedServiceId, serviceInterface);
044    }
045
046    @Override
047    public <T> T getService(Class<T> serviceInterface)
048    {
049        return registry.getService(serviceInterface);
050    }
051
052    @Override
053    public <T> T getService(Class<T> serviceInterface, Class<? extends Annotation>... markerTypes)
054    {
055        return registry.getService(serviceInterface, markerTypes);
056    }
057
058    @Override
059    public <T> T getObject(Class<T> objectType, AnnotationProvider annotationProvider)
060    {
061        return registry.getObject(objectType, annotationProvider, this, module);
062    }
063
064    @Override
065    public <T> T autobuild(Class<T> clazz)
066    {
067        return registry.autobuild(clazz);
068    }
069
070    @Override
071    public <T> T autobuild(String description, Class<T> clazz)
072    {
073        return registry.autobuild(description, clazz);
074    }
075
076    @Override
077    public <T> T proxy(Class<T> interfaceClass, Class<? extends T> implementationClass)
078    {
079        return registry.proxy(interfaceClass, implementationClass, this);
080    }
081}