Java Code Examples for org.springframework.util.ClassUtils#getQualifiedMethodName()

The following examples show how to use org.springframework.util.ClassUtils#getQualifiedMethodName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoutingInterceptor.java    From compass with Apache License 2.0 6 votes vote down vote up
protected boolean isMasterMode(Method method) {

		// 先检查配置项,再检查注解项
		if (masterSlaveAttributeSource != null) {
			MasterSlaveAttribute attr = masterSlaveAttributeSource
					.getMasterSlaveAttribute(method, method.getClass());
			if (attr == null)
				throw new MasterSlaveConfigNotFoundException(
						ClassUtils.getQualifiedMethodName(method)
								+ "can not match MASTER/SLAVE");
			return attr == MasterSlaveAttribute.MASTER ? true : false;
		}
		if (method.getAnnotation(Slave.class) != null)
			return false;
		if (method.getAnnotation(Master.class) != null)
			return true;
		if (method.getDeclaringClass().getAnnotation(Slave.class) != null)
			return false;
		if (method.getDeclaringClass().getAnnotation(Master.class) != null)
			return true;
		throw new MasterSlaveConfigNotFoundException(
				ClassUtils.getQualifiedMethodName(method)
						+ "cannot match MASTER/SLAVE");

	}
 
Example 2
Source File: RoutingInterceptor.java    From compass with Apache License 2.0 5 votes vote down vote up
protected Object extractRouteKey(MethodInvocation mi) {
	Method method = mi.getMethod();
	Annotation[][] parameterAnnotations = method.getParameterAnnotations();
	Object[] args = mi.getArguments();
	Object routeKey = null;

	// 没有设置路由标识,如果useFirstArgumentAsRoutingKey=true,那么以第一个参数作为路由标识
	if (useFirstArgumentAsRouteKey) {
		if (args.length < 1) {
			throw new IllegalArgumentException(
					"use firstArgumentAsRoutingKey, but no arguments for method: "
							+ ClassUtils.getQualifiedMethodName(method));
		}
		routeKey = args[0];
		return routeKey;
	}
	int i = 0;
	for (Annotation[] annotations : parameterAnnotations) {
		Object parameter = args[i++];
		for (Annotation annotation : annotations) {
			if (null == routeKey && annotation instanceof RouteKey) {
				routeKey = parameter;
			}
		}
	}
	return routeKey;
}
 
Example 3
Source File: CustomizableTraceInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Writes a log message before the invocation based on the value of {@code enterMessage}.
 * If the invocation succeeds, then a log message is written on exit based on the value
 * {@code exitMessage}. If an exception occurs during invocation, then a message is
 * written based on the value of {@code exceptionMessage}.
 * @see #setEnterMessage
 * @see #setExitMessage
 * @see #setExceptionMessage
 */
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
	String name = ClassUtils.getQualifiedMethodName(invocation.getMethod());
	StopWatch stopWatch = new StopWatch(name);
	Object returnValue = null;
	boolean exitThroughException = false;
	try {
		stopWatch.start(name);
		writeToLog(logger,
				replacePlaceholders(this.enterMessage, invocation, null, null, -1));
		returnValue = invocation.proceed();
		return returnValue;
	}
	catch (Throwable ex) {
		if (stopWatch.isRunning()) {
			stopWatch.stop();
		}
		exitThroughException = true;
		writeToLog(logger, replacePlaceholders(
				this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex);
		throw ex;
	}
	finally {
		if (!exitThroughException) {
			if (stopWatch.isRunning()) {
				stopWatch.stop();
			}
			writeToLog(logger, replacePlaceholders(
					this.exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis()));
		}
	}
}
 
Example 4
Source File: FunctionReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute a function represented as a java.lang.reflect.Method.
 * @param state the expression evaluation state
 * @param method the method to invoke
 * @return the return value of the invoked Java method
 * @throws EvaluationException if there is any problem invoking the method
 */
