Skip to content

Commit

Permalink
Remove Jaxb reference from JRecord & Utilities
Browse files Browse the repository at this point in the history
Adding syncronise to getFieldMap and getCobolItems etc methods
Adding option to rename cobol fields in utilities (in particular CobolToXml)
  • Loading branch information
bmTas committed Feb 2, 2020
1 parent 02852bd commit 9e21a3f
Show file tree
Hide file tree
Showing 94 changed files with 1,650 additions and 1,450 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import net.sf.JRecord.Common.IFieldDetail;
import net.sf.JRecord.CsvParser.ICsvCharLineParser;
import net.sf.JRecord.CsvParser.CsvDefinition;
import net.sf.JRecord.CsvParser.CsvParserManagerChar;
import net.sf.JRecord.Types.Type;
import net.sf.JRecord.Types.TypeChar;
import net.sf.JRecord.Types.TypeManager;
Expand Down Expand Up @@ -224,15 +223,17 @@ protected void setField(int typeId , IFieldDetail field, Object value) {
super.checkForOdUpdate(field);

} else {
ICsvCharLineParser parser = CsvParserManagerChar.getInstance().get(field.getRecord().getRecordStyle());
Type typeVal = TypeManager.getSystemTypeManager().getType(typeId);
String s = typeVal.formatValueForRecord(field, value.toString());

data =
parser.setField(field.calculateActualPosition(this) - 1,
typeVal.getFieldType(),
data,
new CsvDefinition(layout.getDelimiterDetails(), field.getQuoteDefinition()), s);
ICsvCharLineParser parser = field.getRecord().getCharParser();
if (parser.isUpdatable()) {
Type typeVal = TypeManager.getSystemTypeManager().getType(typeId);
String s = typeVal.formatValueForRecord(field, value.toString());

data =
parser.setField(field.calculateActualPosition(this) - 1,
typeVal.getFieldType(),
data,
new CsvDefinition(layout.getDelimiterDetails(), field.getQuoteDefinition()), s);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import java.util.ArrayList;

import net.sf.JRecord.CsvParser.ICsvCharLineParser;

public class CsvLine extends ListLine {


Expand Down Expand Up @@ -64,7 +66,7 @@ public String getFullLine() {
RecordDetail record = layout.getRecord( getPrefIdx());

return record
.getParser()
.getCharParser()
.formatFieldList(
fields, record, record.getFieldTypes());
}
Expand All @@ -73,8 +75,12 @@ public String getFullLine() {
public void setData(String newVal) {
RecordDetail record = layout.getRecord(getPrefIdx());

fields = new ArrayList<Object>(
record.getParser().getFieldList(newVal, record));
ICsvCharLineParser parser = record.getCharParser();

if (parser.isUpdatable()) {
fields = new ArrayList<Object>(
parser.getFieldList(newVal, record));
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ public final Object getCsvField(final byte[] record, int type, IFieldDetail fiel
*/
@Deprecated
public final Object formatCsvField(IFieldDetail field, int type, String value) {
ICsvCharLineParser parser = CsvParserManagerChar.getInstance().get(field.getRecord().getRecordStyle());
ICsvCharLineParser parser = field.getRecord().getCharParser();
String val = parser.getField(field.getPos() - 1,
value,
new CsvDefinition(delimiter, field.getQuoteDefinition()));
Expand Down Expand Up @@ -880,70 +880,76 @@ public Set<String> getDuplicateFieldNames() {
private void buildFieldNameMap() {

if (fieldNameMap == null) {
int i, j, k, size;
IFieldDetail fld;
String name, nameTmp;

size = 0;
for (i = 0; i < recordCount; i++) {
size += records[i].getFieldCount();
}
size = Math.max(16, (size * 4) / 3 + 4);

fieldNameMap = new HashMap<String, IFieldDetail>(size);
recordFieldNameMap = new HashMap<String, IFieldDetail>(size);
duplicateFieldNames = new HashSet<String>(10);

for (i = 0; i < recordCount; i++) {
for (j = 0; j < records[i].getFieldCount(); j++) {
fld = records[i].getField(j);
nameTmp = fld.getName();
name = nameTmp;
nameTmp = nameTmp + "~";
k = 1;
while (fieldNameMap.containsKey(name.toUpperCase())) {
name = nameTmp + k++;
}
String ucFieldName;
if (k > 1 && ! duplicateFieldNames.contains((ucFieldName = fld.getName().toUpperCase()))) {
IFieldDetail iFieldDetail = fieldNameMap.get(ucFieldName);
if (fld.getPos() != iFieldDetail.getPos()
|| fld.getLen() != iFieldDetail.getLen()
|| fld.getDecimal() != iFieldDetail.getDecimal()
|| fld.getType() != iFieldDetail.getType()
|| fld.getFormat() != iFieldDetail.getFormat()
|| (fld.getParamater() != null && ! fld.getParamater().equals(iFieldDetail.getParamater()))) {
duplicateFieldNames.add(ucFieldName);
}
}
fld.setLookupName(name);
fieldNameMap.put(name.toUpperCase(), fld);
recordFieldNameMap.put(
records[i].getRecordName() + "." + name.toUpperCase(),
fld);
synchronized (this) {
if (fieldNameMap == null) {
int i, j, k, size;
IFieldDetail fld;
String name, nameTmp;

size = 0;
for (i = 0; i < recordCount; i++) {
size += records[i].getFieldCount();
}
size = Math.max(16, (size * 4) / 3 + 4);

HashMap<String, IFieldDetail> tmpFieldNameMap = new HashMap<String, IFieldDetail>(size);
recordFieldNameMap = new HashMap<String, IFieldDetail>(size);
duplicateFieldNames = new HashSet<String>(10);

for (i = 0; i < recordCount; i++) {
for (j = 0; j < records[i].getFieldCount(); j++) {
fld = records[i].getField(j);
nameTmp = fld.getName();
name = nameTmp;
nameTmp = nameTmp + "~";
k = 1;
while (tmpFieldNameMap.containsKey(name.toUpperCase())) {
name = nameTmp + k++;
}
String ucFieldName;
if (k > 1 && ! duplicateFieldNames.contains((ucFieldName = fld.getName().toUpperCase()))) {
IFieldDetail iFieldDetail = tmpFieldNameMap.get(ucFieldName);
if (fld.getPos() != iFieldDetail.getPos()
|| fld.getLen() != iFieldDetail.getLen()
|| fld.getDecimal() != iFieldDetail.getDecimal()
|| fld.getType() != iFieldDetail.getType()
|| fld.getFormat() != iFieldDetail.getFormat()
|| (fld.getParamater() != null && ! fld.getParamater().equals(iFieldDetail.getParamater()))) {
duplicateFieldNames.add(ucFieldName);
}
}
fld.setLookupName(name);
tmpFieldNameMap.put(name.toUpperCase(), fld);
recordFieldNameMap.put(
records[i].getRecordName() + "." + name.toUpperCase(),
fld);
}
records[i].setNumberOfFieldsAdded(0);
}
fieldNameMap = tmpFieldNameMap;
}
records[i].setNumberOfFieldsAdded(0);
}
} else if (this.isBuildLayout()) {
int j;
IFieldDetail fld;

for (int i = 0; i < recordCount; i++) {
if (records[i].getNumberOfFieldsAdded() > 0) {
for (j = 1; j <= records[i].getFieldCount(); j++) {
fld = records[i].getField(records[i].getFieldCount() - j);
// System.out.println("Adding ... " + (records[i].getFieldCount() - j)
// + " " + fld.getName());
fieldNameMap.put(fld.getName().toUpperCase(), fld);
recordFieldNameMap.put(
records[i].getRecordName() + "." + fld.getName().toUpperCase(),
fld);

}
records[i].setNumberOfFieldsAdded(0);
}
}

synchronized (this) {
int j;
IFieldDetail fld;

for (int i = 0; i < recordCount; i++) {
if (records[i].getNumberOfFieldsAdded() > 0) {
for (j = 1; j <= records[i].getFieldCount(); j++) {
fld = records[i].getField(records[i].getFieldCount() - j);
// System.out.println("Adding ... " + (records[i].getFieldCount() - j)
// + " " + fld.getName());
fieldNameMap.put(fld.getName().toUpperCase(), fld);
recordFieldNameMap.put(
records[i].getRecordName() + "." + fld.getName().toUpperCase(),
fld);

}
records[i].setNumberOfFieldsAdded(0);
}
}
}
}
}

Expand Down Expand Up @@ -1088,11 +1094,15 @@ public List<IItemDetails> getCobolItems(String cobolName) {

private void updateCobolMaps() {
if (groupMap == null) {
groupMap = new HashMap<String, List<IItemDetails>>();
groupFieldMap = new HashMap<String, List<IItemDetails>>();

for (int i = 0; i < recordCount; i++) {
records[i].updateNameCobolItemMap(groupMap, groupFieldMap);
synchronized (this) {
if (groupMap == null) {
groupMap = new HashMap<String, List<IItemDetails>>();
groupFieldMap = new HashMap<String, List<IItemDetails>>();

for (int i = 0; i < recordCount; i++) {
records[i].updateNameCobolItemMap(groupMap, groupFieldMap);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ public final int[] getFieldTypes() {
@Override
public int getDelimiterOrganisation() {
int delimiterOrganisation = ICsvDefinition.NORMAL_SPLIT;
ICsvCharLineParser parser = getParser();
ICsvCharLineParser parser = getCharParser();
if (parser != null && parser instanceof BasicCsvLineParser) {
BasicCsvLineParser bp = (BasicCsvLineParser) parser;
delimiterOrganisation = bp.delimiterOrganisation;
Expand Down Expand Up @@ -1400,32 +1400,38 @@ public ICsvByteLineParser getCsvByteParser() {
return csvByteParser;
}

public final ICsvCharLineParser getParser() {
@Override
public final ICsvCharLineParser getCharParser() {
return csvCharParser;
}

public final FieldDetail[] getArrayFields(FieldDetail field, String aname) {
if (arrays == null) {
arrays = new HashMap<String, RecordDetail.ArrayDtls>();
ArrayList<RecordDetail.ArrayDtls> arrayList = new ArrayList<RecordDetail.ArrayDtls>();
int pos;
for (int i = 0; i < fields.length; i++) {
if ((pos = fields[i].getName().indexOf('(')) > 0) {
String arrayName = fields[i].getName().substring(0, pos-1);
String id = (fields[i].getGroupName() + arrayName).toLowerCase();
ArrayDtls dtls = arrays.get(id);
if (dtls == null) {
dtls = new ArrayDtls(fields[i].getGroupName(), arrayName);
arrays.put(id, dtls);
arrayList.add(dtls);
synchronized (this) {
if (arrays == null) {
HashMap<String, RecordDetail.ArrayDtls> tmpArrays = new HashMap<String, RecordDetail.ArrayDtls>();
ArrayList<RecordDetail.ArrayDtls> arrayList = new ArrayList<RecordDetail.ArrayDtls>();
int pos;
for (int i = 0; i < fields.length; i++) {
if ((pos = fields[i].getName().indexOf('(')) > 0) {
String arrayName = fields[i].getName().substring(0, pos-1);
String id = (fields[i].getGroupName() + arrayName).toLowerCase();
ArrayDtls dtls = tmpArrays.get(id);
if (dtls == null) {
dtls = new ArrayDtls(fields[i].getGroupName(), arrayName);
tmpArrays.put(id, dtls);
arrayList.add(dtls);
}
dtls.fieldList.add(fields[i]);
}
}
dtls.fieldList.add(fields[i]);
for (RecordDetail.ArrayDtls ad : arrayList) {
ad.fields = ad.fieldList.toArray(new FieldDetail[ad.fieldList.size()]);
ad.fieldList = null;
}
arrays = tmpArrays;
}
}
for (RecordDetail.ArrayDtls ad : arrayList) {
ad.fields = ad.fieldList.toArray(new FieldDetail[ad.fieldList.size()]);
ad.fieldList = null;
}
}

RecordDetail.ArrayDtls a = arrays.get((field.getGroupName() + aname) .toLowerCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import java.util.HashMap;
import java.util.List;

import javax.xml.bind.JAXBException;

import net.sf.JRecord.JRecordInterface1;
import net.sf.JRecord.Common.Conversion;
import net.sf.JRecord.Common.RecordException;
Expand All @@ -45,9 +43,10 @@
import net.sf.JRecord.External.ExternalRecord;
import net.sf.JRecord.External.ICopybookLoaderCobol;
import net.sf.JRecord.IO.builders.CblIOBuilderMultiSchemaBase;
import net.sf.JRecord.Option.IReformatFieldNames;
import net.sf.JRecord.def.IO.builders.ISchemaIOBuilder;
import net.sf.JRecord.detailsBasic.IItemDetails;
import net.sf.JRecord.fieldNameConversion.IRenameField;
import net.sf.JRecord.schema.fieldRename.StdFieldRenameItems;
import net.sf.JRecord.schema.jaxb.ItemRecordDtls;


Expand All @@ -73,7 +72,8 @@ public class CobolSchemaReader<T> extends CblIOBuilderMultiSchemaBase<T> impleme
// private Copybook copybook = null;
//private UpdateSchemaItems itemDtls = null;

private int tagFormat = IReformatFieldNames.RO_LEAVE_ASIS;
// private int tagFormat = IReformatFieldNames.RO_LEAVE_ASIS;
private IRenameField renameFieldClass = StdFieldRenameItems.LEAVE_ASIS;

private HashMap<String, IArrayItemCheck> arrayChecks = new HashMap<String, IArrayItemCheck>();

Expand All @@ -100,7 +100,7 @@ protected void clearLayout() {
}
}

public CobolSchemaDetails getCobolSchemaDetails() throws IOException, JAXBException {
public CobolSchemaDetails getCobolSchemaDetails() throws IOException {
CobolSchemaDetails cblDtls = cobolDtls;
if (cblDtls == null) {
synchronized (this) {
Expand Down Expand Up @@ -128,7 +128,7 @@ public CobolSchemaDetails getCobolSchemaDetails() throws IOException, JAXBExcept
}
UpdateSchemaItems itemDtls = new UpdateSchemaItems(
recordItems, schema, arrayChecks,
super.isDropCopybookNameFromFields(), schema.getLayoutName(), tagFormat);
super.isDropCopybookNameFromFields(), schema.getLayoutName(), renameFieldClass);
// if (schema.getRecordCount() == 1 && recordItems.size() > 1) {
// recordItems = new ArrayList<Item>(1);
// Item recItem = new Item();
Expand Down Expand Up @@ -176,14 +176,19 @@ public final ISchemaIOBuilder asIOBuilder() {
* @see ICobolSchemaDetails#setTagFormat(int)
*/
public final T setTagFormat(int tagFormat) {
this.tagFormat = tagFormat;
return setRenameFieldClass( StdFieldRenameItems.getRenameField(tagFormat));
}

public T setRenameFieldClass(IRenameField renameFieldClass) {
this.renameFieldClass = renameFieldClass;
synchronized (this) {
this.cobolDtls = null;
}

return super.self;
}


/**
* @return the rootRecordName
*/
Expand All @@ -198,6 +203,14 @@ public final T setRootRecord(String recordName) {
return super.self;
}

public static class CblSchemaReader extends CobolSchemaReader<ICobolSchemaReader> implements ICobolSchemaReader {

public CblSchemaReader(String copybookName, ICopybookLoaderCobol loader) {
super(copybookName, loader);
}

}


/**
* Create a new <b>Extended Cobol Schema Reader</b>
Expand All @@ -219,7 +232,7 @@ public static ICobolSchemaReader newCobolSchemaReader(String cobolCopybook) {
* @return Extended Cobol Schema Reader
*/
public static ICobolSchemaReader newCobolSchemaReader(Reader cobolCopybookReader, String copybookName) {
return (new CobolSchemaReader<ICobolSchemaReader>(copybookName, new CobolCopybookLoader()))
return (new CblSchemaReader(copybookName, new CobolCopybookLoader()))
.addCopyBook(cobolCopybookReader, copybookName);
}
}
Loading

0 comments on commit 9e21a3f

Please sign in to comment.