FileDocCategorySizeDatePackage
AbstractHandler.javaAPI DocGlassfish v2 API8855Fri May 04 22:31:34 BST 2007com.sun.enterprise.deployment.annotation.handlers

AbstractHandler

public abstract class AbstractHandler extends Object implements com.sun.enterprise.deployment.annotation.AnnotationHandler
This is an abstract base class for Handlers. Concrete subclass need to implements the following methods: public Class<? extends Annotation> getAnnotationType(); public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException;
author
Shing Wai Chan

Fields Summary
protected static final com.sun.enterprise.util.LocalStringManagerImpl
localStrings
protected Logger
logger
Constructors Summary
Methods Summary
protected com.sun.enterprise.deployment.annotation.HandlerProcessingResultgetDefaultFailedResult()

return
a default failed result

        return HandlerProcessingResultImpl.getDefaultResult(
                getAnnotationType(), ResultType.FAILED);
    
protected com.sun.enterprise.deployment.annotation.HandlerProcessingResultgetDefaultProcessedResult()

return
a default processed result

        return HandlerProcessingResultImpl.getDefaultResult(
                getAnnotationType(), ResultType.PROCESSED);
    
protected java.lang.Class[]getEjbAnnotationTypes()
This is called by getTypeDependencies().

return
an array of all ejb annotation types

        return new Class[] {
                MessageDriven.class, Stateful.class, Stateless.class };
    
protected java.lang.StringgetInjectionMethodPropertyName(java.lang.reflect.Method method, com.sun.enterprise.deployment.annotation.AnnotationInfo ainfo)

        String methodName = method.getName();
        String propertyName = methodName;

        if( (methodName.length() > 3) &&
            methodName.startsWith("set") ) {
            // Derive javabean property name.
            propertyName = 
                methodName.substring(3, 4).toLowerCase() +
                methodName.substring(4);
        }  else {
            throw new AnnotationProcessorException(
                localStrings.getLocalString(
                "enterprise.deployment.annotation.handlers.invalidinjectionmethodname",
                "Injection method name must start with \"set\""),
                ainfo);
        }

        return propertyName;
    
protected com.sun.enterprise.deployment.annotation.HandlerProcessingResultgetInvalidAnnotatedElementHandlerResult(com.sun.enterprise.deployment.annotation.AnnotatedElementHandler aeHandler, com.sun.enterprise.deployment.annotation.AnnotationInfo ainfo)

param
aeHandler
param
ainfo
return
a result for invalid AnnotatedElementHandler


        if (logger.isLoggable(Level.FINE)) {
            log(Level.FINE, ainfo, 
                localStrings.getLocalString(
                "enterprise.deployment.annotation.handlers.invalidaehandler",
                "Invalid annotation symbol found for this type of class."));
        }
        if (logger.isLoggable(Level.FINER)) {
            logger.finer("Invalid AnnotatedElementHandler: " + aeHandler);
        }

        return getDefaultProcessedResult();
    
protected com.sun.enterprise.deployment.annotation.HandlerProcessingResultgetOverallProcessingResult(java.util.List resultList)

        HandlerProcessingResult overallProcessingResult = null;
        for (HandlerProcessingResult result : resultList) {
            if (overallProcessingResult == null ||
                    (result.getOverallResult().compareTo(
                    overallProcessingResult.getOverallResult()) > 0)) {
                overallProcessingResult = result;
            }
        }
        return overallProcessingResult;
    
public java.lang.Class[]getTypeDependencies()

return
an array of annotation types this annotation handler would require to be processed (if present) before it processes it's own annotation type.


                                
         
        return null;
    
protected voidlog(java.util.logging.Level level, com.sun.enterprise.deployment.annotation.AnnotationInfo ainfo, java.lang.String localizedMessage)

        if (Level.SEVERE.equals(level)) {
            ainfo.getProcessingContext().getErrorHandler().error(
                new AnnotationProcessorException(localizedMessage, ainfo));
        } else if (Level.WARNING.equals(level)) {
            ainfo.getProcessingContext().getErrorHandler().warning(
                new AnnotationProcessorException(localizedMessage, ainfo));
        } else if (Level.FINE.equals(level)) {
            ainfo.getProcessingContext().getErrorHandler().fine(
                new AnnotationProcessorException(localizedMessage, ainfo));
        } else if (ainfo != null) {
            ainfo.getProcessingContext().getProcessor().log(
                level, ainfo, localizedMessage);
        } else {
            logger.log(level, localizedMessage);
        }
    
protected voidvalidateInjectionMethod(java.lang.reflect.Method method, com.sun.enterprise.deployment.annotation.AnnotationInfo ainfo)
Check if given method is a valid injection method. Throw Exception if it is not.

exception
AnnotationProcessorException

        if (method.getParameterTypes().length!=1){
            throw new AnnotationProcessorException(
                localStrings.getLocalString(
                "enterprise.deployment.annotation.handlers.invalidinjectionmethod",
                "Injection on a method requires a JavaBeans setter method type with one parameter "),
                ainfo);
                
        }
        if (!void.class.equals(method.getReturnType())) {
            throw new AnnotationProcessorException(
                localStrings.getLocalString(
                "enterprise.deployment.annotation.handlers.injectionmethodmustreturnvoid",
                "Injection on a method requires a void return type"),
                ainfo);
        }