private TypedValue executeFunctionJLRMethod(ExpressionState state, Method method) throws EvaluationException {
	this.method = null;
	Object[] functionArgs = getArguments(state);

	if (!method.isVarArgs() && method.getParameterTypes().length != functionArgs.length) {
		throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
				functionArgs.length, method.getParameterTypes().length);
	}
	// Only static methods can be called in this way
	if (!Modifier.isStatic(method.getModifiers())) {
		throw new SpelEvaluationException(getStartPosition(),
				SpelMessage.FUNCTION_MUST_BE_STATIC, ClassUtils.getQualifiedMethodName(method), this.name);
	}

	this.argumentConversionOccurred = false;
	// Convert arguments if necessary and remap them for varargs if required
	if (functionArgs != null) {
		TypeConverter converter = state.getEvaluationContext().getTypeConverter();
		this.argumentConversionOccurred = ReflectionHelper.convertAllArguments(converter, functionArgs, method);
	}
	if (method.isVarArgs()) {
		functionArgs = ReflectionHelper.setupArgumentsForVarargsInvocation(
				method.getParameterTypes(), functionArgs);
	}

	try {
		ReflectionUtils.makeAccessible(method);
		Object result = method.invoke(method.getClass(), functionArgs);
		if (!argumentConversionOccurred) {
			this.method = method;
			this.exitTypeDescriptor = CodeFlow.toDescriptor(method.getReturnType());
		}
		return new TypedValue(result, new TypeDescriptor(new MethodParameter(method, -1)).narrow(result));
	}
	catch (Exception ex) {
		throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_FUNCTION_CALL,
				this.name, ex.getMessage());
	}
}
 
Example 5
Source File: InitDestroyAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public LifecycleElement(Method method) {
	if (method.getParameterCount() != 0) {
		throw new IllegalStateException("Lifecycle method annotation requires a no-arg method: " + method);
	}
	this.method = method;
	this.identifier = (Modifier.isPrivate(method.getModifiers()) ?
			ClassUtils.getQualifiedMethodName(method) : method.getName());
}
 
Example 6
Source File: CustomizableTraceInterceptor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Writes a log message before the invocation based on the value of {@code enterMessage}.
 * If the invocation succeeds, then a log message is written on exit based on the value
 * {@code exitMessage}. If an exception occurs during invocation, then a message is
 * written based on the value of {@code exceptionMessage}.
 * @see #setEnterMessage
 * @see #setExitMessage
 * @see #setExceptionMessage
 */
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
	String name = ClassUtils.getQualifiedMethodName(invocation.getMethod());
	StopWatch stopWatch = new StopWatch(name);
	Object returnValue = null;
	boolean exitThroughException = false;
	try {
		stopWatch.start(name);
		writeToLog(logger,
				replacePlaceholders(this.enterMessage, invocation, null, null, -1));
		returnValue = invocation.proceed();
		return returnValue;
	}
	catch (Throwable ex) {
		if (stopWatch.isRunning()) {
			stopWatch.stop();
		}
		exitThroughException = true;
		writeToLog(logger, replacePlaceholders(
				this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex);
		throw ex;
	}
	finally {
		if (!exitThroughException) {
			if (stopWatch.isRunning()) {
				stopWatch.stop();
			}
			writeToLog(logger, replacePlaceholders(
					this.exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis()));
		}
	}
}
 
Example 7
Source File: InitDestroyAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public LifecycleElement(Method method) {
	if (method.getParameterTypes().length != 0) {
		throw new IllegalStateException("Lifecycle method annotation requires a no-arg method: " + method);
	}
	this.method = method;
	this.identifier = (Modifier.isPrivate(method.getModifiers()) ?
			ClassUtils.getQualifiedMethodName(method) : method.getName());
}
 
Example 8
Source File: AbstractFallbackTransactionAttributeSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determine the transaction attribute for this method invocation.
 * <p>Defaults to the class's transaction attribute if no method attribute is found.
 * @param method the method for the current invocation (never {@code null})
 * @param targetClass the target class for this invocation (may be {@code null})
 * @return TransactionAttribute for this method, or {@code null} if the method
 * is not transactional
 */
