Coverage Report - org.apache.commons.inject.impl.DefaultInjector
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultInjector
23%
5/21
0%
0/2
1,6
DefaultInjector$1
0%
0/5
0%
0/2
1,6
 
 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.IBinding;
 20  
 import org.apache.commons.inject.api.IInjector;
 21  
 import org.apache.commons.inject.api.IKey;
 22  
 import org.apache.commons.inject.api.IPoint;
 23  
 import org.apache.commons.inject.api.IProvider;
 24  
 import org.apache.commons.inject.api.NoSuchBindingException;
 25  
 import org.apache.commons.inject.impl.AbstractBindingSet.MappedKey;
 26  
 import org.apache.commons.inject.impl.AbstractBindingSet.ReducedKey;
 27  
 import org.apache.commons.inject.impl.bind.DefaultBinding;
 28  
 
 29  
 /**
 30  
  * Default implementation of an {@link IInjector injector}.
 31  
  */
 32  0
 public class DefaultInjector extends AbstractInjector {
 33  
         private final ImmutableBindingSet bindings;
 34  
         
 35  9
         public DefaultInjector(ImmutableBindingSet pBindings) {
 36  9
                 bindings = pBindings;
 37  9
         }
 38  
 
 39  
         protected <T> IBinding<T> getBinding(IKey<T> pKey) {
 40  27
                 synchronized(bindings) {
 41  27
                         return bindings.getBinding(pKey);
 42  0
                 }
 43  
         }
 44  
         
 45  
         protected <T> IBinding<T> requireBinding(IKey<T> pKey) {
 46  0
                 synchronized(bindings) {
 47  
                         IBinding<T> binding;
 48  0
                         binding = bindings.getBinding(pKey);
 49  0
                         if (binding == null) {
 50  0
                                 final IMutableBindingSource bindingSource = getBindingSource();
 51  0
                                 final Class<T> cl = pKey.getType();
 52  0
                                 final IPoint<T> point = Introspector.getInstance().getPoint(cl, bindingSource);
 53  0
                                 final IProvider<T> provider = Introspector.getInstance().getProvider(cl, point, bindingSource);
 54  0
                                 binding = new DefaultBinding<T>(provider, point);
 55  0
                                 final ReducedKey<T> rkey = new ReducedKey<T>(cl, pKey.getName());
 56  0
                                 final MappedKey<T> key = new MappedKey<T>(cl, pKey.getName(), null, null);
 57  0
                                 bindings.add(rkey, key, binding);
 58  
                         }
 59  0
                         return binding;
 60  0
                 }
 61  
         }
 62  
 
 63  
         protected IMutableBindingSource getBindingSource() {
 64  0
                 return new IMutableBindingSource() {
 65  
                         @Override
 66  
                         public <T> IBinding<T> requireBinding(IKey<T> pKey, String pCause) {
 67  0
                                 final IBinding<T> binding = bindings.getBinding(pKey);
 68  0
                                 if (binding == null) {
 69  0
                                         throw new NoSuchBindingException("No binding registered for key: " + pKey);
 70  
                                 }
 71  0
                                 return binding;
 72  
                         }
 73  
                         
 74  
                 };
 75  
         }
 76  
         
 77  
 }