source: java/main/src/main/java/com/framsticks/communication/queries/CallRequest.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1package com.framsticks.communication.queries;
2
3import com.framsticks.util.Misc;
4import com.framsticks.util.lang.Pair;
5
6import java.util.ArrayList;
7import java.util.Collection;
8import java.util.List;
9
10/**
11 * @author Piotr Sniegowski
12 */
13public class CallRequest extends ApplicationRequest {
14
15        protected final List<Object> arguments = new ArrayList<>();
16        protected String procedure;
17
18        public CallRequest addArguments(String arguments) {
19                return this;
20        }
21
22        /**
23         * @return the arguments
24         */
25        public List<Object> getArguments() {
26                return arguments;
27        }
28
29        /**
30         * @return the procedure
31         */
32        public String getProcedure() {
33                return procedure;
34        }
35
36        /**
37         * @param arguments the arguments to set
38         */
39        public CallRequest arguments(Collection<Object> arguments) {
40                this.arguments.clear();
41                this.arguments.addAll(arguments);
42                return this;
43        }
44
45        public CallRequest argument(Object argument) {
46                arguments.add(argument);
47                return this;
48        }
49
50        public CallRequest procedure(String procedure) {
51                this.procedure = procedure;
52                return this;
53        }
54
55        @Override
56        protected StringBuilder construct(StringBuilder buffer) {
57                super.construct(buffer);
58                Misc.throwIfNull(procedure);
59                buffer.append(' ').append(procedure);
60                for (Object arg : arguments) {
61                        buffer.append(' ');
62                        quoteArgumentIfNeeded(buffer, arg);
63                }
64                return buffer;
65        }
66
67        @Override
68        public String getCommand() {
69                return "call";
70        }
71
72        @Override
73        public CharSequence parseRest(CharSequence rest) {
74                rest = super.parseRest(rest);
75                Pair<CharSequence, CharSequence> p = Misc.throwIfNull(takeIdentifier(rest));
76                this.procedure = p.first.toString();
77                while ((p = takeString(p.second)) != null) {
78                        arguments.add(p.first);
79                }
80                return null;
81        }
82
83}
Note: See TracBrowser for help on using the repository browser.