jdave.injection
Class InjectionSupport

java.lang.Object
  extended by jdave.injection.InjectionSupport

public class InjectionSupport
extends java.lang.Object

Support class to inject values to specifications. This can be used to inject e.g. beans in Spring context into Specification.

 public class MySpecification extends Specification<Something> {
     private SomeInjectedField field;
     
     public MySpecification() {
         new InjectionSupport().inject(this, new SpringInjector());
     }
     
     public class SomeContext {
         ...
     }
 }
 
 public class SpringInjector implements IFieldInjector {
     private BeanFactory factory = new ClassPathXmlApplicationContext("/myAppContext.xml");

     public void inject(Field field) {
         if (factory.containsBean(field.field().getName())) {
             field.set(factory.getBean(field.field().getName()));
         }
     }
 }
 

Author:
Joni Freeman

Constructor Summary
InjectionSupport()
           
InjectionSupport(int modifiers)
           
 
Method Summary
 void inject(java.lang.Object object, IFieldInjector injector)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InjectionSupport

public InjectionSupport()

InjectionSupport

public InjectionSupport(int modifiers)
Method Detail

inject

public void inject(java.lang.Object object,
                   IFieldInjector injector)


Copyright © 2008. All Rights Reserved.