Method for creating interceptors prior to the creation of the bean
instance, in case @AroundConstruct exists. <p>
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");
    }
642838
public Interceptors<BeansDescriptor> getOrCreateInterceptors()
   {
      List<Node> nodeList = model.get("interceptors");
      if (nodeList != null && nodeList.size() > 0)
      {
         return new InterceptorsImpl<BeansDescriptor>(this, "interceptors", model, nodeList.get(0));
      }
      return createInterceptors();
   }
36059
public EnvEntryType<InterceptorType<T>> getOrCreateEnvEntry()
   {
      List<Node> nodeList = childNode.get("env-entry");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new EnvEntryTypeImpl<InterceptorType<T>>(this, "env-entry", childNode, nodeList.get(0));
      }
      return createEnvEntry();
   }
729488
private static <T, G extends T> void generateDrawMethod(DexMaker dexMaker,
                                                            TypeId<G> generatedType,
                                                            TypeId<T> baseType,
                                                            ViewMethod viewMethod) {
        final FieldId<G, Interceptor> interceptorField =
                generatedType.getField(INTERCEPTOR_TYPE, FIELD_NAME_INTERCEPTOR);

        final String methodName = viewMethod.getName();

        final MethodId<T, Void> superMethod = baseType.getMethod(VOID_TYPE, methodName, CANVAS_TYPE);
        final MethodId<Interceptor, Void> drawMethod =
                INTERCEPTOR_TYPE.getMethod(VOID_TYPE, methodName, VIEW_TYPE, CANVAS_TYPE);

        final MethodId<G, Void> methodId = generatedType.getMethod(VOID_TYPE, methodName, CANVAS_TYPE);
        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<Canvas> localCanvas = code.getParameter(0, CANVAS_TYPE);

        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(drawMethod, null, localInterceptor, localThis, localCanvas);
        code.returnVoid();

        // Interceptor is null, call super method.
        code.mark(interceptorNullCase);
        code.invokeSuper(superMethod, null, localThis, localCanvas);
        code.returnVoid();

        final MethodId<G, Void> callsSuperMethod =
                generatedType.getMethod(VOID_TYPE, viewMethod.getInvokeName(), CANVAS_TYPE);

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

        final Local<G> superThis = superCode.getThis(generatedType);
        final Local<Canvas> superLocalCanvas = superCode.getParameter(0, CANVAS_TYPE);
        superCode.invokeSuper(superMethod, null, superThis, superLocalCanvas);
        superCode.returnVoid();
    }
900413
public ContextualReference<T> create(CreationalContext<T> ctx) {
        if (this.instance != null) {
            throw new IllegalStateException("Trying to call create() on already constructed instance");
        }
        if (disposed) {
            throw new IllegalStateException("Trying to call create() on an already disposed instance");
        }
        this.instance = bean.create(ctx);
        return this;
    }
926786
private void initCdiConstructorInterceptors(Multimap<Class<? extends Annotation>, Annotation> classBindingAnnotations) {
        Set<Annotation> constructorBindings = getMemberBindingAnnotations(classBindingAnnotations, constructor.getMetaAnnotations(InterceptorBinding.class));
        if (constructorBindings.isEmpty()) {
            return;
        }
        initLifeCycleInterceptor(InterceptionType.AROUND_CONSTRUCT, this.constructor, constructorBindings);
    }
1229994
@Override
    protected T createInstance() throws Exception {
        for (final String beanName : this.delegateBeanNames) {
            try {
                final T bean;
                if (this.type == null) {
                    bean = (T) this.getBeanFactory().getBean(beanName);
                } else {
                    bean = this.getBeanFactory().getBean(beanName, this.type);
                }

                if (this.logger.isInfoEnabled()) {
                    this.logger.info("Loaded bean for name " + beanName);
                }

                return bean;
            } catch (final Exception e) {
                final String msg =
                        "Failed to load bean '"
                                + beanName
                                + "' from ApplicationContext"
                                + (this.type != null ? " expecting type: " + this.type : "")
                                + ". Will try to load the next bean in the list instead. Error message from the attempt to load this bean ('"
                                + beanName
                                + "'): ";

                if (this.logger.isDebugEnabled()) {
                    this.logger.debug(msg, e);
                } else if (this.logger.isInfoEnabled()) {
                    this.logger.info(
                            msg + " " + e.getMessage() + " (enable debug for stack trace)");
                }
            }
        }

        throw new BeanCreationException(
                "None of the configured bean names could be loaded. BeanNames: "
                        + this.delegateBeanNames);
    }
