📄 annotationservicefactory.java
字号:
throw new AnnotationException("Couldn't find endpoint interface " + webServiceAnnotation.getEndpointInterface(), e); } } else { namespace = createServiceNamespace(endpointInterface, webServiceAnnotation, namespace); portType = createPortType(name, webServiceAnnotation); } if (webAnnotations.hasSOAPBindingAnnotation(endpointInterface)) { SOAPBindingAnnotation soapBindingAnnotation = webAnnotations.getSOAPBindingAnnotation(endpointInterface); style = soapBindingAnnotation.getStyleString(); use = soapBindingAnnotation.getUseString(); } // Allow the user to override informations given in the annotations if (!properties.containsKey(PORT_TYPE)) { properties.put(PORT_TYPE, new QName(namespace, portType)); } if (!properties.containsKey(STYLE)) { properties.put(STYLE, style); } if (!properties.containsKey(USE)) { properties.put(USE, use); } if (!properties.containsKey(PORT_NAME)) { String pname = webServiceAnnotation.getPortName(); if (pname != null && pname.length() > 0) { properties.put(PORT_NAME, new QName(namespace, pname)); } } Map props = webAnnotations.getServiceProperties(clazz); if(props!= null){ properties.putAll(props); } if (webAnnotations.hasHandlerChainAnnotation(clazz)) { log.error("@HandlerChain attributes are not supported yet!"); } Service service = super.create(endpointInterface, name, namespace, properties); String wsdl = webServiceAnnotation.getWsdlLocation(); if (wsdl != null && wsdl.length() > 0) { try { service.setWSDLWriter(new ResourceWSDL(wsdl)); } catch (IOException e) { throw new AnnotationException("Couldn't load wsdl from " + wsdl, e); } } if (clazz != endpointInterface) { service.setProperty(ObjectInvoker.SERVICE_IMPL_CLASS, clazz); } Collection inHandlers = webAnnotations.getInHandlers(clazz); Collection outHandlers = webAnnotations.getOutHandlers(clazz); Collection faultHandlers = webAnnotations.getFaultHandlers(clazz); service.getInHandlers().addAll(processHandlers(inHandlers)); service.getOutHandlers().addAll(processHandlers(outHandlers)); service.getFaultHandlers().addAll(processHandlers(faultHandlers)); return service; } else { throw new AnnotationException("Class " + clazz.getName() + " does not have a WebService annotation"); } } private Collection processHandlers(Collection handlers){ Collection handlersObjects = new ArrayList(); for(Iterator iter = handlers.iterator();iter.hasNext();){ String handlerClass = (String) iter.next(); Class clazz; try { clazz = ClassLoaderUtils.loadClass(handlerClass, this.getClass()); handlersObjects.add(clazz.newInstance()); } catch (ClassNotFoundException e) { throw new RuntimeException("Can't load class : "+ handlerClass,e); } catch (InstantiationException e) { throw new RuntimeException("Can't create object of class :"+ handlerClass,e); } catch (IllegalAccessException e) { throw new RuntimeException("Can't create object of class :"+ handlerClass,e); } } return handlersObjects; } private void assertValidImplementationClass(Class clazz, WebAnnotations webAnnotations2, Map properties) { if (Modifier.isFinal(clazz.getModifiers())) { throw new AnnotationException("Service class cannot be final: " + clazz.getName()); } if (/*clazz.isMemberClass() ||*/ !Modifier.isPublic(clazz.getModifiers())) { throw new AnnotationException("Service class must be an outter public class: " + clazz.getName()); } WebServiceAnnotation wsAnn = webAnnotations2.getWebServiceAnnotation(clazz); if (wsAnn.getEndpointInterface().length() > 0) { Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getDeclaringClass().equals(clazz) && webAnnotations2.hasWebMethodAnnotation(methods[i])) { throw new AnnotationException("@WebMethod attributes are only allowed on the endpointInterface! " + "Offending class: " + clazz.getName()); } } } } /** * Attempt to load a class first from this class's ClassLoader, then from the context classloader. * * @param endpointInterface * @return * @throws ClassNotFoundException */ protected Class loadClass(String endpointInterface) throws ClassNotFoundException { return ClassLoaderUtils.loadClass(endpointInterface, getClass()); } protected String createServiceNamespace(Class clazz, WebServiceAnnotation webServiceAnnotation, String current) { String ns = current; if (ns == null && webServiceAnnotation.getTargetNamespace().length() > 0) { ns = webServiceAnnotation.getTargetNamespace(); } if (ns == null) { ns = NamespaceHelper.makeNamespaceFromClassName(clazz.getName(), "http"); } return ns; } protected String createServiceName(Class clazz, WebServiceAnnotation webServiceAnnotation, String current) { String name = current; if (name == null && webServiceAnnotation.getServiceName().length() > 0) { name = webServiceAnnotation.getServiceName(); } if (name == null) { name = makeServiceNameFromClassName(clazz); } return name; } protected String createPortType(String name, WebServiceAnnotation webServiceAnnotation) { String portType = null; if (webServiceAnnotation.getName().length() > 0) { portType = webServiceAnnotation.getName(); } else { portType = name + "PortType"; } return portType; } public Service create(Class clazz, QName name, URL wsdlUrl, Map properties) { if (properties == null) properties = new HashMap(); properties.put(ALLOW_INTERFACE, Boolean.TRUE); return super.create(clazz, name, wsdlUrl, properties); } public AnnotationsValidator getValidator() { return validator; } public void setValidator(AnnotationsValidator validator) { this.validator = validator; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -