📄 wsdlcpp.java
字号:
elementflag = false; String uscore=""; if(isreturn) uscore="_"; if(nmessageNode!=null) messageNode= nmessageNode.getNode(); else{ System.out.println("message of message name" +messageName+ "not found"); System.exit(0); } if(messageNode==null) { System.out.println("message of message name" +messageName+ "not found"); } NsNodeSearch part = new NsNodeSearch(messageNode,docNS+"part",nmessageNode.getNameSpace()); //StringBuffer messageEq = new StringBuffer(); NsNode npartNode=part.getNextNode(); if((npartNode==null)&&(defWsdl)) { part = new NsNodeSearch(messageNode,"part",nmessageNode.getNameSpace()); npartNode=part.getNextNode(); } Node partNode=null; if(npartNode!=null) partNode = npartNode.getNode(); for(int i=0;i<part.getTotalMatches();i++) { String partName=null; String partType=null; String partElement=null; partName = getAttrValue(partNode,"name"); partType = getAttrValue(partNode,"type"); partElement = getAttrValue(partNode,"element");/*not need in * soap encoding*/ if(partName == null) { System.out.println("name field for part is NOT found"); } String xsdNS = getNsEquivalent(npartNode.getNameSpace(),"xsdNS"); if(partType == null)//means it is specidied in othere way (element) { if(partElement!=null) {/* System.out.println("type specified by element"); partType = partElement;*/ elementflag = true; String eleEq; if(isXsd(partElement,xsdNS)) { eleEq = dataType(new String("xsd:"+getName(partElement))+uscore+convertToCpp(partName,true)+ ", "); } else { eleEq = (String)allDataType.get(getName(partElement)); eleEq = eleEq.substring(eleEq.indexOf('{')+1,eleEq.lastIndexOf('}')); eleEq = eleEq.replace(';',','); eleEq = eleEq.replace('\n',' '); //System.out.println(eleEq); StringTokenizer st = new StringTokenizer(eleEq," "); String token; eleEq =""; while(st.hasMoreTokens()) { token= st.nextToken(); if(token.compareToIgnoreCase("struct")==0) { eleEq+= token; token = st.nextToken(); StringTokenizer lst = new StringTokenizer(token,"*"); token = lst.nextToken(); eleEq+= " "+token; token = lst.nextToken(); eleEq+= "*_"+token; /*token = st.nextToken(); eleEq+= "+ _"+token;*/ } else if(token.startsWith("xsd")) { eleEq+= token; token = st.nextToken(); eleEq+= " _"+token; } else eleEq+=" "+token; } } //System.out.println("new " +eleEq); equivalentString.append(eleEq); } else System.out.println("Type not specified by element or type!!"); } else { if(isXsd(partType,xsdNS)) partType = new String("xsd:"+getName(partType)); else partType = new String("struct "+partType); equivalentString.append(dataType(partType)+ " " +uscore+convertToCpp(partName,true)+ ", "); } npartNode = part.getNextNode(); if(npartNode!=null) partNode = npartNode.getNode(); } //System.out.println("msg eq is "+equivalentString.toString()); return equivalentString.toString(); } boolean isXsd(String name,String currentXSDNS) { String typeName = getName(name); if(typeName.indexOf('[')!=-1) typeName = typeName.substring(0,typeName.indexOf('[')); if(currentXSDNS!=null) if(getNS(name).compareToIgnoreCase(currentXSDNS)==0) { allPrimitiveDataType.put(typeName,new Boolean(true)); return true; } if(getNS(name).compareToIgnoreCase("")==0) { if(allPrimitiveDataType.containsKey(typeName)) { allPrimitiveDataType.put(typeName,new Boolean(true)); return true; } } return false; } Vector keyWords = new Vector(); private void intitlizePrimitiveType() { keyWords.add("auto"); keyWords.add("bool"); keyWords.add("break"); keyWords.add("case"); keyWords.add("char"); keyWords.add("class"); keyWords.add("const"); keyWords.add("continue"); keyWords.add("default"); keyWords.add("do"); keyWords.add("double"); keyWords.add("else"); keyWords.add("enum"); keyWords.add("extern"); keyWords.add("false"); keyWords.add("float"); keyWords.add("for"); keyWords.add("goto"); keyWords.add("if"); keyWords.add("inline"); keyWords.add("int"); keyWords.add("long"); keyWords.add("LONG64"); keyWords.add("mustUnderstand"); keyWords.add("namespace"); keyWords.add("operator"); keyWords.add("private"); keyWords.add("protected"); keyWords.add("public"); keyWords.add("register"); keyWords.add("return"); keyWords.add("short"); keyWords.add("signed"); keyWords.add("sizeof"); keyWords.add("static"); keyWords.add("struct"); keyWords.add("switch"); keyWords.add("time_t"); keyWords.add("true"); keyWords.add("typedef"); keyWords.add("ULONG64"); keyWords.add("union"); keyWords.add("unsigned"); keyWords.add("using"); keyWords.add("virtual"); keyWords.add("void"); keyWords.add("volatile"); keyWords.add("wchar_t"); keyWords.add("while"); allPrimitiveDataType.put("anyURI",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("anyURI","typedef char * xsd__anyURI;\n"); allPrimitiveDataType.put("base64Binary",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("base64Binary","typedef struct {\nunsigned char *__ptr;\nint __size;\n}xsd__base64Binary;\n"); allPrimitiveDataType.put("boolean",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("boolean","typedef char * xsd__boolean;\n"); allPrimitiveDataType.put("byte",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("byte","typedef char xsd__byte;\n"); allPrimitiveDataType.put("dateTime",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("dateTime","typedef char * xsd__dateTime;\n"); allPrimitiveDataType.put("date",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("date","typedef char * xsd__date;\n"); allPrimitiveDataType.put("decimal",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("decimal","typedef char * xsd__decimal;\n"); allPrimitiveDataType.put("double",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("double","typedef char * xsd__double;\n"); allPrimitiveDataType.put("duration",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("duration","typedef char * xsd__duration;\n"); allPrimitiveDataType.put("float",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("float","typedef float xsd__float;\n"); allPrimitiveDataType.put("hexBinary",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("hexBinary","typedef struct {\nunsigned char *__ptr;\nint __size;\n}xsd__hexBinary;\n"); allPrimitiveDataType.put("int",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("int","typedef int xsd__int;\n"); allPrimitiveDataType.put("integer",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("integer","typedef char * xsd_integer;\n"); allPrimitiveDataType.put("long",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("long","typedef LONG64 xsd__long;\n"); allPrimitiveDataType.put("negativeInteger",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("negativeInteger","typedef char * xsd__negativeInteger;\n"); allPrimitiveDataType.put("nonNegativeInteger",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("nonNegativeInteger","typedef char * xsd__nonNegativeInteger;\n"); allPrimitiveDataType.put("nonPositiveInteger",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("nonPositiveInteger","typedef char * xsd__nonPositiveInteger;\n"); allPrimitiveDataType.put("normalizedString",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("normalizedString","typedef char * xsd__normalizedString;\n"); allPrimitiveDataType.put("positiveInteger",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("positiveInteger","typedef char * xsd__positiveInteger;\n"); allPrimitiveDataType.put("short",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("short","typedef char * xsd__short;\n"); allPrimitiveDataType.put("string",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("string","typedef char * xsd__string;\n"); allPrimitiveDataType.put("time",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("time","typedef char * xsd__time;\n"); allPrimitiveDataType.put("token",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("token","typedef char * xsd__token;\n"); allPrimitiveDataType.put("unsignedByte",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("unsignedByte","typedef unsigned char xsd__unsignedByte;\n"); allPrimitiveDataType.put("unsignedInt",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("unsignedInt","typedef unsigned int xsd__unsignedInt;\n"); allPrimitiveDataType.put("unsignedLong",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("unsignedLong","typedef unsigned LONG64 xsd__unsignedLong;\n"); allPrimitiveDataType.put("unsignedShort",new Boolean(false)); allPrimitiveDataTypeEquivalent.put("unsignedShort","typedef unsigned short xsd__unsignedShort;\n"); } public void printTypesInformation(Node node) { NsNodeSearch types = new NsNodeSearch(node,docNS+"types",new Hashtable()); NsNode ntypesNode = types.getNextNode(); if(ntypesNode==null) { if(defWsdl){ types = new NsNodeSearch(node,"types",new Hashtable()); ntypesNode = types.getNextNode(); } if(ntypesNode==null){ System.out.println(" Types node not found"); return;} } Node typesNode = ntypesNode.getNode(); NsNodeSearch schema = new NsNodeSearch(typesNode,"schema",ntypesNode.getNameSpace()); NsNode schemaNode = schema.getNextPartialMatch(); /*System.out.println("*********************Type Information**************************************");*/ for(int i=0; i<schema.getTotalMatches();i++) { Node cnode = schemaNode.getNode(); /*find a element node just below the schema node*/ String dataName = null; NodeList cnodes = cnode.getChildNodes(); String schemaNS = cnode.getNodeName().substring(0,cnode.getNodeName().indexOf("schema")); boolean processed=false; for (int j=0; j<cnodes.getLength(); j++){ // System.out.println(cnodes.item(j).getNodeName()); if(cnodes.item(j).getNodeName().equalsIgnoreCase(schemaNS+"element")) { dataName = getAttrValue(cnodes.item(j),"name"); //System.out.println("data Name set to : "+ dataName); NsNode celementNode = new NsNode(cnodes.item(j),schemaNode.getNameSpace()); processSchema(celementNode,dataName,schemaNS); processed=true; // System.out.println("element procesing"); } else { NsNode celementNode = new NsNode(cnodes.item(j),schemaNode.getNameSpace()); processSchema(celementNode,null,schemaNS); // System.out.println("normall "+cnodes.getLength()); } } /*end find a element node just below the schema node*/ if (!processed){ processSchema(schemaNode,null,null);} schemaNode = schema.getNextPartialMatch(); } //System.out.println("processing strucutres"); processAllStructures(); /*System.out.println("*****************End Type Information**************************************");*/ } void processSchema(NsNode nnode,String dataName,String schNS) { String localXSDNS=getNsEquivalent(nnode.getNameSpace(),"xsdNS"); String tns=getNsEquivalent(nnode.getNameSpace(),"tns"); String currentNS=getNsEquivalent(nnode.getNameSpace(),"definitionNS"); String schemaNS =null; String localencodingNS=getNsEquivalent(nnode.getNameSpace(),"encodingNS"); String wsdlNS = getNsEquivalent(nnode.getNameSpace(),"wsdlNS"); Node node=null; if(nnode!=null) node = nnode.getNode(); if(schNS==null) { String nodeName = node.getNodeName(); schemaNS = nodeName.substring(0,nodeName.indexOf("schema")); } else schemaNS = schNS; NsNodeSearch complexType = new NsNodeSearch(node,schemaNS+"complexType",nnode.getNameSpace()); NsNode ncomplexNode = complexType.getNextNode(); Node complexNode=null; if(ncomplexNode!=null) complexNode = ncomplexNode.getNode(); Hashtable referenceNameSpace=null; for(int i=0;i<complexType.getTotalMatches();i++) { String arrayType,arrayName; /*processing for a Array identified by restricition*/ if((new NodeSearch(complexNode,schemaNS+"restriction").getNextNode())!=null) { /*System.out.println("Structure "+currentNS+ getAttrValue(complexNode,"name")+" { ");*/ if(dataName==null) arrayName = getAttrValue(complexNode,"name"); else arrayName = getName(dataName); Hashtable attributesref = new Hashtable(); attributesref.put("ref",localencodingNS+"Array"); NsNodeSearch attribute = new NsNodeSearch(complexNode,schemaNS+"attribute",ncomplexNode.getNameSpace()); NsNode nattributeNode = attribute.getNextNode(); Node attributeNode=null; if(nattributeNode!=null) { attributeNode = nattributeNode.getNode(); referenceNameSpace = nattributeNode.getNameSpace(); wsdlNS = getNsEquivalent(nattributeNode.getNameSpace(),"wsdlNS"); } if(attributeNode == null) { //this case occurs in some docs where the //typeof array is specified using attribute // element qualified by a arraytype //waring NsNodeSearch element = new NsNodeSearch(complexNode,schemaNS+"element",nnode.getNameSpace()); NsNode nelementNode = element.getNextNode(); Node elementNode =null; if(nelementNode!=null) { elementNode = nelementNode.getNode(); referenceNameSpace = nelementNode.getNameSpace(); } if(elementNode==null) { System.out.println("even element Node not found"); continue; } arrayType = getAttrValue(elementNode,"type"); arrayType = arrayType+"[]"; //assumption that the datatype is a one dimension array of the give type //System.out.println("array type is "+arrayType); } else { arrayType =getAttrValue(attributeNode,wsdlNS+"arrayType"); } if(arrayType==null) { System.out.println("No Type attribute found for element "+arrayName); ncomplexNode = complexType.getNextNode(); if(ncomplexNode!=null) complexNode = ncomplexNode.getNode(); continue; } //System.out.println("calling single for "+arrayType); String curlocalXSDNS = getNsEquivalent(referenceNameSpace,"xsdNS"); boolean xsdflag=false; /*if(getNS(arrayType).compareToIgnoreCase(curlocalXSDNS)==0)*/ if(isXsd(arrayType,curlocalXSDNS)) { xsdflag=true; arrayType = new String("xsd:"+getName(arrayType)); } /* else arrayType = new String("struct arrayType);*/ if(singleLevelArray(arrayType)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -