/*
 * 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.context.weaving;

import org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.instrument.classloading.LoadTimeWeaver;
import org.springframework.util.Assert;

/**
 * Post-processor that registers AspectJ's
 * {@link org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter}
 * with the Spring application context's default
 * {@link org.springframework.instrument.classloading.LoadTimeWeaver}.
 *
 * @author Juergen Hoeller
 * @since 2.1
 */
public class AspectJWeavingEnabler implements BeanFactoryPostProcessor, LoadTimeWeaverAware {

	private LoadTimeWeaver loadTimeWeaver;


	public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) {
		this.loadTimeWeaver = loadTimeWeaver;
	}


	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		Assert.state(this.loadTimeWeaver != null,
				"LoadTimeWeaver must be available - typically autodetected as bean with name 'loadTimeWeaver'");
		this.loadTimeWeaver.addTransformer(new ClassPreProcessorAgentAdapter());
	}

}

@@ -932,16 +932,57 @@
 actory;%0A
+import org.springframework.core.Ordered;%0A
 import o
@@ -1456,16 +1456,25 @@
 verAware
+, Ordered
  %7B%0A%0A%09pri
@@ -1619,16 +1619,74 @@
 er;%0A%09%7D%0A%0A
+%09public int getOrder() %7B%0A%09%09return HIGHEST_PRECEDENCE;%0A%09%7D%0A%0A
 %0A%09public

implement Ordered, exposing HIGHEST_PRECEDENCE (executing before other factory post-processors)