@Override
public TransactionAttribute getTransactionAttribute(Method method, Class<?> targetClass) {
	if (method.getDeclaringClass() == Object.class) {
		return null;
	}

	// First, see if we have a cached value.
	Object cacheKey = getCacheKey(method, targetClass);
	Object cached = this.attributeCache.get(cacheKey);
	if (cached != null) {
		// Value will either be canonical value indicating there is no transaction attribute,
		// or an actual transaction attribute.
		if (cached == NULL_TRANSACTION_ATTRIBUTE) {
			return null;
		}
		else {
			return (TransactionAttribute) cached;
		}
	}
	else {
		// We need to work it out.
		TransactionAttribute txAttr = computeTransactionAttribute(method, targetClass);
		// Put it in the cache.
		if (txAttr == null) {
			this.attributeCache.put(cacheKey, NULL_TRANSACTION_ATTRIBUTE);
		}
		else {
			String methodIdentification = ClassUtils.getQualifiedMethodName(method, targetClass);
			if (txAttr instanceof DefaultTransactionAttribute) {
				((DefaultTransactionAttribute) txAttr).setDescriptor(methodIdentification);
			}
			if (logger.isDebugEnabled()) {
				logger.debug("Adding transactional method '" + methodIdentification + "' with attribute: " + txAttr);
			}
			this.attributeCache.put(cacheKey, txAttr);
		}
		return txAttr;
	}
}
 
Example 9
Source File: InitDestroyAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
public LifecycleElement(Method method) {
	if (method.getParameterCount() != 0) {
		throw new IllegalStateException("Lifecycle method annotation requires a no-arg method: " + method);
	}
	this.method = method;
	this.identifier = (Modifier.isPrivate(method.getModifiers()) ?
			ClassUtils.getQualifiedMethodName(method) : method.getName());
}
 
Example 10
Source File: CustomizableTraceInterceptor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Writes a log message before the invocation based on the value of {@code enterMessage}.
 * If the invocation succeeds, then a log message is written on exit based on the value
 * {@code exitMessage}. If an exception occurs during invocation, then a message is
 * written based on the value of {@code exceptionMessage}.
 * @see #setEnterMessage
 * @see #setExitMessage
 * @see #setExceptionMessage
 */
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
	String name = ClassUtils.getQualifiedMethodName(invocation.getMethod());
	StopWatch stopWatch = new StopWatch(name);
	Object returnValue = null;
	boolean exitThroughException = false;
	try {
		stopWatch.start(name);
		writeToLog(logger,
				replacePlaceholders(this.enterMessage, invocation, null, null, -1));
		returnValue = invocation.proceed();
		return returnValue;
	}
	catch (Throwable ex) {
		if (stopWatch.isRunning()) {
			stopWatch.stop();
		}
		exitThroughException = true;
		writeToLog(logger, replacePlaceholders(
				this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex);
		throw ex;
	}
	finally {
		if (!exitThroughException) {
			if (stopWatch.isRunning()) {
				stopWatch.stop();
			}
			writeToLog(logger, replacePlaceholders(
					this.exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis()));
		}
	}
}
 
Example 11
Source File: TestContextTransactionUtils.java    From java-technology-stack with MIT License 4 votes vote down vote up
public TestContextTransactionAttribute(TransactionAttribute targetAttribute, TestContext testContext) {
	super(targetAttribute);
	this.name = ClassUtils.getQualifiedMethodName(testContext.getTestMethod(), testContext.getTestClass());
}
 
Example 12
Source File: FunctionReference.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Execute a function represented as a {@code java.lang.reflect.Method}.
 * @param state the expression evaluation state
 * @param method the method to invoke
 * @return the return value of the invoked Java method
 * @throws EvaluationException if there is any problem invoking the method
 */
private TypedValue executeFunctionJLRMethod(ExpressionState state, Method method) throws EvaluationException {
	Object[] functionArgs = getArguments(state);

	if (!method.isVarArgs()) {
		int declaredParamCount = method.getParameterCount();
		if (declaredParamCount != functionArgs.length) {
			throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
					functionArgs.length, declaredParamCount);
		}
	}
	if (!Modifier.isStatic(method.getModifiers())) {
		throw new SpelEvaluationException(getStartPosition(),
				SpelMessage.FUNCTION_MUST_BE_STATIC, ClassUtils.getQualifiedMethodName(method), this.name);
	}

	// Convert arguments if necessary and remap them for varargs if required
	TypeConverter converter = state.getEvaluationContext().getTypeConverter();
	boolean argumentConversionOccurred = ReflectionHelper.convertAllArguments(converter, functionArgs, method);
	if (method.isVarArgs()) {
		functionArgs = ReflectionHelper.setupArgumentsForVarargsInvocation(
				method.getParameterTypes(), functionArgs);
	}
	boolean compilable = false;

	try {
		ReflectionUtils.makeAccessible(method);
		Object result = method.invoke(method.getClass(), functionArgs);
		compilable = !argumentConversionOccurred;
		return new TypedValue(result, new TypeDescriptor(new MethodParameter(method, -1)).narrow(result));
	}
	catch (Exception ex) {
		throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_FUNCTION_CALL,
				this.name, ex.getMessage());
	}
	finally {
		if (compilable) {
			this.exitTypeDescriptor = CodeFlow.toDescriptor(method.getReturnType());
			this.method = method;
		}
		else {
			this.exitTypeDescriptor = null;
			this.method = null;
		}
	}
}
 
