Merges bean interceptor bindings (including inherited ones) with method interceptor bindings. Method interceptor bindings
override bean interceptor bindings. The bean binding map is not modified - a copy is used.
426781
protected Multimap<Class<? extends Annotation>, Annotation> mergeMemberInterceptorBindings(Multimap<Class<? extends Annotation>, Annotation> beanBindings,
            Set<Annotation> methodBindingAnnotations) {

        Multimap<Class<? extends Annotation>, Annotation> mergedBeanBindings = SetMultimap.newSetMultimap(beanBindings);
        Multimap<Class<? extends Annotation>, Annotation> methodBindings = SetMultimap.newSetMultimap();

        for (Annotation methodBinding : methodBindingAnnotations) {
            methodBindings.put(methodBinding.annotationType(), methodBinding);
        }
        for (Class<? extends Annotation> key : methodBindings.keySet()) {
            mergedBeanBindings.replaceValues(key, methodBindings.get(key));
        }
        return mergedBeanBindings;
    }
898664
private void mergeMethodHandleStore(final int index, final MethodHandle methodHandle) {
        localVariables.merge(index, new MethodHandle(methodHandle), Element::merge);
    }
169688
protected void configureAop() {
        final RepositoryMethodInterceptor proxy = new RepositoryMethodInterceptor();
        requestInjection(proxy);
        // repository specific method annotations (query, function, delegate, etc.)
        bindInterceptor(Matchers.any(), new AbstractMatcher<Method>() {
            @Override
            public boolean matches(final Method method) {
                // this will throw error if two or more annotations specified (fail fast)
                try {
                    return ExtUtils.findMethodAnnotation(method) != null;
                } catch (Exception ex) {
                    throw new MethodDefinitionException(String.format("Error declaration on method %s",
                            RepositoryUtils.methodToString(method)), ex);
                }
            }
        }, proxy);
    }
568688
private void overrideUseMavenPatterns(T overrider, Class overriderClass) {
        if (useMavenPatternsOverrideList.contains(overriderClass.getSimpleName())) {
            try {
                Field useMavenPatternsField = overriderClass.getDeclaredField("useMavenPatterns");
                useMavenPatternsField.setAccessible(true);
                Object useMavenPatterns = useMavenPatternsField.get(overrider);

                if (useMavenPatterns == null) {
                    Field notM2CompatibleField = overriderClass.getDeclaredField("notM2Compatible");
                    notM2CompatibleField.setAccessible(true);
                    Object notM2Compatible = notM2CompatibleField.get(overrider);
                    if (notM2Compatible instanceof Boolean && notM2Compatible != null) {
                        useMavenPatternsField.set(overrider, !(Boolean)notM2Compatible);
                    }
                }
            } catch (NoSuchFieldException | IllegalAccessException e) {
                converterErrors.add(getConversionErrorMessage(overrider, e));
            }
        }
    }
213154
private void addDefaultInterceptors()
                    throws EJBConfigurationException
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
        {
            Tr.entry(tc, "addDefaultInterceptorNames");
        }

        // Get list of default interceptor names from interceptor-binding for EJB name *.
        List<String> names = new LinkedList<String>();
        if (ivModuleInterceptorBinding != null)
        {
            if (!ivModuleInterceptorBinding.ivInterceptorClassNames.isEmpty()) // d453477
            {
                names = ivModuleInterceptorBinding.ivInterceptorClassNames;
            }
            else if (!ivModuleInterceptorBinding.ivInterceptorOrder.isEmpty()) // d453477
            {
                // interceptor-order and interceptor-classes are mutually exclusive
                // in xml schema.  So only 1 will occur, not both.
                names = ivModuleInterceptorBinding.ivInterceptorOrder;
            }
        }

        // Process any default interceptor names found for the module this bean is in.
        if (names.size() > 0)
        {
            updateNamesToClassMap(names); // d630717

            // Remember list of default interceptor names.
            ivDefaultInterceptorNames.addAll(names);
        }

        if (isTraceOn && tc.isEntryEnabled())
        {
            Tr.exit(tc, "addDefaultInterceptorNames: " + ivDefaultInterceptorNames);
        }
    }
978432
private void removeOverriddenMethod(ExecutableElement method) {
        TypeElement overriddenClass = utils.overriddenClass(method);
        if (overriddenClass != null) {
            for (int i = 0; i < methlist.size(); i++) {
                TypeElement te = utils.getEnclosingTypeElement(methlist.get(i));
                if (te == overriddenClass || utils.isSubclassOf(overriddenClass, te)) {
                    methlist.remove(i);  // remove overridden method
                    return;
                }
            }
        }
    }
