当前位置: 首页>>代码示例>>Java>>正文


Java BeanUtils.instantiate方法代码示例

本文整理汇总了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));
    }
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:28,代码来源:ConfigBeanFactory.java

示例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());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:AbstractJaxWsServiceExporter.java

示例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;
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:9,代码来源:EnableConfigServiceImportSelector.java

示例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;
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:16,代码来源:WxGroupMessage.java

示例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;
}
 
开发者ID:saturnism,项目名称:spring-data-spanner,代码行数:8,代码来源:SpannerReadContextTemplate.java

示例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);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:14,代码来源:BlueprintContainerProcessor.java

示例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));
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:15,代码来源:OsgiPropertyEditorRegistrar.java

示例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()));
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:8,代码来源:WxWebConfiguration.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:CglibSubclassingInstantiationStrategy.java

示例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);
    }
 
开发者ID:cwenao,项目名称:springboot_cwenao,代码行数:15,代码来源:HbaseFindBuilder.java

示例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);
    }
}
 
开发者ID:cybozu,项目名称:spring-data-jdbc-template,代码行数:9,代码来源:EntityRowMapper.java

示例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;
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:15,代码来源:WxUserMessage.java

示例13: instantiate

import org.springframework.beans.BeanUtils; //导入方法依赖的package包/类
public static <T> T instantiate(Class<T> type) {
    return BeanUtils.instantiate(type);
}
 
开发者ID:ElectronicArmory,项目名称:Armory,代码行数:4,代码来源:CassandraConfiguration.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:43,代码来源:MethodInvokingJobDetailFactoryBean.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:59,代码来源:BeanPropertyRowMapper.java


注:本文中的org.springframework.beans.BeanUtils.instantiate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。