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.processor;
017
018import com.sun.codemodel.JCodeModel;
019import com.sun.codemodel.JDefinedClass;
020import org.androidtransfuse.adapter.ASTType;
021import org.androidtransfuse.gen.FilerResourceWriter;
022import org.androidtransfuse.gen.FilerSourceCodeWriter;
023import org.androidtransfuse.transaction.TransactionProcessor;
024import org.androidtransfuse.transaction.TransactionProcessorBuilder;
025import org.androidtransfuse.transaction.TransactionProcessorPool;
026import org.androidtransfuse.transaction.TransactionWorker;
027
028import javax.inject.Inject;
029import javax.inject.Provider;
030
031/**
032 * Builds a Transaction supporting the AnalysisGeneration
033 *
034 * @author John Ericksen
035 */
036public class AnalysisGenerationTransactionProcessorBuilder implements TransactionProcessorBuilder<Provider<ASTType>, JDefinedClass> {
037
038    private final ScopedTransactionFactory scopedTransactionFactory;
039    private final TransactionProcessorPool<Provider<ASTType>, JDefinedClass> transactionProcessor;
040    private final CodeGenerationWrapperProvider<Provider<ASTType>, JDefinedClass> workerProvider;
041
042    @Inject
043    public AnalysisGenerationTransactionProcessorBuilder(
044            /*@Assisted*/ Provider<TransactionWorker<Provider<ASTType>, JDefinedClass>> workerProvider,
045            Provider<JCodeModel> codeModelProvider,
046            Provider<FilerSourceCodeWriter> sourceCodeWriterProvider,
047            Provider<FilerResourceWriter> resourceCodeWriterProvider,
048            ScopedTransactionFactory scopedTransactionFactory) {
049        this.scopedTransactionFactory = scopedTransactionFactory;
050        transactionProcessor = new TransactionProcessorPool<Provider<ASTType>, JDefinedClass>();
051        this.workerProvider = new CodeGenerationWrapperProvider<Provider<ASTType>, JDefinedClass>(workerProvider, codeModelProvider, sourceCodeWriterProvider, resourceCodeWriterProvider);
052    }
053
054    @Override
055    public void submit(Provider<ASTType> astTypeProvider) {
056        transactionProcessor.submit(scopedTransactionFactory.buildTransaction(astTypeProvider, workerProvider));
057    }
058
059    @Override
060    public TransactionProcessor<Provider<ASTType>, JDefinedClass> getTransactionProcessor() {
061        return transactionProcessor;
062    }
063}