Example #1
0
  private static ComponentImpl _loadComponent(
      PageContext pc,
      CIPage page,
      String callPath,
      boolean isRealPath,
      boolean isExtendedComponent,
      boolean executeConstr)
      throws PageException {
    ComponentImpl rtn = null;
    if (pc.getConfig().debug()) {
      DebugEntryTemplate debugEntry = pc.getDebugger().getEntry(pc, page.getPageSource());
      pc.addPageSource(page.getPageSource(), true);

      int currTime = pc.getExecutionTime();
      long exeTime = 0;
      long time = System.nanoTime();
      try {
        debugEntry.updateFileLoadTime((int) (System.nanoTime() - time));
        exeTime = System.nanoTime();
        rtn = initComponent(pc, page, callPath, isRealPath, isExtendedComponent, executeConstr);

      } finally {
        if (rtn != null) rtn.setLoaded(true);
        int diff = ((int) (System.nanoTime() - exeTime) - (pc.getExecutionTime() - currTime));
        pc.setExecutionTime(pc.getExecutionTime() + (int) (System.nanoTime() - time));
        debugEntry.updateExeTime(diff);
        pc.removeLastPageSource(true);
      }
    }
    // no debug
    else {
      pc.addPageSource(page.getPageSource(), true);
      try {
        rtn = initComponent(pc, page, callPath, isRealPath, isExtendedComponent, executeConstr);
      } finally {
        if (rtn != null) rtn.setLoaded(true);
        pc.removeLastPageSource(true);
      }
    }

    return rtn;
  }
Example #2
0
  private static ComponentImpl initComponent(
      PageContext pc,
      CIPage page,
      String callPath,
      boolean isRealPath,
      boolean isExtendedComponent,
      boolean executeConstr)
      throws PageException {
    // is not a component, then it has to be a interface
    if (!(page instanceof ComponentPageImpl))
      throw new ApplicationException(
          "you cannot instantiate the interface ["
              + page.getPageSource().getDisplayPath()
              + "] as a component ("
              + page.getClass().getName()
              + ""
              + (page instanceof InterfacePageImpl)
              + ")");

    ComponentPageImpl cp = (ComponentPageImpl) page;
    ComponentImpl c = cp.newInstance(pc, callPath, isRealPath, isExtendedComponent, executeConstr);

    // abstract/final check
    if (!isExtendedComponent) {
      if (c.getModifier() == Component.MODIFIER_ABSTRACT)
        throw new ApplicationException(
            "you cannot instantiate an abstract component ["
                + page.getPageSource().getDisplayPath()
                + "], this component can only be extended by other components");
    } else if (c.getModifier() == Component.MODIFIER_FINAL)
      throw new ApplicationException(
          "you cannot extend a final component [" + page.getPageSource().getDisplayPath() + "]");

    c.setInitalized(true);
    return c;
  }