829310
private List<EndpointInterceptor> adaptInterceptors(List<Object> interceptors) {
        List<EndpointInterceptor> endpointInterceptors = new ArrayList<EndpointInterceptor>();

        if (interceptors != null) {
            for (Object interceptor : interceptors) {
                if (interceptor instanceof EndpointInterceptor) {
                    endpointInterceptors.add((EndpointInterceptor) interceptor);
                }
            }
        }

        return endpointInterceptors;
    }
1345597
protected Method mapControlBeanMethodToEJB(Method m) {
        Method ejbMethod = findEjbMethod(m, _homeInterface);
        if (ejbMethod == null) {
            if (_beanInstance == null) {
                _beanInstance = resolveBeanInstance();
                if (_beanInstance == null) {
                    throw new ControlException("Unable to resolve bean instance");
                }
            }
            ejbMethod = findEjbMethod(m, _beanInstance.getClass());
            if (ejbMethod == null) {
                throw new ControlException("Unable to map ejb control interface method to EJB method: " + m.getName());
            }
        }
        return ejbMethod;
    }
504008
function (interfaceMethods, interceptor, allInterceptors) {
        var interceptedMethods = allInterceptors || {};
        // for a class object, intercept specific methods
        for (var m in interfaceMethods) {
            if (interfaceMethods.hasOwnProperty(m) && __hasBeenIntercepted(m, interceptor)) {
                (interceptedMethods[m] || (interceptedMethods[m] = [])).push({
                    fn : __callInterceptorMethod,
                    scope : interceptor
                });
            }
        }
        return interceptedMethods;
    }
965169
@Reqiured
    public void setInterceptors(Interceptor[] interceptors) {
        Listener last = null;
        for (int i = interceptors.length - 1; i >= 0; i--) {
            final Interceptor current = interceptors[i];
            final Listener next = last;
            last = new Listener() {
                public void render(Context context) throws IOException, ParseException {
                    if (next == null) {
                        Listener listener = (Listener) context.get(LISTENER_KEY);
                        if (listener != null) {
                            current.render(context, listener);
                        }
                    } else {
                        current.render(context, next);
                    }
                }
            };
        }
        this.chain = last;
    }
300676
public boolean extendsClassOrInterface(Types types,
                                         TypeMirror typeMirror,
                                         TypeMirror toImplement) {
    String clearedToImplement = this.removeGenericsFromClassName(toImplement.toString());
    Set<TypeMirror> setOfSuperType = this.getFlattenedSupertypeHierarchy(types,
                                                                         typeMirror);
    for (TypeMirror mirror : setOfSuperType) {
      if (clearedToImplement.equals(this.removeGenericsFromClassName(mirror.toString()))) {
        return true;
      }
    }
    return false;
  }
324300
protected void createInterceptorsAndInstance(CallbackContextHelper contextHelper) throws InvocationTargetException {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "createInterceptorsAndInstance : " + contextHelper);

        BeanMetaData bmd = home.beanMetaData;
        ManagedObjectFactory<?> managedObjectFactory = bmd.ivEnterpriseBeanFactory;
        if (managedObjectFactory != null) {
            try {
                ivEjbManagedObjectContext = managedObjectFactory.createContext();
            } catch (ManagedObjectException e) {
                throw ExceptionUtil.EJBException("AroundConstruct interceptors for the " + bmd.enterpriseBeanName +
                                                 " bean in the " + bmd._moduleMetaData.ivName +
                                                 " module in the " + bmd._moduleMetaData.ivAppName +
                                                 " application resulted in an exception being thrown from the ManagedObjectFactory.createContext() method", e);
            }
        }

        InterceptorMetaData imd = bmd.ivInterceptorMetaData;
        if (imd != null && !bmd.managedObjectManagesInjectionAndInterceptors) {
            createInterceptors(imd);
            if (bmd.ivCallbackKind == CallbackKind.InvocationContext) {
                InterceptorProxy[] aroundConstructProxies = imd.ivAroundConstructInterceptors;
                if (aroundConstructProxies != null) {
                    InvocationContextImpl<?> context = callAroundConstructInterceptors(aroundConstructProxies, contextHelper);
                    // If InvocationContext.proceed() was not called, the bean's
                    // constructor was never called and ivEjbInstance will be null.
                    if (ivEjbInstance == null) {
                        // If the interceptor swallowed an exception from
                        // proceed(), we re-throw it now to give a better
                        // error message than a generic "failed to create".
                        if (context.ivAroundConstructException != null) {
                            Throwable t = context.ivAroundConstructException.getCause();
                            if (t == null) {
                                // Don't lose the application exception if it doesn't happen to be nested
                                t = context.ivAroundConstructException;
                            }
                            throw ExceptionUtil.EJBException("AroundConstruct interceptors for the " + bmd.enterpriseBeanName +
                                                             " bean in the " + bmd._moduleMetaData.ivName +
                                                             " module in the " + bmd._moduleMetaData.ivAppName +
                                                             " application resulted in an exception being thrown from the constructor of the " +
                                                             bmd.enterpriseBeanClassName + " class.", t);
                        }

                        // Otherwise, the interceptor must not have called proceed().
                        throw new EJBException("AroundConstruct interceptors for the " + bmd.enterpriseBeanName +
                                               " bean in the " + bmd._moduleMetaData.ivName +
                                               " module in the " + bmd._moduleMetaData.ivAppName +
                                               " application did not call InvocationContext.proceed()");
                    }
                }
            }
        }

        // If no @AroundConstructor interceptor, create the instance now.
        if (ivEjbInstance == null) {
            createInstance();
        }
        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "createInterceptorsAndInstance");
    }
