private static IAutoTextEventHandler getEventHandler(
     ReportItemDesign design, ExecutionContext context) {
   try {
     return (IAutoTextEventHandler) getInstance(design, context);
   } catch (ClassCastException e) {
     addClassCastException(context, e, design.getHandle(), IAutoTextEventHandler.class);
   } catch (EngineException e) {
     addException(context, e, design.getHandle());
   }
   return null;
 }
 public static void handleOnPageBreak(IAutoTextContent content, ExecutionContext context) {
   Object generateBy = content.getGenerateBy();
   if (generateBy == null) {
     return;
   }
   ReportItemDesign autoTextDesign = (ReportItemDesign) generateBy;
   try {
     if (!needOnPageBreak(autoTextDesign)) {
       return;
     }
     // fromGrid doesn't matter here since row data is null
     IAutoTextInstance autoText = new AutoTextInstance(content, context, RunningState.PAGEBREAK);
     if (handleScript(autoText, autoTextDesign.getOnPageBreak(), context).didRun()) return;
     IAutoTextEventHandler eh = getEventHandler(autoTextDesign, context);
     if (eh != null) eh.onPageBreak(autoText, context.getReportContext());
   } catch (Exception e) {
     addException(context, e, autoTextDesign.getHandle());
   }
 }
  public static void handleOnCreate(IAutoTextContent content, ExecutionContext context) {
    Object generateBy = content.getGenerateBy();
    if (generateBy == null) {
      return;
    }
    ReportItemDesign autoTextItemDesign = (ReportItemDesign) generateBy;
    try {
      if (!needOnCreate(autoTextItemDesign)) {
        return;
      }
      IAutoTextInstance autoText = new AutoTextInstance(content, context, RunningState.CREATE);
      if (handleScript(autoText, autoTextItemDesign.getOnCreate(), context).didRun()) return;
      IAutoTextEventHandler eh = getEventHandler(autoTextItemDesign, context);
      if (eh != null) eh.onCreate(autoText, context.getReportContext());

    } catch (Exception e) {
      addException(context, e, autoTextItemDesign.getHandle());
    }
  }