source: java/main/src/main/java/com/framsticks/communication/Request.java @ 77

Last change on this file since 77 was 77, checked in by psniegowski, 11 years ago

Add new java codebase.

File size: 1.4 KB
Line 
1package com.framsticks.communication;
2
3import com.framsticks.communication.queries.*;
4
5import java.util.Collection;
6import java.util.regex.Matcher;
7import java.util.regex.Pattern;
8
9/**
10 * Class stores information about query sent to manager.
11 */
12public abstract class Request {
13
14    public static void quoteValue(StringBuilder builder, String value) {
15                String quote = ((value.indexOf(' ') > 0) || (value.length() == 0) ? "\"" : "");
16                builder.append(quote).append(value).append(quote);
17        }
18
19        public abstract String getCommand();
20
21    protected abstract StringBuilder construct(StringBuilder buffer);
22        //private static Pattern queryPattern = Pattern.compile("^(\\S+)\\s+(\\S+)(?:\\s+(\\S+))?$");
23
24        public static Request createRequestByTypeString(String type) {
25                if (type.equals("get")) {
26                        return new GetRequest();
27                }
28                if (type.equals("set")) {
29                        return new SetRequest();
30                }
31                if (type.equals("info")) {
32                        return new InfoRequest();
33                }
34                if (type.equals("call")) {
35                        return new CallRequest();
36                }
37        if (type.equals("reg")) {
38            return new RegistrationRequest();
39        }
40        if (type.equals("use")) {
41            return new UseRequest();
42        }
43        if (type.equals("version")) {
44            return new VersionRequest();
45        }
46        return null;
47        }
48
49    public abstract void parseRest(String rest);
50
51    @Override
52    public String toString() {
53        return construct(new StringBuilder().append(getCommand())).toString();
54    }
55}
Note: See TracBrowser for help on using the repository browser.