I guess the best place to provide a default would be around line 233 in
http://code.google.com/p/legstar/source/browse/trunk/legstar-core/legstar-coxbrt/src/main/java/com/legstar/coxb/impl/reflect/CComplexReflectBinding.java.
Otherwise, just to make it clear, in legstar, the translation process,
when the starting point is a POJO, has 2 steps (see
http://code.google.com/p/legstar-xsd2cob/) :
1. Use JAXB schemagen to produce an XSD out of the POJO
2. Parse the XSD and produce a COBOL-annotated XSD (this is where
mapping XSD types to COBOL types takes place)
Then the binding process again has 2 steps:
3. Use JAXB xjc to produce a COBOL-annotated POJO. This is where
@CobolElement annotations, which are derived from the XSD COBOL
annotations produced at step 2, are injected in the JAXB POJO
4. Reflect on the COBOL-annotated POJO to produce binding classes
At runtime, you have the choice of using the output from step 4, using
transformers, which has the best performances, or the output of step 3,
using reflection, like I did in my last reply.
In summary, there are 2 difficulties here:
1. legstar does not infer a COBOL type directly from a java type. An
intermediary XSD type is used instead.
2. Type inference happens in a different tool (xsd2cob) than binding
(coxbrt)
so it seems to me relatively difficult at this stage to support implicit
types.
Fady
COBOL variable size arrays are declared like so:
05 SOME-COUNTER PIC 99.
05 VSARRAY OCCURS 1 TO 100 DEPENDING ON SOME-COUNTER.
10 ...
As you can see the array size can vary at runtime but the actual size
must be given by the SOME-COUNTER counter.
Now for legstar, when the starting point is java (or XSD), lists are
mapped to such an array and counter. That counter is qualified of
dynamic because it does not map any field from the original POJO and it
is added on the fly at binding time.
In addition to generating an extra binding for the counter, legstar also
has code to keep the value of the counter equal to the array size (java
-> cobol). The code that does that shows up in
com.legstar.coxb.common.CArrayBinding#getCurrentOccurs(). Similarly,
upon receiving mainframe data (cobol -> java), the counter tells legstar
when to stop marshaling data for the array.
Hope this helps.
Fady
This being said, there is another utility within legstar called cobcgen
that is used internally to generate COBOL using the JAXB class directly
(the one with annotations).
cobcgen is an ant task but you can also use it programmatically like so:
----------------------------------------------------------------------------------
package com.legsem.test;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.apache.tools.ant.BuildException;
import com.legstar.cobc.gen.CobolGenerator;
public class CobolGenTest extends TestCase {
private static final File GEN_DIR = new File("target");
public void testGen() throws Exception {
try {
CobolGenerator gen = new CobolGenerator();
gen.setJaxbTypeName("MyDateClass");
gen.setJaxbPackageName("legstar.trans.patrick");
gen.setTargetDir(GEN_DIR);
gen.execute();
String cobol = FileUtils.readFileToString(new File(GEN_DIR,
"MyDateClass.cbl"), "UTF-8");
assertEquals("", cobol);
} catch (BuildException e) {
fail(e.getMessage());
} catch (IOException e) {
fail(e.getMessage());
}
}
}
----------------------------------------------------------------------------------
Can you give it a try?
Fady
P.S. TIMES is not mandatory with Enterprise COBOL for z/OS. legstar is
not guaranteed to work with any other COBOL compiler
If you use Maven, you can get it like so (it is in Maven central):
<dependency>
<groupId>com.legsem.legstar</groupId>
<artifactId>legstar-cobcgen</artifactId>
<version>1.5.3</version>
</dependency>
Let me know how it goes.
Fady
Hopefully, the copybook will work out for you mainframe people.
I guess we could have done without the JAXB objectfactory in most cases
but there are circumstances when it is necessary (Typically when
JAXBElement wrappers are needed).
Also, sorry for the confusion about legstar-core versus legstar-coxbgen.
legstar-core is a Maven parent POM (no code there) for a number of
subprojects, legstar-coxbgen being one of them. There should be a
legstar-core distributable but currently, all the legstar-core
subprojects are distributed as part of legstar-coxbgen for historical
reasons. So when you download legstar-coxbgen, you actually get all the
legstar-core modules.
Fady