Skip to content

Creating Structures

Structures are programmatically created in sdmx-core using the Mutable Bean, and then converted into an immutable instance.

CodelistMutableBean clMutable = new CodelistMutableBeanImpl();
clMutable.setAgencyId("BIS");
clMutable.setId("CL_FREQ");
clMutable.setVersion("1.0");
clMutable.addName("en", "Frequency Codelist");
clMutable.createItem("A", "Annual");
clMutable.createItem("M", "Monthly");
clMutable.createItem("Q", "Quarterly");

//Create a validated immutable copy
CodelistBean cl = clMutable.getImmutableInstance();

For test purposes, the sdmx-core framework provides static helper classes for each structure type, starting with the prefix Test.

CodelistBean cl = TestCodelistUtil.generateCodelist("BIS", "CL_FREQ", "1.0", "A", "M", "Q");

In addition, the sdmx-core framework provides a higher-level 'Test Instance' class for each structure type, which provides pre-packaged structures

CodelistBean cl = TestCodelistInstances.getFREQ("BIS", "1.0");

Editing Structures

Structures are edited by converting the bean back into the mutable counterpart, modifying, and then converting back into the immutable instance

CodelistBean cl = TestCodelistUtil.generateCodelist("BIS", "CL_FREQ", "1.0", "A", "M", "Q");
CodelistMutableBean clMut = cl.getMutableInstance();

clMut.addDescription("en", "An English Description");

cl = clMut.getImmutableInstance();