public class Cob2Xsd extends Object
There are 6 steps involved:
All options are bundled in Cob2XsdConfig instance that is received at
construction time.
To invoke the translator, you normally call the translate method.
Any error encountered and recovered from is available in
getErrorHistory().
| Constructor and Description |
|---|
Cob2Xsd(Cob2XsdConfig config) |
| Modifier and Type | Method and Description |
|---|---|
String |
clean(Reader cobolReader)
Remove any non COBOL Structure characters from the source.
|
protected org.apache.ws.commons.schema.XmlSchema |
createXmlSchema(String encoding,
String targetNamespace)
Create an empty XML Schema.
|
List<CobolDataItem> |
emitModel(org.antlr.runtime.tree.CommonTree ast)
Generates a model from an Abstract Syntax Tree.
|
org.apache.ws.commons.schema.XmlSchema |
emitXsd(List<CobolDataItem> cobolDataItems,
String targetNamespace)
Generate an XML Schema using a model of COBOL data items.
|
Cob2XsdConfig |
getConfig()
The execution parameters for the COBOL to XML Schema utility.
|
List<String> |
getErrorHistory()
list of errors encountered while translating.
|
protected static void |
getNonUniqueCobolNames(CobolDataItem cobolDataItem,
List<String> cobolNames,
List<String> nonUniqueCobolNames)
If data item COBOL name is already used, we add it to the non unique
list.
|
static List<String> |
getNonUniqueCobolNames(List<CobolDataItem> cobolDataItems)
Create a list of COBOL names which are not unique.
|
org.antlr.runtime.CommonTokenStream |
lex(String cleanedCobolSource)
Apply the lexer to produce a token stream from source.
|
org.antlr.runtime.tree.CommonTree |
parse(org.antlr.runtime.CommonTokenStream tokens)
Apply Parser to produce an abstract syntax tree from a token stream.
|
List<CobolDataItem> |
toModel(Reader cobolReader)
Parses a COBOL source into an in-memory model.
|
String |
translate(Reader cobolReader,
String targetNamespace,
String xsltFileName)
Execute the translation from COBOL to XML Schema.
|
String |
xsdToString(org.apache.ws.commons.schema.XmlSchema xsd,
String xsltFileName)
Serialize the XML Schema to a string.
|
public Cob2Xsd(Cob2XsdConfig config)
config - configuration parameters for the COBOL to XML Schema utilitypublic String translate(Reader cobolReader, String targetNamespace, String xsltFileName) throws XsdGenerationException
cobolReader - reads the raw COBOL sourcetargetNamespace - the generated XML schema target namespace (null
for no namespace)xsltFileName - an optional xslt to apply on the XML SchemaXsdGenerationException - if XML schema generation process failspublic List<CobolDataItem> toModel(Reader cobolReader) throws RecognizerException
cobolReader - reads the raw COBOL sourceRecognizerException - if COBOL recognition failspublic String clean(Reader cobolReader) throws CleanerException
cobolReader - reads the raw COBOL sourceCleanerException - if source cannot be readpublic org.antlr.runtime.CommonTokenStream lex(String cleanedCobolSource) throws RecognizerException
cleanedCobolSource - the source code (clean outside columns 7 to 72)RecognizerException - if lexer failed to tokenize COBOL sourcepublic org.antlr.runtime.tree.CommonTree parse(org.antlr.runtime.CommonTokenStream tokens)
throws RecognizerException
tokens - the stream token produced by lexerRecognizerException - if source contains unsupported statementspublic List<CobolDataItem> emitModel(org.antlr.runtime.tree.CommonTree ast) throws RecognizerException
ast - the abstract syntax tree produced by parserRecognizerException - if tree cannot be walkedpublic org.apache.ws.commons.schema.XmlSchema emitXsd(List<CobolDataItem> cobolDataItems, String targetNamespace)
cobolDataItems - a list of COBOL data itemstargetNamespace - the target namespace to use (null for no namespace)public String xsdToString(org.apache.ws.commons.schema.XmlSchema xsd, String xsltFileName) throws XsdGenerationException
If we are provided with an XSLT customization file then we transform the XMLSchema.
xsd - the XML Schema before customizationxsltFileName - an optional xslt to apply on the XML SchemaXsdGenerationException - if customization failspublic static List<String> getNonUniqueCobolNames(List<CobolDataItem> cobolDataItems)
cobolDataItems - a list of root data itemsprotected static void getNonUniqueCobolNames(CobolDataItem cobolDataItem, List<String> cobolNames, List<String> nonUniqueCobolNames)
We don't add COBOL FILLERs as they are always considered non unique.
cobolDataItem - a COBOL data itemcobolNames - the list of all COBOL names used so farnonUniqueCobolNames - the list of non unique COBOL namesprotected org.apache.ws.commons.schema.XmlSchema createXmlSchema(String encoding, String targetNamespace)
If no targetNamespace, make sure there is no default namespace otherwise our complex types would be considered part of that default namespace (usually XML Schema namespace).
encoding - the character set used to encode this XML SchematargetNamespace - the target namespace to use (null for no namespace)public Cob2XsdConfig getConfig()
Copyright © 2021 LegSem. All rights reserved.