public void configure(Container container) { for (Class<?> clazz : getClasses(container)) { try { processClass(clazz, container); } catch (Exception ex) { Loggers.STARTUP.error("Failed to process class: " + clazz.getName(), ex); } } }
/** * Process the annotations on a given class * @param clazz The class to search for annotations * @param container The IoC container to configure * @throws IllegalAccessException If annotation processing fails * @throws InstantiationException If annotation processing fails */ protected void processClass(Class<?> clazz, Container container) throws InstantiationException, IllegalAccessException { RemoteProxy createAnn = clazz.getAnnotation(RemoteProxy.class); if (createAnn != null) { processCreate(clazz, createAnn, container); } DataTransferObject convertAnn = clazz.getAnnotation(DataTransferObject.class); if (convertAnn != null) { processConvert(clazz, convertAnn, container); } GlobalFilter globalFilterAnn = clazz.getAnnotation(GlobalFilter.class); if (globalFilterAnn != null) { processGlobalFilter(clazz, globalFilterAnn, container); } }
params.putAll(getParamsMap(createAnn.creatorParams())); if (createAnn.name() != null && !createAnn.name().equals("")) for (Filter filter : fs) processFilter(filter, scriptName, container); if (filterAnn != null) processFilter(filterAnn, scriptName, container);
/** * Global Filters apply to all classes * @param clazz The class to use as a filter * @param globalFilterAnn The filter annotation * @param container The IoC container to configure * @throws InstantiationException In case we can't create the given clazz * @throws IllegalAccessException In case we can't create the given clazz */ protected void processGlobalFilter(Class<?> clazz, GlobalFilter globalFilterAnn, Container container) throws InstantiationException, IllegalAccessException { if (!AjaxFilter.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException(clazz.getName() + " is not an AjaxFilter implementation"); } Map<String, String> filterParams = getParamsMap(globalFilterAnn.params()); AjaxFilter filter = (AjaxFilter) clazz.newInstance(); if (filter != null) { LocalUtil.setParams(filter, filterParams, null); AjaxFilterManager filterManager = container.getBean(AjaxFilterManager.class); filterManager.addAjaxFilter(filter); } }
/** * Annotations must not break 1.3, so we use reflection to create an * <code>org.directwebremoting.annotations.AnnotationsConfigurator</code> * and the catch all sorts of random exceptions for the benefit of * Websphere. * @param container The container to configure * @return true if the configuration worked. */ public static boolean configureFromAnnotations(Container container) { Object data = container.getBean("classes"); if (null != data) { Configurator configurator = new AnnotationsConfigurator(); configurator.configure(container); Loggers.STARTUP.debug("Java5 AnnotationsConfigurator enabled"); return true; } return false; }
Map<String, String> params = getParamsMap(convertAnn.params()); if (LocalUtil.hasText(convertAnn.javascript()))
/** * Process the @Filter annotation * @param filterAnn The filter annotation * @param name The Javascript name of the class to filter * @param container The IoC container to configure */ protected void processFilter(Filter filterAnn, String name, Container container) { Map<String, String> filterParams = getParamsMap(filterAnn.params()); AjaxFilter filter = LocalUtil.classNewInstance(name, filterAnn.type().getName(), AjaxFilter.class); if (filter != null) { LocalUtil.setParams(filter, filterParams, null); AjaxFilterManager filterManager = container.getBean(AjaxFilterManager.class); filterManager.addAjaxFilter(filter, name); } }