List of usage examples for org.springframework.util ReflectionUtils findMethod
@Nullable public static Method findMethod(Class<?> clazz, String name, @Nullable Class<?>... paramTypes)
From source file:com.expedia.seiso.domain.service.impl.ItemServiceImplTests.java
private void setUpTestData() { // @formatter:off this.person = new Person().setUsername("wwheeler").setFirstName("Willie").setLastName("Wheeler"); this.newPerson = new Person().setUsername("Donkey").setFirstName("Donkey").setLastName("Hotey"); // @formatter:on this.personList = Arrays.asList(person); this.personFindByKeyMethod = ReflectionUtils.findMethod(PersonRepo.class, "findByUsername", String.class); log.trace("method={}", personFindByKeyMethod); when(personMeta.getRepositoryFindByKeyMethod()).thenReturn(personFindByKeyMethod); this.personKey = new SimpleItemKey(Person.class, person.getUsername()); }
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 www.j av a 2 s. com } return newModel; } } return null; }
From source file:com.haulmont.cuba.web.sys.singleapp.SingleAppWebServletListener.java
@Override public void contextInitialized(ServletContextEvent sce) { try {//from w ww . j ava2s .c om ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); //need to put the following class to WebAppClassLoader, to share it between for web and core contextClassLoader.loadClass("com.haulmont.cuba.core.sys.remoting.LocalServiceDirectory"); ServletContext servletContext = sce.getServletContext(); String dependenciesFile; try { dependenciesFile = IOUtils.toString(servletContext.getResourceAsStream("/WEB-INF/web.dependencies"), "UTF-8"); } catch (IOException e) { throw new RuntimeException("An error occurred while loading dependencies file", e); } String[] dependenciesNames = dependenciesFile.split("\\n"); URL[] urls = Arrays.stream(dependenciesNames).map((String name) -> { try { return servletContext.getResource("/WEB-INF/lib/" + name); } catch (MalformedURLException e) { throw new RuntimeException("An error occurred while loading dependency " + name, e); } }).toArray(URL[]::new); URLClassLoader webClassLoader = new CubaSingleAppClassLoader(urls, contextClassLoader); Thread.currentThread().setContextClassLoader(webClassLoader); Class<?> appContextLoaderClass = webClassLoader.loadClass(getAppContextLoaderClassName()); appContextLoader = appContextLoaderClass.newInstance(); Method setJarsNamesMethod = ReflectionUtils.findMethod(appContextLoaderClass, "setJarNames", String.class); ReflectionUtils.invokeMethod(setJarsNamesMethod, appContextLoader, dependenciesFile); Method contextInitializedMethod = ReflectionUtils.findMethod(appContextLoaderClass, "contextInitialized", ServletContextEvent.class); ReflectionUtils.invokeMethod(contextInitializedMethod, appContextLoader, sce); Thread.currentThread().setContextClassLoader(contextClassLoader); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException("An error occurred while starting single WAR application", e); } }
From source file:com.github.hateoas.forms.spring.AffordanceBuilderFactoryTest.java
@Test public void testLinkToMethodNoArgsBuild() throws Exception { final Method getEventMethod = ReflectionUtils.findMethod(EventControllerSample.class, "getEvent", String.class); final Affordance affordance = factory.linkTo(getEventMethod, new Object[0]).rel("foo").build(); assertEquals("http://example.com/events/{eventId}", affordance.getHref()); assertEquals("foo", affordance.getRel()); }
From source file:com.haulmont.cuba.core.sys.singleapp.SingleAppCoreServletListener.java
@Override public void contextInitialized(ServletContextEvent sce) { try {/*from w ww . j av a 2 s. c o m*/ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); //need to put the following class to WebAppClassLoader, to share it between for web and core contextClassLoader.loadClass("com.haulmont.cuba.core.sys.remoting.LocalServiceDirectory"); ServletContext servletContext = sce.getServletContext(); String dependenciesFile; try { dependenciesFile = IOUtils .toString(servletContext.getResourceAsStream("/WEB-INF/core.dependencies"), "UTF-8"); } catch (IOException e) { throw new RuntimeException("An error occurred while loading dependencies file", e); } String[] dependenciesNames = dependenciesFile.split("\\n"); URL[] urls = Arrays.stream(dependenciesNames).map((String name) -> { try { return servletContext.getResource("/WEB-INF/lib/" + name); } catch (MalformedURLException e) { throw new RuntimeException("An error occurred while loading dependency " + name, e); } }).toArray(URL[]::new); URLClassLoader coreClassLoader = new CubaSingleAppClassLoader(urls, contextClassLoader); Thread.currentThread().setContextClassLoader(coreClassLoader); Class<?> appContextLoaderClass = coreClassLoader.loadClass(getAppContextLoaderClassName()); appContextLoader = appContextLoaderClass.newInstance(); Method setJarsNamesMethod = ReflectionUtils.findMethod(appContextLoaderClass, "setJarNames", String.class); ReflectionUtils.invokeMethod(setJarsNamesMethod, appContextLoader, dependenciesFile); Method contextInitializedMethod = ReflectionUtils.findMethod(appContextLoaderClass, "contextInitialized", ServletContextEvent.class); ReflectionUtils.invokeMethod(contextInitializedMethod, appContextLoader, sce); Thread.currentThread().setContextClassLoader(contextClassLoader); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException("An error occurred while starting single WAR application", e); } }
From source file:com.expedia.seiso.web.assembler.ResourceAssemblerTests.java
private void setUpTestData() { this.queryMethod = ReflectionUtils.findMethod(ServiceRepo.class, "findByName", String.class); this.queryMethods = Arrays.asList(queryMethod); when(repoInfo.getQueryMethods()).thenReturn(queryMethods); // @formatter:off this.person = new Person().setUsername("mkozelek").setFirstName("Mark").setLastName("Kozelek"); this.service = new Service().setKey("benji").setName("Benji").setDescription("My Benji service") .setOwner(person);/*from w w w . ja v a 2s .c o m*/ // @formatter:on this.itemList = Arrays.asList(service); this.itemPage = new PageImpl<Service>(itemList, PAGE_REQUEST, 8675309); }
From source file:com.consol.citrus.selenium.action.PageAction.java
private Method getMethod(Class<T> pageClass, Class<?>[] methodTypes) throws IllegalArgumentException, InvocationTargetException, IllegalAccessException, CitrusRuntimeException { Method methodToRun = ReflectionUtils.findMethod(pageClass, pageAction, methodTypes); if (methodToRun == null) { throw new CitrusRuntimeException("Unable to find method '" + pageAction + "(" + StringUtils.arrayToCommaDelimitedString(methodTypes) + ")' for class '" + pageClass + "'"); }//from w w w. j av a2 s .c o m return methodToRun; }
From source file:grails.plugin.searchable.internal.compass.config.mapping.CompassAnnotationSearchableGrailsDomainClassMappingConfigurator.java
private Method findGetAnnotationMethod() { return ReflectionUtils.findMethod(Class.class, "getAnnotation", new Class[] { Class.class }); }
From source file:com.github.hateoas.forms.spring.AffordanceBuilderFactoryTest.java
@Test public void testLinkToMethodInvocationNoArgsBuild() throws Exception { final Method getEventMethod = ReflectionUtils.findMethod(EventControllerSample.class, "getEvent", String.class); final Affordance affordance = factory .linkTo(AffordanceBuilder.methodOn(EventControllerSample.class).getEvent((String) null)).rel("foo") .build();/* ww w .j av a 2 s .c o m*/ assertEquals("http://example.com/events/{eventId}", affordance.getHref()); assertEquals("foo", affordance.getRel()); }
From source file:com.haulmont.cuba.core.sys.singleapp.SingleAppCoreServletListener.java
@Override public void contextDestroyed(ServletContextEvent sce) { Method contextInitialized = ReflectionUtils.findMethod(appContextLoader.getClass(), "contextDestroyed", ServletContextEvent.class); ReflectionUtils.invokeMethod(contextInitialized, appContextLoader, sce); }