JavaNameGenerator

The JavaNameGenerator class is responsible for converting COBOL field names intoJava™ names.

This class can be subclassed by a user written class to provide an alternative naming convention to affect the names that are used within the generated helper classes.

You can allow a user class to override the naming conventions for Java class names by using the following methods:
  • Java class names
  • variable instance names
  • static names
  • accessor names
  • level separators
Two utility methods are also provided which can be used to convert a COBOL symbol name into either a camel case or _ separated string, for example, the COBOL symbol TEST-RECORD can be converted into either TestRecord or TEST_RECORD. All of the available methods are documented in the Javadoc.

For more information, see JavaNameGenerator.

For more information, see Javadoc for IBM Record Generator for Java in IBM® Documentation.

Examples

This first example class prefixes the class name with the String Generated to denote this as a generated class.

package com.mycompany.naming;
import com.ibm.recordgen.cobol.JavaNameGenerator;
public class ClassNamingVariation extends JavaNameGenerator {
    @Override
    public String getJavaClassName(String cobolSymbol) {
          return "Generated" + getCamelCasedName(cobolSymbol, true);
    }
}
Compiling and exporting this class to the file namingConventions.jar and using it when you are running the RecordClassGenerator by using the command

java -cp ibm-recgen.jar:ibmjzos.jar:namingConventions.jar \
com.ibm.recordgen.cobol.RecordClassGenerator adatafile=myrecord.adata \
nameGenerator=com.mycompany.naming.ClassNamingVariation
against an ADATA file generated from the BasicRecord COBOL example, will generate a class that has the following declaration:

public class  GeneratedBasicRecord {

This naming convention can be overridden by the class parameter when running RecordClassGenerator.

This next sample class overrides the default accessor method name generation

package com.mycompany.naming;
import com.ibm.recordgen.cobol.JavaNameGenerator;
public class AccessorNamingVariation extends JavaNameGenerator {
    @Override
    public String getJavaAccessorName(String cobolSymbol) {
          return getUppercasedUnderscoreDelimitedName(cobolSymbol);
    }
}
By default the Java accessor method for a COBOL field CLAIM-NUMBER would appear in the generated class as:

public String getClaimNumber() {
    if (claimNumber == null) {  
        claimNumber = CLAIM_NUMBER.getString(_byteBuffer);
    }
    return claimNumber;
}
However, by using the AccessorNamingVariation class when you are running the RecordClassGenerator they appear as:

public String getCLAIM_NUMBER() {
    if (claimNumber == null) {
        claimNumber = CLAIM_NUMBER.getString(_byteBuffer);
    }
return claimNumber;
}