<commit_before>/*
 * Copyright 2002-2007 the original author or authors.
 *
 * 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.
 */

package org.springframework.ejb.interceptor;

import java.util.Map;
import java.util.WeakHashMap;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
import javax.interceptor.InvocationContext;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference;
import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;

/**
 * EJB3-compliant interceptor class that injects Spring beans into
 * fields and methods which are annotated with <code>@Autowired</code>.
 * Performs injection after construction as well as after activation
 * of a passivated bean.
 *
 * <p>To be applied through an <code>@Interceptors</code> annotation in
 * the EJB Session Bean or Message-Driven Bean class, or through an
 * <code>interceptor-binding</code> XML element in the EJB deployment descriptor.
 *
 * <p>Delegates to Spring's {@link AutowiredAnnotationBeanPostProcessor}
 * underneath, allowing for customization of its specific settings through
 * overriding the {@link #configureBeanPostProcessor} template method.
 *
 * <p>The actual BeanFactory to obtain Spring beans from is determined
 * by the {@link #getBeanFactory} template method. The default implementation
 * obtains the Spring {@link ContextSingletonBeanFactoryLocator}, initialized
 * from the default resource location <strong>classpath*:beanRefContext.xml</strong>,
 * and obtains the single ApplicationContext defined there.
 *
 * <p><b>NOTE: If you have more than one shared ApplicationContext definition available
 * in your EJB class loader, you need to override the {@link #getBeanFactoryLocatorKey}
 * method and provide a specific locator key for each autowired EJB.</b>
 * Alternatively, override the {@link #getBeanFactory} template method and
 * obtain the target factory explicitly.
 *
 * @author <NAME>
 * @since 2.5.1
 * @see org.springframework.beans.factory.annotation.Autowired
 * @see org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
 * @see org.springframework.context.access.ContextSingletonBeanFactoryLocator
 * @see #getBeanFactoryLocatorKey
 * @see org.springframework.ejb.support.AbstractEnterpriseBean#setBeanFactoryLocator
 * @see org.springframework.ejb.support.AbstractEnterpriseBean#setBeanFactoryLocatorKey
 */
public class SpringBeanAutowiringInterceptor {

	/*
	 * We're keeping the BeanFactoryReference per target object in order to
	 * allow for using a shared interceptor instance on pooled target beans.
	 * This is not strictly necessary for EJB3 Session Beans and Message-Driven
	 * Beans, where interceptor instances get created per target bean instance.<commit_msg>added warning regarding double deployment<commit_after>/*
 * Copyright 2002-2008 the original author or authors.
 *
 * 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.
 */

package org.springframework.ejb.interceptor;

import java.util.Map;
import java.util.WeakHashMap;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
import javax.interceptor.InvocationContext;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference;
import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;

/**
 * EJB3-compliant interceptor class that injects Spring beans into
 * fields and methods which are annotated with <code>@Autowired</code>.
 * Performs injection after construction as well as after activation
 * of a passivated bean.
 *
 * <p>To be applied through an <code>@Interceptors</code> annotation in
 * the EJB Session Bean or Message-Driven Bean class, or through an
 * <code>interceptor-binding</code> XML element in the EJB deployment descriptor.
 *
 * <p>Delegates to Spring's {@link AutowiredAnnotationBeanPostProcessor}
 * underneath, allowing for customization of its specific settings through
 * overriding the {@link #configureBeanPostProcessor} template method.
 *
 * <p>The actual BeanFactory to obtain Spring beans from is determined
 * by the {@link #getBeanFactory} template method. The default implementation
 * obtains the Spring {@link ContextSingletonBeanFactoryLocator}, initialized
 * from the default resource location <strong>classpath*:beanRefContext.xml</strong>,
 * and obtains the single ApplicationContext defined there.
 *
 * <p><b>NOTE: If you have more than one shared ApplicationContext definition available
 * in your EJB class loader, you need to override the {@link #getBeanFactoryLocatorKey}
 * method and provide a specific locator key for each autowired EJB.</b>
 * Alternatively, override the {@link #getBeanFactory} template method and
 * obtain the target factory explicitly.
 *
 * <p><b>WARNING: Do not define the same bean as Spring-managed bean and as
 * EJB3 session bean in the same deployment unit.</b> In particular, be
 * careful when using the <code>&lt;context:component-scan&gt;</code> feature
 * in combination with the deployment of Spring-based EJB3 session beans:
 * Make sure that the EJB3 session beans are <i>not</i> autodetected as
 * Spring-managed beans as well, using appropriate package restrictions.
 *
 * @author <NAME>
 * @since 2.5.1
 * @see org.springframework.beans.factory.annotation.Autowired
 * @see org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
 * @see org.springframework.context.access.ContextSingletonBeanFactoryLocator
 * @see #getBeanFactoryLocatorKey
 * @see org.springframework.ejb.support.AbstractEnterpriseBean#setBeanFactoryLocator
 * @see org.springframework.ejb.support.AbstractEnterpriseBean#setBeanFactoryLocatorKey
 */
public class SpringBeanAutowiringInterceptor {

	/*
	 * We're keeping the BeanFactoryReference per target object in order to
	 * allow for using a shared interceptor instance on pooled target beans.
	 * This is not strictly necessary for EJB3 Session Beans and Message-Driven
	 * Beans, where interceptor instances get created per target bean instance.
{'fraction_non_alphanumeric': 0.07507155867811606, 'fraction_numerical': 0.004813947436898257, 'mean_word_length': 5.331960461285008, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3024423', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1915, 'n_words': 733}