Coverage Report - org.apache.commons.inject.impl.AbstractBaseProvider
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractBaseProvider
100%
11/11
50%
1/2
1,25
 
 1  
 /**
 2  
  Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  contributor license agreements.  See the NOTICE file distributed with
 4  
  this work for additional information regarding copyright ownership.
 5  
  The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  (the "License"); you may not use this file except in compliance with
 7  
  the License.  You may obtain a copy of the License at
 8  
 
 9  
       http://www.apache.org/licenses/LICENSE-2.0
 10  
 
 11  
  Unless required by applicable law or agreed to in writing, software
 12  
  distributed under the License is distributed on an "AS IS" BASIS,
 13  
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  See the License for the specific language governing permissions and
 15  
  limitations under the License.
 16  
 */
 17  
 package org.apache.commons.inject.impl;
 18  
 
 19  
 import org.apache.commons.inject.api.IInjector;
 20  
 import org.apache.commons.inject.api.IPoint;
 21  
 import org.apache.commons.inject.api.IProvider;
 22  
 
 23  
 /**
 24  
  * Abstract implementation of a base provider: In general, bindings are using
 25  
  * a {@link AbstractScopedProvider scoped provider}, which controls the bindings
 26  
  * scope ({@code When} is the instance created?) The actual instantiation, and
 27  
  * the injection of values, is delegated to the base provider. ({@code How} is
 28  
  * the instance created?)
 29  
  */
 30  
 public abstract class AbstractBaseProvider<T> implements IProvider<T>, IInjectorAware {
 31  
         private final Class<T> type;
 32  
         private final IPoint<T> point;
 33  
 
 34  
         /**
 35  
          * Creates a new base provider.
 36  
          * @param pType The type of the instance, which is being created
 37  
          * by the provider.
 38  
          * @param pPoint The point, which is being used to inject values
 39  
          * into the created instance.
 40  
          */
 41  36
         protected AbstractBaseProvider(Class<T> pType, IPoint<T> pPoint) {
 42  36
                 type = pType;
 43  36
                 point = pPoint;
 44  36
         }
 45  
 
 46  
         @Override
 47  
         public T get(IInjector pInjector) {
 48  221
                 final T t = get();
 49  221
                 point.injectTo(t, pInjector);
 50  221
                 return t;
 51  
         }
 52  
 
 53  
         @Override
 54  
         public Class<T> getType() {
 55  163
                 return type;
 56  
         }
 57  
 
 58  
         @Override
 59  
         public void init(IInjector pInjector) {
 60  122
                 if (point instanceof IInjectorAware) {
 61  122
                         ((IInjectorAware) point).init(pInjector);
 62  
                 }
 63  122
         }
 64  
 }