208359
@Override
    public Object newInstance(Object[] args) throws BeanConstructorNotFoundException {
        Constructor<?> constructor = getSuitableConstructor(args);
        return LdiConstructorUtil.newInstance(constructor, args);
    }
848272
protected void configureHandlerInterceptor(ApplicationContext context) {
        if (context.containsBean(HANDLER_INTERCEPTOR_BEAN_NAME)) {
            DelegatingHandlerInterceptor handlerInterceptor = context.getBean(HANDLER_INTERCEPTOR_BEAN_NAME, DelegatingHandlerInterceptor.class);
            handlerInterceptor.setInterceptors(adaptInterceptors(httpServer.getInterceptors(), context));
        }
    }
338387
private static Map<Method, List<InterceptorInvoker>> initInterceptorInvokers(BeanManager beanManager,
                                                                                 CreationalContext<?> creationalContext,
                                                                                 Class<?> restClient) {
        Map<Method, List<InterceptorInvoker>> invokers = new HashMap<>();
        // Interceptor as a key in a map is not entirely correct (custom interceptors) but should work in most cases
        Map<Interceptor<?>, Object> interceptorInstances = new HashMap<>();
        
        AnnotatedType<?> restClientType = beanManager.createAnnotatedType(restClient);

        List<Annotation> classBindings = getBindings(restClientType.getAnnotations(), beanManager);

        for (AnnotatedMethod<?> method : restClientType.getMethods()) {
            Method javaMethod = method.getJavaMember();
            if (javaMethod.isDefault() || method.isStatic()) {
                continue;
            }
            List<Annotation> methodBindings = getBindings(method.getAnnotations(), beanManager);

            if (!classBindings.isEmpty() || !methodBindings.isEmpty()) {
                // Liberty change begin - handle aggregated FT annotation
                if (FT_ANNO_CLASS != null && containsFTannotation(methodBindings)) {
                    methodBindings.add(getFTAnnotation());
                }
                // 
                Annotation[] interceptorBindings = merge(methodBindings, classBindings);

                List<Interceptor<?>> interceptors =
                    new ArrayList<>(beanManager.resolveInterceptors(InterceptionType.AROUND_INVOKE, 
                                                                    interceptorBindings));
                if (LOG.isLoggable(Level.FINEST)) {
                    LOG.finest("Resolved interceptors from beanManager, " + beanManager + ":" + interceptors);
                }

                if (!interceptors.isEmpty()) {
                    List<InterceptorInvoker> chain = new ArrayList<>();
                    for (Interceptor<?> interceptor : interceptors) {
                        chain.add(
                            new InterceptorInvoker(interceptor, 
                                                   interceptorInstances.computeIfAbsent(interceptor, 
                                                       i -> beanManager.getReference(i, 
                                                                                     i.getBeanClass(), 
                                                                                     creationalContext))));
                    }
                    invokers.put(javaMethod, chain);
                }
            }
        }
        return invokers.isEmpty() ? Collections.emptyMap() : invokers;
    }
1058711
protected void configureHandlerInterceptor(ApplicationContext context) {
        if (context.containsBean(ENDPOINT_INTERCEPTOR_BEAN_NAME)) {
            DelegatingEndpointInterceptor endpointInterceptor = context.getBean(ENDPOINT_INTERCEPTOR_BEAN_NAME, DelegatingEndpointInterceptor.class);
            endpointInterceptor.setInterceptors(adaptInterceptors(webServiceServer.getInterceptors()));
        }
    }
808926
private E createUsingConstructor() throws CheckedAnalysisException {
        Constructor<E> constructor;
        try {
            constructor = databaseClass.getConstructor(new Class[0]);
        } catch (NoSuchMethodException e) {
            return null;
        }

        try {
            return constructor.newInstance(new Object[0]);
        } catch (InstantiationException e) {
            throw new CheckedAnalysisException("Could not create " + databaseClass.getName(), e);
        } catch (IllegalAccessException e) {
            throw new CheckedAnalysisException("Could not create " + databaseClass.getName(), e);
        } catch (InvocationTargetException e) {
            throw new CheckedAnalysisException("Could not create " + databaseClass.getName(), e);
        }
    }
649093
public void setInterceptors(List<ClientInterceptor> interceptors) {
        this.interceptors = interceptors;
        getWebServiceTemplate().setInterceptors(interceptors.toArray(new ClientInterceptor[interceptors.size()]));
    }
