1818package com .cloud .utils .component ;
1919
2020import java .util .ArrayList ;
21+ import java .util .Collection ;
2122import java .util .HashMap ;
2223import java .util .List ;
2324import java .util .Map ;
2425
25- import javax .inject . Inject ;
26+ import javax .annotation . PostConstruct ;
2627import javax .naming .ConfigurationException ;
2728
2829import org .apache .log4j .Logger ;
5051public class ComponentContext implements ApplicationContextAware {
5152 private static final Logger s_logger = Logger .getLogger (ComponentContext .class );
5253
53- private static ApplicationContext s_appContext ;
54+ private static ApplicationContext s_appContext ;
5455
55- @ Inject List <GenericDao > daos ;
56- @ Inject List <Manager > mgrs ;
57- @ Inject List <Adapter > adapters ;
58-
5956 @ Override
6057 public void setApplicationContext (ApplicationContext applicationContext ) {
61- s_appContext = applicationContext ;
58+ s_appContext = applicationContext ;
6259 }
6360
6461 public static ApplicationContext getApplicationContext () {
6562 return s_appContext ;
66- }
67-
68- public void init () {
63+ }
64+
65+ public void initComponentsLifeCycle () {
66+ @ SuppressWarnings ("rawtype" )
67+ Collection <GenericDao > daos = ComponentContext .getApplicationContext ().getBeansOfType (GenericDao .class ).values ();
68+ Collection <Manager > mgrs = ComponentContext .getApplicationContext ().getBeansOfType (Manager .class ).values ();
69+ Collection <Adapter > adapters = ComponentContext .getApplicationContext ().getBeansOfType (Adapter .class ).values ();
70+
6971 Map <String , Object > params = new HashMap <String , Object >();
7072 for (GenericDao dao : daos ) {
7173 try {
@@ -77,7 +79,7 @@ public void init() {
7779 }
7880 }
7981
80- List <String > avoidMap = new ArrayList <String >();
82+ List <String > avoidMap = new ArrayList <String >();
8183 for (Manager manager : mgrs ) {
8284 if (avoidMap .contains (manager .getName ())) {
8385 s_logger .info ("Skip manager: " + ComponentContext .getTargetClass (manager ).getName () + " as it is already started" );
0 commit comments