001    /*******************************************************************************
002     * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
003     * Thomschke.
004     * 
005     * All Rights Reserved. This program and the accompanying materials
006     * are made available under the terms of the Eclipse Public License v1.0
007     * which accompanies this distribution, and is available at
008     * http://www.eclipse.org/legal/epl-v10.html
009     * 
010     * Contributors:
011     *     Sebastian Thomschke - initial implementation.
012     *******************************************************************************/
013    package net.sf.oval.integration.spring;
014    
015    import net.sf.oval.Check;
016    import net.sf.oval.configuration.CheckInitializationListener;
017    import net.sf.oval.constraint.CheckWithCheck;
018    
019    /**
020     * Injects Spring bean dependencies into {@link Check} instances.
021     * 
022     * Required dependencies must be annotated with <code>@Autowired</code> within {@link Check} the class.
023     * 
024     * Requires the {@link SpringInjector} be setup correctly.
025     * 
026     * @author Sebastian Thomschke
027     */
028    public class BeanInjectingCheckInitializationListener implements CheckInitializationListener
029    {
030            public static final BeanInjectingCheckInitializationListener INSTANCE = new BeanInjectingCheckInitializationListener();
031    
032            /**
033             * {@inheritDoc}
034             */
035            public void onCheckInitialized(final Check check)
036            {
037                    SpringInjector.get().inject(check);
038    
039                    if (check instanceof CheckWithCheck)
040                    {
041                            final CheckWithCheck checkWith = (CheckWithCheck) check;
042                            SpringInjector.get().inject(checkWith.getSimpleCheck());
043                    }
044            }
045    }