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    public <T> T getService(String serviceId, Class<T> serviceInterface)
039    {
040        String expandedServiceId = registry.expandSymbols(serviceId);
041
042        return registry.getService(expandedServiceId, serviceInterface);
043    }
044
045    public <T> T getService(Class<T> serviceInterface)
046    {
047        return registry.getService(serviceInterface);
048    }
049
050    public <T> T getService(Class<T> serviceInterface, Class<? extends Annotation>... markerTypes)
051    {
052        return registry.getService(serviceInterface, markerTypes);
053    }
054
055    public <T> T getObject(Class<T> objectType, AnnotationProvider annotationProvider)
056    {
057        return registry.getObject(objectType, annotationProvider, this, module);
058    }
059
060    public <T> T autobuild(Class<T> clazz)
061    {
062        return registry.autobuild(clazz);
063    }
064
065    public <T> T autobuild(String description, Class<T> clazz)
066    {
067        return registry.autobuild(description, clazz);
068    }
069
070    public <T> T proxy(Class<T> interfaceClass, Class<? extends T> implementationClass)
071    {
072        return registry.proxy(interfaceClass, implementationClass, this);
073    }
074}