当前位置: 首页>>代码示例>>Java>>正文


Java Method.getParameterTypes方法代码示例

本文整理汇总了Java中java.lang.reflect.Method.getParameterTypes方法的典型用法代码示例。如果您正苦于以下问题:Java Method.getParameterTypes方法的具体用法?Java Method.getParameterTypes怎么用?Java Method.getParameterTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Method的用法示例。


在下文中一共展示了Method.getParameterTypes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getProperty

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static Object getProperty(Object bean, String property)
		throws IllegalArgumentException, IllegalAccessException,
		InvocationTargetException, SecurityException, IntrospectionException,
		NoSuchMethodException {
	Object object = null;
	Method getter = getReadMethod(bean.getClass(), property);
	StringTokenizer st = new StringTokenizer(property, "[](,)", false);
	capitalize(st.nextToken());
	Object params[] = new Object[st.countTokens()];
	for (int j = 0; j < params.length; j++) {
		params[j] = st.nextToken();
		if (getter.getParameterTypes()[0] == int.class) {
			params[j] = new Integer((String) params[j]);
		}
	}
	object = getter == null ? null : getter.invoke(bean, params);
	return object;
}
 
开发者ID:dvbern,项目名称:doctemplate,代码行数:19,代码来源:PropertyUtils.java

示例2: getBeanValue

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * 将ResultSet转换为指定class的Bean.
 * @param rs ResultSet实例
 * @param rsmd ResultSet元数据
 * @param beanClass 空属性的Bean的class
 * @param propMap Bean属性对应的Map
 * @param <T> 泛型方法
 * @return 值
 * @throws IllegalAccessException IllegalAccessException
 * @throws SQLException SQLException
 * @throws InvocationTargetException InvocationTargetException
 * @throws InstantiationException InstantiationException
 */
public static <T> T getBeanValue(ResultSet rs, ResultSetMetaData rsmd, Class<T> beanClass,
        Map<String, PropertyDescriptor> propMap) throws IllegalAccessException, SQLException,
        InvocationTargetException, InstantiationException {
    T bean = beanClass.newInstance();
    for (int i = 0, cols = rsmd.getColumnCount(); i < cols; i++) {
        String columnName = JdbcHelper.getColumn(rsmd, i + 1);
        if (propMap.containsKey(columnName)) {
            PropertyDescriptor prop = propMap.get(columnName);
            // 获取并调用setter方法.
            Method propSetter = prop.getWriteMethod();
            if (propSetter == null || propSetter.getParameterTypes().length != 1) {
                log.warn("类'{}'的属性'{}'没有标准的setter方法", beanClass.getName(), columnName);
                continue;
            }

            // 得到属性类型并将该数据库列值转成Java对应类型的值
            Class<?> propType = prop.getPropertyType();
            Object value = FieldHandlerChain.newInstance().getColumnValue(rs, i + 1, propType);
            propSetter.invoke(bean, value);
        }
    }
    return bean;
}
 
开发者ID:blinkfox,项目名称:adept,代码行数:37,代码来源:JdbcHelper.java

示例3: LevelDListener

