commformat.java
来自「OO 图书馆系统」· Java 代码 · 共 85 行
JAVA
85 行
import java.net.*;
import org.apache.axis.message.SOAPEnvelope;
import org.w3c.dom.*;
// The classes that implement a concrete strategy should implement this
// The CommFormt class uses this to call the concrete strategy
interface IStrategy
{
public Document getResponse();
}
// Implements the algorithm using the strategy interface
class ConcreteStrategySOAP implements IStrategy
{
//create a request SOAPEvelope object
private SOAPEnvelope requestenv;
//create Document object
private Document doc;
//create a URL object
private URL url;
//constructor initialization
public ConcreteStrategySOAP(URL url,SOAPEnvelope env){
this.url=url;
this.requestenv=env;
}
public Document getResponse()
{
CommSoapProxy x = new CommSoapProxy(url,requestenv);
x.sendRequest();
this.doc = x.getResponse();
return doc;
}
}
class ConcreteStrategyREST implements IStrategy
{
//create Document object
private Document doc;
//create a URL object
private URL url;
//constructor initialization
public ConcreteStrategyREST(URL url){
this.url=url;
}
public Document getResponse()
{
CommRESTProxy x = new CommRESTProxy(url);
x.sendRequest();
this.doc = x.getResponse();
return doc;
}
}
// Configured with a ConcreteStrategy object and maintains a reference to a Strategy object
class CommFormat
{
private IStrategy strategy;
//create a document object
private Document doc;
// Constructor
public CommFormat(IStrategy strategy)
{
this.strategy = strategy;
}
public Document getResponse()
{
this.doc=strategy.getResponse();
return doc;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?