Example 13
Source File: AbstractFallbackTransactionAttributeSource.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Determine the transaction attribute for this method invocation.
 * <p>Defaults to the class's transaction attribute if no method attribute is found.
 * @param method the method for the current invocation (never {@code null})
 * @param targetClass the target class for this invocation (may be {@code null})
 * @return a TransactionAttribute for this method, or {@code null} if the method
 * is not transactional
 */
@Override
@Nullable
public TransactionAttribute getTransactionAttribute(Method method, @Nullable Class<?> targetClass) {
	if (method.getDeclaringClass() == Object.class) {
		return null;
	}

	// First, see if we have a cached value.
	Object cacheKey = getCacheKey(method, targetClass);
	TransactionAttribute cached = this.attributeCache.get(cacheKey);
	if (cached != null) {
		// Value will either be canonical value indicating there is no transaction attribute,
		// or an actual transaction attribute.
		if (cached == NULL_TRANSACTION_ATTRIBUTE) {
			return null;
		}
		else {
			return cached;
		}
	}
	else {
		// We need to work it out.
		TransactionAttribute txAttr = computeTransactionAttribute(method, targetClass);
		// Put it in the cache.
		if (txAttr == null) {
			this.attributeCache.put(cacheKey, NULL_TRANSACTION_ATTRIBUTE);
		}
		else {
			String methodIdentification = ClassUtils.getQualifiedMethodName(method, targetClass);
			if (txAttr instanceof DefaultTransactionAttribute) {
				((DefaultTransactionAttribute) txAttr).setDescriptor(methodIdentification);
			}
			if (logger.isTraceEnabled()) {
				logger.trace("Adding transactional method '" + methodIdentification + "' with attribute: " + txAttr);
			}
			this.attributeCache.put(cacheKey, txAttr);
		}
		return txAttr;
	}
}
 
Example 14
Source File: TestContextTransactionUtils.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public TestContextTransactionAttribute(TransactionAttribute targetAttribute, TestContext testContext) {
	super(targetAttribute);
	this.name = ClassUtils.getQualifiedMethodName(testContext.getTestMethod(), testContext.getTestClass());
}
 
Example 15
Source File: FunctionReference.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Execute a function represented as a {@code java.lang.reflect.Method}.
 * @param state the expression evaluation state
 * @param method the method to invoke
 * @return the return value of the invoked Java method
 * @throws EvaluationException if there is any problem invoking the method
 */
private TypedValue executeFunctionJLRMethod(ExpressionState state, Method method) throws EvaluationException {
	Object[] functionArgs = getArguments(state);

	if (!method.isVarArgs()) {
		int declaredParamCount = method.getParameterCount();
		if (declaredParamCount != functionArgs.length) {
			throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
					functionArgs.length, declaredParamCount);
		}
	}
	if (!Modifier.isStatic(method.getModifiers())) {
		throw new SpelEvaluationException(getStartPosition(),
				SpelMessage.FUNCTION_MUST_BE_STATIC, ClassUtils.getQualifiedMethodName(method), this.name);
	}

	// Convert arguments if necessary and remap them for varargs if required
	TypeConverter converter = state.getEvaluationContext().getTypeConverter();
	boolean argumentConversionOccurred = ReflectionHelper.convertAllArguments(converter, functionArgs, method);
	if (method.isVarArgs()) {
		functionArgs = ReflectionHelper.setupArgumentsForVarargsInvocation(
				method.getParameterTypes(), functionArgs);
	}
	boolean compilable = false;

	try {
		ReflectionUtils.makeAccessible(method);
		Object result = method.invoke(method.getClass(), functionArgs);
		compilable = !argumentConversionOccurred;
		return new TypedValue(result, new TypeDescriptor(new MethodParameter(method, -1)).narrow(result));
	}
	catch (Exception ex) {
		throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_FUNCTION_CALL,
				this.name, ex.getMessage());
	}
	finally {
		if (compilable) {
			this.exitTypeDescriptor = CodeFlow.toDescriptor(method.getReturnType());
			this.method = method;
		}
		else {
			this.exitTypeDescriptor = null;
			this.method = null;
		}
	}
}
 
