📄 wsdlservicebuilder.java
字号:
protected void visit(PortType portType) { ServiceInfo serviceInfo = new ServiceInfo(null, Object.class); portType2serviceInfo.put(portType, serviceInfo); serviceInfo.setPortType(portType.getQName()); Element documentation = portType.getDocumentationElement(); if( documentation != null ){ String docText = documentation.getNodeValue() ;//TextContent(); serviceInfo.setDocumentation(docText); } if (forceBare) { isWrapped = false; } else { isWrapped = true; Iterator itr = portType.getOperations().iterator(); while (isWrapped && itr.hasNext()) { Operation o = (Operation) itr.next(); isWrapped = isWrapped(o, schemas); } } serviceInfo.setWrapped(isWrapped); List operations = portType.getOperations(); for (int i = 0; i < operations.size(); i++) { Operation operation = (Operation) operations.get(i); visit(operation); { Input input = operation.getInput(); visit(input); } { Output output = operation.getOutput(); if (output != null) visit(output); } Collection faults = operation.getFaults().values(); for (Iterator iterator2 = faults.iterator(); iterator2.hasNext();) { Fault fault = (Fault) iterator2.next(); visit(fault); } } } protected ServiceInfo getServiceInfo(PortType portType) { return (ServiceInfo) portType2serviceInfo.get(portType); } protected void visit(Fault fault) { FaultInfo faultInfo = opInfo.addFault(fault.getName()); faultInfo.setMessageName(fault.getMessage().getQName()); if(fault.getDocumentationElement()!= null ){ faultInfo.setDocumentation(fault.getDocumentationElement().getNodeValue());//TextContent()); } wfault2msg.put(fault, faultInfo); createMessageParts(faultInfo, fault.getMessage()); } protected void visit(Input input) { if (isWrapped) { Part part = (Part) input.getMessage().getParts().values().iterator().next(); MessageInfo info = opInfo.createMessage(new QName(part.getElementName().getNamespaceURI(), input.getMessage().getQName().getLocalPart())); winput2msg.put(input, info); opInfo.setInputMessage(info); createMessageParts(info, getWrappedSchema(input.getMessage())); } else { MessageInfo info = opInfo.createMessage(input.getMessage().getQName()); winput2msg.put(input, info); opInfo.setInputMessage(info); createMessageParts(info, input.getMessage()); } } protected void visit(Operation operation) { opInfo = getServiceInfo(portType).addOperation(operation.getName(), null); Element docElem = operation.getDocumentationElement(); if (docElem != null) { String docText = docElem.getNodeValue();// TextContent(); opInfo.setDocumenation(docText); } wop2op.put(operation, opInfo); } private void createMessageParts(MessageInfo info, XmlSchemaElement el) { if (el == null) { return; } XmlSchemaComplexType type = (XmlSchemaComplexType) el.getSchemaType(); if (type == null) { return; } if (type.getParticle() instanceof XmlSchemaSequence) { XmlSchemaSequence seq = (XmlSchemaSequence) type.getParticle(); XmlSchemaObjectCollection col = seq.getItems(); for (Iterator itr = col.getIterator(); itr.hasNext();) { XmlSchemaObject schemaObj = (XmlSchemaObject) itr.next(); if (schemaObj instanceof XmlSchemaElement) { createMessagePart(info, (XmlSchemaElement) schemaObj, el.getQName()); } } } } private void createMessagePart(MessageInfo info, XmlSchemaElement element, QName type) { int index = info.size(); boolean globalElement = element.getRefName() != null; QName name; QName schemaType; if (globalElement) { name = element.getRefName(); schemaType = name; } else { name = element.getQName(); schemaType = element.getSchemaTypeName(); } MessagePartInfo part = info.addMessagePart(name, XmlSchemaElement.class); part.setIndex(index); part.setSchemaElement(globalElement); part.setWrappedType(type); SchemaType st = getBindingProvider().getSchemaType(schemaType, service); part.setSchemaType(st); } /** * A message is wrapped IFF: * * The input message has a single part. * The part is an element. * The element has the same name as the operation. * The element's complex type has no attributes. * * @return */ public static boolean isWrapped(Operation op, XmlSchemaCollection schemas) { Input input = op.getInput(); Output output = op.getOutput(); boolean hasOutput = output != null && output.getMessage().getParts() != null; if (input.getMessage().getParts().size() != 1 || (hasOutput && output.getMessage().getParts().size() != 1)) return false; Part inPart = (Part) input.getMessage().getParts().values().iterator().next(); Part outPart = null; if (hasOutput) outPart = (Part) output.getMessage().getParts().values().iterator().next(); QName inElementName = inPart.getElementName(); QName outElementName = null; if (hasOutput) outElementName = outPart.getElementName(); if (inElementName == null || (hasOutput && outElementName == null)) return false; if (!inElementName.getLocalPart().equals(op.getName()) || (hasOutput && !outElementName.getLocalPart().equals(op.getName() + "Response"))) return false; XmlSchemaElement reqSchemaEl = schemas.getElementByQName(inElementName); XmlSchemaElement resSchemaEl = null; if (hasOutput) resSchemaEl = schemas.getElementByQName(outElementName); if (reqSchemaEl == null) throw new XFireRuntimeException("Couldn't find schema part: " + inElementName); if (hasOutput && resSchemaEl == null) throw new XFireRuntimeException("Couldn't find schema part: " + outElementName); // Now lets see if we have any attributes... // This should probably look at the restricted and substitute types too. if (reqSchemaEl.getSchemaType() instanceof XmlSchemaComplexType) { XmlSchemaComplexType ct = (XmlSchemaComplexType) reqSchemaEl.getSchemaType(); if (hasAttributes(ct) || ct.getContentModel() != null) return false; // only do a wrapped operation with sequences and all if (ct.getParticle() != null && !(ct.getParticle() instanceof XmlSchemaSequence) && !(ct.getParticle() instanceof XmlSchemaAll)) return false; if (containsAnonymousTypes(ct)) return false; } else if (reqSchemaEl.getSchemaType() != null) { return false; } if (hasOutput && resSchemaEl.getSchemaType() instanceof XmlSchemaComplexType) { XmlSchemaComplexType ct = (XmlSchemaComplexType) resSchemaEl.getSchemaType(); if (hasAttributes(ct)) return false; if (ct.getContentModel() != null) return false; if (ct.getParticle() != null && !(ct.getParticle() instanceof XmlSchemaSequence) && !(ct.getParticle() instanceof XmlSchemaAll)) return false; if (containsAnonymousTypes(ct)) return false; } else if (hasOutput && resSchemaEl.getSchemaType() != null) { return false; } return true; } private static boolean containsAnonymousTypes(XmlSchemaComplexType ct) { XmlSchemaGroupBase particle = (XmlSchemaGroupBase)ct.getParticle(); if (particle == null) { return false; } XmlSchemaObjectCollection items = particle.getItems(); for (int i = 0; i < items.getCount(); i++) { XmlSchemaObject item = items.getItem(i); if (item instanceof XmlSchemaElement) { XmlSchemaElement el = (XmlSchemaElement) item; if (el.getSchemaTypeName() == null) return true; } else if (item instanceof XmlSchemaElement) { XmlSchemaComplexType el = (XmlSchemaComplexType) item; if (el.getParticle() != null) return true; } } return false; } private XmlSchemaElement getWrappedSchema(Message message) { Part part = (Part) message.getParts().values().iterator().next(); XmlSchemaElement schemaEl = schemas.getElementByQName(part.getElementName()); if (schemaEl.getSchemaType() instanceof XmlSchemaComplexType) return schemaEl; return null; } protected static boolean hasAttributes(XmlSchemaComplexType complexType) { // Now lets see if we have any attributes... // This should probably look at the restricted and substitute types too. if (complexType.getAnyAttribute() != null || complexType.getAttributes().getCount() > 0) return true; else return false; } private void createMessageParts(MessagePartContainer info, Message msg) { List parts = msg.getOrderedParts(null); for (Iterator itr = parts.iterator(); itr.hasNext();) { Part entry = (Part) itr.next(); // We're extending an abstract schema type QName typeName = entry.getTypeName(); if (typeName != null) { QName partName = new QName(getTargetNamespace(), entry.getName()); MessagePartInfo part = info.addMessagePart(partName, null); part.setSchemaElement(false); part.setSchemaType(getBindingProvider().getSchemaType(typeName, service)); part.setIndex(info.size()-1); } // We've got a concrete schema type QName elementName = entry.getElementName(); if (elementName != null) { MessagePartInfo part = info.addMessagePart(elementName, null); part.setSchemaType(getBindingProvider().getSchemaType(typeName, service)); part.setIndex(info.size()-1); if( entry.getDocumentationElement()!= null ){ part.setDocumentation(entry.getDocumentationElement().getNodeValue());//TextContent()); } } } } protected String getTargetNamespace() { return getDefinition().getTargetNamespace(); } protected void visit(Output output) { MessageInfo info = opInfo.createMessage( new QName(opInfo.getInputMessage().getName().getNamespaceURI(), output.getMessage().getQName().getLocalPart())); opInfo.setOutputMessage(info); woutput2msg.put(output, info); if (isWrapped) { createMessageParts(info, getWrappedSchema(output.getMessage())); } else { createMessageParts(info, output.getMessage()); } } /** * Returns a Collection of SchemaInfo objects. * @return */ public List getSchemas() { return schemaInfos; } public XmlSchemaCollection getSchemaCollection() { return schemas; } public boolean isForceBare() { return forceBare; } public void setForceBare(boolean forceBare) { this.forceBare = forceBare; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -