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


Java Method.getExceptionTypes方法代码示例

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


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

示例1: isPublicStaticVoid

import java.lang.reflect.Method; //导入方法依赖的package包/类
private boolean isPublicStaticVoid( Method method )
{
    // check modifiers: public static
    int modifiers =  method.getModifiers ();
    if (!Modifier.isPublic (modifiers) || !Modifier.isStatic (modifiers)) {
        logError( method.getName() + " is not public static" ) ;
        return false ;
    }

    // check return type and exceptions
    if (method.getExceptionTypes ().length != 0) {
        logError( method.getName() + " declares exceptions" ) ;
        return false ;
    }

    if (!method.getReturnType().equals (Void.TYPE)) {
        logError( method.getName() + " does not have a void return type" ) ;
        return false ;
    }

    return true ;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ServerMain.java

示例2: _throwsException

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Return true iff the given method throws the given exception.
 */
private boolean _throwsException(
  Method method,
  Class<?> exception
  )
{
  Class exs[] = method.getExceptionTypes();

  for (int i = 0; i < exs.length; i++)
  {
    if (exs[i] == exception)
    {
      return true;
    }
  }

  return false;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:21,代码来源:JavaIntrospector.java

示例3: CodeGeneratorMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
public CodeGeneratorMethod(Method m) {
    this.underlyingMethod = m;
    this.methodName = m.getName();
    this.returnType = m.getReturnType();
//    Paranamer para = new BytecodeReadingParanamer();
    Paranamer para = new AnnotationParanamer();
    String[] parameterNames = para.lookupParameterNames(m, true);
    if (parameterNames == null) {
      throw new RuntimeException(String.format("Unable to read the parameter names for method %s.  This is likely due to the class files not including the appropriate debugging information.  Look up java -g for more information.", m));
    }
    Class<?>[] types = m.getParameterTypes();
    if (parameterNames.length != types.length) {
      throw new RuntimeException(String.format("Unexpected number of parameter names %s.  Expected %s on method %s.", Arrays.toString(parameterNames), Arrays.toString(types), m.toGenericString()));
    }
    arguments = new CodeGeneratorArgument[parameterNames.length];
    for (int i = 0 ; i < parameterNames.length; i++) {
      arguments[i] = new CodeGeneratorArgument(parameterNames[i], types[i]);
    }
    exs = m.getExceptionTypes();
  }
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:21,代码来源:CodeGeneratorMethod.java

示例4: checkMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Verifies that the supplied method has at least one declared exception
 * type that is RemoteException or one of its superclasses.  If not,
 * then this method throws IllegalArgumentException.
 *
 * @throws IllegalArgumentException if m is an illegal remote method
 */
private static void checkMethod(Method m) {
    Class<?>[] ex = m.getExceptionTypes();
    for (int i = 0; i < ex.length; i++) {
        if (ex[i].isAssignableFrom(RemoteException.class))
            return;
    }
    throw new IllegalArgumentException(
        "illegal remote method encountered: " + m);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Util.java

示例5: declaresException

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Determine whether the given method explicitly declares the given
 * exception or one of its superclasses, which means that an exception
 * of that type can be propagated as-is within a reflective invocation.
 * @param method the declaring method
 * @param exceptionType the exception to throw
 * @return {@code true} if the exception can be thrown as-is;
 * {@code false} if it needs to be wrapped
 */
public static boolean declaresException(Method method, Class<?> exceptionType) {
	Assert.notNull(method, "Method must not be null");
	Class<?>[] declaredExceptions = method.getExceptionTypes();
	for (Class<?> declaredException : declaredExceptions) {
		if (declaredException.isAssignableFrom(exceptionType)) {
			return true;
		}
	}
	return false;
}
 
开发者ID:drinkjava2,项目名称:jDialects,代码行数:20,代码来源:ReflectionUtils.java

示例6: addProxyMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Add another method to be proxied, either by creating a new
 * ProxyMethod object or augmenting an old one for a duplicate
 * method.
 *
 * "fromClass" indicates the proxy interface that the method was
 * found through, which may be different from (a subinterface of)
 * the method's "declaring class".  Note that the first Method
 * object passed for a given name and descriptor identifies the
 * Method object (and thus the declaring class) that will be
 * passed to the invocation handler's "invoke" method for a given
 * set of duplicate methods.
 */
private void addProxyMethod(Method m, Class<?> fromClass) {
    String name = m.getName();
    Class<?>[] parameterTypes = m.getParameterTypes();
    Class<?> returnType = m.getReturnType();
    Class<?>[] exceptionTypes = m.getExceptionTypes();

    String sig = name + getParameterDescriptors(parameterTypes);
    List<ProxyMethod> sigmethods = proxyMethods.get(sig);
    if (sigmethods != null) {
        for (ProxyMethod pm : sigmethods) {
            if (returnType == pm.returnType) {
                /*
                 * Found a match: reduce exception types to the
                 * greatest set of exceptions that can thrown
                 * compatibly with the throws clauses of both
                 * overridden methods.
                 */
                List<Class<?>> legalExceptions = new ArrayList<>();
                collectCompatibleTypes(
                    exceptionTypes, pm.exceptionTypes, legalExceptions);
                collectCompatibleTypes(
                    pm.exceptionTypes, exceptionTypes, legalExceptions);
                pm.exceptionTypes = new Class<?>[legalExceptions.size()];
                pm.exceptionTypes =
                    legalExceptions.toArray(pm.exceptionTypes);
                return;
            }
        }
    } else {
        sigmethods = new ArrayList<>(3);
        proxyMethods.put(sig, sigmethods);
    }
    sigmethods.add(new ProxyMethod(name, parameterTypes, returnType,
                                   exceptionTypes, fromClass));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:49,代码来源:ProxyGenerator.java

示例7: needDoCap

import java.lang.reflect.Method; //导入方法依赖的package包/类
private boolean needDoCap(Method method, Object[] args) {

            if (method.getExceptionTypes().length == 0
                    || !method.getExceptionTypes()[0].getName().equals(IOException.class.getName())) {
                return false;
            }
            String methodName = method.getName();
            if (queueNameIndex.containsKey(methodName) && args.length != 0) {

                if (isTempQueue((String) args[queueNameIndex.get(methodName)])) {
                    return false;
                }
            }
            return true;
        }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:16,代码来源:RabbitmqIT.java

示例8: invoke

import java.lang.reflect.Method; //导入方法依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    SQLException exceptionToThrow = SQLError.createSQLException(Messages.getString("LoadBalancedConnectionProxy.unusableConnection"),
            SQLError.SQL_STATE_INVALID_TRANSACTION_STATE, MysqlErrorNumbers.ERROR_CODE_NULL_LOAD_BALANCED_CONNECTION, true, null);
    Class<?>[] declaredException = method.getExceptionTypes();
    for (Class<?> declEx : declaredException) {
        if (declEx.isAssignableFrom(exceptionToThrow.getClass())) {
            throw exceptionToThrow;
        }
    }
    throw new IllegalStateException(exceptionToThrow.getMessage(), exceptionToThrow);
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:12,代码来源:LoadBalancedConnectionProxy.java

示例9: DynamicMethodMarshallerImpl

import java.lang.reflect.Method; //导入方法依赖的package包/类
public DynamicMethodMarshallerImpl( Method method )
{
    this.method = method ;
    ehandler = new ExceptionHandlerImpl( method.getExceptionTypes() ) ;
    needsArgumentCopy = false ;

    Class[] argTypes = method.getParameterTypes() ;
    hasArguments = argTypes.length > 0 ;
    if (hasArguments) {
        argRWs = new ReaderWriter[ argTypes.length ] ;
        for (int ctr=0; ctr<argTypes.length; ctr++ ) {
            // This could be further optimized to avoid
            // copying if argTypes contains at most one
            // immutable object type.
            if (!argTypes[ctr].isPrimitive())
                needsArgumentCopy = true ;
            argRWs[ctr] = makeReaderWriter( argTypes[ctr] ) ;
        }
    }

    Class resultType = method.getReturnType() ;
    needsResultCopy = false ;
    hasVoidResult = resultType.equals( void.class ) ;
    if (!hasVoidResult) {
        needsResultCopy = !resultType.isPrimitive() ;
        resultRW = makeReaderWriter( resultType ) ;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:DynamicMethodMarshallerImpl.java

示例10: createMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static List<String> createMethod(Class<?> interfaceClass, ClassPool mPool) {
        Method methodAry[] = interfaceClass.getMethods();
        StringBuilder sb = new StringBuilder();
        List<String> resultList = new ArrayList<String>();
        for (Method m : methodAry) {
            Class<?>[] mType = m.getParameterTypes();
            Class<?> returntype = m.getReturnType();

//            String returnString = returntype.equals(void.class) ? "void" : ReflectUtils.getBoxedClass(returntype).getCanonicalName();
            sb.append(Modifier.toString(m.getModifiers()).replace("abstract", "") + " " +
                    ReflectUtils.getName(returntype) + " " + m.getName() + "( ");
            int c = 0;

            for (Class<?> mp : mType) {
                sb.append(" " + mp.getCanonicalName() + " arg" + c + " ,");
//                sb.append(" " + ReflectUtils.getBoxedClass(mp).getCanonicalName() + " arg" + c + " ,");
                c++;
            }
            sb.deleteCharAt(sb.length() - 1);
            sb.append(")");
            Class<?> exceptions[] = m.getExceptionTypes();
            if (exceptions.length > 0) {
                sb.append(" throws ");
                for (Class<?> exception : exceptions) {
                    sb.append(exception.getCanonicalName() + " ,");
                }
                sb = sb.deleteCharAt(sb.length() - 1);
            }
            sb.append("{");

            sb.append(" Class clazz = " + interfaceClass.getCanonicalName() + ".class;");
            sb.append(" String methodName = \"" + m.getName() + "\";");
            sb.append(" Class[] paramTypes = new Class[" + c + "];");
            sb.append(" Object[] paramValues = new Object[" + c + "];");
            for (int i = 0; i < c; i++) {
                sb.append("paramValues[" + i + "] = ($w)$" + (i + 1) + ";");
//                sb.append("paramTypes[" + i + "] = arg" + i + ".getClass();");
//                sb.append("paramTypes[" + i + "] = " + ClassTypeUtils.class.getCanonicalName() + ".getClass(\""
//                                + mType[i].getCanonicalName() + "\");");
                sb.append("paramTypes[" + i + "] = " + mType[i].getCanonicalName() + ".class;");
//				sb.append("paramTypes[" + i + "] = " + (mType[i].isPrimitive() ? mType[i].getCanonicalName() + ".class;"
//                                                : "arg" + i + ".getClass();"));
            }

//            RequestMessage requestMessage = MessageBuilder.buildRequest(clazz, methodName, paramTypes, paramValues);
//            ResponseMessage responseMessage = proxyInvoker.invoke(requestMessage);
//            if(responseMessage.isError()){
//                throw responseMessage.getException();
//            }
//            return responseMessage.getResponse();

            sb.append(RequestMessage.class.getCanonicalName() + " requestMessage = " +
                    MessageBuilder.class.getCanonicalName() +
                    ".buildRequest(clazz, methodName, paramTypes, paramValues);");
            sb.append(ResponseMessage.class.getCanonicalName() + " responseMessage = " +
                    "proxyInvoker.invoke(requestMessage);");
            sb.append("if(responseMessage.isError()){ throw responseMessage.getException(); }");

            if (returntype.equals(void.class)) {
                sb.append(" return;");
            } else {
                sb.append(" return ").append(asArgument( returntype, "responseMessage.getResponse()")).append(";");
            }

            sb.append("}");
            resultList.add(sb.toString());
            sb.delete(0, sb.length());
        }
        return resultList;
    }
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:71,代码来源:JavassistProxy.java

示例11: initRpcProxys

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * 初始化本地服务代理
 * 
 * @param packageName
 * @throws IOException
 * @throws ReflectiveOperationException
 * @throws Exception
 */
private void initRpcProxys() throws ServiceXProxyException, IOException, ReflectiveOperationException {
	clientProxys.clear();
	List<Class<?>> classesByPackage = new ArrayList<>();
	for (String temp : this.config.getServicePackages()) {
		classesByPackage.addAll(ReflectionUtil.getClassesByPackage(temp, Object.class));
	}
	for (Class<?> clazz : classesByPackage) {
		ServiceX annotation = clazz.getAnnotation(ServiceX.class);
		if (annotation == null) {
			continue;
		}
		if (!clazz.isInterface()) {
			throw new ServiceXProxyException(clazz.getName() + "RPC服务器必须是一个接口!");
		}
		// 检查参数是否符合标准
		String provider = annotation.provider();
		if (StringUtil.isEmptyOrNull(provider)) {
			throw new ServiceXProxyException("服务:" + clazz.getName() + "的提供商为空!");
		}
		String serviceName = RpcUtil.getServiceName(new RpcProviderName(provider), clazz);
		// 检查方法
		Method[] methods = clazz.getMethods();
		for (Method method : methods) {
			String methodOverloadName = ReflectionUtil.getMethodOverloadName(method);
			// 检查参数
			Class<?>[] parameterTypes = method.getParameterTypes();
			for (Class<?> paramsType : parameterTypes) {
				RpcUtil.checkParamType(paramsType);
			}
			// 检查返回参数是否合法
			RpcUtil.checkParamType(method.getReturnType());
			// 异常抛出检查
			Class<?>[] exceptionTypes = method.getExceptionTypes();
			if (exceptionTypes == null || exceptionTypes.length < 1) {
				throw new ServiceXProxyException("类" + clazz.getName() + "的方法" + methodOverloadName + "必须要抛出异常:"
						+ Exception.class.getName());
			}
			boolean exOk = false;
			for (Class<?> ex : exceptionTypes) {
				if (ex == Exception.class) {
					exOk = true;
				}
			}
			if (!exOk) {
				throw new ServiceXProxyException("类" + clazz.getName() + "的方法" + methodOverloadName + "的异常抛出必须有:"
						+ Exception.class.getName());
			}
		}
		// 创建动态代理类
		Object newProxyInstance = ReflectionUtil.newProxy(clazz,
				(InvocationHandler) (proxy, method, args) -> proxyExecute(serviceName, proxy, method.getName(),
						ReflectionUtil.getMethodOverloadName(method), args, ConsumerX.this.config.getSelector(),
						null));
		if (serviceProxyClasses.containsKey(serviceName)) {
			throw new ServiceXProxyException("服务名重复:" + serviceName);
		}
		serviceProxyClasses.put(serviceName, clazz);
		clientProxys.put(clazz, newProxyInstance);
		log.info("创建服务动态代理:" + serviceName + ",服务提供商:" + provider + ",代理实例:" + newProxyInstance);
	}
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:70,代码来源:ConsumerX.java

示例12: processExceptions

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * models the exceptions thrown by <code>method</code> and adds them to the <code>javaMethod</code>
 * runtime model object
 * @param javaMethod the runtime model object to add the exception model objects to
 * @param method the <code>method</code> from which to find the exceptions to model
 */
protected void processExceptions(JavaMethodImpl javaMethod, Method method) {
    Action actionAnn = getAnnotation(method, Action.class);
    FaultAction[] faultActions = {};
    if(actionAnn != null)
        faultActions = actionAnn.fault();
    for (Class<?> exception : method.getExceptionTypes()) {

        //Exclude RuntimeException, RemoteException and Error etc
        if (!EXCEPTION_CLASS.isAssignableFrom(exception))
            continue;
        if (RUNTIME_EXCEPTION_CLASS.isAssignableFrom(exception) || isRemoteException(exception))
            continue;
        if (getAnnotation(exception, javax.xml.bind.annotation.XmlTransient.class) != null)
            continue;
        Class exceptionBean;
        Annotation[] anns;
        WebFault webFault = getAnnotation(exception, WebFault.class);
        Method faultInfoMethod = getWSDLExceptionFaultInfo(exception);
        ExceptionType exceptionType = ExceptionType.WSDLException;
        String namespace = targetNamespace;
        String name = exception.getSimpleName();
        String beanPackage = packageName + PD_JAXWS_PACKAGE_PD;
        if (packageName.length() == 0)
            beanPackage = JAXWS_PACKAGE_PD;
        String className = beanPackage+ name + BEAN;
        String messageName = exception.getSimpleName();
        if (webFault != null) {
            if (webFault.faultBean().length()>0)
                className = webFault.faultBean();
            if (webFault.name().length()>0)
                name = webFault.name();
            if (webFault.targetNamespace().length()>0)
                namespace = webFault.targetNamespace();
            if (webFault.messageName().length()>0)
                messageName = webFault.messageName();
        }
        if (faultInfoMethod == null)  {
            exceptionBean = getExceptionBeanClass(className, exception, name, namespace);
            exceptionType = ExceptionType.UserDefined;
            anns = getAnnotations(exceptionBean);
        } else {
            exceptionBean = faultInfoMethod.getReturnType();
            anns = getAnnotations(faultInfoMethod);
        }
        QName faultName = new QName(namespace, name);
        TypeInfo typeRef = new TypeInfo(faultName, exceptionBean, anns);
        CheckedExceptionImpl checkedException =
            new CheckedExceptionImpl(javaMethod, exception, typeRef, exceptionType);
        checkedException.setMessageName(messageName);
        checkedException.setFaultInfoGetter(faultInfoMethod);
        for(FaultAction fa: faultActions) {
            if(fa.className().equals(exception) && !fa.value().equals("")) {
                checkedException.setFaultAction(fa.value());
                break;
            }
        }
        javaMethod.addException(checkedException);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:RuntimeModeler.java

示例13: isPropertyAccessorMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Return true if given method is legal property accessor as defined in
 * Section 1.3.4.3 of Java2IDL spec.
 */
public boolean isPropertyAccessorMethod(Method m, Class c) {

    String methodName = m.getName();
    Class returnType  = m.getReturnType();
    Class[] parameters = m.getParameterTypes();
    Class[] exceptionTypes = m.getExceptionTypes();
    String propertyType = null;

    if( methodName.startsWith(GET_PROPERTY_PREFIX) ) {

        if((parameters.length == 0) && (returnType != Void.TYPE) &&
            !readHasCorrespondingIsProperty(m, c)) {
            propertyType = GET_PROPERTY_PREFIX;
        }

    } else if( methodName.startsWith(SET_PROPERTY_PREFIX) ) {

        if((returnType == Void.TYPE) && (parameters.length == 1)) {
            if (hasCorrespondingReadProperty(m, c, GET_PROPERTY_PREFIX) ||
                hasCorrespondingReadProperty(m, c, IS_PROPERTY_PREFIX)) {
                propertyType = SET_PROPERTY_PREFIX;
            }
        }

    } else if( methodName.startsWith(IS_PROPERTY_PREFIX) ) {
        if((parameters.length == 0) && (returnType == Boolean.TYPE) &&
            !isHasCorrespondingReadProperty(m, c)) {
            propertyType = IS_PROPERTY_PREFIX;
        }
    }

    // Some final checks that apply to all properties.
    if( propertyType != null ) {
        if(!validPropertyExceptions(m) ||
           (methodName.length() <= propertyType.length())) {
            propertyType = null;
        }
    }

    return (propertyType != null);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:46,代码来源:IDLTypesUtil.java

示例14: isDeclaredException

import java.lang.reflect.Method; //导入方法依赖的package包/类
public boolean isDeclaredException(Method m, Class<?> clazz) {
    for (Class<?> cl : m.getExceptionTypes()) {
        if (cl.equals(clazz) || cl.isAssignableFrom(clazz)) return true;
    }
    return false;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:7,代码来源:TrapException.java

示例15: checkMethodExceptionSignature

import java.lang.reflect.Method; //导入方法依赖的package包/类
private boolean checkMethodExceptionSignature(Method method) {
    Class<?>[] exps = method.getExceptionTypes();
    return exps!=null && exps.length>0;
}
 
开发者ID:TFdream,项目名称:mango,代码行数:5,代码来源:ReferenceInvocationHandler.java


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