Rev | Line | |
---|
[77] | 1 | package com.framsticks.communication.queries; |
---|
| 2 | |
---|
| 3 | import com.framsticks.communication.Request; |
---|
| 4 | |
---|
| 5 | import java.util.Collection; |
---|
| 6 | |
---|
| 7 | /** |
---|
| 8 | * @author Piotr Sniegowski |
---|
| 9 | */ |
---|
| 10 | public abstract class ApplicationRequest extends Request { |
---|
| 11 | |
---|
| 12 | protected String path; |
---|
| 13 | protected String fields; |
---|
| 14 | |
---|
| 15 | public ApplicationRequest setPath(String path) { |
---|
| 16 | assert path != null; |
---|
| 17 | this.path = path; |
---|
| 18 | return this; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | public ApplicationRequest setField(String field) { |
---|
| 22 | this.fields = field; |
---|
| 23 | return this; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | public ApplicationRequest setFields(Collection<String> fields) { |
---|
| 27 | StringBuilder fieldString = new StringBuilder(); |
---|
| 28 | boolean notFirst = false; |
---|
| 29 | for (String field : fields) { |
---|
| 30 | if (notFirst) { |
---|
| 31 | fieldString.append(","); |
---|
| 32 | |
---|
| 33 | } else { |
---|
| 34 | notFirst = true; |
---|
| 35 | } |
---|
| 36 | fieldString.append(field); |
---|
| 37 | } |
---|
| 38 | return setField(fieldString.toString()); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | public String getPath() { |
---|
| 43 | return path; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | @Override |
---|
| 47 | protected StringBuilder construct(StringBuilder buffer) { |
---|
| 48 | buffer.append(' ').append(path); |
---|
| 49 | if (fields != null) { |
---|
| 50 | buffer.append(' ').append(fields); |
---|
| 51 | } |
---|
| 52 | return buffer; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | @Override |
---|
| 56 | public void parseRest(String rest) { |
---|
| 57 | path = rest; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.