1326116
private static <T, G extends T> void generateOnLayoutMethod(DexMaker dexMaker,
                                                                TypeId<G> generatedType,
                                                                TypeId<T> baseType) {
        final FieldId<G, Interceptor> interceptorField =
                generatedType.getField(INTERCEPTOR_TYPE, FIELD_NAME_INTERCEPTOR);

        final String methodName = ViewMethod.ON_LAYOUT.getName();

        final MethodId<T, Void> superMethod = baseType.getMethod(VOID_TYPE, methodName,
                TypeId.BOOLEAN, TypeId.INT, TypeId.INT, TypeId.INT, TypeId.INT);
        final MethodId<Interceptor, Void> onLayoutMethod =
                INTERCEPTOR_TYPE.getMethod(VOID_TYPE, methodName, VIEW_TYPE, TypeId.BOOLEAN,
                        TypeId.INT, TypeId.INT, TypeId.INT, TypeId.INT);

        final MethodId<G, Void> methodId = generatedType.getMethod(VOID_TYPE, methodName,
                TypeId.BOOLEAN, TypeId.INT, TypeId.INT, TypeId.INT, TypeId.INT);
        final Code code = dexMaker.declare(methodId, PUBLIC);

        final Local<G> localThis = code.getThis(generatedType);
        final Local<Interceptor> nullInterceptor = code.newLocal(INTERCEPTOR_TYPE);
        final Local<Interceptor> localInterceptor = code.newLocal(INTERCEPTOR_TYPE);
        final Local<Boolean> localChanged = code.getParameter(0, TypeId.BOOLEAN);
        final Local<Integer> localLeft = code.getParameter(1, TypeId.INT);
        final Local<Integer> localTop = code.getParameter(2, TypeId.INT);
        final Local<Integer> localRight = code.getParameter(3, TypeId.INT);
        final Local<Integer> localBottom = code.getParameter(4, TypeId.INT);

        code.iget(interceptorField, localInterceptor, localThis);
        code.loadConstant(nullInterceptor, null);

        // Interceptor is not null, call it.
        final Label interceptorNullCase = new Label();
        code.compare(Comparison.EQ, interceptorNullCase, nullInterceptor, localInterceptor);
        code.invokeVirtual(onLayoutMethod, null, localInterceptor, localThis, localChanged,
                localLeft, localTop, localRight, localBottom);
        code.returnVoid();

        // Interceptor is null, call super method.
        code.mark(interceptorNullCase);
        code.invokeSuper(superMethod, null, localThis, localChanged, localLeft, localTop,
                localRight, localBottom);
        code.returnVoid();

        final MethodId<G, Void> callsSuperMethod = generatedType.getMethod(VOID_TYPE,
                ViewMethod.ON_LAYOUT.getInvokeName(), TypeId.BOOLEAN, TypeId.INT, TypeId.INT,
                TypeId.INT, TypeId.INT);

        final Code superCode = dexMaker.declare(callsSuperMethod, PUBLIC);

        final Local<G> superThis = superCode.getThis(generatedType);
        final Local<Boolean> superLocalChanged = superCode.getParameter(0, TypeId.BOOLEAN);
        final Local<Integer> superLocalLeft = superCode.getParameter(1, TypeId.INT);
        final Local<Integer> superLocalTop = superCode.getParameter(2, TypeId.INT);
        final Local<Integer> superLocalRight = superCode.getParameter(3, TypeId.INT);
        final Local<Integer> superLocalBottom = superCode.getParameter(4, TypeId.INT);
        superCode.invokeSuper(superMethod, null, superThis, superLocalChanged, superLocalLeft,
                superLocalTop, superLocalRight, superLocalBottom);
        superCode.returnVoid();
    }
