- Timestamp:
- 07/04/13 20:29:50 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/communication/queries/CallRequest.java
r84 r96 1 1 package com.framsticks.communication.queries; 2 2 3 import com.framsticks.communication.Request; 3 import com.framsticks.util.Misc; 4 import com.framsticks.util.lang.Pair; 4 5 6 import java.util.ArrayList; 7 import java.util.Collection; 5 8 import java.util.List; 6 9 … … 10 13 public class CallRequest extends ApplicationRequest { 11 14 12 protected String arguments;13 protected String method;15 protected final List<Object> arguments = new ArrayList<>(); 16 protected String procedure; 14 17 15 public CallRequest setArguments(String arguments) {16 this.arguments = arguments;18 public CallRequest addArguments(String arguments) { 19 // this.arguments = arguments; 17 20 return this; 18 21 } 19 22 20 public CallRequest setArguments(List<String> arguments) { 21 StringBuilder buffer = new StringBuilder(); 22 for (String a : arguments) { 23 buffer.append(" "); 24 Request.quoteValue(buffer, a.trim()); 25 } 26 return this.setArguments(buffer.toString()); 23 /** 24 * @return the arguments 25 */ 26 public List<Object> getArguments() { 27 return arguments; 27 28 } 28 29 29 public CallRequest setMethod(String method) { 30 this.method = method; 30 /** 31 * @return the procedure 32 */ 33 public String getProcedure() { 34 return procedure; 35 } 36 37 /** 38 * @param arguments the arguments to set 39 */ 40 public CallRequest arguments(Collection<Object> arguments) { 41 this.arguments.clear(); 42 this.arguments.addAll(arguments); 43 return this; 44 } 45 46 public CallRequest argument(Object argument) { 47 arguments.add(argument); 48 return this; 49 } 50 51 public CallRequest procedure(String procedure) { 52 this.procedure = procedure; 31 53 return this; 32 54 } … … 35 57 protected StringBuilder construct(StringBuilder buffer) { 36 58 super.construct(buffer); 37 if (method != null) {38 buffer.append(" ").append(method);39 }40 if (arguments != null) {41 buffer.append(arguments);59 Misc.throwIfNull(procedure); 60 buffer.append(' ').append(procedure); 61 for (Object arg : arguments) { 62 buffer.append(' '); 63 quoteArgumentIfNeeded(buffer, arg); 42 64 } 43 65 return buffer; … … 49 71 } 50 72 73 @Override 74 public CharSequence parseRest(CharSequence rest) { 75 rest = super.parseRest(rest); 76 Pair<CharSequence, CharSequence> p = Misc.throwIfNull(takeIdentifier(rest)); 77 this.procedure = p.first.toString(); 78 while ((p = takeString(p.second)) != null) { 79 arguments.add(p.first); 80 } 81 return null; 82 } 83 51 84 }
Note: See TracChangeset
for help on using the changeset viewer.