Java 类org.springframework.cache.annotation.AnnotationCacheOperationSource 实例源码

项目:lams    文件:CacheAdviceParser.java   
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    builder.addPropertyReference("cacheManager", CacheNamespaceHandler.extractCacheManager(element));
    CacheNamespaceHandler.parseKeyGenerator(element, builder.getBeanDefinition());

    List<Element> cacheDefs = DomUtils.getChildElementsByTagName(element, DEFS_ELEMENT);
    if (cacheDefs.size() >= 1) {
        // Using attributes source.
        List<RootBeanDefinition> attributeSourceDefinitions = parseDefinitionsSources(cacheDefs, parserContext);
        builder.addPropertyValue("cacheOperationSources", attributeSourceDefinitions);
    } else {
        // Assume annotations source.
        builder.addPropertyValue("cacheOperationSources", new RootBeanDefinition(
                AnnotationCacheOperationSource.class));
    }
}
项目:my-spring-cache-redis    文件:CacheAdviceParser.java   
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    builder.addPropertyReference("cacheManager", CacheNamespaceHandler.extractCacheManager(element));
    CacheNamespaceHandler.parseKeyGenerator(element, builder.getBeanDefinition());

    List<Element> cacheDefs = DomUtils.getChildElementsByTagName(element, DEFS_ELEMENT);
    if (cacheDefs.size() >= 1) {
        // Using attributes source.
        List<RootBeanDefinition> attributeSourceDefinitions = parseDefinitionsSources(cacheDefs, parserContext);
        builder.addPropertyValue("cacheOperationSources", attributeSourceDefinitions);
    } else {
        // Assume annotations source.
        builder.addPropertyValue("cacheOperationSources", new RootBeanDefinition(
                AnnotationCacheOperationSource.class));
    }
}
项目:class-guard    文件:CacheAdviceParser.java   
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    builder.addPropertyReference("cacheManager", CacheNamespaceHandler.extractCacheManager(element));
    CacheNamespaceHandler.parseKeyGenerator(element, builder.getBeanDefinition());

    List<Element> cacheDefs = DomUtils.getChildElementsByTagName(element, DEFS_ELEMENT);
    if (cacheDefs.size() >= 1) {
        // Using attributes source.
        List<RootBeanDefinition> attributeSourceDefinitions = parseDefinitionsSources(cacheDefs, parserContext);
        builder.addPropertyValue("cacheOperationSources", attributeSourceDefinitions);
    } else {
        // Assume annotations source.
        builder.addPropertyValue("cacheOperationSources", new RootBeanDefinition(
                AnnotationCacheOperationSource.class));
    }
}
项目:lams    文件:AnnotationDrivenCacheBeanDefinitionParser.java   
public static void configureAutoProxyCreator(Element element, ParserContext parserContext) {
    AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);

    if (!parserContext.getRegistry().containsBeanDefinition(CACHE_ADVISOR_BEAN_NAME)) {
        Object eleSource = parserContext.extractSource(element);

        // Create the CacheOperationSource definition.
        RootBeanDefinition sourceDef = new RootBeanDefinition(AnnotationCacheOperationSource.class);
        sourceDef.setSource(eleSource);
        sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);

        // Create the CacheInterceptor definition.
        RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class);
        interceptorDef.setSource(eleSource);
        interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        parseCacheManagerProperty(element, interceptorDef);
        CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef);
        interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName));
        String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);

        // Create the CacheAdvisor definition.
        RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class);
        advisorDef.setSource(eleSource);
        advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
        advisorDef.getPropertyValues().add("adviceBeanName", interceptorName);
        if (element.hasAttribute("order")) {
            advisorDef.getPropertyValues().add("order", element.getAttribute("order"));
        }
        parserContext.getRegistry().registerBeanDefinition(CACHE_ADVISOR_BEAN_NAME, advisorDef);

        CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(),
                eleSource);
        compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
        compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
        compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CACHE_ADVISOR_BEAN_NAME));
        parserContext.registerComponent(compositeDef);
    }
}
项目:my-spring-cache-redis    文件:AnnotationDrivenCacheBeanDefinitionParser.java   
public static void configureAutoProxyCreator(Element element, ParserContext parserContext) {
    AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);

    if (!parserContext.getRegistry().containsBeanDefinition(CACHE_ADVISOR_BEAN_NAME)) {
        Object eleSource = parserContext.extractSource(element);

        // Create the CacheOperationSource definition.
        RootBeanDefinition sourceDef = new RootBeanDefinition(AnnotationCacheOperationSource.class);
        sourceDef.setSource(eleSource);
        sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);

        // Create the CacheInterceptor definition.
        RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class);
        interceptorDef.setSource(eleSource);
        interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        parseCacheManagerProperty(element, interceptorDef);
        CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef);
        interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName));
        String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);

        // Create the CacheAdvisor definition.
        RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class);
        advisorDef.setSource(eleSource);
        advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
        advisorDef.getPropertyValues().add("adviceBeanName", interceptorName);
        if (element.hasAttribute("order")) {
            advisorDef.getPropertyValues().add("order", element.getAttribute("order"));
        }
        parserContext.getRegistry().registerBeanDefinition(CACHE_ADVISOR_BEAN_NAME, advisorDef);

        CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(),
                eleSource);
        compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
        compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
        compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CACHE_ADVISOR_BEAN_NAME));
        parserContext.registerComponent(compositeDef);
    }
}
项目:class-guard    文件:AnnotationDrivenCacheBeanDefinitionParser.java   
public static void configureAutoProxyCreator(Element element, ParserContext parserContext) {
    AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);

    if (!parserContext.getRegistry().containsBeanDefinition(CACHE_ADVISOR_BEAN_NAME)) {
        Object eleSource = parserContext.extractSource(element);

        // Create the CacheOperationSource definition.
        RootBeanDefinition sourceDef = new RootBeanDefinition(AnnotationCacheOperationSource.class);
        sourceDef.setSource(eleSource);
        sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);

        // Create the CacheInterceptor definition.
        RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class);
        interceptorDef.setSource(eleSource);
        interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        parseCacheManagerProperty(element, interceptorDef);
        CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef);
        interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName));
        String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);

        // Create the CacheAdvisor definition.
        RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class);
        advisorDef.setSource(eleSource);
        advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
        advisorDef.getPropertyValues().add("adviceBeanName", interceptorName);
        if (element.hasAttribute("order")) {
            advisorDef.getPropertyValues().add("order", element.getAttribute("order"));
        }
        parserContext.getRegistry().registerBeanDefinition(CACHE_ADVISOR_BEAN_NAME, advisorDef);

        CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(),
                eleSource);
        compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
        compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
        compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CACHE_ADVISOR_BEAN_NAME));
        parserContext.registerComponent(compositeDef);
    }
}