1 16 17 package org.springframework.beans.factory.config; 18 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import org.springframework.beans.BeansException; 23 import org.springframework.core.Ordered; 24 25 36 public class CustomScopeConfigurer implements BeanFactoryPostProcessor, Ordered { 37 38 private int order = Ordered.LOWEST_PRECEDENCE; 39 40 private Map scopes; 41 42 43 48 public void setScopes(Map scopes) { 49 this.scopes = scopes; 50 } 51 52 public void setOrder(int order) { 53 this.order = order; 54 } 55 56 public int getOrder() { 57 return order; 58 } 59 60 61 public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { 62 if (this.scopes != null) { 63 for (Iterator it = this.scopes.entrySet().iterator(); it.hasNext();) { 64 Map.Entry entry = (Map.Entry ) it.next(); 65 Object key = entry.getKey(); 66 if (!(key instanceof String )) { 67 throw new IllegalArgumentException ( 68 "Invalid scope key [" + key + "]: only Strings allowed"); 69 } 70 Object value = entry.getValue(); 71 if (!(value instanceof Scope)) { 72 throw new IllegalArgumentException ("Mapped value [" + value + "] for scope key [" + 73 key + "] is not of required type [" + Scope.class.getName() + "]"); 74 } 75 beanFactory.registerScope((String ) key, (Scope) value); 76 } 77 } 78 } 79 80 } 81 | Popular Tags |