polish
This commit is contained in:
parent
2e7e982487
commit
dfab514568
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2009 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.config.java;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.MethodProxy;
|
||||
|
||||
|
||||
public class NoOpInterceptor implements MethodInterceptor {
|
||||
|
||||
public static final NoOpInterceptor INSTANCE = new NoOpInterceptor();
|
||||
|
||||
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,18 +18,17 @@ package org.springframework.config.java;
|
|||
|
||||
/**
|
||||
* Enumerates the names of the scopes supported out of the box in Spring.
|
||||
* <p>
|
||||
* Not modeled as an actual java enum because annotations that accept a scope attribute must
|
||||
* allow for user-defined scope names. Given that java enums are not extensible, these must
|
||||
* remain simple string constants.
|
||||
*
|
||||
* <p>Not modeled as an actual java enum because annotations that accept a scope attribute
|
||||
* must allow for user-defined scope names. Given that java enums are not extensible, these
|
||||
* must remain simple string constants.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.0
|
||||
*/
|
||||
public class StandardScopes {
|
||||
|
||||
private StandardScopes() {
|
||||
}
|
||||
private StandardScopes() { }
|
||||
|
||||
public static final String SINGLETON = "singleton";
|
||||
|
||||
|
|
|
|||
|
|
@ -29,21 +29,19 @@ import net.sf.cglib.core.DefaultGeneratorStrategy;
|
|||
import net.sf.cglib.proxy.Callback;
|
||||
import net.sf.cglib.proxy.CallbackFilter;
|
||||
import net.sf.cglib.proxy.Enhancer;
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.MethodProxy;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.objectweb.asm.ClassAdapter;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.config.java.BeanDefinitionRegistrar;
|
||||
import org.springframework.config.java.BeanMethod;
|
||||
import org.springframework.config.java.Configuration;
|
||||
import org.springframework.config.java.ConfigurationClass;
|
||||
import org.springframework.config.java.ConfigurationModel;
|
||||
import org.springframework.config.java.NoOpInterceptor;
|
||||
import org.springframework.config.java.ext.BeanMethodInterceptor;
|
||||
import org.springframework.config.java.ext.BeanRegistrar;
|
||||
|
||||
|
|
@ -85,15 +83,13 @@ public class ConfigurationEnhancer {
|
|||
*/
|
||||
public ConfigurationEnhancer(DefaultListableBeanFactory beanFactory) {
|
||||
notNull(beanFactory, "beanFactory must be non-null");
|
||||
//notNull(model, "model must be non-null");
|
||||
|
||||
//populateRegistrarsAndCallbacks(beanFactory, model);
|
||||
|
||||
registrars.add(new BeanRegistrar());
|
||||
BeanMethodInterceptor beanMethodInterceptor = new BeanMethodInterceptor();
|
||||
beanMethodInterceptor.setBeanFactory(beanFactory);
|
||||
callbackInstances.add(beanMethodInterceptor);
|
||||
|
||||
// add no-op default registrar and method interceptor
|
||||
registrars.add(new BeanDefinitionRegistrar() {
|
||||
|
||||
public boolean accepts(Method method) {
|
||||
|
|
@ -104,47 +100,14 @@ public class ConfigurationEnhancer {
|
|||
// no-op
|
||||
}
|
||||
});
|
||||
callbackInstances.add(NoOpInterceptor.INSTANCE);
|
||||
callbackInstances.add(new MethodInterceptor() {
|
||||
|
||||
for (Callback callback : callbackInstances)
|
||||
callbackTypes.add(callback.getClass());
|
||||
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
|
||||
throws Throwable {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads the contents of {@code model} in order to populate {@link #registrars},
|
||||
* {@link #callbackInstances} and {@link #callbackTypes} appropriately.
|
||||
*
|
||||
* @see #callbackFilter
|
||||
*/
|
||||
private void populateRegistrarsAndCallbacks(DefaultListableBeanFactory beanFactory,
|
||||
ConfigurationModel model) {
|
||||
|
||||
for (ConfigurationClass configClass : model.getAllConfigurationClasses()) {
|
||||
for (BeanMethod method : configClass.getMethods()) {
|
||||
registrars.add(new BeanRegistrar());
|
||||
|
||||
Callback callback = new BeanMethodInterceptor();
|
||||
|
||||
if (callback instanceof BeanFactoryAware)
|
||||
((BeanFactoryAware) callback).setBeanFactory(beanFactory);
|
||||
|
||||
callbackInstances.add(callback);
|
||||
}
|
||||
}
|
||||
|
||||
// register a 'catch-all' registrar
|
||||
registrars.add(new BeanDefinitionRegistrar() {
|
||||
|
||||
public boolean accepts(Method method) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void register(BeanMethod method, BeanDefinitionRegistry registry) {
|
||||
// no-op
|
||||
}
|
||||
});
|
||||
callbackInstances.add(NoOpInterceptor.INSTANCE);
|
||||
|
||||
for (Callback callback : callbackInstances)
|
||||
callbackTypes.add(callback.getClass());
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
* Copyright 2002-2009 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.config.java.support;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
|
|
@ -13,8 +28,9 @@ import org.springframework.config.java.Configuration;
|
|||
import org.springframework.config.java.ext.Bean;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ConfigurationClassPostProcessor}
|
||||
* Unit tests for {@link ConfigurationClassPostProcessor}.
|
||||
*
|
||||
* @author Chris Beams
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue