⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 annotationsvalidatorimpl.java

📁 Xfire文件 用于开发web service 的一个开源工具 很好用的
💻 JAVA
字号:
package org.codehaus.xfire.annotations;import java.lang.reflect.Method;import java.lang.reflect.Modifier;/** * @author <a href="mailto:tsztelak@gmail.com">Tomasz Sztelak</a> *  */public class AnnotationsValidatorImpl implements AnnotationsValidator {	private WebAnnotations annotations;	protected void validateClass(Class clazz) throws AnnotationException {		WebServiceAnnotation webAnn = annotations				.getWebServiceAnnotation(clazz);		if (webAnn.getPortName() != null && webAnn.getPortName().length() > 0				&& clazz.isInterface()) {			throwException("Port name can't be defined on interface", "4.1.1", "Class : "+clazz.getName());		}		if (webAnn.getEndpointInterface() != null				&& webAnn.getEndpointInterface().length() > 0				&& clazz.isInterface()) {			throwException("EndpointInterface can't be defined on interface",					"4.1.1", " Class : "+clazz.getName());		}		Method[] methods = clazz.getMethods();		for (int m = 0; m < methods.length; m++) {			Method method = methods[m];			if (annotations.hasWebMethodAnnotation(method)) {				validateMethod(method);			}		}	}	protected void validateOneWay(Method method) throws AnnotationException {		if (method.getExceptionTypes().length > 0				|| !method.getGenericReturnType().equals(void.class)) {			throwException(					"Method annotated with @OneWay annotation cannot  have return value or declarated exceptions",					"4.3.1","Method : "+ method.getName());		}		for (int p = 0; p < method.getParameterTypes().length; p++) {			WebParamAnnotation param = annotations.getWebParamAnnotation(					method, p);			if (param != null					&& (param.getMode() == WebParamAnnotation.MODE_INOUT || param							.getMode() == WebParamAnnotation.MODE_OUT)) {				throwException(						"Method annotated with @OneWay annotation cannot have INOUT/OUT parameters",						"4.3.1", "Method : "+ method.getName());			}		}	}	protected void validateMethod(Method method) throws AnnotationException {		if (!Modifier.isPublic(method.getModifiers())) {			throwException("Method annotated with @WebMethod must be public",					"3.3", "Method : "+ method.getName());		}		if (annotations.hasOnewayAnnotation(method)) {			validateOneWay(method);		}		/*for (int p = 0; p < method.getParameterTypes().length; p++) {			WebParamAnnotation param = annotations.getWebParamAnnotation(					method, p);			if (param != null					&& (param.getMode() == WebParamAnnotation.MODE_INOUT || param							.getMode() == WebParamAnnotation.MODE_OUT)					&& !param.isHeader()) {				throwException(						"Parameters with mode INOUT/OUT must be marked as header=true",						"4.4.1","Method : "+ method.getName());			}		}*/	}	public void validate(WebAnnotations annotations, Class clazz)			throws AnnotationException {		this.annotations = annotations;		validateClass(clazz);	}	private void throwException(String message, String spec, String details)			throws AnnotationException {		throw new AnnotationException(message + ". JSR181 spec : " + spec + ". "+ details);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -