List of usage examples for org.springframework.beans BeanUtils instantiate
@Deprecated public static <T> T instantiate(Class<T> clazz) throws BeanInstantiationException
From source file:newcontroller.handler.impl.DefaultRequest.java
@Override public <T> T params(Class<T> clazz) { T obj = BeanUtils.instantiate(clazz); WebDataBinder binder = new WebDataBinder(obj); binder.bind(new MutablePropertyValues(this.request.getParameterMap())); return obj;/*from www . j av a 2s . c o m*/ }
From source file:com.kurento.kmf.jsonrpcconnector.internal.server.BeanCreatingHelper.java
@SuppressWarnings("unchecked") public T createBean() { if (logger.isTraceEnabled()) { logger.trace("Creating instance for handler type {}", this.beanType); }//from w ww.j a v a 2 s . co m if (this.beanFactory == null) { logger.warn("No BeanFactory available, attempting to use default constructor"); return BeanUtils.instantiate(this.beanType); } else { if (beanType != null) { return this.beanFactory.createBean(this.beanType); } else { T bean = (T) beanFactory.getBean(beanName); createdBeanType = bean.getClass(); return bean; } } }
From source file:com.sishuok.bigpipe.view.velocity.VelocityPageletViewResolver.java
@Override public PageletView resolve(final PageletResult pageletResult) { AbstractVelocityPageletView pageletView = null; if (pageletResult.isFrameResult()) { pageletView = (AbstractVelocityPageletView) BeanUtils.instantiate(framePageletViewClass); } else {// ww w . j av a 2s . co m pageletView = (AbstractVelocityPageletView) BeanUtils.instantiate(pageletViewClass); } pageletView.setContextType(getContentType()); pageletView.setEncoding(getEncoding()); pageletView.setUrl(getPrefix() + pageletResult.getViewName() + getSuffix()); pageletView.setPageletResult(pageletResult); pageletView.initApplicationContext(applicationContext); return pageletView; }
From source file:com.luna.common.repository.support.SimpleBaseRepositoryFactoryBean.java
protected Object getTargetRepository(RepositoryMetadata metadata) { Class<?> repositoryInterface = metadata.getRepositoryInterface(); if (isBaseRepository(repositoryInterface)) { JpaEntityInformation<M, ID> entityInformation = getEntityInformation( (Class<M>) metadata.getDomainType()); SimpleBaseRepository repository = new SimpleBaseRepository<M, ID>(entityInformation, entityManager); SearchableQuery searchableQuery = AnnotationUtils.findAnnotation(repositoryInterface, SearchableQuery.class); if (searchableQuery != null) { String countAllQL = searchableQuery.countAllQuery(); if (!StringUtils.isEmpty(countAllQL)) { repository.setCountAllQL(countAllQL); }// w ww .j av a 2 s.co m String findAllQL = searchableQuery.findAllQuery(); if (!StringUtils.isEmpty(findAllQL)) { repository.setFindAllQL(findAllQL); } Class<? extends SearchCallback> callbackClass = searchableQuery.callbackClass(); if (callbackClass != null && callbackClass != SearchCallback.class) { repository.setSearchCallback(BeanUtils.instantiate(callbackClass)); } repository.setJoins(searchableQuery.joins()); } return repository; } return super.getTargetRepository(metadata); }
From source file:org.grails.datastore.mapping.model.AbstractMappingContext.java
public ProxyFactory getProxyFactory() { if (this.proxyFactory == null) { ClassLoader classLoader = AbstractMappingContext.class.getClassLoader(); if (ClassUtils.isPresent(JAVASIST_PROXY_FACTORY, classLoader)) { proxyFactory = DefaultProxyFactoryCreator.create(); } else if (ClassUtils.isPresent(GROOVY_PROXY_FACTORY_NAME, classLoader)) { try { proxyFactory = (ProxyFactory) BeanUtils .instantiate(ClassUtils.forName(GROOVY_PROXY_FACTORY_NAME, classLoader)); } catch (ClassNotFoundException e) { proxyFactory = DefaultProxyFactoryCreator.create(); }// www . j ava 2s.com } else { proxyFactory = DefaultProxyFactoryCreator.create(); } } return proxyFactory; }
From source file:org.grails.datastore.mapping.config.AbstractGormMappingFactory.java
@Override public T createMappedForm(@SuppressWarnings("rawtypes") PersistentProperty mpp) { Map<String, T> properties = entityToPropertyMap.get(mpp.getOwner()); if (properties != null && properties.containsKey(mpp.getName())) { return properties.get(mpp.getName()); } else if (properties != null) { Property property = (Property) properties.get(IDENTITY_PROPERTY); if (property != null && mpp.getName().equals(property.getName())) { return (T) property; }// ww w. java 2 s. c o m } return BeanUtils.instantiate(getPropertyMappedFormType()); }
From source file:org.shept.persistence.provider.hibernate.HibernateUtils_old.java
public static Object copyTemplate(HibernateDaoSupport dao, Object entityModelTemplate) { if (entityModelTemplate != null) { // hier besser die Metadaten von Hibernate fragen if (null != getClassMetadata(dao, entityModelTemplate)) { // if (null != AnnotationUtils.findAnnotation(entityModelTemplate.getClass(), Entity.class)) { String idName = HibernateUtils_old.getIdentifierPropertyName(dao, entityModelTemplate); Object newModel = BeanUtils.instantiateClass(entityModelTemplate.getClass()); BeanUtils.copyProperties(entityModelTemplate, newModel, new String[] { idName }); Serializable idx = getIdValue(dao, entityModelTemplate); ClassMetadata meta = getClassMetadata(dao, idx); Type type = meta.getIdentifierType(); if (meta != null && type.isComponentType()) { // alternaitv if (id != null && (null != AnnotationUtils.findAnnotation(id.getClass(), Embeddable.class))) { Serializable copyId = BeanUtils.instantiate(idx.getClass()); BeanUtils.copyProperties(idx, copyId); Method idMth = ReflectionUtils.findMethod(entityModelTemplate.getClass(), "set" + StringUtils.capitalize(idName), new Class[] {}); if (idMth != null) { ReflectionUtils.invokeMethod(idMth, newModel, copyId); }/*from w w w . j a va 2 s. c om*/ } return newModel; } } return null; }
From source file:ch.rasc.wampspring.method.PayloadArgumentResolver.java
public PayloadArgumentResolver(ApplicationContext applicationContext, MethodParameterConverter methodParameterConverter) { this.methodParameterConverter = methodParameterConverter; if (applicationContext.containsBean(MVC_VALIDATOR_NAME)) { this.validator = applicationContext.getBean(MVC_VALIDATOR_NAME, Validator.class); } else if (ClassUtils.isPresent("javax.validation.Validator", getClass().getClassLoader())) { Class<?> clazz;//ww w . ja v a2s .c o m try { String className = "org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean"; clazz = ClassUtils.forName(className, AbstractMessageBrokerConfiguration.class.getClassLoader()); } catch (Throwable ex) { throw new BeanInitializationException("Could not find default validator class", ex); } this.validator = (Validator) BeanUtils.instantiate(clazz); } else { this.validator = new Validator() { @Override public boolean supports(Class<?> clazz) { return false; } @Override public void validate(Object target, Errors errors) { // nothing here } }; } }
From source file:com.sshdemo.common.schedule.generate.quartz.EwcmsMethodInvokingJobDetailFactoryBean.java
@Override public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException { prepare();// w w w. j av a 2 s.c om String name = this.name == null ? beanName : this.name; Class<? extends MethodInvokingJob> jobClass = concurrent ? EwcmsMethodInvokingJobDetailFactoryBean.MethodInvokingJob.class : EwcmsMethodInvokingJobDetailFactoryBean.StatefulMethodInvokingJob.class; if (jobDetailImplClass != null) { jobDetail = (JobDetail) BeanUtils.instantiate(jobDetailImplClass); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(jobDetail); bw.setPropertyValue("name", name); bw.setPropertyValue("group", group); bw.setPropertyValue("jobClass", jobClass); bw.setPropertyValue("durability", Boolean.valueOf(true)); ((JobDataMap) bw.getPropertyValue("jobDataMap")).put("methodInvoker", this); } else { jobDetail = newJob(jobClass).withIdentity(name, group).build(); if (!(jobDetail instanceof JobDetailImpl)) throw new RuntimeException("Expected JobDetail to be an instance of '" + JobDetailImpl.class + "' but instead we got '" + jobDetail.getClass().getName() + "'"); ((JobDetailImpl) jobDetail).setDurability(true); jobDetail.getJobDataMap().put("methodInvoker", this); } if (jobListenerNames != null) { String as[]; int j = (as = jobListenerNames).length; for (int i = 0; i < j; i++) { String jobListenerName = as[i]; if (jobDetailImplClass != null) throw new IllegalStateException( "Non-global JobListeners not supported on Quartz 2 - manually register a Matcher against the Quartz ListenerManager instead"); JobKey jk = jobDetail.getKey(); Matcher<JobKey> matcher = KeyMatcher.keyEquals(jk); try { getScheduler().getListenerManager().addJobListenerMatcher(jobListenerName, matcher); } catch (org.quartz.SchedulerException e) { throw new RuntimeException("Error adding Quartz Trigger Listener: " + e.getMessage()); } //jobDetail.addJobListener(jobListenerName); } } postProcessJobDetail(jobDetail); }
From source file:cn.guoyukun.spring.jpa.repository.support.SimpleBaseRepositoryFactoryBean.java
private Object doGetTargetRepository(RepositoryMetadata metadata) { Class<?> repositoryInterface = metadata.getRepositoryInterface(); JpaEntityInformation<M, ID> entityInformation = getEntityInformation((Class<M>) metadata.getDomainType()); SimpleBaseRepository<M, ID> repository = new SimpleBaseRepository<M, ID>(entityInformation, entityManager); SearchableQuery searchableQuery = AnnotationUtils.findAnnotation(repositoryInterface, SearchableQuery.class); if (searchableQuery != null) { String countAllQL = searchableQuery.countAllQuery(); if (!StringUtils.isEmpty(countAllQL)) { repository.setCountAllQL(countAllQL); }// ww w . j a v a 2s . c om String findAllQL = searchableQuery.findAllQuery(); if (!StringUtils.isEmpty(findAllQL)) { repository.setFindAllQL(findAllQL); } Class<? extends SearchCallback> callbackClass = searchableQuery.callbackClass(); if (callbackClass != null && callbackClass != SearchCallback.class) { repository.setSearchCallback(BeanUtils.instantiate(callbackClass)); } repository.setJoins(searchableQuery.joins()); } LOG.debug("?DAO {}", repository); return repository; }