public synchronized Object ensureControl ( ) { if ( _control == null ) { // // See if the property map specifies an implementation class for the control; // if not, use default binding. // String implBinding = null ; BaseProperties bp = _properties . getPropertySet ( BaseProperties . class ) ; if ( bp != null ) implBinding = bp . controlImplementation ( ) ; else implBinding = ControlUtils . getDefaultControlBinding ( _controlIntf ) ; try { _implClass = _controlIntf . getClassLoader ( ) . loadClass ( implBinding ) ; // // Validate that the specified implementation class has an @ControlImplementation // annotation, else downstream requirements (such as having a valid control init // class) will not be met. // if ( _implClass . getAnnotation ( ControlImplementation . class ) == null ) { throw new ControlException ( "@" + ControlImplementation . class . getName ( ) + " annotation is missing from control implementation class: " + _implClass . getName ( ) ) ; } } catch ( ClassNotFoundException cnfe ) { throw new ControlException ( "Unable to load control implementation: " + implBinding , cnfe ) ; } // // Cache the threading policy associated with the impl // Threading thr = ( Threading ) _implClass . getAnnotation ( Threading . class ) ; if ( thr != null ) _threadingPolicy = thr . value ( ) ; else _threadingPolicy = ThreadingPolicy . SINGLE_THREADED ; // default to single-threaded ensureThreadingBehaviour ( ) ; try { // // Create and initialize the new instance // _control = _implClass . newInstance ( ) ; try { /* Run the ImplInitializer. This class is code generated based on metadata from a control implementation. If a Control implementation declares event handlers for the ControlBeanContext or for the ResourceContext, executing this code generated class will add the appropriate LifeCycle and / or Resource event listeners. */ getImplInitializer ( ) . initialize ( this , _control ) ; _hasServices = true ; } catch ( Exception e ) { throw new ControlException ( "Control initialization failure" , e ) ; } // // Once the control is initialized, then allow the associated context // to do any initialization. // ControlBeanContext cbcs = getBeanContextProxy ( ) ; /* Implementation note: this call will run the LifeCycleListener(s) that have been wired-up to the ControlBeanContext object associated with this ControlBean. */ cbcs . initializeControl ( ) ; } catch ( RuntimeException re ) { // never mask RuntimeExceptions throw re ; } catch ( Exception e ) { throw new ControlException ( "Unable to create control instance" , e ) ; } } // // If the implementation instance does not currently have contextual services, they // are lazily restored here. // if ( ! _hasServices ) { getImplInitializer ( ) . initServices ( this , _control ) ; _hasServices = true ; } return _control ; }
Returns the target control instance associated with this ControlBean performing lazy instantiation and initialization of the instance .