380820
@Override
    protected void createForwardingMethodBody(ClassMethod classMethod, final MethodInformation methodInfo, ClassMethod staticConstructor) {
        final Method method = methodInfo.getMethod();
        // we can only use bytecode based invocation for some methods
        // at the moment we restrict it solely to public methods with public
        // return and parameter types
        boolean bytecodeInvocationAllowed = Modifier.isPublic(method.getModifiers()) && Modifier.isPublic(method.getReturnType().getModifiers());
        for (Class<?> paramType : method.getParameterTypes()) {
            if (!Modifier.isPublic(paramType.getModifiers())) {
                bytecodeInvocationAllowed = false;
                break;
            }
        }
        if (!bytecodeInvocationAllowed) {
            createInterceptorBody(classMethod, methodInfo, staticConstructor);
            return;
        }

        // create a new interceptor invocation context whenever we invoke a method on a client proxy
        // we use a try-catch block in order to make sure that endInterceptorContext() is invoked regardless whether
        // the method has succeeded or not

        new RunWithinInterceptionDecorationContextGenerator(classMethod, this) {

            @Override
            void doWork(CodeAttribute b, ClassMethod classMethod) {
                loadBeanInstance(classMethod.getClassFile(), methodInfo, b);
                //now we should have the target bean instance on top of the stack
                // we need to dup it so we still have it to compare to the return value
                b.dup();

                //lets create the method invocation
                String methodDescriptor = methodInfo.getDescriptor();
                b.loadMethodParameters();
                if (method.getDeclaringClass().isInterface()) {
                    b.invokeinterface(methodInfo.getDeclaringClass(), methodInfo.getName(), methodDescriptor);
                } else {
                    b.invokevirtual(methodInfo.getDeclaringClass(), methodInfo.getName(), methodDescriptor);
                }
            }

            @Override
            void doReturn(CodeAttribute b, ClassMethod classMethod) {
                // assumes doWork() result is on top of the stack
                // if this method returns a primitive we just return
                if (method.getReturnType().isPrimitive()) {
                    b.returnInstruction();
                } else {
                    // otherwise we have to check that the proxy is not returning 'this;
                    // now we need to check if the proxy has return 'this' and if so return
                    // an
                    // instance of the proxy.
                    // currently we have result, beanInstance on the stack.
                    b.dupX1();
                    // now we have result, beanInstance, result
                    // we need to compare result and beanInstance

                    // first we need to build up the inner conditional that just returns
                    // the
                    // result
                    final BranchEnd returnInstruction = b.ifAcmpeq();
                    b.returnInstruction();
                    b.branchEnd(returnInstruction);

                    // now add the case where the proxy returns 'this';
                    b.aload(0);
                    b.checkcast(methodInfo.getMethod().getReturnType().getName());
                    b.returnInstruction();
                }
            }
        }.runStartIfNotEmpty();
    }
505041
public void configInterceptor(Interceptors me) {
		// add excetion interceptor
		me.add(new ExceptionInterceptor());
		if (this.getHttpPostMethod()) {
			me.add(new POST());
		}
		// config others
		configMoreInterceptors(me);
	}
1080602
private static <T, G extends T> void generateSetInterceptor(DexMaker dexMaker,
                                                                TypeId<G> generatedType,
                                                                TypeId<T> baseType) {
        final FieldId<G, Interceptor> interceptorField =
                generatedType.getField(INTERCEPTOR_TYPE, FIELD_NAME_INTERCEPTOR);

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

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

        final Local<G> localThis = code.getThis(generatedType);
        final Local<Interceptor> localInterceptor = code.getParameter(0, INTERCEPTOR_TYPE);
        code.iput(interceptorField, localThis, localInterceptor);
        code.returnVoid();
    }
447805
private void createInstanceUsingConstructor() throws InvocationTargetException {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "createInstanceUsingConstructor");

        try {
            if (isTraceOn && tc.isDebugEnabled())
                Tr.debug(tc, "calling Constructor.newInstance");
            Constructor<?> con = home.beanMetaData.getEnterpriseBeanClassConstructor();
            setEnterpriseBean(con.newInstance());
        } catch (InvocationTargetException e) {
            FFDCFilter.processException(e, CLASS_NAME + ".createInstanceUsingConstructor", "360", this);
            throw e;
        } catch (Exception e) {
            // Reflection exceptions are unexpected.
            FFDCFilter.processException(e, CLASS_NAME + ".createInstanceUsingConstructor", "364", this);
            throw new EJBException(home.beanMetaData.enterpriseBeanClassName, e);
        }

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