Here are the examples of the java api org.springframework.util.ReflectionUtils.invokeMethod() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
118 Examples
19
View Source File : AnnotationsPropertySource.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
private void collectProperties(Annotation annotation, Method attribute, PropertyMapping typeMapping, Map<String, Object> properties) {
PropertyMapping attributeMapping = AnnotationUtils.getAnnotation(attribute, PropertyMapping.clreplaced);
SkipPropertyMapping skip = getMappingType(typeMapping, attributeMapping);
if (skip == SkipPropertyMapping.YES) {
return;
}
String name = getName(typeMapping, attributeMapping, attribute);
ReflectionUtils.makeAccessible(attribute);
Object value = ReflectionUtils.invokeMethod(attribute, annotation);
if (skip == SkipPropertyMapping.ON_DEFAULT_VALUE) {
Object defaultValue = AnnotationUtils.getDefaultValue(annotation, attribute.getName());
if (ObjectUtils.nullSafeEquals(value, defaultValue)) {
return;
}
}
putProperties(name, value, properties);
}
19
View Source File : ConditionalOnJavaTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
private String getJavaVersion(Clreplaced<?>... hiddenClreplacedes) throws Exception {
FilteredClreplacedLoader clreplacedLoader = new FilteredClreplacedLoader(hiddenClreplacedes);
Clreplaced<?> javaVersionClreplaced = clreplacedLoader.loadClreplaced(JavaVersion.clreplaced.getName());
Method getJavaVersionMethod = ReflectionUtils.findMethod(javaVersionClreplaced, "getJavaVersion");
Object javaVersion = ReflectionUtils.invokeMethod(getJavaVersionMethod, null);
clreplacedLoader.close();
return javaVersion.toString();
}
19
View Source File : DataSourceClosingSpringLiquibase.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
private void closeDataSource() {
Clreplaced<?> dataSourceClreplaced = getDataSource().getClreplaced();
Method closeMethod = ReflectionUtils.findMethod(dataSourceClreplaced, "close");
if (closeMethod != null) {
ReflectionUtils.invokeMethod(closeMethod, getDataSource());
}
}
19
View Source File : TomcatErrorPage.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
private void callMethod(Object target, String name, Object value, Clreplaced<?> type) {
Method method = ReflectionUtils.findMethod(target.getClreplaced(), name, type);
ReflectionUtils.invokeMethod(method, target, value);
}
19
View Source File : DefaultLogbackConfiguration.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
private void setMaxFileSize(SizeAndTimeBasedRollingPolicy<ILoggingEvent> rollingPolicy, String maxFileSize) {
try {
rollingPolicy.setMaxFileSize(FileSize.valueOf(maxFileSize));
} catch (NoSuchMethodError ex) {
// Logback < 1.1.8 used String configuration
Method method = ReflectionUtils.findMethod(SizeAndTimeBasedRollingPolicy.clreplaced, "setMaxFileSize", String.clreplaced);
ReflectionUtils.invokeMethod(method, rollingPolicy, maxFileSize);
}
}
19
View Source File : RedisAutoConfig.java
License : Apache License 2.0
Project Creator : yanghaiji
License : Apache License 2.0
Project Creator : yanghaiji
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean(RedissonClient.clreplaced)
public RedissonClient redissonClient() throws IOException {
Config config = null;
Method clusterMethod = ReflectionUtils.findMethod(RedisProperties.clreplaced, "getCluster");
Method timeoutMethod = ReflectionUtils.findMethod(RedisProperties.clreplaced, "getTimeout");
Object timeoutValue = ReflectionUtils.invokeMethod(timeoutMethod, redisProperties);
int timeout;
if (null == timeoutValue) {
timeout = 60000;
} else if (!(timeoutValue instanceof Integer)) {
Method millisMethod = ReflectionUtils.findMethod(timeoutValue.getClreplaced(), "toMillis");
timeout = ((Long) ReflectionUtils.invokeMethod(millisMethod, timeoutValue)).intValue();
} else {
timeout = (Integer) timeoutValue;
}
// spring.redis.redisson.config=clreplacedpath:redisson.yaml
if (redissonProperties.getConfig() != null) {
try {
InputStream is = getConfigStream();
config = Config.fromJSON(is);
} catch (IOException e) {
// trying next format
try {
InputStream is = getConfigStream();
config = Config.fromYAML(is);
} catch (IOException e1) {
throw new IllegalArgumentException("Can't parse config", e1);
}
}
} else if (redisProperties.getSentinel() != null) {
// 哨兵配置
Method nodesMethod = ReflectionUtils.findMethod(Sentinel.clreplaced, "getNodes");
Object nodesValue = ReflectionUtils.invokeMethod(nodesMethod, redisProperties.getSentinel());
String[] nodes;
if (nodesValue instanceof String) {
nodes = convert(Arrays.asList(((String) nodesValue).split(",")));
} else {
nodes = convert((List<String>) nodesValue);
}
config = new Config();
config.useSentinelServers().setMasterName(redisProperties.getSentinel().getMaster()).addSentinelAddress(nodes).setDatabase(redisProperties.getDatabase()).setConnectTimeout(timeout).setPreplacedword(redisProperties.getPreplacedword());
} else if (clusterMethod != null && ReflectionUtils.invokeMethod(clusterMethod, redisProperties) != null) {
// 集群配置
Object clusterObject = ReflectionUtils.invokeMethod(clusterMethod, redisProperties);
Method nodesMethod = ReflectionUtils.findMethod(clusterObject.getClreplaced(), "getNodes");
List<String> nodesObject = (List) ReflectionUtils.invokeMethod(nodesMethod, clusterObject);
String[] nodes = convert(nodesObject);
config = new Config();
config.useClusterServers().addNodeAddress(nodes).setConnectTimeout(timeout).setPreplacedword(redisProperties.getPreplacedword());
} else {
// 单机redssion默认配置
config = new Config();
String prefix = "redis://";
Method method = ReflectionUtils.findMethod(RedisProperties.clreplaced, "isSsl");
if (method != null && (Boolean) ReflectionUtils.invokeMethod(method, redisProperties)) {
prefix = "rediss://";
}
config.useSingleServer().setAddress(prefix + redisProperties.getHost() + ":" + redisProperties.getPort()).setConnectTimeout(timeout).setDatabase(redisProperties.getDatabase()).setPreplacedword(redisProperties.getPreplacedword());
}
return Redisson.create(config);
}
19
View Source File : FacesRequestAttributes.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Override
public String getSessionId() {
Object session = getExternalContext().getSession(true);
try {
// HttpSession has a getId() method.
Method getIdMethod = session.getClreplaced().getMethod("getId");
return String.valueOf(ReflectionUtils.invokeMethod(getIdMethod, session));
} catch (NoSuchMethodException ex) {
throw new IllegalStateException("Session object [" + session + "] does not have a getId() method");
}
}
19
View Source File : SqlScriptsTestExecutionListener.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Nullable
private DataSource getDataSourceFromTransactionManager(PlatformTransactionManager transactionManager) {
try {
Method getDataSourceMethod = transactionManager.getClreplaced().getMethod("getDataSource");
Object obj = ReflectionUtils.invokeMethod(getDataSourceMethod, transactionManager);
if (obj instanceof DataSource) {
return (DataSource) obj;
}
} catch (Exception ex) {
// ignore
}
return null;
}
19
View Source File : HibernateTemplate.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Deprecated
@Override
@SuppressWarnings({ "rawtypes", "deprecation" })
public int bulkUpdate(final String queryString, @Nullable final Object... values) throws DataAccessException {
Integer result = executeWithNativeSession(session -> {
org.hibernate.Query queryObject = queryObject(ReflectionUtils.invokeMethod(createQueryMethod, session, queryString));
prepareQuery(queryObject);
if (values != null) {
for (int i = 0; i < values.length; i++) {
queryObject.setParameter(i, values[i]);
}
}
return queryObject.executeUpdate();
});
replacedert.state(result != null, "No update count");
return result;
}
19
View Source File : HeadersMethodArgumentResolver.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
Clreplaced<?> paramType = parameter.getParameterType();
if (Map.clreplaced.isreplacedignableFrom(paramType)) {
return message.getHeaders();
} else if (MessageHeaderAccessor.clreplaced == paramType) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.clreplaced);
return accessor != null ? accessor : new MessageHeaderAccessor(message);
} else if (MessageHeaderAccessor.clreplaced.isreplacedignableFrom(paramType)) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.clreplaced);
if (accessor != null && paramType.isreplacedignableFrom(accessor.getClreplaced())) {
return accessor;
} else {
Method method = ReflectionUtils.findMethod(paramType, "wrap", Message.clreplaced);
if (method == null) {
throw new IllegalStateException("Cannot create accessor of type " + paramType + " for message " + message);
}
return ReflectionUtils.invokeMethod(method, null, message);
}
} else {
throw new IllegalStateException("Unexpected parameter of type " + paramType + " in method " + parameter.getMethod() + ". ");
}
}
19
View Source File : HeadersMethodArgumentResolver.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Override
@Nullable
public Object resolveArgumentValue(MethodParameter parameter, Message<?> message) {
Clreplaced<?> paramType = parameter.getParameterType();
if (Map.clreplaced.isreplacedignableFrom(paramType)) {
return message.getHeaders();
} else if (MessageHeaderAccessor.clreplaced == paramType) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.clreplaced);
return accessor != null ? accessor : new MessageHeaderAccessor(message);
} else if (MessageHeaderAccessor.clreplaced.isreplacedignableFrom(paramType)) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.clreplaced);
if (accessor != null && paramType.isreplacedignableFrom(accessor.getClreplaced())) {
return accessor;
} else {
Method method = ReflectionUtils.findMethod(paramType, "wrap", Message.clreplaced);
if (method == null) {
throw new IllegalStateException("Cannot create accessor of type " + paramType + " for message " + message);
}
return ReflectionUtils.invokeMethod(method, null, message);
}
} else {
throw new IllegalStateException("Unexpected parameter of type " + paramType + " in method " + parameter.getMethod() + ". ");
}
}
19
View Source File : JmsListenerAnnotationBeanPostProcessorTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void sendToAnnotationFoundOnCglibProxy() throws Exception {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.clreplaced, ProxyConfig.clreplaced, ClreplacedProxyTestBean.clreplaced);
try {
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.clreplaced);
replacedertEquals("one container should have been registered", 1, factory.getListenerContainers().size());
JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
replacedertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.clreplaced, endpoint.getClreplaced());
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
replacedertTrue(AopUtils.isCglibProxy(methodEndpoint.getBean()));
replacedertTrue(methodEndpoint.getBean() instanceof ClreplacedProxyTestBean);
replacedertEquals(ClreplacedProxyTestBean.clreplaced.getMethod("handleIt", String.clreplaced, String.clreplaced), methodEndpoint.getMethod());
replacedertEquals(ClreplacedProxyTestBean.clreplaced.getMethod("handleIt", String.clreplaced, String.clreplaced), methodEndpoint.getMostSpecificMethod());
Method method = ReflectionUtils.findMethod(endpoint.getClreplaced(), "getDefaultResponseDestination");
ReflectionUtils.makeAccessible(method);
Object destination = ReflectionUtils.invokeMethod(method, endpoint);
replacedertEquals("SendTo annotation not found on proxy", "foobar", destination);
} finally {
context.close();
}
}
19
View Source File : JmsListenerAnnotationBeanPostProcessorTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void sendToAnnotationFoundOnInterfaceProxy() throws Exception {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.clreplaced, ProxyConfig.clreplaced, InterfaceProxyTestBean.clreplaced);
try {
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.clreplaced);
replacedertEquals("one container should have been registered", 1, factory.getListenerContainers().size());
JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
replacedertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.clreplaced, endpoint.getClreplaced());
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
replacedertTrue(AopUtils.isJdkDynamicProxy(methodEndpoint.getBean()));
replacedertTrue(methodEndpoint.getBean() instanceof SimpleService);
replacedertEquals(SimpleService.clreplaced.getMethod("handleIt", String.clreplaced, String.clreplaced), methodEndpoint.getMethod());
replacedertEquals(InterfaceProxyTestBean.clreplaced.getMethod("handleIt", String.clreplaced, String.clreplaced), methodEndpoint.getMostSpecificMethod());
Method method = ReflectionUtils.findMethod(endpoint.getClreplaced(), "getDefaultResponseDestination");
ReflectionUtils.makeAccessible(method);
Object destination = ReflectionUtils.invokeMethod(method, endpoint);
replacedertEquals("SendTo annotation not found on proxy", "foobar", destination);
} finally {
context.close();
}
}
19
View Source File : JmsResourceHolder.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Commit all of this resource holder's Sessions.
* @throws JMSException if thrown from a Session commit attempt
* @see Session#commit()
*/
public void commitAll() throws JMSException {
for (Session session : this.sessions) {
try {
session.commit();
} catch (TransactionInProgressException ex) {
// Ignore -> can only happen in case of a JTA transaction.
} catch (javax.jms.IllegalStateException ex) {
if (this.connectionFactory != null) {
try {
Method getDataSourceMethod = this.connectionFactory.getClreplaced().getMethod("getDataSource");
Object ds = ReflectionUtils.invokeMethod(getDataSourceMethod, this.connectionFactory);
while (ds != null) {
if (TransactionSynchronizationManager.hasResource(ds)) {
// IllegalStateException from sharing the underlying JDBC Connection
// which typically gets committed first, e.g. with Oracle AQ --> ignore
return;
}
try {
// Check for decorated DataSource a la Spring's DelegatingDataSource
Method getTargetDataSourceMethod = ds.getClreplaced().getMethod("getTargetDataSource");
ds = ReflectionUtils.invokeMethod(getTargetDataSourceMethod, ds);
} catch (NoSuchMethodException nsme) {
ds = null;
}
}
} catch (Throwable ex2) {
if (logger.isDebugEnabled()) {
logger.debug("No working getDataSource method found on ConnectionFactory: " + ex2);
}
// No working getDataSource method - cannot perform DataSource transaction check
}
}
throw ex;
}
}
}
19
View Source File : IdToEntityConverter.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}
Method finder = getFinder(targetType.getType());
replacedert.state(finder != null, "No finder method");
Object id = this.conversionService.convert(source, sourceType, TypeDescriptor.valueOf(finder.getParameterTypes()[0]));
return ReflectionUtils.invokeMethod(finder, source, id);
}
19
View Source File : TypeMappedAnnotation.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Nullable
private Object getValueFromMetaAnnotation(int attributeIndex, boolean forMirrorResolution) {
if (this.useMergedValues && !forMirrorResolution) {
return this.mapping.getMappedAnnotationValue(attributeIndex);
}
Method attribute = this.mapping.getAttributes().get(attributeIndex);
return ReflectionUtils.invokeMethod(attribute, this.mapping.getAnnotation());
}
19
View Source File : SynthesizedMergedAnnotationInvocationHandler.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* See {@link Annotation#equals(Object)} for a definition of the required algorithm.
* @param other the other object to compare against
*/
private boolean annotationEquals(Object other) {
if (this == other) {
return true;
}
if (!this.type.isInstance(other)) {
return false;
}
for (int i = 0; i < this.attributes.size(); i++) {
Method attribute = this.attributes.get(i);
Object thisValue = getAttributeValue(attribute);
Object otherValue = ReflectionUtils.invokeMethod(attribute, other);
if (!ObjectUtils.nullSafeEquals(thisValue, otherValue)) {
return false;
}
}
return true;
}
19
View Source File : AnnotationTypeMapping.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Get a mapped attribute value from the most suitable
* {@link #getAnnotation() meta-annotation}. The resulting value is obtained
* from the closest meta-annotation, taking into consideration both
* convention and alias based mapping rules. For root mappings, this method
* will always return {@code null}.
* @param attributeIndex the attribute index of the source attribute
* @return the mapped annotation value, or {@code null}
*/
@Nullable
Object getMappedAnnotationValue(int attributeIndex) {
int mapped = this.annotationValueMappings[attributeIndex];
if (mapped == -1) {
return null;
}
AnnotationTypeMapping source = this.annotationValueSource[attributeIndex];
return ReflectionUtils.invokeMethod(source.attributes.get(mapped), source.annotation);
}
19
View Source File : LocalValidatorFactoryBean.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void afterPropertiesSet() {
Configuration<?> configuration;
if (this.providerClreplaced != null) {
ProviderSpecificBootstrap bootstrap = Validation.byProvider(this.providerClreplaced);
if (this.validationProviderResolver != null) {
bootstrap = bootstrap.providerResolver(this.validationProviderResolver);
}
configuration = bootstrap.configure();
} else {
GenericBootstrap bootstrap = Validation.byDefaultProvider();
if (this.validationProviderResolver != null) {
bootstrap = bootstrap.providerResolver(this.validationProviderResolver);
}
configuration = bootstrap.configure();
}
// Try Hibernate Validator 5.2's externalClreplacedLoader(ClreplacedLoader) method
if (this.applicationContext != null) {
try {
Method eclMethod = configuration.getClreplaced().getMethod("externalClreplacedLoader", ClreplacedLoader.clreplaced);
ReflectionUtils.invokeMethod(eclMethod, configuration, this.applicationContext.getClreplacedLoader());
} catch (NoSuchMethodException ex) {
// Ignore - no Hibernate Validator 5.2+ or similar provider
}
}
MessageInterpolator targetInterpolator = this.messageInterpolator;
if (targetInterpolator == null) {
targetInterpolator = configuration.getDefaultMessageInterpolator();
}
configuration.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator));
if (this.traversableResolver != null) {
configuration.traversableResolver(this.traversableResolver);
}
ConstraintValidatorFactory targetConstraintValidatorFactory = this.constraintValidatorFactory;
if (targetConstraintValidatorFactory == null && this.applicationContext != null) {
targetConstraintValidatorFactory = new SpringConstraintValidatorFactory(this.applicationContext.getAutowireCapableBeanFactory());
}
if (targetConstraintValidatorFactory != null) {
configuration.constraintValidatorFactory(targetConstraintValidatorFactory);
}
if (this.parameterNameDiscoverer != null) {
configureParameterNameProvider(this.parameterNameDiscoverer, configuration);
}
if (this.mappingLocations != null) {
for (Resource location : this.mappingLocations) {
try {
configuration.addMapping(location.getInputStream());
} catch (IOException ex) {
throw new IllegalStateException("Cannot read mapping resource: " + location);
}
}
}
this.validationPropertyMap.forEach(configuration::addProperty);
// Allow for custom post-processing before we actually build the ValidatorFactory.
postProcessConfiguration(configuration);
this.validatorFactory = configuration.buildValidatorFactory();
setTargetValidator(this.validatorFactory.getValidator());
}
19
View Source File : MBeanClientInterceptor.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
private Collection<?> convertDataArrayToTargetCollection(Object[] array, Clreplaced<?> collectionType, Clreplaced<?> elementType) throws NoSuchMethodException {
Method fromMethod = elementType.getMethod("from", array.getClreplaced().getComponentType());
Collection<Object> resultColl = CollectionFactory.createCollection(collectionType, Array.getLength(array));
for (int i = 0; i < array.length; i++) {
resultColl.add(ReflectionUtils.invokeMethod(fromMethod, null, array[i]));
}
return resultColl;
}
19
View Source File : MBeanClientInterceptor.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
private Object convertDataArrayToTargetArray(Object[] array, Clreplaced<?> targetClreplaced) throws NoSuchMethodException {
Clreplaced<?> targetType = targetClreplaced.getComponentType();
Method fromMethod = targetType.getMethod("from", array.getClreplaced().getComponentType());
Object resultArray = Array.newInstance(targetType, array.length);
for (int i = 0; i < array.length; i++) {
Array.set(resultArray, i, ReflectionUtils.invokeMethod(fromMethod, null, array[i]));
}
return resultArray;
}
19
View Source File : MBeanClientInterceptor.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Convert the given result object (from attribute access or operation invocation)
* to the specified target clreplaced for returning from the proxy method.
* @param result the result object as returned by the {@code MBeanServer}
* @param parameter the method parameter of the proxy method that's been invoked
* @return the converted result object, or the preplaceded-in object if no conversion
* is necessary
*/
@Nullable
protected Object convertResultValueIfNecessary(@Nullable Object result, MethodParameter parameter) {
Clreplaced<?> targetClreplaced = parameter.getParameterType();
try {
if (result == null) {
return null;
}
if (ClreplacedUtils.isreplacedignableValue(targetClreplaced, result)) {
return result;
}
if (result instanceof CompositeData) {
Method fromMethod = targetClreplaced.getMethod("from", CompositeData.clreplaced);
return ReflectionUtils.invokeMethod(fromMethod, null, result);
} else if (result instanceof CompositeData[]) {
CompositeData[] array = (CompositeData[]) result;
if (targetClreplaced.isArray()) {
return convertDataArrayToTargetArray(array, targetClreplaced);
} else if (Collection.clreplaced.isreplacedignableFrom(targetClreplaced)) {
Clreplaced<?> elementType = ResolvableType.forMethodParameter(parameter).asCollection().resolveGeneric();
if (elementType != null) {
return convertDataArrayToTargetCollection(array, targetClreplaced, elementType);
}
}
} else if (result instanceof TabularData) {
Method fromMethod = targetClreplaced.getMethod("from", TabularData.clreplaced);
return ReflectionUtils.invokeMethod(fromMethod, null, result);
} else if (result instanceof TabularData[]) {
TabularData[] array = (TabularData[]) result;
if (targetClreplaced.isArray()) {
return convertDataArrayToTargetArray(array, targetClreplaced);
} else if (Collection.clreplaced.isreplacedignableFrom(targetClreplaced)) {
Clreplaced<?> elementType = ResolvableType.forMethodParameter(parameter).asCollection().resolveGeneric();
if (elementType != null) {
return convertDataArrayToTargetCollection(array, targetClreplaced, elementType);
}
}
}
throw new InvocationFailureException("Incompatible result value [" + result + "] for target type [" + targetClreplaced.getName() + "]");
} catch (NoSuchMethodException ex) {
throw new InvocationFailureException("Could not obtain 'from(CompositeData)' / 'from(TabularData)' method on target type [" + targetClreplaced.getName() + "] for conversion of MXBean data structure [" + result + "]");
}
}
19
View Source File : JaxbElementWrapper.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
private Object wrap(Object input, Method method) {
Clreplaced<?> wrapperClreplaced = method.getDeclaringClreplaced();
Object wrapper = wrapperCache.computeIfAbsent(wrapperClreplaced, BeanUtils::instantiate);
return ReflectionUtils.invokeMethod(method, wrapper, input);
}
19
View Source File : RedissonAutoConfiguration.java
License : Apache License 2.0
Project Creator : tiankong0310
License : Apache License 2.0
Project Creator : tiankong0310
/**
* 默认的redisson配置
*
* @return
*/
@Bean
@ConditionalOnMissingBean(Config.clreplaced)
public Config defaultConfig() {
Config config = null;
Method clusterMethod = ReflectionUtils.findMethod(RedisProperties.clreplaced, "getCluster");
Method timeoutMethod = ReflectionUtils.findMethod(RedisProperties.clreplaced, "getTimeout");
Object timeoutValue = ReflectionUtils.invokeMethod(timeoutMethod, redisProperties);
int timeout;
if (null == timeoutValue) {
timeout = 0;
} else if (!(timeoutValue instanceof Integer)) {
Method millisMethod = ReflectionUtils.findMethod(timeoutValue.getClreplaced(), "toMillis");
timeout = ((Long) ReflectionUtils.invokeMethod(millisMethod, timeoutValue)).intValue();
} else {
timeout = (Integer) timeoutValue;
}
if (redissonProperties.getConfig() != null) {
try {
InputStream is = getConfigStream();
config = Config.fromJSON(is);
} catch (IOException e) {
// trying next format
try {
InputStream is = getConfigStream();
config = Config.fromYAML(is);
} catch (IOException e1) {
throw new IllegalArgumentException("Can't parse config", e1);
}
}
} else if (redisProperties.getSentinel() != null) {
// 哨兵
Method nodesMethod = ReflectionUtils.findMethod(RedisProperties.Sentinel.clreplaced, "getNodes");
Object nodesValue = ReflectionUtils.invokeMethod(nodesMethod, redisProperties.getSentinel());
String[] nodes;
if (nodesValue instanceof String) {
nodes = convert(Arrays.asList(((String) nodesValue).split(",")));
} else {
nodes = convert((List<String>) nodesValue);
}
config = new Config();
config.useSentinelServers().setMasterName(redisProperties.getSentinel().getMaster()).addSentinelAddress(nodes).setDatabase(redisProperties.getDatabase()).setConnectTimeout(timeout).setPreplacedword(redisProperties.getPreplacedword());
} else if (clusterMethod != null && ReflectionUtils.invokeMethod(clusterMethod, redisProperties) != null) {
// 集群
Object clusterObject = ReflectionUtils.invokeMethod(clusterMethod, redisProperties);
Method nodesMethod = ReflectionUtils.findMethod(clusterObject.getClreplaced(), "getNodes");
List<String> nodesObject = (List) ReflectionUtils.invokeMethod(nodesMethod, clusterObject);
String[] nodes = convert(nodesObject);
config = new Config();
config.useClusterServers().addNodeAddress(nodes).setConnectTimeout(timeout).setPreplacedword(redisProperties.getPreplacedword());
} else {
// 单机
config = new Config();
Method urlMethod = ReflectionUtils.findMethod(RedisProperties.clreplaced, "getUrl");
String url = (String) ReflectionUtils.invokeMethod(urlMethod, redisProperties);
if (StringUtils.isEmpty(url)) {
String prefix = "redis://";
Method method = ReflectionUtils.findMethod(RedisProperties.clreplaced, "isSsl");
if (method != null && (Boolean) ReflectionUtils.invokeMethod(method, redisProperties)) {
prefix = "rediss://";
}
url = prefix + redisProperties.getHost() + ":" + redisProperties.getPort();
}
config.useSingleServer().setAddress(url).setConnectTimeout(timeout).setDatabase(redisProperties.getDatabase()).setPreplacedword(redisProperties.getPreplacedword());
}
config.setCodec(JsonJacksonCodec.INSTANCE);
return config;
}
19
View Source File : ThinJarAppWrapper.java
License : Apache License 2.0
Project Creator : spring-projects-experimental
License : Apache License 2.0
Project Creator : spring-projects-experimental
private void close() {
if (this.app != null) {
try {
Method method = ReflectionUtils.findMethod(this.app.getClreplaced(), "close");
ReflectionUtils.invokeMethod(method, this.app);
} catch (Exception e) {
this.state = LaunchState.error;
logger.error("Cannot undeploy " + resource, e);
} finally {
reset();
if (this.app != null) {
try {
((URLClreplacedLoader) app.getClreplaced().getClreplacedLoader()).close();
this.app = null;
} catch (Exception e) {
this.state = LaunchState.error;
logger.error("Cannot clean up " + resource, e);
} finally {
this.app = null;
System.gc();
}
}
}
}
}
19
View Source File : ThinJarAppWrapper.java
License : Apache License 2.0
Project Creator : spring-projects-experimental
License : Apache License 2.0
Project Creator : spring-projects-experimental
private void runContext(String mainClreplaced, Map<String, String> properties, String... args) {
Method method = ReflectionUtils.findMethod(this.app.getClreplaced(), "run", String.clreplaced, Map.clreplaced, String[].clreplaced);
ReflectionUtils.invokeMethod(method, this.app, mainClreplaced, properties, args);
}
19
View Source File : MessageUtils.java
License : Apache License 2.0
Project Creator : spring-cloud
License : Apache License 2.0
Project Creator : spring-cloud
/**
* Create a message for the handler. If the handler is a wrapper for a function in an
* isolated clreplaced loader, then the message will be created with the target clreplaced
* loader (therefore the {@link Message} clreplaced must be on the clreplacedpath of the target
* clreplaced loader).
* @param handler the function that will be applied to the message
* @param payload the payload of the message
* @param headers the headers for the message
* @return a message with the correct clreplaced loader
*/
public static Object create(Object handler, Object payload, Map<String, Object> headers) {
if (handler instanceof FluxWrapper) {
handler = ((FluxWrapper<?>) handler).getTarget();
}
if (payload instanceof Message) {
headers = new HashMap<>(headers);
headers.putAll(((Message<?>) payload).getHeaders());
payload = ((Message<?>) payload).getPayload();
}
if (!(handler instanceof Isolated)) {
return MessageBuilder.withPayload(payload).copyHeaders(headers).build();
}
ClreplacedLoader clreplacedLoader = ((Isolated) handler).getClreplacedLoader();
Clreplaced<?> builder = ClreplacedUtils.resolveClreplacedName(MessageBuilder.clreplaced.getName(), clreplacedLoader);
Method withPayload = ClreplacedUtils.getMethod(builder, "withPayload", Object.clreplaced);
Method copyHeaders = ClreplacedUtils.getMethod(builder, "copyHeaders", Map.clreplaced);
Method build = ClreplacedUtils.getMethod(builder, "build");
Object instance = ReflectionUtils.invokeMethod(withPayload, null, payload);
ReflectionUtils.invokeMethod(copyHeaders, instance, headers);
return ReflectionUtils.invokeMethod(build, instance);
}
19
View Source File : JmsListenerAnnotationBeanPostProcessorTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void sendToAnnotationFoundOnInterfaceProxy() throws Exception {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.clreplaced, ProxyConfig.clreplaced, InterfaceProxyTestBean.clreplaced);
try {
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.clreplaced);
replacedertThat(factory.getListenerContainers().size()).as("one container should have been registered").isEqualTo(1);
JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
replacedertThat(endpoint.getClreplaced()).as("Wrong endpoint type").isEqualTo(MethodJmsListenerEndpoint.clreplaced);
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
replacedertThat(AopUtils.isJdkDynamicProxy(methodEndpoint.getBean())).isTrue();
boolean condition = methodEndpoint.getBean() instanceof SimpleService;
replacedertThat(condition).isTrue();
replacedertThat(methodEndpoint.getMethod()).isEqualTo(SimpleService.clreplaced.getMethod("handleIt", String.clreplaced, String.clreplaced));
replacedertThat(methodEndpoint.getMostSpecificMethod()).isEqualTo(InterfaceProxyTestBean.clreplaced.getMethod("handleIt", String.clreplaced, String.clreplaced));
Method method = ReflectionUtils.findMethod(endpoint.getClreplaced(), "getDefaultResponseDestination");
ReflectionUtils.makeAccessible(method);
Object destination = ReflectionUtils.invokeMethod(method, endpoint);
replacedertThat(destination).as("SendTo annotation not found on proxy").isEqualTo("foobar");
} finally {
context.close();
}
}
19
View Source File : JmsListenerAnnotationBeanPostProcessorTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void sendToAnnotationFoundOnCglibProxy() throws Exception {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.clreplaced, ProxyConfig.clreplaced, ClreplacedProxyTestBean.clreplaced);
try {
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.clreplaced);
replacedertThat(factory.getListenerContainers().size()).as("one container should have been registered").isEqualTo(1);
JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
replacedertThat(endpoint.getClreplaced()).as("Wrong endpoint type").isEqualTo(MethodJmsListenerEndpoint.clreplaced);
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
replacedertThat(AopUtils.isCglibProxy(methodEndpoint.getBean())).isTrue();
boolean condition = methodEndpoint.getBean() instanceof ClreplacedProxyTestBean;
replacedertThat(condition).isTrue();
replacedertThat(methodEndpoint.getMethod()).isEqualTo(ClreplacedProxyTestBean.clreplaced.getMethod("handleIt", String.clreplaced, String.clreplaced));
replacedertThat(methodEndpoint.getMostSpecificMethod()).isEqualTo(ClreplacedProxyTestBean.clreplaced.getMethod("handleIt", String.clreplaced, String.clreplaced));
Method method = ReflectionUtils.findMethod(endpoint.getClreplaced(), "getDefaultResponseDestination");
ReflectionUtils.makeAccessible(method);
Object destination = ReflectionUtils.invokeMethod(method, endpoint);
replacedertThat(destination).as("SendTo annotation not found on proxy").isEqualTo("foobar");
} finally {
context.close();
}
}
19
View Source File : AnnotationTypeMapping.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
/**
* Get a mapped attribute value from the most suitable
* {@link #getAnnotation() meta-annotation}.
* <p>The resulting value is obtained from the closest meta-annotation,
* taking into consideration both convention and alias based mapping rules.
* For root mappings, this method will always return {@code null}.
* @param attributeIndex the attribute index of the source attribute
* @param metaAnnotationsOnly if only meta annotations should be considered.
* If this parameter is {@code false} then aliases within the annotation will
* also be considered.
* @return the mapped annotation value, or {@code null}
*/
@Nullable
Object getMappedAnnotationValue(int attributeIndex, boolean metaAnnotationsOnly) {
int mappedIndex = this.annotationValueMappings[attributeIndex];
if (mappedIndex == -1) {
return null;
}
AnnotationTypeMapping source = this.annotationValueSource[attributeIndex];
if (source == this && metaAnnotationsOnly) {
return null;
}
return ReflectionUtils.invokeMethod(source.attributes.get(mappedIndex), source.annotation);
}
19
View Source File : ExtensionComponent.java
License : Apache License 2.0
Project Creator : sofastack
License : Apache License 2.0
Project Creator : sofastack
@Override
public void activate() throws ServiceRuntimeException {
if (componentStatus != ComponentStatus.RESOLVED) {
return;
}
ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
ComponentName extensionPointComponentName = extension.getTargetComponentName();
ComponentInfo extensionPointComponentInfo = componentManager.getComponentInfo(extensionPointComponentName);
if (extensionPointComponentInfo == null || !extensionPointComponentInfo.isActivated()) {
return;
}
loadContributions(((ExtensionPointComponent) extensionPointComponentInfo).getExtensionPoint(), extension);
Object target = extensionPointComponentInfo.getImplementation().getTarget();
if (target instanceof Extensible) {
try {
((Extensible) target).registerExtension(extension);
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
} else {
Method method = ReflectionUtils.findMethod(target.getClreplaced(), "registerExtension", Extension.clreplaced);
ReflectionUtils.invokeMethod(method, target, extension);
}
componentStatus = ComponentStatus.ACTIVATED;
}
19
View Source File : NamePropertyDefaultValueDubboConfigBeanCustomizer.java
License : Apache License 2.0
Project Creator : smallFive55
License : Apache License 2.0
Project Creator : smallFive55
@Override
public void customize(String beanName, AbstractConfig dubboConfigBean) {
PropertyDescriptor propertyDescriptor = getPropertyDescriptor(dubboConfigBean.getClreplaced(), PROPERTY_NAME);
if (propertyDescriptor != null) {
// "name" property is present
Method getNameMethod = propertyDescriptor.getReadMethod();
if (getNameMethod == null) {
// if "getName" method is absent
return;
}
Object propertyValue = ReflectionUtils.invokeMethod(getNameMethod, dubboConfigBean);
if (propertyValue != null) {
// If The return value of "getName" method is not null
return;
}
Method setNameMethod = propertyDescriptor.getWriteMethod();
if (setNameMethod != null && getNameMethod != null) {
// "setName" and "getName" methods are present
if (Arrays.equals(of(String.clreplaced), setNameMethod.getParameterTypes())) {
// the param type is String
// set bean name to the value of the "name" property
ReflectionUtils.invokeMethod(setNameMethod, dubboConfigBean, beanName);
}
}
}
}
19
View Source File : CodeGeneratorService.java
License : GNU General Public License v2.0
Project Creator : sanri1993
License : GNU General Public License v2.0
Project Creator : sanri1993
/**
* 用于创建 PackageConfig 中的所有目录 , 基于基本目录 {@param javaDir}
* @param javaDir
* @param packageConfig
*/
private void mkdirs(File javaDir, CodeGeneratorConfig.PackageConfig packageConfig) {
PropertyDescriptor[] beanGetters = ReflectUtils.getBeanGetters(CodeGeneratorConfig.PackageConfig.clreplaced);
for (int i = 0; i < beanGetters.length; i++) {
Method readMethod = beanGetters[i].getReadMethod();
String path = Objects.toString(ReflectionUtils.invokeMethod(readMethod, packageConfig));
String[] split = StringUtils.split(path, '.');
StringBuffer currentPath = new StringBuffer();
for (String partPath : split) {
currentPath.append("/").append(partPath);
File dir = new File(javaDir, currentPath.toString());
if (!dir.exists()) {
log.info("创建目录 : {} ", dir);
dir.mkdir();
}
}
}
}
19
View Source File : RandomDataService.java
License : GNU General Public License v2.0
Project Creator : sanri1993
License : GNU General Public License v2.0
Project Creator : sanri1993
/**
* 注入复杂对象值,只能注入复杂类型 ; 这个是真正的主入口,注入一个复杂类型对象数据
* @param clazz
* @return
*/
private Object populateDataComplex(Clreplaced<?> clazz) {
Object object = ReflectUtils.newInstance(clazz);
PropertyDescriptor[] beanSetters = ReflectUtils.getBeanSetters(clazz);
for (PropertyDescriptor beanSetter : beanSetters) {
Method writeMethod = beanSetter.getWriteMethod();
String columnName = beanSetter.getName();
Type genericParameterType = writeMethod.getGenericParameterTypes()[0];
Object populateData = populateData(genericParameterType, columnName);
ReflectionUtils.invokeMethod(writeMethod, object, populateData);
}
return object;
}
19
View Source File : MethodInvoker.java
License : Apache License 2.0
Project Creator : rocketmq
License : Apache License 2.0
Project Creator : rocketmq
/**
* 对目标方法进行调用
*
* @param delegate 方法所在对象
* @param method 对应方法
* @param args 方法参数
*/
void invoke(Object delegate, final Method method, Object... args) {
try {
if (!hook.preHandle(args)) {
return;
}
} catch (Exception e) {
handleHookException(e);
}
Clreplaced<?>[] parmTypes = method.getParameterTypes();
// 检查方法中是否有MessageContext参数
boolean hasContext = Arrays.stream(parmTypes).anyMatch(parmClazz -> parmClazz.equals(MessageContext.clreplaced));
try {
if (hasContext) {
ReflectionUtils.invokeMethod(method, delegate, args);
} else {
ReflectionUtils.invokeMethod(method, delegate, args[0]);
}
} catch (Exception e) {
hook.nextHandle(false, args);
throw new ConsumeException(e);
}
try {
hook.nextHandle(true, args);
} catch (Exception e) {
handleHookException(e);
}
}
19
View Source File : FriendRequestHandler.java
License : Apache License 2.0
Project Creator : PowerJob
License : Apache License 2.0
Project Creator : PowerJob
private void onReceiveRemoteProcessReq(RemoteProcessReq req) {
AskResponse response = new AskResponse();
response.setSuccess(true);
try {
Object[] args = req.getArgs();
String[] parameterTypes = req.getParameterTypes();
Clreplaced<?>[] parameters = new Clreplaced[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
parameters[i] = Clreplaced.forName(parameterTypes[i]);
Object arg = args[i];
if (arg != null) {
args[i] = JSONObject.parseObject(JSONObject.toJSONBytes(arg), parameters[i]);
}
}
Clreplaced<?> clz = Clreplaced.forName(req.getClreplacedName());
Object bean = SpringUtils.getBean(clz);
Method method = ReflectionUtils.findMethod(clz, req.getMethodName(), parameters);
replacedert method != null;
Object invokeResult = ReflectionUtils.invokeMethod(method, bean, args);
response.setData(JSONObject.toJSONBytes(invokeResult));
} catch (Throwable t) {
log.error("[FriendActor] process remote request[{}] failed!", req, t);
response.setSuccess(false);
response.setMessage(ExceptionUtils.getMessage(t));
}
getSender().tell(response, getSelf());
}
19
View Source File : AggregateTestUtils.java
License : Apache License 2.0
Project Creator : odrotbohm
License : Apache License 2.0
Project Creator : odrotbohm
/**
* Extracts all domain events from the given aggregate that uses Spring Data's {@link DomainEvents} annotation to
* expose them.
*
* @param aggregate must not be {@literal null}.
* @return {@link PublishedEvents} for all events contained in the given aggregate, will never be {@literal null}.
*/
public static PublishedEvents eventsOf(Object aggregate) {
Collection<?> events = CACHE.computeIfAbsent(aggregate.getClreplaced(), AggregateTestUtils::findAnnotatedMethod).map(//
it -> ReflectionUtils.invokeMethod(it, aggregate)).map(//
Collection.clreplaced::cast).orElseGet(Collections::emptyList);
return PublishedEvents.of(events);
}
19
View Source File : HeadersMethodArgumentResolver.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
Clreplaced<?> paramType = parameter.getParameterType();
if (Map.clreplaced.isreplacedignableFrom(paramType)) {
return message.getHeaders();
} else if (MessageHeaderAccessor.clreplaced == paramType) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.clreplaced);
return (accessor != null ? accessor : new MessageHeaderAccessor(message));
} else if (MessageHeaderAccessor.clreplaced.isreplacedignableFrom(paramType)) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.clreplaced);
if (accessor != null && paramType.isreplacedignableFrom(accessor.getClreplaced())) {
return accessor;
} else {
Method method = ReflectionUtils.findMethod(paramType, "wrap", Message.clreplaced);
if (method == null) {
throw new IllegalStateException("Cannot create accessor of type " + paramType + " for message " + message);
}
return ReflectionUtils.invokeMethod(method, null, message);
}
} else {
throw new IllegalStateException("Unexpected method parameter type " + paramType + "in method " + parameter.getMethod() + ". " + "@Headers method arguments must be replacedignable to java.util.Map.");
}
}
19
View Source File : JmsResourceHolder.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
public void commitAll() throws JMSException {
for (Session session : this.sessions) {
try {
session.commit();
} catch (TransactionInProgressException ex) {
// Ignore -> can only happen in case of a JTA transaction.
} catch (javax.jms.IllegalStateException ex) {
if (this.connectionFactory != null) {
try {
Method getDataSourceMethod = this.connectionFactory.getClreplaced().getMethod("getDataSource");
Object ds = ReflectionUtils.invokeMethod(getDataSourceMethod, this.connectionFactory);
while (ds != null) {
if (TransactionSynchronizationManager.hasResource(ds)) {
// IllegalStateException from sharing the underlying JDBC Connection
// which typically gets committed first, e.g. with Oracle AQ --> ignore
return;
}
try {
// Check for decorated DataSource a la Spring's DelegatingDataSource
Method getTargetDataSourceMethod = ds.getClreplaced().getMethod("getTargetDataSource");
ds = ReflectionUtils.invokeMethod(getTargetDataSourceMethod, ds);
} catch (NoSuchMethodException nsme) {
ds = null;
}
}
} catch (Throwable ex2) {
if (logger.isDebugEnabled()) {
logger.debug("No working getDataSource method found on ConnectionFactory: " + ex2);
}
// No working getDataSource method - cannot perform DataSource transaction check
}
}
throw ex;
}
}
}
19
View Source File : SynthesizedAnnotationInvocationHandler.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
/**
* See {@link Annotation#equals(Object)} for a definition of the required algorithm.
* @param other the other object to compare against
*/
private boolean annotationEquals(Object other) {
if (this == other) {
return true;
}
if (!annotationType().isInstance(other)) {
return false;
}
for (Method attributeMethod : AnnotationUtils.getAttributeMethods(annotationType())) {
Object thisValue = getAttributeValue(attributeMethod);
Object otherValue = ReflectionUtils.invokeMethod(attributeMethod, other);
if (!ObjectUtils.nullSafeEquals(thisValue, otherValue)) {
return false;
}
}
return true;
}
19
View Source File : TransactionalServiceAnnotationReflectionBootstrap.java
License : Apache License 2.0
Project Creator : mercyblitz
License : Apache License 2.0
Project Creator : mercyblitz
private static void printAnnotationAttribute(Annotation annotation) {
Clreplaced<?> annotationType = annotation.annotationType();
// 完全 Java 反射实现(ReflectionUtils 为 Spring 反射工具类)
ReflectionUtils.doWithMethods(annotationType, method -> System.out.printf("@%s.%s() = %s\n", annotationType.getSimpleName(), method.getName(), // 执行 Method 反射调用
ReflectionUtils.invokeMethod(method, annotation)), // , method -> method.getParameterCount() == 0); // 选择无参数方法
method -> !method.getDeclaringClreplaced().equals(Annotation.clreplaced));
}
19
View Source File : MybatisTrackEventCommitter.java
License : MIT License
Project Creator : logtube
License : MIT License
Project Creator : logtube
@Nullable
private static String extractDatabaseURL(@NotNull DataSource dataSource) {
if (dataSource instanceof AbstractRoutingDataSource) {
AbstractRoutingDataSource abstractRoutingDataSource = (AbstractRoutingDataSource) dataSource;
Method method = ReflectionUtils.findMethod(abstractRoutingDataSource.getClreplaced(), "determineTargetDataSource");
if (method == null) {
LOGGER.debug("executor.transaction.dataSource with type AbstractRoutingDataSource has no method named 'determineTargetDataSource'");
return null;
}
ReflectionUtils.makeAccessible(method);
DataSource dataSource1 = (DataSource) ReflectionUtils.invokeMethod(method, abstractRoutingDataSource);
if (dataSource1 == null) {
LOGGER.debug("executor.transaction.dataSource.determineTargetDataSource() returns null");
return null;
}
return extractDatabaseURL(dataSource1);
}
Method method = ReflectionUtils.findMethod(dataSource.getClreplaced(), "getUrl");
if (method == null) {
LOGGER.debug("dataSource has no method getUrl()");
return null;
}
ReflectionUtils.makeAccessible(method);
Object result = ReflectionUtils.invokeMethod(method, dataSource);
if (result == null) {
LOGGER.debug("dataSource.getUrl() returns null");
return null;
}
return result.toString();
}
19
View Source File : CEKHandlerMethod.java
License : Apache License 2.0
Project Creator : line
License : Apache License 2.0
Project Creator : line
public Object invoke(Object[] args) {
return ReflectionUtils.invokeMethod(method, bean, args);
}
19
View Source File : ReflectUtil.java
License : GNU Lesser General Public License v3.0
Project Creator : lets-mica
License : GNU Lesser General Public License v3.0
Project Creator : lets-mica
/**
* 重写 invokeMethod 的方法,用于处理 setAccessible 的问题
*
* @param method Method
* @param target Object
* @param args args
* @return value
*/
@Nullable
public static Object invokeMethod(Method method, @Nullable Object target, @Nullable Object... args) {
makeAccessible(method);
return ReflectionUtils.invokeMethod(method, target, args);
}
19
View Source File : VelocityToolboxView.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* Overridden to check for the ViewContext interface which is part of the
* view package of Velocity Tools. This requires a special Velocity context,
* like ChainedContext as set up by {@link #createVelocityContext} in this clreplaced.
*/
@Override
protected void initTool(Object tool, Context velocityContext) throws Exception {
// Velocity Tools 1.3: a clreplaced-level "init(Object)" method.
Method initMethod = ClreplacedUtils.getMethodIfAvailable(tool.getClreplaced(), "init", Object.clreplaced);
if (initMethod != null) {
ReflectionUtils.invokeMethod(initMethod, tool, velocityContext);
}
}
19
View Source File : FacesRequestAttributes.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Override
public String getSessionId() {
Object session = getExternalContext().getSession(true);
try {
// Both HttpSession and PortletSession have a getId() method.
Method getIdMethod = session.getClreplaced().getMethod("getId", new Clreplaced<?>[0]);
return ReflectionUtils.invokeMethod(getIdMethod, session).toString();
} catch (NoSuchMethodException ex) {
throw new IllegalStateException("Session object [" + session + "] does not have a getId() method");
}
}
19
View Source File : SqlScriptsTestExecutionListener.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
private DataSource getDataSourceFromTransactionManager(PlatformTransactionManager transactionManager) {
try {
Method getDataSourceMethod = transactionManager.getClreplaced().getMethod("getDataSource");
Object obj = ReflectionUtils.invokeMethod(getDataSourceMethod, transactionManager);
if (obj instanceof DataSource) {
return (DataSource) obj;
}
} catch (Exception e) {
/* ignore */
}
return null;
}
19
View Source File : HeadersMethodArgumentResolver.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Override
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
Clreplaced<?> paramType = parameter.getParameterType();
if (Map.clreplaced.isreplacedignableFrom(paramType)) {
return message.getHeaders();
} else if (MessageHeaderAccessor.clreplaced == paramType) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.clreplaced);
return (accessor != null ? accessor : new MessageHeaderAccessor(message));
} else if (MessageHeaderAccessor.clreplaced.isreplacedignableFrom(paramType)) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.clreplaced);
if (accessor != null && paramType.isreplacedignableFrom(accessor.getClreplaced())) {
return accessor;
} else {
Method method = ReflectionUtils.findMethod(paramType, "wrap", Message.clreplaced);
replacedert.notNull(method, "Cannot create accessor of type " + paramType + " for message " + message);
return ReflectionUtils.invokeMethod(method, null, message);
}
} else {
throw new IllegalStateException("Unexpected method parameter type " + paramType + "in method " + parameter.getMethod() + ". " + "@Headers method arguments must be replacedignable to java.util.Map.");
}
}
19
View Source File : JmsListenerAnnotationBeanPostProcessorTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void sendToAnnotationFoundOnProxy() throws Exception {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.clreplaced, ProxyConfig.clreplaced, ProxyTestBean.clreplaced);
try {
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.clreplaced);
replacedertEquals("one container should have been registered", 1, factory.getListenerContainers().size());
JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
replacedertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.clreplaced, endpoint.getClreplaced());
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
replacedertTrue(AopUtils.isJdkDynamicProxy(methodEndpoint.getBean()));
replacedertTrue(methodEndpoint.getBean() instanceof SimpleService);
replacedertEquals(SimpleService.clreplaced.getMethod("handleIt", String.clreplaced), methodEndpoint.getMethod());
replacedertEquals(ProxyTestBean.clreplaced.getMethod("handleIt", String.clreplaced), methodEndpoint.getMostSpecificMethod());
Method m = ReflectionUtils.findMethod(endpoint.getClreplaced(), "getDefaultResponseDestination");
ReflectionUtils.makeAccessible(m);
Object destination = ReflectionUtils.invokeMethod(m, endpoint);
replacedertEquals("SendTo annotation not found on proxy", "foobar", destination);
} finally {
context.close();
}
}
19
View Source File : JmsTemplate.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* Actually send the given JMS message.
* @param producer the JMS MessageProducer to send with
* @param message the JMS Message to send
* @throws JMSException if thrown by JMS API methods
*/
protected void doSend(MessageProducer producer, Message message) throws JMSException {
if (this.deliveryDelay >= 0) {
if (setDeliveryDelayMethod == null) {
throw new IllegalStateException("setDeliveryDelay requires JMS 2.0");
}
ReflectionUtils.invokeMethod(setDeliveryDelayMethod, producer, this.deliveryDelay);
}
if (isExplicitQosEnabled()) {
producer.send(message, getDeliveryMode(), getPriority(), getTimeToLive());
} else {
producer.send(message);
}
}
See More Examples