Example 16
Source File: AbstractFallbackTransactionAttributeSource.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Determine the transaction attribute for this method invocation.
 * <p>Defaults to the class's transaction attribute if no method attribute is found.
 * @param method the method for the current invocation (never {@code null})
 * @param targetClass the target class for this invocation (may be {@code null})
 * @return a TransactionAttribute for this method, or {@code null} if the method
 * is not transactional
 */
@Override
@Nullable
public TransactionAttribute getTransactionAttribute(Method method, @Nullable Class<?> targetClass) {
	if (method.getDeclaringClass() == Object.class) {
		return null;
	}

	// First, see if we have a cached value.
	Object cacheKey = getCacheKey(method, targetClass);
	TransactionAttribute cached = this.attributeCache.get(cacheKey);
	if (cached != null) {
		// Value will either be canonical value indicating there is no transaction attribute,
		// or an actual transaction attribute.
		if (cached == NULL_TRANSACTION_ATTRIBUTE) {
			return null;
		}
		else {
			return cached;
		}
	}
	else {
		// We need to work it out.
		// 注释 9.3 提取事务标签
		TransactionAttribute txAttr = computeTransactionAttribute(method, targetClass);
		// Put it in the cache.
		if (txAttr == null) {
			this.attributeCache.put(cacheKey, NULL_TRANSACTION_ATTRIBUTE);
		}
		else {
			String methodIdentification = ClassUtils.getQualifiedMethodName(method, targetClass);
			if (txAttr instanceof DefaultTransactionAttribute) {
				((DefaultTransactionAttribute) txAttr).setDescriptor(methodIdentification);
			}
			if (logger.isTraceEnabled()) {
				logger.trace("Adding transactional method '" + methodIdentification + "' with attribute: " + txAttr);
			}
			this.attributeCache.put(cacheKey, txAttr);
		}
		return txAttr;
	}
}
 
Example 17
Source File: CacheAspectSupport.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Convenience method to return a String representation of this Method
 * for use in logging. Can be overridden in subclasses to provide a
 * different identifier for the given method.
 * @param method the method we're interested in
 * @param targetClass class the method is on
 * @return log message identifying this method
 * @see org.springframework.util.ClassUtils#getQualifiedMethodName
 */
protected String methodIdentification(Method method, Class<?> targetClass) {
	Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
	return ClassUtils.getQualifiedMethodName(specificMethod);
}
 
Example 18
Source File: CacheAspectSupport.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Convenience method to return a String representation of this Method
 * for use in logging. Can be overridden in subclasses to provide a
 * different identifier for the given method.
 * @param method the method we're interested in
 * @param targetClass class the method is on
 * @return log message identifying this method
 * @see org.springframework.util.ClassUtils#getQualifiedMethodName
 */
protected String methodIdentification(Method method, Class<?> targetClass) {
	Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
	return ClassUtils.getQualifiedMethodName(specificMethod);
}
 
Example 19
Source File: CacheAspectSupport.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Convenience method to return a String representation of this Method
 * for use in logging. Can be overridden in subclasses to provide a
 * different identifier for the given method.
 * @param method the method we're interested in
 * @param targetClass class the method is on
 * @return log message identifying this method
 * @see org.springframework.util.ClassUtils#getQualifiedMethodName
 */
protected String methodIdentification(Method method, Class<?> targetClass) {
	Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
	return ClassUtils.getQualifiedMethodName(specificMethod);
}
 
Example 20
Source File: CacheAspectSupport.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Convenience method to return a String representation of this Method
 * for use in logging. Can be overridden in subclasses to provide a
 * different identifier for the given method.
 * @param method the method we're interested in
 * @param targetClass class the method is on
 * @return log message identifying this method
 * @see org.springframework.util.ClassUtils#getQualifiedMethodName
 */
protected String methodIdentification(Method method, Class<?> targetClass) {
	Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
	return ClassUtils.getQualifiedMethodName(specificMethod);
}