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; }
private void createFormBeanConfigIfNecessary( ModuleConfig config, Mapping mapping, final String formName) { FormBeanConfig formBeanConfig = config.findFormBeanConfig(formName); if (formBeanConfig == null) { formBeanConfig = new FormBeanConfig(); formBeanConfig.setType(mapping.formBeanClass().getName()); formBeanConfig.setName(formName); config.addFormBeanConfig(formBeanConfig); } }
private static ActionMapping createCustomActionMapping(Mapping mapping) { try { return mapping.customMappingClass().newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; }
public PartialTileDefinition( Forward forward, Forwards forwards, Mapping mapping, String defaultBundleName) { Tile localTile = forward.tileProperties(); Tile globalTile = forwards.tileProperties(); path = forward.path(); extend = getDefinedValue(localTile.extend(), globalTile.extend(), getDefaultValue("extend")); title = getDefinedValue(localTile.title(), globalTile.title(), getDefaultValue("title")); customBundleName = getDefinedValue(localTile.bundle(), globalTile.bundle(), getDefaultValue("bundle")); this.defaultBundleName = (defaultBundleName == null) ? mapping.module() : defaultBundleName; for (Method tileMethod : tileMethods) { TileCustomPropertyName tileCustomProperty = tileMethod.getAnnotation(TileCustomPropertyName.class); String tileMethodName = (tileCustomProperty != null) ? tileCustomProperty.value() : tileMethod.getName(); String localValue = invokeAnnotationMethod(tileMethod, localTile); String globalValue = invokeAnnotationMethod(tileMethod, globalTile); attributeValues.put( tileMethodName, getDefinedValue(localValue, globalValue, (String) tileMethod.getDefaultValue())); attributeDefaults.put(tileMethodName, (String) tileMethod.getDefaultValue()); } }
@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); } }