List of usage examples for org.springframework.beans BeanUtils instantiateClass
public static <T> T instantiateClass(Class<T> clazz) throws BeanInstantiationException
From source file:org.lightadmin.core.web.util.RepositoryNewEntityController.java
@RequestMapping(value = BASE_MAPPING + "/new", method = GET) public ResponseEntity<Resource<?>> getItemResource(RootResourceInformation resourceInformation, PersistentEntityResourceAssembler assembler) throws HttpRequestMethodNotSupportedException { Constructor<?> constructor = getConstructorIfAvailable(resourceInformation.getDomainType()); if (constructor == null) { return new ResponseEntity<Resource<?>>(NOT_IMPLEMENTED); }//from www. jav a 2s . c om Object domainObj = BeanUtils.instantiateClass(constructor); return new ResponseEntity<Resource<?>>(assembler.toResource(domainObj), OK); }
From source file:biz.c24.io.spring.core.C24Model.java
/** * Creates a new {@link C24Model} from the given {@link Element}. * /*from w w w.j a v a 2s. c om*/ * @param element */ @SuppressWarnings("unchecked") public C24Model(Element element) { Assert.notNull(element); this.rootElement = element; Class<? extends ComplexDataObject> type = element.getType().getValidObjectClass(); if (!DocumentRoot.class.isAssignableFrom(type)) { // If the model wraps something which is not a document root class, // then just use it as-is map.put(type, element); } else { // For document root classes, inspect the child elements. DocumentRoot root = (DocumentRoot) BeanUtils.instantiateClass(type); for (int i = 0; i < root.getElementDeclCount(); i++) { Element declaredElement = root.getElementDecl(i); map.put(declaredElement.getType().getValidObjectClass(), element); } } }
From source file:com.googlecode.flyway.core.migration.java.JavaMigrationResolver.java
public Collection<Migration> resolveMigrations() { Collection<Migration> migrations = new ArrayList<Migration>(); ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( false);/* w w w.j a v a 2 s .c om*/ provider.addIncludeFilter(new AssignableTypeFilter(JavaMigration.class)); Set<BeanDefinition> components = provider.findCandidateComponents(basePackage); for (BeanDefinition beanDefinition : components) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Class<?> clazz = ClassUtils.resolveClassName(beanDefinition.getBeanClassName(), classLoader); JavaMigration javaMigration = (JavaMigration) BeanUtils.instantiateClass(clazz); migrations.add(new JavaMigrationExecutor(javaMigration)); } return migrations; }
From source file:org.hobsoft.symmetry.spring.SymmetryMethodArgumentResolver.java
@Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { Object target = BeanUtils.instantiateClass(parameter.getParameterType()); T component = reflector.getComponentType().cast(target); reflector.absorb(component, webRequest.getParameterMap()); return component; }
From source file:com.helpinput.spring.servlet.mvc.EnhanceDispachServlet.java
@Override protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) { ContextHolder.beanRegistIntercpterHolder.register(new UrlInterceptorBeanRegistInterceptor()); Class<?> contextClass = getContextClass(); if (logger.isDebugEnabled()) { logger.debug("Servlet with name '" + getServletName() + "' will try to create custom WebApplicationContext context of class '" + contextClass.getName() + "'" + ", using parent context [" + parent + "]"); }//from w ww .j a v a 2 s . c om if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) { throw new ApplicationContextException("Fatal initialization error in servlet with name '" + getServletName() + "': custom WebApplicationContext class [" + contextClass.getName() + "] is not of type ConfigurableWebApplicationContext"); } ConfigurableWebApplicationContext wac; if (parent instanceof ConfigurableWebApplicationContext) wac = (ConfigurableWebApplicationContext) parent; else { wac = (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass); wac.setEnvironment(getEnvironment()); wac.setParent(parent); wac.setConfigLocation(getContextConfigLocation()); configureAndRefreshWebApplicationContext(wac); } return wac; }
From source file:ua.com.manometer.jasperreports.ConfigurableJasperReportsView.java
/** * Returns a new instance of the specified {@link JRExporter} class. * @see #setExporterClass(Class)//from w ww. ja v a2 s . co m * @see BeanUtils#instantiateClass(Class) */ @Override protected JRExporter createExporter() { return BeanUtils.instantiateClass(this.exporterClass); }
From source file:corner.tree.services.impl.MoveUpProcessor.java
@Override public TreeAdapter constructRootNode() { TreeAdapter rootNode;//from ww w .ja v a 2 s . c om try { rootNode = (TreeAdapter) BeanUtils.instantiateClass(Class.forName(getTreeClassName())); } catch (BeanInstantiationException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } rootNode.setLeft(0); rootNode.setRight(Integer.MAX_VALUE); return rootNode; }
From source file:corner.tree.services.impl.MoveDownProcessor.java
@Override protected TreeAdapter constructRootNode() { TreeAdapter rootNode;//from w w w . j ava 2 s. com try { rootNode = (TreeAdapter) BeanUtils.instantiateClass(Class.forName(getTreeClassName())); } catch (BeanInstantiationException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } rootNode.setLeft(0); long rowCount = getEntityService().count(getTreeClass(), null); rootNode.setRight((int) (rowCount * 2 + 1)); return rootNode; }
From source file:corner.tree.services.impl.TreeServiceImpl.java
/** * @see corner.tree.services.ouriba.eweb.services.tree.TreeService#saveTreeChildNode(corner.tree.base.ouriba.eweb.entities.base.TreeAdapter, corner.tree.base.ouriba.eweb.entities.base.TreeAdapter, java.lang.Class) *///from ww w . j a v a 2 s.c om @Override public void saveTreeChildNode(TreeAdapter node, TreeAdapter parentNode, Class<? extends TreeAdapter> clazz) { String treeClassName = getTreeClassName(node, clazz); TreeAdapter currentParentNode = parentNode; if (currentParentNode == null) { // ? currentParentNode = (TreeAdapter) BeanUtils.instantiateClass(entityService.getEntityClass(node)); currentParentNode.setLeft(0); currentParentNode.setDepth(0); long rowCount; try { rowCount = this.entityService.count(Class.forName(treeClassName), null); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } currentParentNode.setRight((int) (rowCount * 2 + 1)); } else { // reload parent object entityService.refresh(currentParentNode); } // ? int parentRight = currentParentNode.getRight(); // /* * update table set left=left+2 where left>parentRight update table set * right=right+2 where right>=parentRight */ String updateLeftHQL = String.format(UPDATE_LEFT_HSQL, treeClassName, 2); hibernateEntityService.bulkUpdate(updateLeftHQL, new Object[] { parentRight }); String updateRightHQL = String.format(UPDATE_RIGHT_HSQL, treeClassName, 2); hibernateEntityService.bulkUpdate(updateRightHQL, new Object[] { parentRight - 1 }); // ? node.setLeft(parentRight); node.setRight(parentRight + 1); node.setDepth(currentParentNode.getDepth() + 1); // ?? hibernateEntityService.saveOrUpdate(node); // if (parentNode.getId() != null) { // entityService.refresh(parentNode); // } }
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 ava2 s. c om } return newModel; } } return null; }