--- Revision None +++ Revision 393963333639 @@ -0,0 +1,60 @@ +public String getRequestString() throws MQException { + RequestBuilder req = new RequestBuilder(); + + req.sessionNumber('0', 3) + .version('0', 3) + .transaction('X', 4) + .language('X', 2) + .callersPhoneNumber('0', 16) + .customerNumber(' ', 16) + .nrUnsuccessfulCalls('0', 3); + + return req.build(); +} + +private class RequestBuilder { + private StringBuilder b = new StringBuilder(); + + public RequestBuilder callersPhoneNumber(char pad, int width) { + add(Helper.leftRightFilled(true, getCallersPhoneNumber(), pad, width)); + return this; + } + + public RequestBuilder customerNumber(char pad, int width) throws MQException { + add(Helper.leftRightFilled(false, dynamicSettingMQ.getCustomerNumber(), pad, width)); + return this; + } + + public RequestBuilder language(char pad, int width) throws MQException { + add(Helper.leftRightFilled(true, getLanguage(), pad, width)); + return this; + } + + public RequestBuilder nrUnsuccessfulCalls(char pad, int width) throws MQException { + add(Helper.leftRightFilled(true, dynamicSettingMQ.getNumberOfUnsucceededCalls(), pad, width)); + return this; + } + + public RequestBuilder sessionNumber(char pad, int width) throws MQException { + add(Helper.leftRightFilled(true, getSessionNumberAndIncreaseIt(), pad, width)); + return this; + } + + public RequestBuilder transaction(char pad, int width) throws MQException { + add(Helper.leftRightFilled(true, getTransaction(), pad, width)); + return this; + } + + public RequestBuilder version(char pad, int width) throws MQException { + add(Helper.leftRightFilled(true, getVersion(), pad, width)); + return this; + } + + public String build() { + return b.toString(); + } + + private void add(String str) { + b.append(str); + } +}