Java Code Examples for org.springframework.beans.PropertyValues
The following examples show how to use
org.springframework.beans.PropertyValues. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring4-understanding Source File: JmsListenerContainerParser.java License: Apache License 2.0 | 6 votes |
@Override protected RootBeanDefinition createContainerFactory(String factoryId, Element containerEle, ParserContext parserContext, PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) { RootBeanDefinition factoryDef = new RootBeanDefinition(); String containerType = containerEle.getAttribute(CONTAINER_TYPE_ATTRIBUTE); String containerClass = containerEle.getAttribute(CONTAINER_CLASS_ATTRIBUTE); if (!"".equals(containerClass)) { return null; // Not supported } else if ("".equals(containerType) || containerType.startsWith("default")) { factoryDef.setBeanClassName("org.springframework.jms.config.DefaultJmsListenerContainerFactory"); } else if (containerType.startsWith("simple")) { factoryDef.setBeanClassName("org.springframework.jms.config.SimpleJmsListenerContainerFactory"); } factoryDef.getPropertyValues().addPropertyValues(commonContainerProperties); factoryDef.getPropertyValues().addPropertyValues(specificContainerProperties); return factoryDef; }
Example 2
Source Project: Zebra Source File: ZebraMapperScannerConfigurer.java License: Apache License 2.0 | 6 votes |
private String updatePropertyValue(String propertyName, PropertyValues values) { PropertyValue property = values.getPropertyValue(propertyName); if (property == null) { return null; } Object value = property.getValue(); if (value == null) { return null; } else if (value instanceof String) { return value.toString(); } else if (value instanceof TypedStringValue) { return ((TypedStringValue) value).getValue(); } else { return null; } }
Example 3
Source Project: rice Source File: UifDictionaryIndex.java License: Educational Community License v2.0 | 6 votes |
/** * Performs additional indexing based on the view type associated with the view instance. The * {@code ViewTypeService} associated with the view type name on the instance is invoked to retrieve * the parameter key/value pairs from the configured property values, which are then used to build up an index * used to key the entry * * @param propertyValues - property values configured on the view bean definition * @param id - id (or bean name if id was not set) for the view */ protected void indexViewForType(PropertyValues propertyValues, String id) { String viewTypeName = ViewModelUtils.getStringValFromPVs(propertyValues, "viewTypeName"); if (StringUtils.isBlank(viewTypeName)) { return; } UifConstants.ViewType viewType = ViewType.valueOf(viewTypeName); ViewTypeService typeService = KRADServiceLocatorWeb.getViewService().getViewTypeService(viewType); if (typeService == null) { // don't do any further indexing return; } // invoke type service to retrieve it parameter name/value pairs Map<String, String> typeParameters = typeService.getParametersFromViewConfiguration(propertyValues); // build the index string from the parameters String index = buildTypeIndex(typeParameters); // get the index for the type and add the view entry ViewTypeDictionaryIndex typeIndex = getTypeIndex(viewType); typeIndex.put(index, id); }
Example 4
Source Project: spring-analysis-note Source File: CommonAnnotationBeanPostProcessor.java License: MIT License | 6 votes |
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz, @Nullable PropertyValues pvs) { // Fall back to class name as cache key, for backwards compatibility with custom callers. String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName()); // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { synchronized (this.injectionMetadataCache) { metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { if (metadata != null) { metadata.clear(pvs); } metadata = buildResourceMetadata(clazz); this.injectionMetadataCache.put(cacheKey, metadata); } } } return metadata; }
Example 5
Source Project: spring-analysis-note Source File: JcaListenerContainerParser.java License: MIT License | 6 votes |
@Override protected RootBeanDefinition createContainer(Element containerEle, Element listenerEle, ParserContext parserContext, PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) { RootBeanDefinition containerDef = new RootBeanDefinition(); containerDef.setSource(parserContext.extractSource(containerEle)); containerDef.setBeanClassName("org.springframework.jms.listener.endpoint.JmsMessageEndpointManager"); containerDef.getPropertyValues().addPropertyValues(specificContainerProperties); RootBeanDefinition configDef = new RootBeanDefinition(); configDef.setSource(parserContext.extractSource(containerEle)); configDef.setBeanClassName("org.springframework.jms.listener.endpoint.JmsActivationSpecConfig"); configDef.getPropertyValues().addPropertyValues(commonContainerProperties); parseListenerConfiguration(listenerEle, parserContext, configDef.getPropertyValues()); containerDef.getPropertyValues().add("activationSpecConfig", configDef); return containerDef; }
Example 6
Source Project: jetcache Source File: CreateCacheAnnotationBeanPostProcessor.java License: Apache License 2.0 | 6 votes |
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, PropertyValues pvs) { // Fall back to class name as cache key, for backwards compatibility with custom callers. String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName()); // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { synchronized (this.injectionMetadataCache) { metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { if (metadata != null) { clear(metadata, pvs); } try { metadata = buildAutowiringMetadata(clazz); this.injectionMetadataCache.put(cacheKey, metadata); } catch (NoClassDefFoundError err) { throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() + "] for autowiring metadata: could not find class that it depends on", err); } } } } return metadata; }
Example 7
Source Project: spring-analysis-note Source File: JmsListenerContainerParser.java License: MIT License | 6 votes |
@Override protected RootBeanDefinition createContainerFactory(String factoryId, Element containerEle, ParserContext parserContext, PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) { RootBeanDefinition factoryDef = new RootBeanDefinition(); String containerType = containerEle.getAttribute(CONTAINER_TYPE_ATTRIBUTE); String containerClass = containerEle.getAttribute(CONTAINER_CLASS_ATTRIBUTE); if (!"".equals(containerClass)) { return null; // Not supported } else if ("".equals(containerType) || containerType.startsWith("default")) { factoryDef.setBeanClassName("org.springframework.jms.config.DefaultJmsListenerContainerFactory"); } else if (containerType.startsWith("simple")) { factoryDef.setBeanClassName("org.springframework.jms.config.SimpleJmsListenerContainerFactory"); } factoryDef.getPropertyValues().addPropertyValues(commonContainerProperties); factoryDef.getPropertyValues().addPropertyValues(specificContainerProperties); return factoryDef; }
Example 8
Source Project: spring-analysis-note Source File: AutowiredAnnotationBeanPostProcessor.java License: MIT License | 6 votes |
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, @Nullable PropertyValues pvs) { // Fall back to class name as cache key, for backwards compatibility with custom callers. String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName()); // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { synchronized (this.injectionMetadataCache) { metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { if (metadata != null) { metadata.clear(pvs); } metadata = buildAutowiringMetadata(clazz); this.injectionMetadataCache.put(cacheKey, metadata); } } } return metadata; }
Example 9
Source Project: Mapper Source File: MapperScannerConfigurer.java License: MIT License | 6 votes |
private String updatePropertyValue(String propertyName, PropertyValues values) { PropertyValue property = values.getPropertyValue(propertyName); if (property == null) { return null; } Object value = property.getValue(); if (value == null) { return null; } else if (value instanceof String) { return value.toString(); } else if (value instanceof TypedStringValue) { return ((TypedStringValue) value).getValue(); } else { return null; } }
Example 10
Source Project: spring-boot-starter-dubbo Source File: InjectAnnotationBeanPostProcessor.java License: Apache License 2.0 | 6 votes |
private InjectionMetadata findReferenceMetadata(String beanName, Class<?> clazz, PropertyValues pvs) { // Fall back to class name as cache key, for backwards compatibility with custom callers. String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName()); // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { synchronized (this.injectionMetadataCache) { metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { if (metadata != null) { metadata.clear(pvs); } try { metadata = buildReferenceMetadata(clazz); this.injectionMetadataCache.put(cacheKey, metadata); } catch (NoClassDefFoundError err) { throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() + "] for reference metadata: could not find class that it depends on", err); } } } } return metadata; }
Example 11
Source Project: java-technology-stack Source File: CommonAnnotationBeanPostProcessor.java License: MIT License | 6 votes |
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz, @Nullable PropertyValues pvs) { // Fall back to class name as cache key, for backwards compatibility with custom callers. String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName()); // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { synchronized (this.injectionMetadataCache) { metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { if (metadata != null) { metadata.clear(pvs); } metadata = buildResourceMetadata(clazz); this.injectionMetadataCache.put(cacheKey, metadata); } } } return metadata; }
Example 12
Source Project: lams Source File: RequiredAnnotationBeanPostProcessor.java License: GNU General Public License v2.0 | 6 votes |
@Override public PropertyValues postProcessPropertyValues( PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException { if (!this.validatedBeanNames.contains(beanName)) { if (!shouldSkip(this.beanFactory, beanName)) { List<String> invalidProperties = new ArrayList<String>(); for (PropertyDescriptor pd : pds) { if (isRequiredProperty(pd) && !pvs.contains(pd.getName())) { invalidProperties.add(pd.getName()); } } if (!invalidProperties.isEmpty()) { throw new BeanInitializationException(buildExceptionMessage(invalidProperties, beanName)); } } this.validatedBeanNames.add(beanName); } return pvs; }
Example 13
Source Project: spring4-understanding Source File: BeanComponentDefinition.java License: Apache License 2.0 | 6 votes |
private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) { List<BeanDefinition> innerBeans = new ArrayList<BeanDefinition>(); List<BeanReference> references = new ArrayList<BeanReference>(); PropertyValues propertyValues = beanDefinition.getPropertyValues(); for (int i = 0; i < propertyValues.getPropertyValues().length; i++) { PropertyValue propertyValue = propertyValues.getPropertyValues()[i]; Object value = propertyValue.getValue(); if (value instanceof BeanDefinitionHolder) { innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition()); } else if (value instanceof BeanDefinition) { innerBeans.add((BeanDefinition) value); } else if (value instanceof BeanReference) { references.add((BeanReference) value); } } this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]); this.beanReferences = references.toArray(new BeanReference[references.size()]); }
Example 14
Source Project: java-technology-stack Source File: HttpServletBean.java License: MIT License | 6 votes |
/** * Map config parameters onto bean properties of this servlet, and * invoke subclass initialization. * @throws ServletException if bean properties are invalid (or required * properties are missing), or if subclass initialization fails. */ @Override public final void init() throws ServletException { // Set bean properties from init parameters. PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties); if (!pvs.isEmpty()) { try { BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext()); bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment())); initBeanWrapper(bw); bw.setPropertyValues(pvs, true); } catch (BeansException ex) { if (logger.isErrorEnabled()) { logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex); } throw ex; } } // Let subclasses do whatever initialization they like. initServletBean(); }
Example 15
Source Project: spring4-understanding Source File: WebRequestDataBinderTests.java License: Apache License 2.0 | 6 votes |
/** * Must contain: forname=Tony surname=Blair age=50 */ protected void doTestTony(PropertyValues pvs) throws Exception { assertTrue("Contains 3", pvs.getPropertyValues().length == 3); assertTrue("Contains forname", pvs.contains("forname")); assertTrue("Contains surname", pvs.contains("surname")); assertTrue("Contains age", pvs.contains("age")); assertTrue("Doesn't contain tory", !pvs.contains("tory")); PropertyValue[] pvArray = pvs.getPropertyValues(); Map<String, String> m = new HashMap<String, String>(); m.put("forname", "Tony"); m.put("surname", "Blair"); m.put("age", "50"); for (PropertyValue pv : pvArray) { Object val = m.get(pv.getName()); assertTrue("Can't have unexpected value", val != null); assertTrue("Val i string", val instanceof String); assertTrue("val matches expected", val.equals(pv.getValue())); m.remove(pv.getName()); } assertTrue("Map size is 0", m.size() == 0); }
Example 16
Source Project: rice Source File: MaintenanceViewTypeServiceImpl.java License: Educational Community License v2.0 | 6 votes |
/** * @see org.kuali.rice.krad.uif.service.ViewTypeService#getParametersFromViewConfiguration(org.springframework.beans.PropertyValues) */ public Map<String, String> getParametersFromViewConfiguration(PropertyValues propertyValues) { Map<String, String> parameters = new HashMap<String, String>(); String viewName = ViewModelUtils.getStringValFromPVs(propertyValues, UifParameters.VIEW_NAME); String dataObjectClassName = ViewModelUtils.getStringValFromPVs(propertyValues, UifParameters.DATA_OBJECT_CLASS_NAME); String docTypeName = ViewModelUtils.getStringValFromPVs(propertyValues, UifParameters.DOC_TYPE_NAME); if (!StringUtils.isEmpty(docTypeName)) { parameters.put(UifParameters.DOC_TYPE_NAME, docTypeName); } else if (!StringUtils.isEmpty(dataObjectClassName)) { parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClassName); } else { throw new IllegalArgumentException("Document type name or bo class not given!"); } parameters.put(UifParameters.VIEW_NAME, viewName); return parameters; }
Example 17
Source Project: java-technology-stack Source File: JmsListenerContainerParser.java License: MIT License | 6 votes |
@Override protected RootBeanDefinition createContainerFactory(String factoryId, Element containerEle, ParserContext parserContext, PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) { RootBeanDefinition factoryDef = new RootBeanDefinition(); String containerType = containerEle.getAttribute(CONTAINER_TYPE_ATTRIBUTE); String containerClass = containerEle.getAttribute(CONTAINER_CLASS_ATTRIBUTE); if (!"".equals(containerClass)) { return null; // Not supported } else if ("".equals(containerType) || containerType.startsWith("default")) { factoryDef.setBeanClassName("org.springframework.jms.config.DefaultJmsListenerContainerFactory"); } else if (containerType.startsWith("simple")) { factoryDef.setBeanClassName("org.springframework.jms.config.SimpleJmsListenerContainerFactory"); } factoryDef.getPropertyValues().addPropertyValues(commonContainerProperties); factoryDef.getPropertyValues().addPropertyValues(specificContainerProperties); return factoryDef; }
Example 18
Source Project: spring4-understanding Source File: AutowiredAnnotationBeanPostProcessor.java License: Apache License 2.0 | 6 votes |
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, PropertyValues pvs) { // Fall back to class name as cache key, for backwards compatibility with custom callers. String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName()); // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { synchronized (this.injectionMetadataCache) { metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { if (metadata != null) { metadata.clear(pvs); } try { metadata = buildAutowiringMetadata(clazz); this.injectionMetadataCache.put(cacheKey, metadata); } catch (NoClassDefFoundError err) { throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() + "] for autowiring metadata: could not find class that it depends on", err); } } } } return metadata; }
Example 19
Source Project: rice Source File: ViewModelUtils.java License: Educational Community License v2.0 | 6 votes |
/** * Helper method for getting the string value of a property from a {@link PropertyValues} * * @param propertyValues property values instance to pull from * @param propertyName name of property whose value should be retrieved * @return String value for property or null if property was not found */ public static String getStringValFromPVs(PropertyValues propertyValues, String propertyName) { String propertyValue = null; if ((propertyValues != null) && propertyValues.contains(propertyName)) { Object pvValue = propertyValues.getPropertyValue(propertyName).getValue(); if (pvValue instanceof TypedStringValue) { TypedStringValue typedStringValue = (TypedStringValue) pvValue; propertyValue = typedStringValue.getValue(); } else if (pvValue instanceof String) { propertyValue = (String) pvValue; } } return propertyValue; }
Example 20
Source Project: spring4-understanding Source File: PersistenceAnnotationBeanPostProcessor.java License: Apache License 2.0 | 6 votes |
private InjectionMetadata findPersistenceMetadata(String beanName, final Class<?> clazz, PropertyValues pvs) { // Fall back to class name as cache key, for backwards compatibility with custom callers. String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName()); // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { synchronized (this.injectionMetadataCache) { metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { if (metadata != null) { metadata.clear(pvs); } try { metadata = buildPersistenceMetadata(clazz); this.injectionMetadataCache.put(cacheKey, metadata); } catch (NoClassDefFoundError err) { throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() + "] for persistence metadata: could not find class that it depends on", err); } } } } return metadata; }
Example 21
Source Project: spring4-understanding Source File: CommonAnnotationBeanPostProcessor.java License: Apache License 2.0 | 6 votes |
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz, PropertyValues pvs) { // Fall back to class name as cache key, for backwards compatibility with custom callers. String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName()); // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { synchronized (this.injectionMetadataCache) { metadata = this.injectionMetadataCache.get(cacheKey); if (InjectionMetadata.needsRefresh(metadata, clazz)) { if (metadata != null) { metadata.clear(pvs); } try { metadata = buildResourceMetadata(clazz); this.injectionMetadataCache.put(cacheKey, metadata); } catch (NoClassDefFoundError err) { throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() + "] for resource metadata: could not find class that it depends on", err); } } } } return metadata; }
Example 22
Source Project: java-technology-stack Source File: AbstractAutowireCapableBeanFactory.java License: MIT License | 6 votes |
/** * Perform a dependency check that all properties exposed have been set, * if desired. Dependency checks can be objects (collaborating beans), * simple (primitives and String), or all (both). * @param beanName the name of the bean * @param mbd the merged bean definition the bean was created with * @param pds the relevant property descriptors for the target bean * @param pvs the property values to be applied to the bean * @see #isExcludedFromDependencyCheck(java.beans.PropertyDescriptor) */ protected void checkDependencies( String beanName, AbstractBeanDefinition mbd, PropertyDescriptor[] pds, @Nullable PropertyValues pvs) throws UnsatisfiedDependencyException { int dependencyCheck = mbd.getDependencyCheck(); for (PropertyDescriptor pd : pds) { if (pd.getWriteMethod() != null && (pvs == null || !pvs.contains(pd.getName()))) { boolean isSimple = BeanUtils.isSimpleProperty(pd.getPropertyType()); boolean unsatisfied = (dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_ALL) || (isSimple && dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_SIMPLE) || (!isSimple && dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_OBJECTS); if (unsatisfied) { throw new UnsatisfiedDependencyException(mbd.getResourceDescription(), beanName, pd.getName(), "Set this property value or disable dependency checking for this bean."); } } } }
Example 23
Source Project: spring-analysis-note Source File: CommonAnnotationBeanPostProcessor.java License: MIT License | 5 votes |
@Override public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) { InjectionMetadata metadata = findResourceMetadata(beanName, bean.getClass(), pvs); try { metadata.inject(bean, beanName, pvs); } catch (Throwable ex) { throw new BeanCreationException(beanName, "Injection of resource dependencies failed", ex); } return pvs; }
Example 24
Source Project: spring-analysis-note Source File: PersistenceAnnotationBeanPostProcessor.java License: MIT License | 5 votes |
@Override public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) { InjectionMetadata metadata = findPersistenceMetadata(beanName, bean.getClass(), pvs); try { metadata.inject(bean, beanName, pvs); } catch (Throwable ex) { throw new BeanCreationException(beanName, "Injection of persistence dependencies failed", ex); } return pvs; }
Example 25
Source Project: spring4-understanding Source File: GenericPortletBean.java License: Apache License 2.0 | 5 votes |
/** * Map config parameters onto bean properties of this portlet, and * invoke subclass initialization. * @throws PortletException if bean properties are invalid (or required * properties are missing), or if subclass initialization fails. */ @Override public final void init() throws PortletException { if (logger.isInfoEnabled()) { logger.info("Initializing portlet '" + getPortletName() + "'"); } // Set bean properties from init parameters. try { PropertyValues pvs = new PortletConfigPropertyValues(getPortletConfig(), this.requiredProperties); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); ResourceLoader resourceLoader = new PortletContextResourceLoader(getPortletContext()); bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment())); initBeanWrapper(bw); bw.setPropertyValues(pvs, true); } catch (BeansException ex) { logger.error("Failed to set bean properties on portlet '" + getPortletName() + "'", ex); throw ex; } // let subclasses do whatever initialization they like initPortletBean(); if (logger.isInfoEnabled()) { logger.info("Portlet '" + getPortletName() + "' configured successfully"); } }
Example 26
Source Project: spring-analysis-note Source File: HttpServletBean.java License: MIT License | 5 votes |
/** * Map config parameters onto bean properties of this servlet, and * invoke subclass initialization. * @throws ServletException if bean properties are invalid (or required * properties are missing), or if subclass initialization fails. */ @Override public final void init() throws ServletException { // Set bean properties from init parameters. // 解析 init-param 并封装到 pvs 变量中 PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties); if (!pvs.isEmpty()) { try { // 将当前的这个 Servlet 类转换为一个 BeanWrapper,从而能够以 Spring 的方式对 init—param 的值注入 BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext()); // 注册自定义属性编辑器,一旦遇到 Resource 类型的属性将会使用 ResourceEditor 进行解析 bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment())); // 空实现,留给子类覆盖 initBeanWrapper(bw); bw.setPropertyValues(pvs, true); } catch (BeansException ex) { if (logger.isErrorEnabled()) { logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex); } throw ex; } } // Let subclasses do whatever initialization they like. // 初始化 servletBean (让子类实现,这里它的实现子类是 FrameworkServlet) initServletBean(); }
Example 27
Source Project: spring4-understanding Source File: HttpServletBean.java License: Apache License 2.0 | 5 votes |
/** * Map config parameters onto bean properties of this servlet, and * invoke subclass initialization. * @throws ServletException if bean properties are invalid (or required * properties are missing), or if subclass initialization fails. */ @Override public final void init() throws ServletException { if (logger.isDebugEnabled()) { logger.debug("Initializing servlet '" + getServletName() + "'"); } // Set bean properties from init parameters. try { PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext()); bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment())); initBeanWrapper(bw); bw.setPropertyValues(pvs, true); } catch (BeansException ex) { logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex); throw ex; } // Let subclasses do whatever initialization they like. initServletBean(); if (logger.isDebugEnabled()) { logger.debug("Servlet '" + getServletName() + "' configured successfully"); } }
Example 28
Source Project: brpc-java Source File: RpcAnnotationResolver.java License: Apache License 2.0 | 5 votes |
@Override public Object annotationAtField(Annotation t, Object value, String beanName, PropertyValues pvs, DefaultListableBeanFactory beanFactory, Field field) throws BeansException { if (t instanceof RpcProxy) { try { LOGGER.info("Annotation 'BrpcProxy' on field '" + field.getName() + "' for target '" + beanName + "' created"); return parseRpcProxyAnnotation((RpcProxy) t, field.getType(), beanFactory); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } return value; }
Example 29
Source Project: spring-analysis-note Source File: JcaListenerContainerParser.java License: MIT License | 5 votes |
@Override protected RootBeanDefinition createContainerFactory(String factoryId, Element containerEle, ParserContext parserContext, PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) { RootBeanDefinition factoryDef = new RootBeanDefinition(); factoryDef.setBeanClassName("org.springframework.jms.config.DefaultJcaListenerContainerFactory"); factoryDef.getPropertyValues().addPropertyValues(commonContainerProperties); factoryDef.getPropertyValues().addPropertyValues(specificContainerProperties); return factoryDef; }
Example 30
Source Project: brpc-java Source File: SpringBootAnnotationResolver.java License: Apache License 2.0 | 5 votes |
@Override public Object annotationAtField(Annotation t, Object value, String beanName, PropertyValues pvs, DefaultListableBeanFactory beanFactory, Field field) throws BeansException { if (t instanceof RpcProxy) { try { log.info("Annotation 'BrpcProxy' on field '" + field.getName() + "' for target '" + beanName + "' created"); return parseRpcProxyAnnotation((RpcProxy) t, field.getType(), beanFactory); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } return value; }