Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: dr/davmgr/protocol/ProtocolCommandController.java


1   package dr.davmgr.protocol;
2   
3   import dr.davmgr.protocol.cmd.*;
4   
5   import dr.davmgr.protocol.tools.*;
6   import dr.davmgr.protocol.tools.cmd.*;
7   
8   import dr.log.LogManager;
9   
10  public class ProtocolCommandController 
11  {
12    private static ProtocolCommandController pcc = null;
13    private ProtocolCommandController() {
14    }
15    public static ProtocolCommandController getInstance() {
16      if (pcc==null) pcc=new ProtocolCommandController();
17      return pcc;
18    }
19    public ProtocolResponse executeCommand(Command cmd) {
20      return executeCommand(cmd, null);
21    }
22    public ProtocolResponse executeCommand(Command cmd, Authorization auth) {
23      ProtocolRequest request = new ProtocolRequest(cmd);
24      request.setAuthorization(auth);
25      ProtocolResponse resp = null;
26      if (cmd instanceof ZIPCommand) 
27        resp=new ZIPCommandController().execute(request);
28      else if (cmd instanceof SplitCommand) 
29        resp=new SplitCommandController().execute(request);
30      else if (cmd instanceof OpenCommand)
31        resp=new OpenCommandController().execute(request);
32      else { 
33        ProtocolController pc = ProtocolController.getInstance();
34        String protocol;
35        if (cmd.getURL()!=null) protocol=cmd.getURL().getProtocol();
36        else if (cmd.getUrls()!=null) 
37    if (cmd.getUrls().getURL()!=null)
38      protocol= cmd.getUrls().getURL().getProtocol();
39    else {
40      throw new IllegalArgumentException(
41        "executeCommand: cmd has no usable URL");
42    } 
43        else { 
44    throw new IllegalArgumentException(
45      "executeCommand: cmd has no usable URL");  
46        }  
47        ProtocolHandler ph = pc.getProtocolHandler(protocol);
48        if (ph==null) return null;
49        resp=ph.executeRequest(request);
50        if (resp==null)
51    return new ProtocolResponse(request, 501, null);
52      }  
53      LogManager.logNormal(resp.getRequest().getCommand().toString()+
54      " statuCode="+resp.getStatus()+
55        " exception="+resp.getException());
56      return resp;  
57    }
58  }