コード例 #1
0
 private String findInputMethod(Class<?> actionClass, Mapping mapping) {
   for (Method method : actionClass.getMethods()) {
     final Input input = method.getAnnotation(Input.class);
     if (input != null) {
       return mapping.path() + INPUT_PAGE_AND_METHOD + method.getName();
     }
   }
   return mapping.path() + INPUT_DEFAULT_PAGE_AND_METHOD;
 }
コード例 #2
0
  @Override
  public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {

    if (!initialized) {
      loadActionsFromFile(actionClasses);
      PartialTileDefinition.init();
      initialized = true;
    }

    final String modulePrefix = StringUtils.removeStart(config.getPrefix(), "/");

    for (Class<?> actionClass : actionClasses) {
      Mapping mapping = actionClass.getAnnotation(Mapping.class);
      if (mapping == null || !modulePrefix.equals(mapping.module())) {
        continue;
      }

      final ActionMapping actionMapping = createCustomActionMapping(mapping);
      if (actionMapping == null) {
        continue;
      }

      actionMapping.setPath(mapping.path());
      actionMapping.setType(actionClass.getName());
      actionMapping.setScope(mapping.scope());
      actionMapping.setParameter(mapping.parameter());
      actionMapping.setValidate(mapping.validate());

      if (mapping.formBeanClass() != ActionForm.class) {
        final String formName = mapping.formBeanClass().getName();
        createFormBeanConfigIfNecessary(config, mapping, formName);
        actionMapping.setName(formName);
      } else if (!mapping.formBean().isEmpty()) {
        actionMapping.setName(mapping.formBean());
      }

      if (mapping.input().isEmpty()) {
        actionMapping.setInput(findInputMethod(actionClass, mapping));
      } else {
        registerInput(actionMapping, mapping.input());
      }

      String defaultResourcesName = getDefaultResourcesName(config);
      Forwards forwards = actionClass.getAnnotation(Forwards.class);
      if (forwards != null) {
        for (final Forward forward : forwards.value()) {
          registerForward(actionMapping, forward, forwards, mapping, defaultResourcesName);
        }
      }
      registerSuperclassForwards(
          actionMapping, actionClass.getSuperclass(), mapping, defaultResourcesName);

      Exceptions exceptions = actionClass.getAnnotation(Exceptions.class);
      if (exceptions != null) {
        registerExceptionHandling(actionMapping, exceptions);
      }

      initializeActionMappingProperties(actionMapping, mapping.customMappingProperties());

      config.addActionConfig(actionMapping);
    }
  }