@@ -161,8 +161,9 @@ public MessageElement getNextElement() throws OLcRemoteException, IOException {
161161 if (this .activearraystart != null )
162162 throw new RuntimeException (
163163 "Incorrect message, received a message array start " + arraystart .getArrayName ()
164- + ", while other array is active " + this .activearraystart .getArrayName ());
164+ + ", while other array is active " + this .activearraystart .getArrayName ());
165165 this .activearraystart = arraystart ;
166+ this .arraylinebuffer = null ;
166167 }
167168
168169 if (currentelement instanceof MessageArrayEnd ) {
@@ -497,4 +498,69 @@ public BigDecimal returnNextDecimalField(String name) throws OLcRemoteException,
497498 * @return
498499 */
499500 public abstract String endrecord ();
501+
502+ /**
503+ * @param arrayname name of the compact array structure
504+ * @return the MessageArrayStart element, or throws an exception if the next
505+ * element does not correspond
506+ * @throws OLcRemoteException if the remote party encounters an error while
507+ * processing the message
508+ * @throws IOException if any communication issue is encountered
509+ */
510+ public MessageArrayStart returnNextMessageStartArray (String arrayname ) throws OLcRemoteException , IOException {
511+ MessageElement nextelement = getNextElement ();
512+ if (!(nextelement instanceof MessageArrayStart ))
513+ throw new RuntimeException (String .format (
514+ "Expecting a MessageArrayStart, got %s \n path: %s\n message: %s" , nextelement .toString (),
515+ this .getCurrentElementPath (), lastelementbuffer .getCompactBufferTrace ()));
516+ MessageArrayStart arraystart = (MessageArrayStart ) nextelement ;
517+ if (!arraystart .getArrayName ().equals (arrayname ))
518+ throw new RuntimeException (String .format (
519+ "Message Array Start does not have the good name, expecting %s, got %s \n path: %s\n message: %s" ,
520+ arrayname , nextelement .toString (), this .getCurrentElementPath (),
521+ lastelementbuffer .getCompactBufferTrace ()));
522+ return arraystart ;
523+ }
524+
525+ private MessageArrayLine arraylinebuffer = null ;
526+
527+ /**
528+ * This convenience method should be called inside the while statement of a loop
529+ * that reads all lines of the compact array. It reads the next element, and if
530+ * this is an arrayline, stores it into a buffer so that it can be retrieved
531+ * with the getArrayNextLine method
532+ *
533+ * @return true if a MessageArrayLine could be found, false if the array is
534+ * finished
535+ * @throws OLcRemoteException if the remote party encounters an error while
536+ * processing the message
537+ * @throws IOException if any communication issue is encountered
538+ */
539+ public boolean hasArrayNextLine () throws OLcRemoteException , IOException {
540+ MessageElement nextelement = getNextElement ();
541+ if (nextelement instanceof MessageArrayEnd )
542+ return false ;
543+ if (nextelement instanceof MessageArrayLine ) {
544+ arraylinebuffer = (MessageArrayLine ) nextelement ;
545+ return true ;
546+ }
547+ throw new RuntimeException (String .format (
548+ "Did not find either a MessageArrayEnd or MessageArrayLine got %s \n path: %s\n message: %s" ,
549+ nextelement .toString (), this .getCurrentElementPath (), lastelementbuffer .getCompactBufferTrace ()));
550+ }
551+
552+ /**
553+ * @return the MessageArrayLine stored in a local buffer after hasArrayNextLine has
554+ * been called.
555+ */
556+ public MessageArrayLine getArrayNextLine () {
557+ if (arraylinebuffer == null )
558+ throw new RuntimeException (String .format (
559+ "Only call this method after a call to hasArrayNextLine has returned true, path: %s\n message: %s" ,
560+ this .getCurrentElementPath (), lastelementbuffer .getCompactBufferTrace ()));
561+ MessageArrayLine linetoreturn = arraylinebuffer ;
562+ arraylinebuffer = null ;
563+ return linetoreturn ;
564+ }
565+
500566}
0 commit comments