imagebeancontextchildsupport.java

来自「程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件」· Java 代码 · 共 92 行

JAVA
92
字号
package examples.beans;
import java.beans.beancontext.*;
import sunw.demo.methodtracer.MethodTracer;
/** This class provides the BeanContextChild support
  * used by the ImageBean4 class
  */
public class ImageBeanContextChildSupport
             extends BeanContextChildSupport
             implements BeanContextServicesListener {
   private Object requestor;
   private MethodTracer tracerService;
   /** Class constructor
     */
   public ImageBeanContextChildSupport( Object r ) {
      requestor = r;
   }
   /** 
     * 
     */
   protected void initializeBeanContextResources() {
      try {
         BeanContextServices bcs
            = (BeanContextServices) getBeanContext();
         if ( bcs.hasService( MethodTracer.class ) ) {
            tracerService
               = (MethodTracer) bcs.getService(
                    this,
                    requestor,
                    MethodTracer.class,
                    null,
                    this );
         } else {
            bcs.addBeanContextServicesListener( this );
         }
      } catch ( ClassCastException x ) {
         // The BeanContext of this object is not a 
         // BeanContextServices object, so there's nothing
         // to do
      } catch ( Exception x ) {
         x.printStackTrace();
      }
   }
   /** 
     * 
     */
   protected void releaseBeanContextServices() {
      if ( tracerService != null ) {
         tracerService = null;
      }
      try {
         BeanContextServices bcs
            = (BeanContextServices) getBeanContext();
         bcs.removeBeanContextServicesListener( this );
      } catch ( ClassCastException x ) {
         // The BeanContext of this object is not a 
         // BeanContextServices object, so there's nothing
         // to do
      } catch ( Exception x ) {
         x.printStackTrace();
      }
   }
   public void
   serviceRevoked( BeanContextServiceRevokedEvent e ) {
      if ( e.getServiceClass() == MethodTracer.class ) {
         tracerService = null;
      }
   }
   public void
   serviceAvailable( BeanContextServiceAvailableEvent e ) {
      try {
         if ( e.getServiceClass() == MethodTracer.class ) {
            BeanContextServices bcs
               = e.getSourceAsBeanContextServices();
            tracerService
               = (MethodTracer) bcs.getService(
                    this,
                    requestor,
                    MethodTracer.class,
                    null,
                    this );
         }
      } catch ( Exception x ) {
         x.printStackTrace();
      }
   }
   /** Return the tracer service object
     * @return the MethodTracer for this context
     */
   public MethodTracer getMethodTracer() {
      return tracerService;
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?