No alternative found for choice element - toHost

154 views
Skip to first unread message

Athul prasanna Venkatesh

unread,
Mar 7, 2015, 2:56:58 AM3/7/15
to legsta...@googlegroups.com
Hi Fady,

Legstar has been really a great software and has been useful to many of our projects. We have been using it for converting COBOL message as a String to Java and this is the first time , we have had a requirement to do javaToHost to push the message over MQ. When trying to convert java to Host we are receiving the below exception even though we have choice defined.

Exception:-
com.legstar.coxb.transform.HostTransformException: No alternative found for choice element GtmLeRoleChoice
at com.legstar.coxb.transform.AbstractJavaToHostTransformer.transform(AbstractJavaToHostTransformer.java:204)
at com.legstar.coxb.transform.AbstractJavaToHostTransformer.transform(AbstractJavaToHostTransformer.java:119)
at com.legstar.coxb.transform.AbstractJavaToHostTransformer.transform(AbstractJavaToHostTransformer.java:100)
at com.legstar.coxb.transform.AbstractTransformers.toHost(AbstractTransformers.java:95)
at main.TestLegstar.main(TestLegstar.java:33)
Caused by: No alternative found for choice element GtmLeRoleChoice
at com.legstar.coxb.impl.visitor.CobolMarshalVisitor.visit(CobolMarshalVisitor.java:204)
at com.legstar.coxb.common.CChoiceBinding.accept(CChoiceBinding.java:81)
at com.legstar.coxb.impl.visitor.CobolMarshalVisitor.visit(CobolMarshalVisitor.java:106)
at com.legstar.coxb.common.CComplexBinding.accept(CComplexBinding.java:72)
at com.legstar.coxb.impl.visitor.CobolMarshalVisitor.visit(CobolMarshalVisitor.java:235)
at com.legstar.coxb.common.CArrayComplexBinding.accept(CArrayComplexBinding.java:71)
at com.legstar.coxb.impl.visitor.CobolMarshalVisitor.visit(CobolMarshalVisitor.java:106)
at com.legstar.coxb.common.CComplexBinding.accept(CComplexBinding.java:72)
at com.legstar.coxb.impl.visitor.CobolMarshalVisitor.visit(CobolMarshalVisitor.java:106)
at com.legstar.coxb.common.CComplexBinding.accept(CComplexBinding.java:72)
at com.legstar.coxb.transform.AbstractJavaToHostTransformer.transform(AbstractJavaToHostTransformer.java:173)
... 4 more

Please see below all the information I have.

Copybook Layout:

*****************************************************************
        01  GTM-ACCOUNTCP-UPDATE.
          05  GTM-CPACCT-PROPERTIES.
              10  GTM-CPACCT-PROP-DETAIL OCCURS 50 TIMES.
                  15  GTM-LE-ROLE               PIC X(12).
                  15  GTM-SERV-PREF-VALUE REDEFINES GTM-LE-ROLE.
                      20  GTM-SERV-PREF-VAL     PIC X(8).
                      20  GTM-SERV-PREF-VAL-FILLER PIC X(4).
 
Legstar Generated XSD:-

Please see attachment

Java Test Class

public static void main(String[] args) {
// TODO Auto-generated method stub

GtmAccountcpUpdate header = new GtmAccountcpUpdate();
GtmCpacctPropDetail gtmCpacctPropDetail=new GtmCpacctPropDetail();
gtmCpacctPropDetail.setGtmLeRole("TESTLEROLE");
GtmCpacctProperties gtmCpacctProperties=new GtmCpacctProperties();
   
gtmCpacctProperties.getGtmCpacctPropDetail().add(gtmCpacctPropDetail);
   
header.setGtmCpacctProperties(gtmCpacctProperties);
   

GtmAccountcpUpdateTransformers accountcpUpdateTransformers = new GtmAccountcpUpdateTransformers();
try {
byte[] out = accountcpUpdateTransformers.toHost(header, "ISO-8859-1");
System.out.println(new String(out));
} catch (HostTransformException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


When I use the same program to do Host To Java , it works perfectly , whereas java to host gives me that exception.
At the same time , if I remove OCCURS 50 TIMES , it works with no issues for both java to host and host to java. 
I am really stuck here and don't understand why it would throw an error for choice class, when I have defined my choice class in XSD.


Please advise.

Thanks,
Athul
GTMToCIWCopybooK.xsd

Fady

unread,
Mar 7, 2015, 11:30:07 AM3/7/15
to legsta...@googlegroups.com
Hello Athul,

Thank you for your kind word on LegStar.

As for the problem you are reporting, it comes from the fact that the array in the COBOL structure is not variable size.

With such an array, you have to provide all 50 occurrences.

What is happening is that you are setting only one occurrence, so when the marshaler attempts at converting the second occurrence, it fails because none of the alternatives is set.

This code works fine:

    public void testApp() throws Exception {

       
GtmAccountcpUpdate header = new  GtmAccountcpUpdate();

       
GtmCpacctProperties properties = new GtmCpacctProperties();
       
for (int i = 0; i < 50; i++) {
           
GtmCpacctPropDetail detail = new GtmCpacctPropDetail();
            detail
.setGtmLeRole("TESTLEROLE" + i);
            properties
.getGtmCpacctPropDetail().add(detail);
       
}
        header
.setGtmCpacctProperties(properties);
       
       
GtmAccountcpUpdateTransformers tf = new GtmAccountcpUpdateTransformers();
       
byte[] hostData = tf.toHost(header);
   
}



Hope this helps.

Fady
Reply all
Reply to author
Forward
0 new messages