當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。