org.apache.velocity.tools.config.DefaultKey Java Examples

The following examples show how to use org.apache.velocity.tools.config.DefaultKey. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassToolTests.java    From velocity-tools with Apache License 2.0 6 votes vote down vote up
public @Test void methodGetAnnotations() throws Exception
{
    ClassTool classTool = new ClassTool();
    // default type is java.lang.Object
    assertTrue(classTool.getAnnotations().isEmpty());
    classTool.setType(MyDeprecated.class);
    assertEquals(1, classTool.getAnnotations().size());
    classTool.setType(ValueParser.class);
    List<Annotation> annotations = classTool.getAnnotations();
    assertEquals(3, annotations.size());
    Collections.sort(annotations, new Comparator<Annotation>()
    {
        @Override
        public int compare(Annotation o1, Annotation o2)
        {
            return o1.toString().compareTo(o2.toString());
        }
    });
    assertTrue(annotations.get(0).annotationType() == DefaultKey.class);
    assertTrue(annotations.get(1).annotationType() == InvalidScope.class);
    assertTrue(annotations.get(2).annotationType() == SkipSetters.class);
}
 
Example #2
Source File: AnnotatedVelocityToolsScanner.java    From velocity-spring-boot-project with Apache License 2.0 4 votes vote down vote up
public AnnotatedVelocityToolsScanner() {
    provider.addIncludeFilter(new AnnotationTypeFilter(DefaultKey.class));
}
 
Example #3
Source File: AnnotatedVelocityToolsScanner.java    From velocity-spring-boot-project with Apache License 2.0 4 votes vote down vote up
@Override
protected void scan(String[] sources, Map<String, VelocityTool> velocityToolsMap) {

    for (String basePackage : sources) {

        Set<BeanDefinition> candidates = provider.findCandidateComponents(basePackage);

        for (BeanDefinition beanDefinition : candidates) {

            Class<?> toolClass = resolveToolClass(beanDefinition);

            DefaultKey defaultKey = findAnnotation(toolClass, DefaultKey.class);

            String key = defaultKey.value();

            String scope = getScope(toolClass);

            VelocityTool velocityTool = new VelocityTool(new ToolInfo(key, toolClass), scope);

            velocityToolsMap.put(key, velocityTool);

        }

    }
}