import java.lang.reflect.Method; //导入方法依赖的package包/类
public LevelDListener(Method method) {
	NullCheck.check(method, "method");
	this.method = method; 
	
	// check the annotation
	if (getAnnotation() == null) {
		throw new ListenerMethodParametersException(method, "There is no ObjectListener annotation on the method!", AnnotationListenerRegistrator.this);				
	}
	
	// check the method signature
	if (method.getParameterTypes().length != 1 ||
	    !method.getParameterTypes()[0].isAssignableFrom(IWorldObjectEvent.class)) { 
		throw new ListenerMethodParametersException(method, method.getAnnotation(ObjectListener.class), AnnotationListenerRegistrator.this);
	}
	
	objectId = getId(method, getAnnotation());
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:18,代码来源:AnnotationListenerRegistrator.java

示例4: covertObjWithMap

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * 根据传递的参数修改数据
 * 
 * @param o
 * @param parameterMap map参数
 */
public static final void covertObjWithMap(Object o, Map<String, String> parameterMap) {
	Class<?> clazz = o.getClass();
	Iterator<Map.Entry<String, String>> iterator = parameterMap.entrySet().iterator();
	while (iterator.hasNext()) {
		Map.Entry<String, String> entry = iterator.next();
		String key = entry.getKey().trim();
		String value = entry.getValue().trim();
		try {
			Method method = setMethod(key, clazz);
			if (method != null) {
				Class<?>[] parameterTypes = method.getParameterTypes();
				if (method != null) {
					Object[] param_value = new Object[] { TypeParseUtil.convert(value, parameterTypes[0], null) };
					method.invoke(o, param_value);
				}
			}
		} catch (Exception e) {
			logger.error("", e);
		}
	}
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:28,代码来源:Request2ModelUtil.java

示例5: findMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static Method findMethod(Class service, String methodName, Object[] args) {
    Method[] methods = service.getMethods();
    Method invokeMethod = null;
    for (Method m : methods) {
        if (m.getName().equals(methodName) && m.getParameterTypes().length == args.length) {
            if (invokeMethod != null) { // 重载
                if (isMatch(invokeMethod.getParameterTypes(), args)) {
                    invokeMethod = m;
                    break;
                }
            } else {
                invokeMethod = m;
            }
        }
    }
    return invokeMethod;
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:18,代码来源:InvokeTelnetHandler.java

示例6: getReadResolve

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
  * Returns the readResolve method
  */
 protected Method getReadResolve(Class cl)
 {
   for (; cl != null; cl = cl.getSuperclass()) {
     Method []methods = cl.getDeclaredMethods();
     
     for (int i = 0; i < methods.length; i++) {
Method method = methods[i];

if (method.getName().equals("readResolve") &&
    method.getParameterTypes().length == 0)
  return method;
     }
   }

   return null;
 }
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:20,代码来源:JavaDeserializer.java

示例7: getAllMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * 获取api类中所有符合要求的api方法并缓存
 *
 * @param injectedCls
 * @return
 * @throws Exception
 */
private static HashMap<String, Method> getAllMethod(Class injectedCls) throws Exception {
    HashMap<String, Method> mMethodsMap = new HashMap<>();
    Method[] methods = injectedCls.getDeclaredMethods();
    for (Method method : methods) {
        String name;
        if (method.getModifiers() != (Modifier.PUBLIC | Modifier.STATIC) || (name = method.getName()) == null) {
            continue;
        }
        Class[] parameters = method.getParameterTypes();
        if (null != parameters && parameters.length == 4) {
            if (parameters[1] == WebView.class && parameters[2] == JSONObject.class && parameters[3] == Callback.class) {
                mMethodsMap.put(name, method);
            }
        }
    }
    return mMethodsMap;
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:25,代码来源:JSBridge.java

示例8: Invocation

import java.lang.reflect.Method; //导入方法依赖的package包/类
public Invocation(Method method, Object[] parameters) {
  this.methodName = method.getName();
  this.parameterClasses = method.getParameterTypes();
  this.parameters = parameters;
  rpcVersion = writableRpcVersion;
  if (method.getDeclaringClass().equals(VersionedProtocol.class)) {
    //VersionedProtocol is exempted from version check.
    clientVersion = 0;
    clientMethodsHash = 0;
  } else {
    this.clientVersion = RPC.getProtocolVersion(method.getDeclaringClass());
    this.clientMethodsHash = ProtocolSignature.getFingerprint(method
        .getDeclaringClass().getMethods());
  }
  this.declaringClassProtocolName = 
      RPC.getProtocolName(method.getDeclaringClass());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:WritableRpcEngine.java

示例9: checkCompatibility

import java.lang.reflect.Method; //导入方法依赖的package包/类
private void checkCompatibility(Event event1, Event event2) {
    Method m1 = event1.getListenerMethod();
    Method m2 = event2.getListenerMethod();
    Class[] params1 = m1.getParameterTypes();
    Class[] params2 = m2.getParameterTypes();
    boolean ok;

    if (params1.length == params2.length) {
        ok = true;
        for (int i=0; i < params1.length; i++)
            if (!params1[i].getName().equals(params2[i].getName())) {
                ok = false;
                break;
            }
        if (ok)
            ok = m1.getReturnType().equals(m2.getReturnType());
    }
    else ok = false;

    if (!ok) {
        IllegalArgumentException iae =
            new IllegalArgumentException("Incompatible event"); // NOI18N
        org.openide.ErrorManager.getDefault().annotate(
            iae, FormUtils.getBundleString("MSG_CannotAttach")); // NOI18N
        throw iae;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:FormEvents.java

示例10: setProperty

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static boolean setProperty(Object target, String name, Object value) {
    try {
        Class<?> clazz = target.getClass();
        if (target instanceof SSLServerSocket) {
            // overcome illegal access issues with internal implementation class
            clazz = SSLServerSocket.class;
        }
        Method setter = findSetterMethod(clazz, name);
        if (setter == null) {
            return false;
        }

        // If the type is null or it matches the needed type, just use the
        // value directly
        if (value == null || value.getClass() == setter.getParameterTypes()[0]) {
            setter.invoke(target, value);
        } else {
            // We need to convert it
            setter.invoke(target, convert(value, setter.getParameterTypes()[0]));
        }
        return true;
    } catch (Exception e) {
        LOG.error(String.format("Could not set property %s on %s", name, target), e);
        return false;
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:27,代码来源:IntrospectionSupport.java

示例11: invokePublicInstanceMethodWithDefaultValues

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static void invokePublicInstanceMethodWithDefaultValues(Object instance, Method method)
    throws InvocationTargetException, IllegalAccessException {
  List<Object> parameters = new ArrayList<>(method.getParameterTypes().length);
  for (Class<?> parameterType : method.getParameterTypes()) {
    parameters.add(Defaults.defaultValue(parameterType));
  }
  method.invoke(instance, parameters.toArray());
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:9,代码来源:FirebaseAppTest.java

示例12: Record

import java.lang.reflect.Method; //导入方法依赖的package包/类
private Record(Object target, Method method) {
    this.target = target;
    this.method = method;

    final TypeToken<?> returnType;
    if(Optional.class.isAssignableFrom(method.getReturnType())) {
        optional = true;
        returnType = Optionals.elementType(method.getGenericReturnType());
    } else {
        optional = false;
        returnType = TypeToken.of(method.getGenericReturnType());
    }

    if(!type.isAssignableFrom(returnType)) {
        throw new IllegalStateException("Method " + method + " return type " + returnType + " is not assignable to " + type);
    }

    if(method.getParameterTypes().length == 0) {
        passElement = false;
    } else  {
        if(!(method.getParameterTypes().length == 1 && Element.class.isAssignableFrom(method.getParameterTypes()[0]))) {
            throw new IllegalStateException("Method " + method + " should take no parameters, or a single Element parameter");
        }
        passElement = true;
    }

    try {
        this.handle = MethodHandleUtils.privateLookup(method.getDeclaringClass())
                                       .unreflect(method)
                                       .bindTo(target);
    } catch(IllegalAccessException e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:35,代码来源:MethodParserMap.java

示例13: getNamedParameters

import java.lang.reflect.Method; //导入方法依赖的package包/类
public LinkedHashSet<NamedParameter> getNamedParameters(String resource, boolean excludeOverriden) throws Exception {
	LinkedHashMap<String, NamedParameter> namedParameters = new LinkedHashMap<String, NamedParameter>();
	Method method = getAnnotatedMethod(resource);
	if (method != null) {
		MethodParameterNames annotation = method.getAnnotation(MethodParameterNames.class);
		String[] parameterNames = null;
		if (annotation != null) {
			parameterNames = annotation.value();
		}
		Class[] parameterTypes = method.getParameterTypes();
		if (parameterNames != null && parameterTypes != null) {
			for (int i = 0; i < parameterNames.length; i++) {
				namedParameters.put(parameterNames[i], new NamedParameter(parameterNames[i], parameterTypes[i]));
			}
		}
	}
	Iterator<Entry<String, Object>> it = defaults.entrySet().iterator();
	while (it.hasNext()) {
		Entry<String, Object> defaultParameter = it.next();
		if (!namedParameters.containsKey(defaultParameter.getKey())) {
			namedParameters.put(defaultParameter.getKey(), new NamedParameter(defaultParameter.getKey(), defaultParameter.getValue().getClass()));
		}
	}
	it = overrides.entrySet().iterator();
	while (it.hasNext()) {
		Entry<String, Object> overrideParameter = it.next();
		namedParameters.put(overrideParameter.getKey(), new NamedParameter(overrideParameter.getKey(), overrideParameter.getValue().getClass()));
	}
	if (excludeOverriden) {
		it = overrides.entrySet().iterator();
		while (it.hasNext()) {
			namedParameters.remove(it.next().getKey());
		}
	}
	return new LinkedHashSet<NamedParameter>(namedParameters.values());
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:37,代码来源:ArgsUriPart.java

示例14: GenericTypeAwarePropertyDescriptor

import java.lang.reflect.Method; //导入方法依赖的package包/类
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
		Method readMethod, Method writeMethod, Class<?> propertyEditorClass)
		throws IntrospectionException {

	super(propertyName, null, null);
	this.beanClass = beanClass;
	this.propertyEditorClass = propertyEditorClass;

	Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
	Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
	if (writeMethodToUse == null && readMethodToUse != null) {
		// Fallback: Original JavaBeans introspection might not have found matching setter
		// method due to lack of bridge method resolution, in case of the getter using a
		// covariant return type whereas the setter is defined for the concrete property type.
		Method candidate = ClassUtils.getMethodIfAvailable(
				this.beanClass, "set" + StringUtils.capitalize(getName()), (Class<?>[]) null);
		if (candidate != null && candidate.getParameterTypes().length == 1) {
			writeMethodToUse = candidate;
		}
	}
	this.readMethod = readMethodToUse;
	this.writeMethod = writeMethodToUse;

	if (this.writeMethod != null && this.readMethod == null) {
		// Write method not matched against read method: potentially ambiguous through
		// several overloaded variants, in which case an arbitrary winner has been chosen
		// by the JDK's JavaBeans Introspector...
		Set<Method> ambiguousCandidates = new HashSet<Method>();
		for (Method method : beanClass.getMethods()) {
			if (method.getName().equals(writeMethodToUse.getName()) &&
					!method.equals(writeMethodToUse) && !method.isBridge()) {
				ambiguousCandidates.add(method);
			}
		}
		if (!ambiguousCandidates.isEmpty()) {
			this.ambiguousWriteMethods = ambiguousCandidates;
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:GenericTypeAwarePropertyDescriptor.java

示例15: invoke

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

    final Myth myth = method.getAnnotation(Myth.class);
    final Class<?>[] arguments = method.getParameterTypes();
    final Class clazz = method.getDeclaringClass();

    if (Objects.nonNull(myth)) {
        final MythTransactionContext mythTransactionContext =
                TransactionContextLocal.getInstance().get();
        try {
            final MythParticipant participant =
                    buildParticipant(mythTransactionContext, myth,
                            method, clazz, args, arguments);
            if (Objects.nonNull(participant)) {
                final MythTransactionManager mythTransactionManager =
                        SpringBeanUtils.getInstance().getBean(MythTransactionManager.class);
                mythTransactionManager.registerParticipant(participant);
            }

            return super.invoke(target, method, args);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return getDefaultValue(method.getReturnType());
        }

    } else {
        return super.invoke(target, method, args);
    }


}
 
开发者ID:yu199195,项目名称:myth,代码行数:33,代码来源:MythInvokerInvocationHandler.java


注:本文中的java.lang.reflect.Method.getParameterTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。