Axaptapedia is now maintained by AgileCadence For more information please click here.
Common Packable
Here is a Class for packing record information into a container. Once packed the record data may be saved to a table field of type Container for instance.
\Classes\Common_Packable\classDeclaration <xpp> class Common_Packable implements SysPackable {
Common common; container packedCommon;
TableId tableId; RecId recId;
#define.CurrentVersion(1) #localMacro.CurrentList tableId, recId, packedCommon #endMacro
} </xpp>
\Classes\Common_Packable\fields <xpp> private Map fields(SysDictTable _sysDictTable) {
SysDictField sysDictField; SysDictField sysDictFieldArray; Map fieldsMap = new Map(Types::Integer, Types::Container); Container con; int cnt; int i; int j;
// // Include fields // cnt = _sysDictTable.fieldCnt(); for (i = 1; i <= cnt; i++) { sysDictField = new SysDictField(tableId, _sysDictTable.fieldCnt2Id(i));
// // Include each array field separately // for (j = 1; j <= sysDictField.arraySize(); j++) { sysDictFieldArray = new SysDictField(tableId, _sysDictTable.fieldCnt2Id(i), j); con = [ fieldid2name(tableId, sysDictFieldArray.id()) ]; fieldsMap.insert(sysDictFieldArray.id(), con); } } return fieldsMap;
} </xpp>
\Classes\Common_Packable\init <xpp> public void init() {
;
tableId = common.TableId; recId = common.RecId;
} </xpp>
\Classes\Common_Packable\pack <xpp> public container pack() {
; this.packCommon(); return [#CurrentVersion, #CurrentList];
} </xpp>
\Classes\Common_Packable\packCommon <xpp> private void packCommon() {
container fieldInfo; container recordInfo; ;
tableId = common.TableId; recId = common.RecId;
fieldInfo = this.packFieldInfo(); recordInfo = this.packRecordInfo();
packedCommon = [fieldInfo, recordInfo];
} </xpp>
\Classes\Common_Packable\packFieldInfo <xpp> private container packFieldInfo() {
container fieldInfo; ;
if (tableId) { fieldInfo = this.fields(SysDictTable::newTableId(tableId)).pack(); }
return fieldInfo;
} </xpp>
\Classes\Common_Packable\packRecordInfo <xpp> private container packRecordInfo() {
SysDictField sysDictField; Map recordMap; MapEnumerator me; container recordInfo; ;
if (tableId) { recordMap = new Map(Types::Integer, Types::Container); me = this.fields(SysDictTable::newTableId(tableId)).getEnumerator(); while (me.moveNext()) { sysDictField = new SysDictField(tableId, me.currentKey()); recordMap.insert(sysDictField.id(), [common.(sysDictField.id())]); } recordInfo = recordMap.pack(); }
return recordInfo;
} </xpp>
\Classes\Common_Packable\parmCommon <xpp> public Common parmCommon(Common _common = common) {
; common = _common; return common;
} </xpp>
\Classes\Common_Packable\unpack <xpp> public boolean unpack(container packedClass) {
Integer _version = conpeek(packedClass,1); ;
switch (_version) { case #CurrentVersion: { [_version,#CurrentList] = packedClass; this.unpackCommon(); break; } default : return false; }
return true;
} </xpp>
\Classes\Common_Packable\unpackCommon
<xpp> private void unpackCommon() {
DictTable dictTable = new DictTable(tableId); SysDictField sysDictField; Map recordMap; MapEnumerator me; container fieldInfo; container recordInfo; int i; ;
if (!dictTable) return;
common = dictTable.makeRecord();
[fieldInfo, recordInfo] = packedCommon;
recordMap = Map::create(recordInfo); me = Map::create(fieldInfo).getEnumerator(); while (me.moveNext()) { sysDictField = new SysDictField(tableId, me.currentKey()); common.(sysDictField.id()) = conPeek(recordMap.lookup(sysDictField.id()), 1); }
} </xpp>
\Classes\Common_Packable\create <xpp> public static Common_Packable create(container _packedContainer) {
Common_Packable common_Packable = new Common_Packable(); ; common_Packable.unpack(_packedContainer); common_Packable.init();
return common_Packable;
} </xpp>
\Classes\Common_Packable\createCommon <xpp> public static Common_Packable createCommon(Common _common) {
Common_Packable common_Packable = new Common_Packable(); ; common_Packable.parmCommon(_common); common_Packable.init();
return common_Packable;
} </xpp>