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

📄 wsdlcpp.java

📁 linux下开发的soap协议。建议大家学习学习!
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	finalString = new StringBuffer();	//finalString.append((String)hyphen.nextElement());	while(hyphen.hasMoreElements())	    {		temp = (String)hyphen.nextElement();		if(temp.equals("_"))		    finalString.append("_");		else		    finalString.append(temp);	    }	String uscores="";	if(keyWords.contains(finalString.toString())&&uscoreflag)	    uscores="_";	return finalString.toString()+uscores;    }        /*get the value of attribute of the given node*/    public String getAttrValue(Node node, String attribute)    {	NamedNodeMap attributes = node.getAttributes();	for (int i=0; i<attributes.getLength(); i++)	    {		Node current = attributes.item(i);		if(current.getNodeName().compareToIgnoreCase(attribute)==0)		    {			return current.getNodeValue();		    }		}	return null;    }    private String serviceName=null;private String serviceAddrLocation=null;private String servicePortName=null;private String servicePortBinding=null;    public boolean getServiceInfo(Node node)    {	Node serviceNode=null;	Node portNode=null;	Node soapAddrNode=null;	/*	String docNS = (String) namespace.get("docNS");	String soapNS = (String) namespace.get("soapNS");	*/	NodeSearch service = new NodeSearch(node,docNS+"service");	serviceNode = service.getNextNode();	if(serviceNode==null)	    {		if(defWsdl)		    service = new NodeSearch(node,"service");		if(serviceNode==null){		System.out.println("Service element not found");		return false;		}	    }		serviceName = getAttrValue(serviceNode,"name");	if(serviceName == null)	    {		System.out.println("name attribute of service not found");		return false;	    }	portNode = (new NodeSearch(serviceNode,docNS+"port")).getNextNode();	if(portNode == null)	    {		if(defWsdl)		    portNode = (new NodeSearch(serviceNode,"port")).getNextNode();		if(portNode == null)		    {		System.out.println("element PORT not found");		return false;}	    }	servicePortName = getAttrValue(portNode,"name");	if(servicePortName == null)	    {		System.out.println("name attribute of PORT not found");		return false;	    }	servicePortBinding = getAttrValue(portNode,"binding");	if(servicePortBinding == null)	    {		System.out.println("Binding attribute of PORT not found");		return false;	    }	soapAddrNode = (new NodeSearch(serviceNode,soapNS+"address")).getNextNode();	if(soapAddrNode == null)	    {		if(defSoap)		soapAddrNode = (new		    NodeSearch(serviceNode,"address")).getNextNode();		if(soapAddrNode == null)		    {			System.out.println("element SOAP ADDRRESS not found");		return false;}	    }	serviceAddrLocation = getAttrValue(soapAddrNode,"location");	if(serviceAddrLocation == null)	    {		System.out.println("Location attribute of SOAP ADDRESS not found");		return false;	    }	    return true;    }private String operationName=null;private String inputName=null;private String outputName=null;public boolean getBindingInfo(Node node, String bindingName)    {	Node bindingNode=null;	Node operationNode=null;	Node inputNode=null;	Node outputNode=null;	Hashtable attrib = new Hashtable();	attrib.put("name",bindingName);	NodeSearch binding = new NodeSearch(node,docNS+"binding",attrib);		bindingNode = binding.getNextNode();		if(bindingNode == null)	    {		if(defWsdl)		    binding = new NodeSearch(node,"binding",attrib);		if(bindingNode == null){		System.out.println("element BINDING not found");		return false;}	    }	String bindingType = getAttrValue(bindingNode,"type");	bindingType = bindingType.substring(bindingType.indexOf(":")+1);		NodeSearch operation = new NodeSearch(bindingNode,docNS+"operation");	/*	System.out.println("*********************Operation Information*********************************");*/	operationNode = operation.getNextNode();	if(operationNode == null)	    {		if(defWsdl){		    operation = new NodeSearch(bindingNode,"operation");		    operationNode = operation.getNextNode();}				if(operationNode == null){		System.out.println("element OPERATION not found");		return false;}	    }		while(operationNode!=null)	    {		operationName = getAttrValue(operationNode,"name");		if(operationName == null)		    {			System.out.println("name attribute of OPERATION not found");			return false;		    }		NodeSearch soapoperation = new NodeSearch(operationNode,soapNS+"operation");		Node soapOperationNode = soapoperation.getNextNode();		if((soapOperationNode==null)&&(defSoap))		    {			soapoperation = new NodeSearch(operationNode,"operation");			soapOperationNode = soapoperation.getNextNode();		    }				String soapact="";		if(soapOperationNode!=null)		    {			soapact = getAttrValue(soapOperationNode,"soapAction");			//System.out.println("soap action "+getAttrValue(soapOperationNode,"soapAction"));		    }		NodeSearch soapbody = new NodeSearch(bindingNode,soapNS+"body");		Node soapBodyNode = soapbody.getNextNode();		if((soapBodyNode==null)&&(defSoap))		    {			soapbody = new NodeSearch(bindingNode,"body");			soapBodyNode = soapbody.getNextNode();		    }		String tdefns = definitionNS.substring(0,definitionNS.length()-1);		if(soapBodyNode!=null)		    {			String tnsp = getAttrValue(soapBodyNode,"namespace");			if(tnsp!=null){			if(bindingsList.containsKey(tnsp))			    tdefns=(String)bindingsList.get(tnsp);			else			    {				if(!bindingsList.containsValue(tdefns))				    {					bindingsList.put(tnsp,tdefns);				    }				else				    {					int cnt=1;					while(bindingsList.containsValue(tdefns+cnt))cnt++;					bindingsList.put(tnsp,tdefns+cnt);					tdefns+=cnt;				    }			    }			}		    }				printOperationInfo(node,bindingType,operationName,tdefns+":",soapact);				operationNode = operation.getNextNode();	    }		/*System.out.println("*****************End Operation Information*********************************");*/	return true;    }    public void printOperationInfo(Node node,String bindingType,String				   operationName,String defns,String soapact)    {	Hashtable bindattrib = new Hashtable();	Hashtable operattrib = new Hashtable();	bindattrib.put("name",bindingType);	operattrib.put("name",operationName);		NodeSearch operations = new NodeSearch(new NodeSearch(node,docNS+"portType",bindattrib).getNextNode(),					       docNS+"operation",operattrib);	Node operation = operations.getNextNode();	if((operation==null)&&(defWsdl))	    {		operations = new NodeSearch(new NodeSearch(node,"portType",bindattrib).getNextNode(),					       "operation",operattrib);		operation = operations.getNextNode();	    }		while(operation!=null)	    {		if(operation!=null)		    {			//System.out.println("operation found "+operationName);		    }		else		    {			System.out.println("operation NOT found "+operationName);			return;		    }		elementflag = false;				NodeSearch input = new NodeSearch(operation,docNS+"input");		Node inputNode = input.getNextNode();		if((inputNode==null)&&(defWsdl))		    {			input = new NodeSearch(operation,"input");			inputNode = input.getNextNode();					    }				StringBuffer inputArgs = new StringBuffer();		StringBuffer outArgs = new StringBuffer();				String messageEquivalent=null;		for(int i=0;i<input.getTotalMatches();i++)		    {			if(inputNode==null)			    {				System.out.println("INput node for operation " +						   convertToCpp(operationName,true)+" Not found");				return;			    }									String inmessage = getAttrValue(inputNode,"message");			inmessage = inmessage.substring(inmessage.indexOf(":")+1);			messageEquivalent = getMessageEquivalent(node,inmessage,false);						//System.out.println("operation "+ operationName+" IN "+ messageEquivalent);						inputArgs.append(messageEquivalent+", ");						inputNode = input.getNextNode(); 		    }				NodeSearch output = new NodeSearch(operation,docNS+"output");		Node outputNode = output.getNextNode();		if((outputNode==null)&&(defWsdl))		    {			output = new NodeSearch(operation,"output");			outputNode = output.getNextNode();		    }				for(int i=0;i<output.getTotalMatches();i++)		    {						if(outputNode==null)			    {				System.out.println("outputput node for operation " +						   convertToCpp(operationName,true)+" Not found");				return;			    }						String outmessage = getAttrValue(outputNode,"message");			outmessage = outmessage.substring(outmessage.indexOf(":")+1);						messageEquivalent = getMessageEquivalent(node,outmessage,true);			//System.out.println(" OUT "+ messageEquivalent);						outArgs.append(messageEquivalent.replace(',',';'));						outputNode = output.getNextNode();					    }		/*		String description =  " ( "+inputArgs.substring(0,inputArgs.length()-2)+		                     " struct "+dataType(definitionNS+operationName)+		                     "Response {"+outArgs.substring(0,outArgs.length())+" } *out) ;";		*/		String description="";		if(!elementflag){		    description=  " ( "+inputArgs.substring(0,inputArgs.length()-2)+		                     " struct "+dataType(defns+operationName)+		                     "Response {"+outArgs.substring(0,outArgs.length())+" } *out) ;";		    addOperation(defns,operationName,description,soapact);		}		else{		    description=  " ( "+inputArgs.substring(0,inputArgs.length()-2)+		                     " struct "+dataType(defns+operationName)+		                     "_Response {"+outArgs.substring(0,outArgs.length())+" } *out) ;";				addOperation(defns,operationName+"_",description,soapact);		}				/*		System.out.println(dataType(definitionNS+operationName)+				   " ( "+inputArgs.substring(0,inputArgs.length()-2)+				   " struct "+dataType(definitionNS+operationName)+"Response {"+				   outArgs.substring(0,outArgs.length())+" } *out) ;");*/		operation = operations.getNextNode();	    }		    }        Hashtable allOperation = new Hashtable();    void addOperation(String ldefNS,String operationName,String		      description,String soapaction)    {	boolean inserted=false;	String opString="";		while(!inserted)	    {		if(!allOperation.containsKey(opString+operationName))		    {						allOperation.put(opString+operationName,dataType(ldefNS)+opString+dataType(operationName)+description);			soapActions.put(opString+operationName,soapaction);			inserted=true;		    }		else		    {			int pos;						if(((String)allOperation.get(opString+operationName)).compareToIgnoreCase(dataType(ldefNS)+opString+dataType(operationName)+description)==0)			    return;			if((pos=description.indexOf(opString+operationName))!=-1)			    {				description = description.substring(0,pos)+"_"+opString+description.substring(pos+opString.length()+operationName.length());			    }			opString = opString+"_";		    }	    }		    }       String getNsEquivalent(Hashtable ht, String name)    {	if(ht==null)	    return null;	else	    return (String)ht.get(name);    }    boolean isdefWsdl(Hashtable ht)    {	String sdefaultNS = (String)ht.get("defaultNS");	if(sdefaultNS!=null)	    {		if(sdefaultNS.endsWith("/wsdl/"))		    {			return true;		    }	    }	return false;    }    boolean isdefSoap(Hashtable ht)    {	String sdefaultNS = (String)ht.get("defaultNS");	if(sdefaultNS!=null)	    {		if(sdefaultNS.endsWith("/soap/"))		    {			return true;		    }	    }	return false;    }        private boolean elementflag;    String getMessageEquivalent(Node node, String messageName,boolean isreturn)    {	Node messageNode=null;	StringBuffer equivalentString = new StringBuffer();		Hashtable attr = new Hashtable();	attr.put("name",messageName);		NsNodeSearch nmessage = new NsNodeSearch(node,docNS+"message",attr,new Hashtable());	NsNode nmessageNode = nmessage.getNextNode();	if((nmessageNode==null)&&(defWsdl))	    {		 nmessage = new NsNodeSearch(node,"message",attr,new Hashtable());		 nmessageNode = nmessage.getNextNode();	    }

⌨️ 快捷键说明

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