FileDocCategorySizeDatePackage
InterceptorBindingTranslator.javaAPI DocGlassfish v2 API12451Fri May 04 22:31:58 BST 2007com.sun.enterprise.deployment.util

InterceptorBindingTranslator

public class InterceptorBindingTranslator extends Object

Fields Summary
private List
interceptorBindings
private com.sun.enterprise.deployment.EjbBundleDescriptor
ejbBundle
private List
defaultInterceptorChain
private List
classInterceptorChain
private boolean
hasTotalClassLevelOrdering
private List
totalClassLevelOrdering
private Map
methodInterceptorsMap
private boolean
isEmpty
Constructors Summary
public InterceptorBindingTranslator(com.sun.enterprise.deployment.EjbBundleDescriptor bundle)


       

        ejbBundle = bundle;
        interceptorBindings = ejbBundle.getInterceptorBindings();

        if( interceptorBindings.isEmpty() ) {

            isEmpty = true;

        } else {

            validateInterceptors();

        }

        
    
Methods Summary
public com.sun.enterprise.deployment.util.InterceptorBindingTranslator$TranslationResultsapply(java.lang.String ejbName)


        if( isEmpty ) {
            return new TranslationResults();
        }

        defaultInterceptorChain.clear();
        classInterceptorChain.clear();

        hasTotalClassLevelOrdering = false;
        totalClassLevelOrdering.clear();

        methodInterceptorsMap.clear();

        // Do a pass through default interceptor bindings.
        for(InterceptorBindingDescriptor binding : interceptorBindings) {

            if( binding.getBindingType() == BindingType.DEFAULT ) {
                defaultInterceptorChain.addAll
                    (binding.getInterceptorClasses());
            } 

        }

        // Do a pass through Class level bindings.
        for(InterceptorBindingDescriptor binding : interceptorBindings) {

            if( binding.getBindingType() == BindingType.CLASS ) {

                if( binding.getEjbName().equals(ejbName) ) {
                    processClassLevelBinding(binding);
                }
            } 

        }

        // Now do method-level bindings.

        Map<MethodDescriptor, List<InterceptorBindingDescriptor>> 
            methodBindings = new HashMap<MethodDescriptor, 
                                         List<InterceptorBindingDescriptor>>();

        // First build a map of all business methods for the current
        // ejb that have binding information, and their associated
        // bindings.
        for(InterceptorBindingDescriptor binding : interceptorBindings) {

            if( (binding.getEjbName().equals(ejbName)) &&
                (binding.getBindingType() == BindingType.METHOD) ) { 

                MethodDescriptor method = binding.getBusinessMethod();

                List<InterceptorBindingDescriptor> methodBindingDescs =
                    methodBindings.get(method);
                if( methodBindingDescs == null ) {
                    methodBindingDescs = 
                        new LinkedList<InterceptorBindingDescriptor>();
                }

                methodBindingDescs.add(binding);

                methodBindings.put(method, methodBindingDescs);
            }

        }

        for(MethodDescriptor next : methodBindings.keySet()) {
            processMethod(next, methodBindings.get(next));
        }

        TranslationResults results = buildResults();
        
        return results;

    
private com.sun.enterprise.deployment.util.InterceptorBindingTranslator$TranslationResultsbuildResults()


        TranslationResults results = new TranslationResults();        

        if( hasTotalClassLevelOrdering ) {

            for(String next : totalClassLevelOrdering ) {
                EjbInterceptor interceptor = 
                    ejbBundle.getInterceptorByClassName(next);
                results.allInterceptorClasses.add(interceptor);
                results.classInterceptorChain.add(interceptor);
            }

        } else {

            for(String next : defaultInterceptorChain) {
                EjbInterceptor interceptor = 
                    ejbBundle.getInterceptorByClassName(next);

                results.allInterceptorClasses.add(interceptor);
                results.classInterceptorChain.add(interceptor);
            }

            for(String next : classInterceptorChain) {
                EjbInterceptor interceptor = 
                    ejbBundle.getInterceptorByClassName(next);

                results.allInterceptorClasses.add(interceptor);
                results.classInterceptorChain.add(interceptor);
            }
        }

        for(MethodDescriptor nextMethod : methodInterceptorsMap.keySet()) {

            List<String> interceptorClassChain = (List<String>)
                methodInterceptorsMap.get(nextMethod);
            
            List<EjbInterceptor> interceptorChain = 
                new LinkedList<EjbInterceptor>();
            
            for(String nextClass : interceptorClassChain) {
                EjbInterceptor interceptor = 
                    ejbBundle.getInterceptorByClassName(nextClass);

                results.allInterceptorClasses.add(interceptor);
                interceptorChain.add(interceptor);

            }
            
            results.methodInterceptorsMap.put(nextMethod, interceptorChain);

        }

        return results;
    
private voidprocessClassLevelBinding(com.sun.enterprise.deployment.InterceptorBindingDescriptor binding)


        if( binding.getExcludeDefaultInterceptors() ) {
            defaultInterceptorChain.clear();
        } 
            
        if( binding.getIsTotalOrdering() ) {

            hasTotalClassLevelOrdering = true;
            totalClassLevelOrdering.clear();
            totalClassLevelOrdering.addAll(binding.getInterceptorClasses());
            
            // totalClassLevelOrdering will take precedence, but keep 
            // classInterceptorChain updated to contain class-level, but not
            // default-level, interceptors.  These might be needed during
            // method-level exclude-class-interceptors processing.
            for(String next : binding.getInterceptorClasses()) {
                if( !defaultInterceptorChain.contains(next) ) {
                    if( !classInterceptorChain.contains(next) ) {
                        classInterceptorChain.add(next);
                    }
                }
            }
        } else {
            classInterceptorChain.addAll(binding.getInterceptorClasses());
        }

    
private voidprocessMethod(com.sun.enterprise.deployment.MethodDescriptor businessMethod, java.util.List bindings)


        LinkedList<String> tempDefaultInterceptorChain = 
            new LinkedList<String>();

        LinkedList<String> tempClassInterceptorChain =
            new LinkedList<String>();

        LinkedList<String> tempMethodInterceptorChain =
            new LinkedList<String>();

        if( hasTotalClassLevelOrdering ) {
            tempClassInterceptorChain.addAll(totalClassLevelOrdering);
        } else {                
            tempDefaultInterceptorChain.addAll(defaultInterceptorChain);
            tempClassInterceptorChain.addAll(classInterceptorChain);
        }

        for(InterceptorBindingDescriptor nextBinding : bindings) {

            if( nextBinding.getExcludeDefaultInterceptors() ) {
                if( hasTotalClassLevelOrdering ) {
                    tempClassInterceptorChain.removeAll
                        (defaultInterceptorChain);
                } else {
                    tempDefaultInterceptorChain.clear();
                }
            }

            if( nextBinding.getExcludeClassInterceptors() ) {
                if( hasTotalClassLevelOrdering ) {
                    tempClassInterceptorChain.removeAll
                        (classInterceptorChain);
                } else {
                    tempClassInterceptorChain.clear();
                }
            }
            
            if( nextBinding.getIsTotalOrdering() ) {
                tempDefaultInterceptorChain.clear();
                tempClassInterceptorChain.clear();
                tempMethodInterceptorChain.clear();
            }

            tempMethodInterceptorChain.addAll
                (nextBinding.getInterceptorClasses());

        }

        LinkedList<String> methodInterceptors = new LinkedList<String>();
        methodInterceptors.addAll(tempDefaultInterceptorChain);
        methodInterceptors.addAll(tempClassInterceptorChain);
        methodInterceptors.addAll(tempMethodInterceptorChain);

        methodInterceptorsMap.put(businessMethod, methodInterceptors);
        
    
private voidvalidateInterceptors()


        // Make sure there's an interceptor defined for every interceptor
        // class name listed in the bindings.
        for(InterceptorBindingDescriptor binding : interceptorBindings) {

            for(String interceptor : binding.getInterceptorClasses()) {

                if(ejbBundle.getInterceptorByClassName(interceptor) == null) {
                    throw new IllegalStateException
                        ("Interceptor binding contains an interceptor class " +
                         " name = " + interceptor + 
                         " that is not defined as an interceptor");
                }
            }
        }