本文整理汇总了Java中org.springframework.beans.BeanUtils.instantiate方法的典型用法代码示例。如果您正苦于以下问题:Java BeanUtils.instantiate方法的具体用法?Java BeanUtils.instantiate怎么用?Java BeanUtils.instantiate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.beans.BeanUtils
的用法示例。
在下文中一共展示了BeanUtils.instantiate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createConfigBean
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
/**
* 创建配置Bean
*
* @param propertyName 属性名
* @param beanType 配置Bean类型
* @param converterType 转换器类型
* @param configBeanPropertyResolver 属性解析器
* @param conversionService 转换服务
* @param <T>
* @return
*/
public static <T> T createConfigBean(String propertyName, Class<T> beanType,
Class<? extends ConfigBeanConverter> converterType,
ConfigPropertyResolver configBeanPropertyResolver,
ConfigBeanConversionService conversionService) {
PropertyResolver propertyResolver = configBeanPropertyResolver.getObject();
String propertyValue = propertyResolver.getRequiredProperty(propertyName);
if (converterType != null && !converterType.isInterface()) {
ConfigBeanConverter converter = BeanUtils.instantiate(converterType);
return (T) converter.convert(propertyName, propertyValue, TypeDescriptor.valueOf(beanType));
} else {
return (T) conversionService.convert(propertyName, propertyValue, TypeDescriptor.valueOf(beanType));
}
}
示例2: convertWebServiceFeature
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
private WebServiceFeature convertWebServiceFeature(Object feature) {
Assert.notNull(feature, "WebServiceFeature specification object must not be null");
if (feature instanceof WebServiceFeature) {
return (WebServiceFeature) feature;
}
else if (feature instanceof Class) {
return (WebServiceFeature) BeanUtils.instantiate((Class<?>) feature);
}
else if (feature instanceof String) {
try {
Class<?> featureClass = getBeanClassLoader().loadClass((String) feature);
return (WebServiceFeature) BeanUtils.instantiate(featureClass);
}
catch (ClassNotFoundException ex) {
throw new IllegalArgumentException("Could not load WebServiceFeature class [" + feature + "]");
}
}
else {
throw new IllegalArgumentException("Unknown WebServiceFeature specification type: " + feature.getClass());
}
}
示例3: instantiateConverters
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
private List<ConfigBeanConverter> instantiateConverters(List<Class<?>> types) {
List<ConfigBeanConverter> converters = new ArrayList<>();
for (Class<?> type : types) {
ConfigBeanConverter converter = (ConfigBeanConverter) BeanUtils.instantiate(type);
converters.add(converter);
}
return converters;
}
示例4: build
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
public WxGroupMessage build() {
WxGroupMessage wxGroupMessage;
if (classMap.containsKey(builder.messageType)) {
wxGroupMessage = BeanUtils.instantiate(classMap.get(builder.messageType));
} else {
wxGroupMessage = new WxGroupMessage();
}
wxGroupMessage.setBody(builder.body);
if (toUsers.isEmpty()) {
wxGroupMessage.filter = filter;
} else {
wxGroupMessage.toUsers = toUsers;
}
return wxGroupMessage;
}
示例5: find
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
public <T> T find(ReadContext readContext, Class<T> entityClass, Key key) {
BasicSpannerPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entityClass);
T object = BeanUtils.instantiate(entityClass);
Struct row = readContext.readRow(persistentEntity.tableName(), key, persistentEntity.columns());
objectMapper.map(row, object);
return object;
}
示例6: BlueprintContainerProcessor
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
public BlueprintContainerProcessor(EventAdminDispatcher dispatcher, BlueprintListenerManager listenerManager,
Bundle extenderBundle) {
this.dispatcher = dispatcher;
this.listenerManager = listenerManager;
this.extenderBundle = extenderBundle;
Class<?> processorClass =
ClassUtils.resolveClassName(
"org.eclipse.gemini.blueprint.blueprint.container.support.internal.config.CycleOrderingProcessor",
BundleContextAware.class.getClassLoader());
cycleBreaker = (BeanFactoryPostProcessor) BeanUtils.instantiate(processorClass);
}
示例7: registerCustomEditors
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
public void registerCustomEditors(PropertyEditorRegistry registry) {
for (Map.Entry<Class<?>, Class<? extends PropertyEditor>> entry : editors.entrySet()) {
Class<?> type = entry.getKey();
PropertyEditor editorInstance;
editorInstance = BeanUtils.instantiate(entry.getValue());
registry.registerCustomEditor(type, editorInstance);
}
// register non-externalized types
registry.registerCustomEditor(Dictionary.class, new CustomMapEditor(Hashtable.class));
registry.registerCustomEditor(Properties.class, new PropertiesEditor());
registry.registerCustomEditor(Class.class, new ClassEditor(userClassLoader));
registry.registerCustomEditor(Class[].class, new ClassArrayEditor(userClassLoader));
}
示例8: wxSessionManager
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean
public WxSessionManager wxSessionManager() {
return new DefaultWxSessionManager(wxProperties.getServer().getSessionTimeout(),
wxProperties.getServer().getMaxActiveLimit(),
BeanUtils.instantiate(wxProperties.getServer().getWxSessionIdGeneratorClass()));
}
示例9: instantiate
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
/**
* Create a new instance of a dynamically generated subclass implementing the
* required lookups.
* @param ctor constructor to use. If this is {@code null}, use the
* no-arg constructor (no parameterization, or Setter Injection)
* @param args arguments to use for the constructor.
* Ignored if the {@code ctor} parameter is {@code null}.
* @return new instance of the dynamically generated subclass
*/
Object instantiate(Constructor<?> ctor, Object[] args) {
Class<?> subclass = createEnhancedSubclass(this.beanDefinition);
Object instance;
if (ctor == null) {
instance = BeanUtils.instantiate(subclass);
}
else {
try {
Constructor<?> enhancedSubclassConstructor = subclass.getConstructor(ctor.getParameterTypes());
instance = enhancedSubclassConstructor.newInstance(args);
}
catch (Exception e) {
throw new BeanInstantiationException(this.beanDefinition.getBeanClass(), String.format(
"Failed to invoke construcor for CGLIB enhanced subclass [%s]", subclass.getName()), e);
}
}
// SPR-10785: set callbacks directly on the instance instead of in the
// enhanced class (via the Enhancer) in order to avoid memory leaks.
Factory factory = (Factory) instance;
factory.setCallbacks(new Callback[] { NoOp.INSTANCE,//
new LookupOverrideMethodInterceptor(beanDefinition, owner),//
new ReplaceOverrideMethodInterceptor(beanDefinition, owner) });
return instance;
}
示例10: reflectBean
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
private void reflectBean(Class<T> tclazz) {
tBean = BeanUtils.instantiate(tclazz);
PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(tclazz);
for (PropertyDescriptor p : propertyDescriptors) {
if (p.getWriteMethod() != null) {
this.fieldsMap.put(p.getName(), p);
}
}
beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(tBean);
}
示例11: instantiateEntityMapper
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static <U> EntityMapper<U> instantiateEntityMapper(@Nullable Class<? extends EntityMapper<?>> mapperClass) {
if (mapperClass == null) {
return new BeanEntityMapper<>();
} else {
return (EntityMapper<U>) BeanUtils.instantiate(mapperClass);
}
}
示例12: build
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
public WxUserMessage build() {
WxUserMessage wxUserMessage;
if (classMap.containsKey(builder.messageType)) {
wxUserMessage = BeanUtils.instantiate(classMap.get(builder.messageType));
} else {
wxUserMessage = new WxUserMessage();
}
wxUserMessage.setMessageType(builder.messageType);
wxUserMessage.setBody(builder.body);
wxUserMessage.setToUser(toUser);
wxUserMessage.setFromUser(fromUser);
wxUserMessage.setCreateTime(createTime);
return wxUserMessage;
}
示例13: instantiate
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
public static <T> T instantiate(Class<T> type) {
return BeanUtils.instantiate(type);
}
示例14: afterPropertiesSet
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException {
prepare();
// Use specific name if given, else fall back to bean name.
String name = (this.name != null ? this.name : this.beanName);
// Consider the concurrent flag to choose between stateful and stateless job.
Class<?> jobClass = (this.concurrent ? MethodInvokingJob.class : StatefulMethodInvokingJob.class);
// Build JobDetail instance.
if (jobDetailImplClass != null) {
// Using Quartz 2.0 JobDetailImpl class...
this.jobDetail = (JobDetail) BeanUtils.instantiate(jobDetailImplClass);
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this.jobDetail);
bw.setPropertyValue("name", name);
bw.setPropertyValue("group", this.group);
bw.setPropertyValue("jobClass", jobClass);
bw.setPropertyValue("durability", true);
((JobDataMap) bw.getPropertyValue("jobDataMap")).put("methodInvoker", this);
}
else {
// Using Quartz 1.x JobDetail class...
this.jobDetail = new JobDetail(name, this.group, jobClass);
this.jobDetail.setVolatility(true);
this.jobDetail.setDurability(true);
this.jobDetail.getJobDataMap().put("methodInvoker", this);
}
// Register job listener names.
if (this.jobListenerNames != null) {
for (String jobListenerName : this.jobListenerNames) {
if (jobDetailImplClass != null) {
throw new IllegalStateException("Non-global JobListeners not supported on Quartz 2 - " +
"manually register a Matcher against the Quartz ListenerManager instead");
}
this.jobDetail.addJobListener(jobListenerName);
}
}
postProcessJobDetail(this.jobDetail);
}
示例15: mapRow
import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
/**
* Extract the values for all columns in the current row.
* <p>Utilizes public setters and result set metadata.
* @see java.sql.ResultSetMetaData
*/
@Override
public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
Assert.state(this.mappedClass != null, "Mapped class was not specified");
T mappedObject = BeanUtils.instantiate(this.mappedClass);
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject);
initBeanWrapper(bw);
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
Set<String> populatedProperties = (isCheckFullyPopulated() ? new HashSet<String>() : null);
for (int index = 1; index <= columnCount; index++) {
String column = JdbcUtils.lookupColumnName(rsmd, index);
PropertyDescriptor pd = this.mappedFields.get(column.replaceAll(" ", "").toLowerCase());
if (pd != null) {
try {
Object value = getColumnValue(rs, index, pd);
if (logger.isDebugEnabled() && rowNumber == 0) {
logger.debug("Mapping column '" + column + "' to property '" +
pd.getName() + "' of type " + pd.getPropertyType());
}
try {
bw.setPropertyValue(pd.getName(), value);
}
catch (TypeMismatchException e) {
if (value == null && primitivesDefaultedForNullValue) {
logger.debug("Intercepted TypeMismatchException for row " + rowNumber +
" and column '" + column + "' with value " + value +
" when setting property '" + pd.getName() + "' of type " + pd.getPropertyType() +
" on object: " + mappedObject);
}
else {
throw e;
}
}
if (populatedProperties != null) {
populatedProperties.add(pd.getName());
}
}
catch (NotWritablePropertyException ex) {
throw new DataRetrievalFailureException(
"Unable to map column " + column + " to property " + pd.getName(), ex);
}
}
}
if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields " +
"necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties);
}
return mappedObject;
}