View Javadoc
1   /*******************************************************************************
2    * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
3    * Thomschke.
4    *
5    * All Rights Reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    * http://www.eclipse.org/legal/epl-v10.html
9    *
10   * Contributors:
11   *     Sebastian Thomschke - initial implementation.
12   *******************************************************************************/
13  package net.sf.oval.integration.spring;
14  
15  import net.sf.oval.Check;
16  import net.sf.oval.configuration.CheckInitializationListener;
17  import net.sf.oval.constraint.CheckWithCheck;
18  
19  /**
20   * Injects Spring bean dependencies into {@link Check} instances.
21   *
22   * Required dependencies must be annotated with <code>@Autowired</code> within {@link Check} the class.
23   *
24   * Requires the {@link SpringInjector} be setup correctly.
25   *
26   * @author Sebastian Thomschke
27   */
28  public class SpringCheckInitializationListener implements CheckInitializationListener
29  {
30  	public static final SpringCheckInitializationListener INSTANCE = new SpringCheckInitializationListener();
31  
32  	public void onCheckInitialized(final Check check)
33  	{
34  		SpringInjector.get().inject(check);
35  
36  		if (check instanceof CheckWithCheck)
37  		{
38  			final CheckWithCheck checkWith = (CheckWithCheck) check;
39  			SpringInjector.get().inject(checkWith.getSimpleCheck());
40  		}
41  	}
42  }