List of usage examples for org.springframework.util ReflectionUtils findMethod
@Nullable public static Method findMethod(Class<?> clazz, String name)
From source file:org.openmrs.module.radiology.hl7.message.RadiologyORMO01Test.java
/** * @see RadiologyORMO01#createRadiologyORMO01Message() * @verifies create ormo01 message// www . j av a2 s .c o m */ @Test public void createRadiologyORMO01Message_shouldCreateOrmo01Message() throws Exception { RadiologyORMO01 radiologyOrderMessage = new RadiologyORMO01(radiologyOrder, CommonOrderOrderControl.NEW_ORDER, CommonOrderPriority.STAT); Method createRadiologyORMO01Message = ReflectionUtils.findMethod(RadiologyORMO01.class, "createRadiologyORMO01Message"); createRadiologyORMO01Message.setAccessible(true); ORM_O01 ormO01 = (ORM_O01) createRadiologyORMO01Message.invoke(radiologyOrderMessage); String encodedOrmMessage = PipeParser.encode(ormO01, encodingCharacters); assertThat(encodedOrmMessage, startsWith("MSH|^~\\&|OpenMRSRadiologyModule|OpenMRS|||")); assertThat(encodedOrmMessage, endsWith("||ORM^O01||P|2.3.1\r" + "PID|||100||Doe^John^Francis||19500401000000|M\r" + "ORC|NW|ORD-20|||||^^^20150204143500^^S\r" + "OBR||||^^^^CT ABDOMEN PANCREAS WITH IV CONTRAST|||||||||||||||ORD-20|1||||CT||||||||||||||||||||^CT ABDOMEN PANCREAS WITH IV CONTRAST\r" + "ZDS|1.2.826.0.1.3680043.8.2186.1.1^^Application^DICOM\r")); }
From source file:org.codehaus.groovy.grails.plugins.springsecurity.AuthorizeTools.java
private static synchronized Method findMethod(final Class<?> clazz) throws SecurityException { Method method = CACHED_METHODS.get(clazz); if (method == null) { method = ReflectionUtils.findMethod(clazz, "getAuthority"); CACHED_METHODS.put(clazz, method); }/*ww w. ja va 2s . c o m*/ return method; }
From source file:com.consol.citrus.admin.service.TestCaseService.java
/** * Get test case model from Java source code. * @param project/* ww w . java 2 s.c om*/ * @param detail * @return */ private TestcaseModel getJavaTestModel(Project project, TestDetail detail) { if (project.isMavenProject()) { try { FileUtils.setSimulationMode(true); ClassLoader classLoader = getTestClassLoader(project); Class testClass = classLoader.loadClass(detail.getPackageName() + "." + detail.getClassName()); if (TestSimulator.class.isAssignableFrom(testClass)) { TestSimulator testInstance = (TestSimulator) testClass.newInstance(); Method testMethod = ReflectionUtils.findMethod(testClass, detail.getMethodName()); Mocks.injectMocks(testInstance); testInstance.simulate(testMethod, Mocks.getTestContextMock(), Mocks.getApplicationContextMock()); testMethod.invoke(testInstance); return getTestcaseModel(testInstance.getTestCase()); } else { throw new ApplicationRuntimeException("Unsupported test case type: " + testClass); } } catch (MalformedURLException e) { throw new ApplicationRuntimeException("Failed to access Java classes output folder", e); } catch (ClassNotFoundException | NoClassDefFoundError e) { log.error("Failed to load Java test class", e); } catch (IOException e) { throw new ApplicationRuntimeException("Failed to access project output folder", e); } catch (InstantiationException | IllegalAccessException e) { log.error("Failed to create test class instance", e); } catch (InvocationTargetException e) { log.error("Failed to invoke test method", e); } finally { FileUtils.setSimulationMode(false); } } TestcaseModel testModel = new TestcaseModel(); testModel.setName(detail.getClassName() + "." + detail.getMethodName()); return testModel; }
From source file:org.hdiv.web.servlet.tags.UrlTagTests.java
private String invokeCreateUrl(UrlTagHDIV tag) { Method createUrl = ReflectionUtils.findMethod(tag.getClass(), "createUrl"); ReflectionUtils.makeAccessible(createUrl); return (String) ReflectionUtils.invokeMethod(createUrl, tag); }
From source file:nivance.jpa.cassandra.prepare.convert.MappingCassandraConverter.java
public List<Clause> getKeyPart(final CassandraPersistentEntity<?> entity, final Object valueBean) { final List<Clause> result = new LinkedList<Clause>(); entity.doWithProperties(new PropertyHandler<CassandraPersistentProperty>() { public void doWithPersistentProperty(CassandraPersistentProperty prop) { //TODO if (prop.getKeyPart() != null) { //keypart? Method method = ReflectionUtils.findMethod(entity.getType(), "get" + StringUtils.capitalize(prop.getColumnName())); Object id = ReflectionUtils.invokeMethod(method, valueBean); result.add(QueryBuilder.eq(prop.getColumnName(), id)); }/*from w w w. j a va 2s . c om*/ } }); if (result.isEmpty()) { throw new MappingException( "Could not form a where clause for the primary key for an entity " + entity.getName()); } return result; }
From source file:com.glaf.core.util.ReflectUtils.java
public static Object invoke(Object object, String methodName) { try {//from w w w . j a v a 2 s.co m Method method = ReflectionUtils.findMethod(object.getClass(), methodName); if (!Modifier.isPublic(method.getModifiers())) { method.setAccessible(true); } return ReflectionUtils.invokeMethod(method, object); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:de.hybris.platform.converters.impl.AbstractConverter.java
@Override public void afterPropertiesSet() throws Exception { if (targetClass == null) { final Class<? extends AbstractConverter> cl = this.getClass(); final Method createTargetMethod = ReflectionUtils.findMethod(cl, "createTarget"); if (AbstractConverter.class.equals(createTargetMethod.getDeclaringClass())) { throw new IllegalStateException("Converter '" + myBeanName + "' doesn't have a targetClass property nor does it override createTarget()!"); }/*from w ww .j a v a2 s . com*/ } }
From source file:net.stickycode.mockwire.spring30.MockwireFieldInjectionAnnotationBeanPostProcessor.java
/** * Determine if the annotated field or method requires its dependency. * <p>A 'required' dependency means that autowiring should fail when no beans * are found. Otherwise, the autowiring process will simply bypass the field * or method when no beans are found./*from ww w . j a va2 s .com*/ * @param annotation the Autowired annotation * @return whether the annotation indicates that a dependency is required */ protected boolean determineRequiredStatus(Annotation annotation) { try { Method method = ReflectionUtils.findMethod(annotation.annotationType(), this.requiredParameterName); return (this.requiredParameterValue == (Boolean) ReflectionUtils.invokeMethod(method, annotation)); } catch (Exception ex) { // required by default return true; } }
From source file:org.artifactory.storage.db.spring.ArtifactoryPoolableConnectionFactory.java
@Override public void passivateObject(Object obj) throws Exception { if (obj instanceof Connection) { Connection conn = (Connection) obj; if (!conn.getAutoCommit() && !conn.isReadOnly()) { conn.rollback();/* www. j a va2 s . co m*/ } conn.clearWarnings(); //if(!conn.getAutoCommit()) { // conn.setAutoCommit(true); //} } if (obj instanceof DelegatingConnection) { Method passivateMethod = ReflectionUtils.findMethod(DelegatingConnection.class, "passivate"); passivateMethod.setAccessible(true); ReflectionUtils.invokeMethod(passivateMethod, obj); } }