001/**
002 * Copyright 2013 John Ericksen
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *    http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.androidtransfuse.analysis.repository;
017
018import org.androidtransfuse.adapter.ASTType;
019import org.androidtransfuse.adapter.classes.ASTClassFactory;
020import org.androidtransfuse.annotations.TransfuseModule;
021import org.androidtransfuse.gen.scopeBuilder.CustomScopeAspectFactoryFactory;
022import org.androidtransfuse.gen.scopeBuilder.SingletonScopeAspectFactory;
023import org.androidtransfuse.scope.ApplicationScope;
024import org.androidtransfuse.scope.ConcurrentDoubleLockingScope;
025
026import javax.inject.Inject;
027import javax.inject.Provider;
028import javax.inject.Singleton;
029
030/**
031 * @author John Ericksen
032 */
033public class ScopeAspectFactoryRepositoryProvider implements Provider<InjectionNodeBuilderRepository> {
034
035    private final SingletonScopeAspectFactory singletonScopeAspectFactory;
036    private final CustomScopeAspectFactoryFactory customScopeAspectFactoryFactory;
037    private final ASTClassFactory astClassFactory;
038
039    @Inject
040    public ScopeAspectFactoryRepositoryProvider(SingletonScopeAspectFactory singletonScopeAspectFactory,
041                                                CustomScopeAspectFactoryFactory customScopeAspectFactoryFactory,
042                                                ASTClassFactory astClassFactory) {
043        this.singletonScopeAspectFactory = singletonScopeAspectFactory;
044        this.customScopeAspectFactoryFactory = customScopeAspectFactoryFactory;
045        this.astClassFactory = astClassFactory;
046    }
047
048
049    @Override
050    public InjectionNodeBuilderRepository get() {
051        InjectionNodeBuilderRepository scopedVariableBuilderRepository = new InjectionNodeBuilderRepository(astClassFactory);
052
053        ASTType concurrentScopeType = astClassFactory.getType(ConcurrentDoubleLockingScope.class);
054
055        scopedVariableBuilderRepository.putScopeAspectFactory(astClassFactory.getType(TransfuseModule.class), concurrentScopeType, singletonScopeAspectFactory);
056        scopedVariableBuilderRepository.putScopeAspectFactory(astClassFactory.getType(Singleton.class), concurrentScopeType, singletonScopeAspectFactory);
057        scopedVariableBuilderRepository.putScopeAspectFactory(
058                astClassFactory.getType(ApplicationScope.ApplicationScopeQualifier.class),
059                astClassFactory.getType(ApplicationScope.class), customScopeAspectFactoryFactory.buildScopeBuilder(astClassFactory.getType(ApplicationScope.ApplicationScopeQualifier.class)));
060
061        return scopedVariableBuilderRepository;
062    }
063}