예제 #1
0
  private void generateEventsHandler() throws Exception {
    if (domain.getCrudevent() != null
        || (domain.getEvent() != null && !domain.getEvent().isEmpty())) {
      final ClassWriter classWriter =
          new ClassWriter(
              this,
              getSrcGeneratedDirectory(),
              GeneratorHelper.getEventPackage(domain),
              GeneratorHelper.getMasterHandlerClassName(domain));

      classWriter.setInterface(true);

      if (domain.getCrudevent() != null) {
        for (final String before : GeneratorHelper.getBeforeEventName()) {
          classWriter.addExtend(before + domain.getName() + "Handler");
        }
        for (final String after : GeneratorHelper.getAfterEventName()) {
          classWriter.addExtend(domain.getName() + after + "Handler");
        }
      }

      if (domain.getEvent() != null) {
        for (final Event event : domain.getEvent()) {
          classWriter.addExtend(GeneratorHelper.getHandlerClassName(event));
        }
      }

      classWriter.generateContentAndStore();
    }
  }
예제 #2
0
  private void generateEvent(final Event event) throws Exception {
    final ClassWriter classWriter =
        new ClassWriter(
            this,
            getSrcGeneratedDirectory(),
            GeneratorHelper.getEventPackage(domain),
            GeneratorHelper.getEventClassName(event));

    if (event.getParameter() != null) {
      for (final Parameter parameter : event.getParameter()) {
        classWriter.addClassMembers(parameter);
      }
    }

    classWriter.addExtend(GeneratorHelper.getBusinessEventExtends(event));

    // Constant
    classWriter.addConstants(
        "public static final com.ponysdk.core.event.Event.Type<"
            + GeneratorHelper.getHandlerClassName(event)
            + "> TYPE = new com.ponysdk.core.event.Event.Type<"
            + GeneratorHelper.getHandlerClassName(event)
            + ">();");

    // Build constructor
    final Parameter sourceComponentParameter = new Parameter();
    sourceComponentParameter.setName("sourceComponent");
    sourceComponentParameter.setClazz("java.lang.Object");
    final List<Parameter> superConstructorParameters = new ArrayList<Parameter>();
    superConstructorParameters.add(sourceComponentParameter);

    final List<Parameter> constructorParameters = new ArrayList<Parameter>(event.getParameter());
    constructorParameters.add(0, sourceComponentParameter);

    final Constructor constructor =
        new Constructor(constructorParameters, superConstructorParameters);
    classWriter.addConstructor(constructor);

    // Build methods
    classWriter.addLine("@Override");
    classWriter.addLine(
        "protected void dispatch(" + GeneratorHelper.getHandlerClassName(event) + " handler) {");
    classWriter.addLine("   handler.on" + event.getName() + "(this);");
    classWriter.addLine("}");
    classWriter.addNewLine();

    classWriter.addLine("@Override");
    classWriter.addLine(
        "public com.ponysdk.core.event.Event.Type<"
            + GeneratorHelper.getHandlerClassName(event)
            + "> getAssociatedType() {");
    classWriter.addLine("   return TYPE;");
    classWriter.addLine("}");

    // Adding
    classWriter.setGenerateGetter(true);
    classWriter.generateContentAndStore();
  }
예제 #3
0
  private void generateHandler(final Event event) throws Exception {
    final ClassWriter classWriter =
        new ClassWriter(
            this,
            getSrcGeneratedDirectory(),
            GeneratorHelper.getEventPackage(domain),
            GeneratorHelper.getHandlerClassName(event));

    classWriter.setInterface(true);
    classWriter.addExtend("com.ponysdk.core.event.EventHandler");

    // Build event method
    classWriter.addLine(
        "public void on"
            + event.getName()
            + "("
            + GeneratorHelper.getEventClassName(event)
            + " event);");

    classWriter.generateContentAndStore();
  }