Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Fabric3
   * Copyright (c) 2009-2015 Metaform Systems
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * Portions originally based on Apache Tuscany 2007
  * licensed under the Apache 2.0 license.
  */
 package org.fabric3.cache.introspection;
 
 
 import  org.oasisopen.sca.annotation.EagerInit;
 import  org.oasisopen.sca.annotation.Reference;
 
Introspects fields, methods and constructor parameters annotated with Cache.
 
 @EagerInit
 public class CacheProcessor extends AbstractAnnotationProcessor<Cache> {
     private IntrospectionHelper helper;
 
     public CacheProcessor(@Reference JavaContractProcessor contractProcessor, @Reference IntrospectionHelper helper) {
         super(Cache.class);
         this. = contractProcessor;
         this. = helper;
     }
 
     public void visitField(Cache annotationField fieldClass<?> implClassInjectingComponentType componentTypeIntrospectionContext context) {
         String name = .getSiteName(fieldnull);
         FieldInjectionSite site = new FieldInjectionSite(field);
         Class<?> type = field.getType();
         ResourceReferenceDefinition definition = create(nameannotationtypefieldcomponentTypecontext);
         componentType.add(definitionsite);
     }
 
     public void visitMethod(Cache annotationMethod methodClass<?> implClassInjectingComponentType componentTypeIntrospectionContext context) {
         if (method.getParameterTypes().length != 1) {
             InvalidCacheSetter error = new InvalidCacheSetter("Setter must contain one parameter: " + methodmethodcomponentType);
             context.addError(error);
             return;
         }
         String name = .getSiteName(methodnull);
         MethodInjectionSite site = new MethodInjectionSite(method, 0);
         Class<?> type = method.getParameterTypes()[0];
         ResourceReferenceDefinition definition = create(nameannotationtypemethodcomponentTypecontext);
         componentType.add(definitionsite);
     }
 
     public void visitConstructorParameter(Cache annotation,
                                           Constructor<?> constructor,
                                           int index,
                                           Class<?> implClass,
                                           InjectingComponentType componentType,
                                           IntrospectionContext context) {
         String name = annotation.name();
         Class<?> type = constructor.getParameterTypes()[index];
         ResourceReferenceDefinition definition = create(nameannotationtypeconstructorcomponentTypecontext);
         componentType.add(definition);
     }
 
     private ResourceReferenceDefinition create(String name,
                                                Cache annotation,
                                                Class<?> type,
                                                Member member,
                                                InjectingComponentType componentType,
                                                IntrospectionContext context) {
         ServiceContract contract = .introspect(typecontextcomponentType);
         String cacheName = annotation.name();
         if (cacheName.length() == 0) {
             MissingCacheName error = new MissingCacheName(membercomponentType);
             context.addError(error);
            return new CacheReferenceDefinition(namecontractfalse"error");
        }
        return new CacheReferenceDefinition(namecontractfalsecacheName);
    }
New to GrepCode? Check out our FAQ X