Coverage Report - org.apache.commons.inject.impl.BindingProxy
 
Classes in this File Line Coverage Branch Coverage Complexity
BindingProxy
72%
16/22
40%
4/10
2
 
 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.IPoint;
 22  
 import org.apache.commons.inject.api.IProvider;
 23  
 
 24  
 public class BindingProxy<T> implements IBinding<T>, IInjectorAware {
 25  
         private IBinding<T> binding;
 26  
         private boolean initialized;
 27  
         private boolean isResolvedLater;
 28  
         private final String cause;
 29  23
         private final RuntimeException rte = new RuntimeException();
 30  
 
 31  23
         public BindingProxy(String pCause) {
 32  23
                 cause = pCause;
 33  23
         }
 34  
 
 35  
         public boolean isResolvedLater() {
 36  23
                 return isResolvedLater;
 37  
         }
 38  
 
 39  
         public void setResolvedLater(boolean pResolvedLater) {
 40  9
                 isResolvedLater = pResolvedLater;
 41  9
         }
 42  
         
 43  
         @Override
 44  
         public synchronized IProvider<T> getProvider() {
 45  199
                 if (!initialized) {
 46  0
                         throw new IllegalStateException("This Binding hasn't been initialized.", rte);
 47  
                 }
 48  199
                 return binding.getProvider();
 49  
         }
 50  
 
 51  
         @Override
 52  
         public IPoint<T> getPoint() {
 53  0
                 if (!initialized) {
 54  0
                         throw new IllegalStateException("This Binding hasn't been initialized.");
 55  
                 }
 56  0
                 return binding.getPoint();
 57  
         }
 58  
 
 59  
         public synchronized void setBinding(IBinding<T> pBinding) {
 60  23
                 if (pBinding == null) {
 61  0
                         throw new NullPointerException("The proxied binding must not be null.");
 62  
                 }
 63  23
                 binding = pBinding;
 64  23
                 initialized = true;
 65  23
         }
 66  
 
 67  
         public String getCause() {
 68  0
                 return cause;
 69  
         }
 70  
 
 71  
         @Override
 72  
         public void init(IInjector pInjector) {
 73  169
                 if (binding != null  &&  binding instanceof IInjectorAware) {
 74  169
                         ((IInjectorAware) binding).init(pInjector);
 75  
                 }
 76  169
         }
 77  
 }