本文整理汇总了Java中org.springframework.core.ParameterNameDiscoverer.getParameterNames方法的典型用法代码示例。如果您正苦于以下问题:Java ParameterNameDiscoverer.getParameterNames方法的具体用法?Java ParameterNameDiscoverer.getParameterNames怎么用?Java ParameterNameDiscoverer.getParameterNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.core.ParameterNameDiscoverer
的用法示例。
在下文中一共展示了ParameterNameDiscoverer.getParameterNames方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOperationParameters
import org.springframework.core.ParameterNameDiscoverer; //导入方法依赖的package包/类
/**
* Create parameter info for the given method.
* <p>The default implementation returns an empty array of {@code MBeanParameterInfo}.
* @param method the {@code Method} to get the parameter information for
* @param beanKey the key associated with the MBean in the beans map
* of the {@code MBeanExporter}
* @return the {@code MBeanParameterInfo} array
*/
protected MBeanParameterInfo[] getOperationParameters(Method method, String beanKey) {
ParameterNameDiscoverer paramNameDiscoverer = getParameterNameDiscoverer();
String[] paramNames = (paramNameDiscoverer != null ? paramNameDiscoverer.getParameterNames(method) : null);
if (paramNames == null) {
return new MBeanParameterInfo[0];
}
MBeanParameterInfo[] info = new MBeanParameterInfo[paramNames.length];
Class<?>[] typeParameters = method.getParameterTypes();
for(int i = 0; i < info.length; i++) {
info[i] = new MBeanParameterInfo(paramNames[i], typeParameters[i].getName(), paramNames[i]);
}
return info;
}
示例2: getOperationParameters
import org.springframework.core.ParameterNameDiscoverer; //导入方法依赖的package包/类
/**
* Create parameter info for the given method.
* <p>The default implementation returns an empty array of {@code MBeanParameterInfo}.
* @param method the {@code Method} to get the parameter information for
* @param beanKey the key associated with the MBean in the beans map
* of the {@code MBeanExporter}
* @return the {@code MBeanParameterInfo} array
*/
protected MBeanParameterInfo[] getOperationParameters(Method method, String beanKey) {
ParameterNameDiscoverer paramNameDiscoverer = getParameterNameDiscoverer();
String[] paramNames = (paramNameDiscoverer != null ? paramNameDiscoverer.getParameterNames(method) : null);
if (paramNames == null) {
return new MBeanParameterInfo[0];
}
MBeanParameterInfo[] info = new MBeanParameterInfo[paramNames.length];
Class<?>[] typeParameters = method.getParameterTypes();
for (int i = 0; i < info.length; i++) {
info[i] = new MBeanParameterInfo(paramNames[i], typeParameters[i].getName(), paramNames[i]);
}
return info;
}
示例3: buildKey
import org.springframework.core.ParameterNameDiscoverer; //导入方法依赖的package包/类
/**
* @param invocation
* @return
* @throws NoSuchMethodException
*/
public Object buildKey(String key, ProceedingJoinPoint invocation) throws NoSuchMethodException {
if (key.indexOf("#") == -1) {// 如果不是表达式,直接返回字符串
return key;
}
String keySpEL = "";
String pre = "";
String str[] = key.split("\\#");
if (str.length > 1) {
pre = str[0];
for (int i = 1; i < str.length; i++) {
keySpEL = keySpEL + "#" + str[i];
}
} else keySpEL = key;
MethodSignature signature = (MethodSignature) invocation.getSignature();
Method method = signature.getMethod();
Class<?>[] parameterTypes = method.getParameterTypes();
ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
String[] parameterNames = parameterNameDiscoverer.getParameterNames(invocation.getTarget().getClass().getDeclaredMethod(method.getName(), parameterTypes));
StandardEvaluationContext context = new StandardEvaluationContext();
for (int i = 0; i < parameterNames.length; i++) {
context.setVariable(parameterNames[i], invocation.getArgs()[i]);
}
Expression expression = expCache.get(keySpEL);
if (null == expression) {
expression = parser.parseExpression(keySpEL);
expCache.put(keySpEL, expression);
}
Object value = expression.getValue(context, Object.class);
if (!StringUtils.isEmpty(pre)) return pre + value;
else return value;
}
示例4: lookupParameterNames
import org.springframework.core.ParameterNameDiscoverer; //导入方法依赖的package包/类
@Override
public String[] lookupParameterNames(
AccessibleObject methodOrConstructor) {
String[] names = null;
ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
if (methodOrConstructor instanceof Method) {
names = parameterNameDiscoverer.getParameterNames((Method) methodOrConstructor);
}
else {
names = parameterNameDiscoverer.getParameterNames((Constructor<?>)methodOrConstructor);
}
if (names==null) {
Annotation[][] parameterAnnotations = ((Method) methodOrConstructor).getParameterAnnotations();
names = new String[parameterAnnotations.length];
for (int index = 0; index < parameterAnnotations.length; index++) {
Annotation[] annotations = parameterAnnotations[index];
boolean found = false;
for (Annotation annotation : annotations) {
if (annotation instanceof Named ) {
Named named = (Named) annotation;
names[index]=named.value();
found=true;
}
}
if (!found) {
names[index]="arg_"+index;
}
}
}
return names;
}
示例5: getCacheKey
import org.springframework.core.ParameterNameDiscoverer; //导入方法依赖的package包/类
/**
* 取得cache 键值
*
* @param pjp
* @param method
* @return 返回string
*/
private String getCacheKey(ProceedingJoinPoint pjp, Method method) {
if (method.isAnnotationPresent(GetCacheVaule.class)) {
// 如果有该注解
String key = method.getAnnotation(GetCacheVaule.class).key();// 得到要缓存的键值
Object[] values = pjp.getArgs();// 得到顺序的参数值
ParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
String[] names = discoverer.getParameterNames(method);
Map<String, Integer> map = new ConcurrentHashMap<String, Integer>();
for (int i = 0; i < names.length; i++) {
map.put(names[i], i);// 将名字和对应的序号放入hashmap
}
// 得到真正的key 、value值
try {
Integer int_value = map.get(key);// hash中没有对应的值,表示getcachekey和名字不符合
if (int_value == null) {
log.warn("your cachekey is not equals" + key
+ "please check this then change them");
} else {
String cache_key_real = (String) values[int_value];// 要缓存键值的真正cahe值
return cache_key_real;
}
} catch (Exception e) {
log.warn("your filed " + key + " must be String.class");
}
}
return null;
}
示例6: getParameterNames
import org.springframework.core.ParameterNameDiscoverer; //导入方法依赖的package包/类
public static String[] getParameterNames(MethodParameter parameter) {
Method method = parameter.getMethod();
// ParameterNameDiscoverer parameterNameDiscoverer = null;
ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
return parameterNameDiscoverer.getParameterNames(method);
}
示例7: afterPropertiesSet
import org.springframework.core.ParameterNameDiscoverer; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
for (Entry<String, Object> entry : namespacedServices.entrySet()) {
Class<?> clazz = entry.getValue().getClass();
try {
clazz = ((Advised) entry.getValue()).getTargetSource().getTarget().getClass();
} catch (Exception ignored) {
}
Namespace namespace = clazz.getAnnotation(Namespace.class);
logger.debug("clazz={}, namespace={}", clazz.getName(), namespace);
if (namespace == null || "".equals(namespace.value())) {
logger.debug("namespace is null or empty. clazz={}", clazz.getName());
continue;
}
String prefix = namespace.value();
boolean exposeAll = namespace.exposeAll();
for (Method method : clazz.getDeclaredMethods()) {
logger.debug("clazz={}, method={}", clazz.getName(), method.getName());
if (!Modifier.isPublic(method.getModifiers())) {
logger.debug("method is not public. clazz={}, method={}", clazz.getName(), method.getName());
continue;
}
Expose expose = method.getAnnotation(Expose.class);
if (!exposeAll && expose == null) {
logger.debug("exposeAll is false and @Expose is not found. clazz={}, method={}", clazz.getName(), method.getName());
continue;
}
String path = Context.PATH_DELIMITER + prefix + Context.PATH_DELIMITER + (expose == null || StringUtils.isBlank(expose.value()) ? method.getName() : expose.value());
Class<?>[] parameterTypes = method.getParameterTypes();
Type[] genericParameterTypes = method.getGenericParameterTypes();
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
String[] parameterNames = parameterNameDiscoverer.getParameterNames(method);
Map<String, Parameter> parameters = Maps.newLinkedHashMap();
for (int i = 0; i < parameterTypes.length; i++) {
parameters.put(parameterNames[i], new Parameter(genericParameterTypes[i], parameterTypes[i], parameterNames[i], parameterNames[i], true, parameterAnnotations[i], null, null));
}
MethodAction methodAction = new MethodAction(entry.getValue(), method, HttpMethod.POST, path, parameters);
interceptorManager.addInterceptors(methodAction);
logger.debug("[remote] {} => {}", new Object[]{path, methodAction.bean().getClass().getSimpleName() + "#" + methodAction.method().getName()});
List<Action> actions = routes.get(path);
if (actions == null) {
actions = Lists.newArrayList();
}
actions.add(methodAction);
routes.put(path, actions);
}
}
}
示例8: getParameterNames
import org.springframework.core.ParameterNameDiscoverer; //导入方法依赖的package包/类
private static List<String> getParameterNames(Method method) {
ParameterNameDiscoverer paramNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
String[] parameterNames = paramNameDiscoverer.getParameterNames(method);
return toList(parameterNames);
}
示例9: main
import org.springframework.core.ParameterNameDiscoverer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();
Method declaredMethod = HttpUtils.class.getDeclaredMethod("getClient", HttpHost.class);
String[] names = discoverer.getParameterNames(declaredMethod);
System.out.println(names[0]);
}