<commit_before>/**
 * Copyright 2013 <NAME>
 *
 * 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.jsconf.core.impl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ApplicationContext;

public class ProxyPostProcessor {

	private final Map<String, BeanProxy> proxyRef = new HashMap<>();

	private final ApplicationContext context;

	public ProxyPostProcessor(ApplicationContext context) {
		this.context = context;
	}

	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if (bean.getClass().getInterfaces().length > 0) {
			BeanProxy proxy = this.proxyRef.get(beanName);
			if (proxy == null) {
				ClassLoader cl = Thread.currentThread().getContextClassLoader();
				List<Class<?>> asList = new ArrayList<>();
				asList.addAll(Arrays.asList(bean.getClass().getInterfaces()));
				asList.add(BeanProxy.class);
				Class<?>[] interfaces = asList.toArray(new Class<?>[asList.size()]);
				proxy = (BeanProxy) Proxy.newProxyInstance(cl, interfaces, new ProxyHandler());
				this.proxyRef.put(beanName, proxy);
			}
			proxy.setBean(bean);
			return proxy;
		} else {
			throw new BeanCreationException(beanName, String.format("Only bean with interface can be proxy : ",
					beanName));
		}
	}

	public void forceProxyInitalization() {
		for (String beanName : this.proxyRef.keySet()) {
			this.context.getBean(beanName);
		}
	}

	@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
	private @interface SetBeanMethod {
	}

	private interface BeanProxy {<commit_msg>Missing parameter on error message<commit_after>/**
 * Copyright 2013 <NAME>
 *
 * 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.jsconf.core.impl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ApplicationContext;

public class ProxyPostProcessor {

	private final Map<String, BeanProxy> proxyRef = new HashMap<>();

	private final ApplicationContext context;

	public ProxyPostProcessor(ApplicationContext context) {
		this.context = context;
	}

	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if (bean.getClass().getInterfaces().length > 0) {
			BeanProxy proxy = this.proxyRef.get(beanName);
			if (proxy == null) {
				ClassLoader cl = Thread.currentThread().getContextClassLoader();
				List<Class<?>> asList = new ArrayList<>();
				asList.addAll(Arrays.asList(bean.getClass().getInterfaces()));
				asList.add(BeanProxy.class);
				Class<?>[] interfaces = asList.toArray(new Class<?>[asList.size()]);
				proxy = (BeanProxy) Proxy.newProxyInstance(cl, interfaces, new ProxyHandler());
				this.proxyRef.put(beanName, proxy);
			}
			proxy.setBean(bean);
			return proxy;
		} else {
			throw new BeanCreationException(beanName, String.format("Only bean with interface can be proxy : %s",
					beanName));
		}
	}

	public void forceProxyInitalization() {
		for (String beanName : this.proxyRef.keySet()) {
			this.context.getBean(beanName);
		}
	}

	@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
	private @interface SetBeanMethod {
	}

	private interface BeanProxy {
{'fraction_non_alphanumeric': 0.10880829015544041, 'fraction_numerical': 0.0037305699481865284, 'mean_word_length': 4.7112426035502954, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '6958364', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1350, 'n_words': 393}