471627
private void setExcludeDefaultInterceptors()
    {
        EJBInterceptorBinding binding = ivClassInterceptorBinding;
        boolean useAnnotation = false;
        if (binding == null)
        {
            // Use annotation provided metadata-complete is false.
            useAnnotation = !ivMetadataComplete;
        }
        else
        {
            // Assumption is xml overrides annotation, although EJB spec implies
            // interceptor-binding is used to augment annotation.  Not clear what
            // is intended, but we are going to assume xml overrides annotation.
            Boolean exclude = binding.ivExcludeDefaultLevelInterceptors;
            if (exclude == null)
            {
                // exclude is not set in ejb-jar.xml for class level binding,
                // Use annotation provided metadata-complete is false.
                useAnnotation = !ivMetadataComplete;
            }
            else if (exclude == Boolean.TRUE)
            {
                ivExcludeDefaultFromClassLevel = true;
            }
            else
            {
                ivExcludeDefaultFromClassLevel = false;
            }
        }

        // If xml did not have a exclude-default-interceptor setting for
        // class level binding, then see if annotation indicates to exclude
        // default level interceptors.
        if (useAnnotation)
        {
            ExcludeDefaultInterceptors a = ivEjbClass.getAnnotation(ExcludeDefaultInterceptors.class);
            if (a != null)
            {
                ivExcludeDefaultFromClassLevel = true;
            }
            else
            {
                ivExcludeDefaultFromClassLevel = false;
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
        {
            Tr.debug(tc, "setExcludeDefaultInterceptors: " + ivExcludeDefaultFromClassLevel);
        }
    }
576269
@Override
    public void merge(JMSDestinationDefinition annotation, Class<?> instanceClass, Member member) throws InjectionException {

        if (member != null) {
            // JMSDestinationDefinition is a class-level annotation only.
            throw new IllegalArgumentException(member.toString());
        }

        name = mergeAnnotationValue(name, isXmlNameSet, annotation.name(), JMSDestinationProperties.NAME.getAnnotationKey(), "");
        interfaceName = mergeAnnotationValue(interfaceName, isXmlInterfaceNameSet, annotation.interfaceName(), JMSDestinationProperties.INTERFACE_NAME.getAnnotationKey(), "");
        className = mergeAnnotationValue(className, isXmlclassNameSet, annotation.className(), JMSDestinationProperties.CLASS_NAME.getAnnotationKey(), "");
        description = mergeAnnotationValue(description, isXmlDescriptionSet, annotation.description(), JMSDestinationProperties.DESCRIPTION.getAnnotationKey(), "");
        destinationName = mergeAnnotationValue(destinationName, isXmlDestinationNameSet, annotation.destinationName(),
                                               JMSDestinationProperties.DESTINATION_NAME.getAnnotationKey(), "");
        resourceAdapter = mergeAnnotationValue(resourceAdapter, isXmlResourceAdapterSet, annotation.resourceAdapter(),
                                               JMSDestinationProperties.RESOURCE_ADAPTER.getAnnotationKey(), "");
        properties = mergeAnnotationProperties(properties, xmlProperties, annotation.properties());

    }
467850
private void visitOverride(AnnotatedNode node, AnnotationNode visited) {
        ClassNode annotationClassNode = visited.getClassNode();
        if (annotationClassNode.isResolved() && annotationClassNode.getName().equals("java.lang.Override")) {
            if (node instanceof MethodNode && !Boolean.TRUE.equals(node.getNodeMetaData(Verifier.DEFAULT_PARAMETER_GENERATED))) {
                boolean override = false;
                MethodNode origMethod = (MethodNode) node;
                ClassNode cNode = origMethod.getDeclaringClass();
                if (origMethod.hasDefaultValue()) {
                    List<MethodNode> variants = cNode.getDeclaredMethods(origMethod.getName());
                    for (MethodNode m : variants) {
                        if (m.getAnnotations().contains(visited) && isOverrideMethod(m)) {
                            override = true;
                            break;
                        }
                    }
                } else {
                    override = isOverrideMethod(origMethod);
                }

                if (!override) {
                    addError("Method '" + origMethod.getName() + "' from class '" + cNode.getName() + "' does not override " +
                            "method from its superclass or interfaces but is annotated with @Override.", visited);
                }
            }
        }
    }
406907
static void mergeResRefsAndBindings(ComponentNameSpaceConfiguration masterCompNSConfig,
                                        List<ComponentNameSpaceConfiguration> compNSConfigs,
                                        InjectionScope scope) throws InjectionException {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "mergeResRefsAndBindings");

        Map<String, ResourceRefConfig[]> resRefMap = new LinkedHashMap<String, ResourceRefConfig[]>();

        Map<JNDIEnvironmentRefType, Map<String, ComponentNameSpaceConfiguration>> allBindingComps = new EnumMap<JNDIEnvironmentRefType, Map<String, ComponentNameSpaceConfiguration>>(JNDIEnvironmentRefType.class);
        for (JNDIEnvironmentRefType refType : JNDIEnvironmentRefType.VALUES) {
            if (refType.getBindingElementName() != null) {
                masterCompNSConfig.setJNDIEnvironmentRefBindings(refType.getType(), new HashMap<String, String>());
                allBindingComps.put(refType, new HashMap<String, ComponentNameSpaceConfiguration>());
            }
        }

        Map<String, String> envEntryValues = new HashMap<String, String>();
        Map<String, ComponentNameSpaceConfiguration> envEntryValueComps = new HashMap<String, ComponentNameSpaceConfiguration>();
        masterCompNSConfig.setEnvEntryValues(envEntryValues);

        boolean refMergeSuccess = true;
        for (int componentIndex = 0; componentIndex < compNSConfigs.size(); componentIndex++) {
            ComponentNameSpaceConfiguration compNSConfig = compNSConfigs.get(componentIndex);
            if (isTraceOn && tc.isDebugEnabled())
                Tr.debug(tc, "merging component " + componentIndex + ": " + compNSConfig.getJ2EEName());

            // d643480 - Build map of resource reference arrays for merging.
            ResourceRefConfigList resRefs = compNSConfig.getResourceRefConfigList();
            if (resRefs != null) {
                for (int i = 0, size = resRefs.size(); i < size; i++) {
                    ResourceRefConfig resRef = resRefs.getResourceRefConfig(i);
                    String resRefName = resRef.getName();

                    if (scope == null ||
                        scope == InjectionScope.match(resRefName)) {
                        ResourceRefConfig[] resRefArray = resRefMap.get(resRefName);
                        if (resRefArray == null) {
                            resRefArray = new ResourceRefConfig[compNSConfigs.size()];
                            resRefMap.put(resRefName, resRefArray);
                        }

                        // Like in previous releases, we won't error if an individual
                        // component has conflicting ResRefs.  ResRefList.findByName
                        // has always returned the first ResRef in the list, so
                        // ignore subsequent ResRefs for this component.
                        if (resRefArray[componentIndex] == null) {
                            resRefArray[componentIndex] = resRef;
                        }
                    }
                }
            }

            for (JNDIEnvironmentRefType refType : JNDIEnvironmentRefType.VALUES) {
                if (refType.getBindingElementName() != null) {
                    refMergeSuccess &= mergeBindings(compNSConfig, scope,
                                                     refType.getBindingElementName(),
                                                     refType.getBindingAttributeName(),
                                                     compNSConfig.getJNDIEnvironmentRefBindings(refType.getType()),
                                                     masterCompNSConfig.getJNDIEnvironmentRefBindings(refType.getType()),
                                                     allBindingComps.get(refType));
                }
            }

            refMergeSuccess &= mergeBindings(compNSConfig, scope,
                                             "env-entry", "value",
                                             compNSConfig.getEnvEntryValues(),
                                             envEntryValues, envEntryValueComps);
        }

        refMergeSuccess &= mergeResRefs(masterCompNSConfig, compNSConfigs, resRefMap); // d643480

        if (!refMergeSuccess) {
            throw new InjectionConfigurationException("There were conflicting references.  " +
                                                      "See CWNEN0061E messages in log for details.");
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "mergeResRefsAndBindings");
    }