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

📄 messagefactory.java

📁 OO 图书馆系统
💻 JAVA
字号:
 
import java.net.*;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPElement;
import org.apache.axis.message.SOAPBody;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.message.SOAPFault;
import org.apache.axis.utils.XMLUtils;
import org.w3c.dom.*;
  class MessageFactory
  {
  	
  	//constructor
  	private MessageFactory(){
  		
  	}
    
    static public String getRESTUrl(String method,String para,String tag,String api_key){
    	String url;
    	ProductREST productrest = new ProductREST(method,para,tag,api_key);
    	url=productrest.getProductREST();
    	return url;
    }
    static public SOAPEnvelope getSOAP(String method,String para,String tag,String api_key){
    	SOAPEnvelope env;
    	ProductSOAP productsoap = new ProductSOAP(method,para,tag,api_key);
    	env=productsoap.getProductSOAP();
    	return env;
    }
    
    
  }
  
  
   // "ProductREST" 

  class ProductREST 
  {
  	//create a url String
    private String url;
    //create a string method
    private String method;
    //create a string para
    private String para;
    //create a string tag
    private String tag;
    //create a string api_key
    private String api_key;
  
    //constructor initialization
    public ProductREST(String method,String para,String tag,String api_key){
      this.method=method;
      this.para=para;
      this.tag=tag;
      this.api_key=api_key;
    	
     
  	}
  	
  	public String getProductREST(){
  		
  	  try{
      	this.url="http://www.flickr.com/services/rest/?method="+method+"&format=rest&"+para+"="+tag+"&api_key="+api_key;
  	    
       }
       catch (Exception e) {
         e.printStackTrace();
       }
    	
  	  return url;
  	}
  	
  	
  }

  // "ProductSOAP"
  class ProductSOAP
  {
  	
  	//create a SOAPEnvelope object env
  	private SOAPEnvelope env;
  	 //create a string method
    private String method;
    //create a string para
    private String para;
    //create a string tag
    private String tag;
    //create a string api_key
    private String api_key;
  	
  	//constructor initialization
  	public ProductSOAP(String method,String para,String tag,String api_key){
      this.method=method;
      this.para=para;
      this.tag=tag;
      this.api_key=api_key;
  		
  		
  	}
  	
  	public SOAPEnvelope getProductSOAP(){
  		
  		try{
  		
  		// build the envelope
            env = new SOAPEnvelope();
            env.addNamespaceDeclaration("xsi",
                    "http://www.w3.org/1999/XMLSchema-instance");
            env.addNamespaceDeclaration("xsd",
                    "http://www.w3.org/1999/XMLSchema");

            // build the body
            Name bodyName = env.createName("FlickrRequest", "x", "urn:flickr");
            SOAPBodyElement body = new SOAPBodyElement(bodyName);

            Element e = XMLUtils.StringToElement("", "format", "soap2");
            SOAPElement sbe = new SOAPBodyElement(e);
            body.addChildElement(sbe);

            // set method name
            e = XMLUtils.StringToElement("", "method",
                    method);
            sbe = new SOAPBodyElement(e);
            body.addChildElement(sbe);

            // set parameters
            e = XMLUtils.StringToElement("", "api_key", api_key);
            sbe = new SOAPBodyElement(e);
            body.addChildElement(sbe);
            
            e = XMLUtils.StringToElement("", para, tag);
            sbe = new SOAPBodyElement(e);
            body.addChildElement(sbe);
           
           
            // put the body in the envelope
            env.addBodyElement(body);
            }
            catch (Exception e) {
              e.printStackTrace();
            }
            
    	
            
            return env;
  	}
  	
  }


⌨️ 快捷键说明

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