## SDAI file format

Last update 2003-09-03

SDAI file is the compressed ZIP format file complying with the following specifications:

- Info-ZIP Application Note 970311 - a detailed description of the Info-ZIP format.
- The limitation to the above specification is that `.ZIP file comment length` field in the `end of central directory record` is equal to 0.
- ZLIB Compressed Data Format Specification version 3.3 (RFC 1950)
- DEFLATE Compressed Data Format Specification version 1.3 (RFC 1951)

SDAI file contains all binary and property files of the SdaiRepository, normally stored in the special SdaiRepository directory. The list of files that could be stored in SDAI file:

- `repository` file is used to store an information about the SdaiRepository, SdaiModels, SchemaInstances and associated SdaiModels. Only the `repository` file is mandatory in SDAI file. SdaiRepository binary file format
- `mX` files are used to store a data of the SdaiModel. There the `X` in the file name means the SdaiModel's identifier which can be obtained using the jsdai.lang.SdaiModel.getId() method. SdaiModel binary file format
- `extdata.properties` file is used to store an information about an external data of SdaiRepository instances. The persistent label of the entity instance is used as a property key and the name of the external data is stored as a property value.
- `eX` files are used to store the external data. There the `X` in the file name means the persistent label of the entity instance.

### SdaiRepository binary file format

>     sdai_repository_file :=
>         'R'         // SdaiRepository start
>         BUILD_NUMBER: integer           // build number
>         JSDAI_VERSION_MAJOR: short      // major version number
>         JSDAI_VERSION_MIDDLE: short     // middle version number
>         JSDAI_VERSION_MINOR: short      // minor version number

>         'B'
>         DESCRIPTION_COUNT: short        // count of descriptions
>         { DESCRIPTION: string }         // descriptions

>         'B'
>         NAME: string                    // SdaiRepository name
>         CHANGE_DATE: string             // SdaiRepository changed date
>         AUTHOR_COUNT: integer           // count of SdaiRepository authors
>         { AUTHOR: string }              // SdaiRepository authors
>         ORGANIZATION_COUNT: integer     // count of SdaiRepository organizations
>         { ORGANIZATION: string }        // SdaiRepository organizations
>         PREPROCESSOR_VERSION: string    // SdaiRepository preprocessor version
>         ORIGINATING_SYSTEM: string      // SdaiRepository originating system
>         AUTHORIZATION: string           // SdaiRepository authorization

>         'B'
>         0: short                        // RESERVED

>         'B'
>         [ 'L' DEFAUL_LANGUAGE: string ] // default/general language
>         [ 'C'
>             CONTEXT_COUNT: short        // count of contexts names
>             { CONTEXT: string }         // contexts names
>         ]
>         'I'
>         LARGEST_PERSISTENT_LABEL: long  // largest persistent label

>         'S'         // section of schema names
>         SCHEMA_COUNT: short             // count of schema
>         { SCHEMA_NAME: string }         // schema names

>         'S'         // section of SdaiModels
>         SDAI_MODEL_COUNT: integer       // count of SdaiModels
>         SDAI_MODEL_COUNT: short         // count of SdaiModels
>         { SDAI_MODEL: sdai_model_definition }   // SdaiModels

>         'S'         // section of SchemaInstances
>         SCHEMA__INSTANCE_COUNT: short   // count of SchemaInstances
>         { SCHEMA_INSTANCE: schema_instance_definition }  // SchemaInstances
>         'E'         // SdaiRepository end

>     sdai_model_definition :=
>         'B'         // SdaiModel start
>         NAME: string                            // name of SdaiModel
>         ID: integer                             // identifier of SdaiModel
>         UNDERLYING_SCHEMA_INDEX: short          // index of underlying schema
>         'D'
>         CHANGE_DATE: string                     // change date
>         [ 'L' DEFAULT_LANGUAGE: string ]        // default language
>         [ 'C'
>         CONTEXT_COUNT: short                    // count of contexts
>         { CONTEXT: string }                     // contexts
>         ]

>     schema_instance_definition :=
>         'B'         // SchemaInstance start
>         NAME: string                            // name of SchemaInstance
>         NATIVE_SCHEMA_INDEX: short              // index of native schema
>         'D'
>         CHANGE_DATE: string                     // change date
>         VALIDATION_DATE: string                 // validation date
>         VALIDATION_RESULT: byte                 // validation result: true, false
>         VALIDATION_LEVEL: short                 // validation level
>         DESCRIPTION_COUNT: short                // count of descriptions
>         { DESCRIPTION }: string                 // descriptions
>         AUTHOR_COUNT: short                     // count of authors
>         { AUTHOR }: string                      // authors
>         ORGANIZATION_COUNT: short               // count of organizations
>         { ORGANIZATION }: string                // organizations
>         [ 'P' PREPROCESSOR_VERSION: string ]    // preprocessor version
>         [ 'O' ORIGINATING_SYSTEM: string ]      // originating system
>         [ 'A' AUTHORIZATION: string ]           // authorization
>         [ 'L' LANGUAGE: string ]                // language
>         'C'
>         CONTEXT_COUNT: short                    // count of contexts
>         { CONTEXT }: string                     // contexts
>         ASSOCIATED_SDAI_MODEL_COUNT: short      // count of associated SdaiModels
>         { ASSCOCIATED_SDAI_MODEL: associated_sdai_model_definition }  // associated SdaiModels

>     associated_sdai_model_definition :=
>         ( 'L' INDEX: integer            // index of SdaiModel
>         | NAME: string                  // name of SdaiModel
>           SDAI_REPOSITORY_NAME: string  // name of SdaiRepository
>         }

### SdaiModel binary file format

>     sdai_model_file :=
>         'D'        // SdaiModel start
>         BUILD_NUMBER: integer        // build number
>         INSTANCE_COUNT: long         // count of instances in this SdaiModel
>         { PERSISTENT_LABEL: long }   // persistent labels (sorted in increasing order) of instances of this SdaiModel

>         'S'
>         DEFINED_TYPE_COUNT: short       // count of defined data types which do not have an immediate underlying select data type
>         { DEFINED_TYPE_NAME: string }   // names of the defined data types

>         'S'
>         ENTITY_TYPE_COUNT: short        // count of entity data types
>         { ENTITY_TYPE: entity_type_definition } // entity data types in upper case, sorted alphabetically

>         'S'
>         POPULATED_COMPLEX_TYPE_COUNT: short  // count of populated complex entity data types, even those with only one entity data type
>         { COMPLEX_ENTITY_INSTANCE: complex_entity_instance_definition } // complex entity instances sorted lexicographically
>         { ENTITY_INSTANCE_VALUE: entity_instance_value_definition }     // entity instance sorted by persistent label
>         'E'        // SdaiModel end

>     entity_type_definition :=
>         ENTITY_TYPE_NAME: string            // entity data type name from dictionary
>         EXPLICIT_ATTRIBUTE_COUNT: short     // count of all non-redeclaring explicit attributes of this entity data type, but not of it's supertypes
>                                             // the order is as defined in express. It can be used as index 0, 1, 2...
>         { EXPLICIT_ATTRIBUTE_NAME: string } // explicit attribute names
>         SUPERTYPE_COUNT: short              // count of supertypes
>         { SUPERTYPE_INDEX: short }          // index of supertypes

>     complex_entity_instance_definition :=
>         ENTITY_TYPE_COUNT: short            // count of leave entity data types
>         { ENTITY_TYPE_INDEX: short }        // indexes of all leave entity data types in upper case, sorted alphabetically
>         INSTANCE_COUNT: long 		        // count of instances
>         { PERSISTENT_LABEL: long } ;        // persistent labels (sorted in increasing order)

>     entity_instance_value_definition :=
>         'c'        // start-indication
>         COMPLEX_TYPE_INDEX: short           // index to complex entity type
>         { VALUE: value_definition }         // values for all attributes in single entity data types sorted in given order above (composing)
>         [{ AIM2ARM_LINK: aim2arm_link_definition }]  // AIM to ARM links

>     value_definition :=  // value of a single attribute
>         ( '$' // MISSING, UNSET
>         | '*' // REDEFINED
>         | 'u' // UNKNOWN
>         | 't' // TRUE
>         | 'f' // FALSE
>         | 'r' VALUE: double       // Real value
>         | 'i' VALUE: integer      // Integer value
>         | 's' VALUE: string       // String value
>         | 'b' VALUE: string       // Binary value
>         | 'B' // Binary value
>               BINARY_LENGTH := long
>               BINARY_UNUSED := byte
>               {BINARY_BYTES := byte ^ 0x80}
>         | 'e' VALUE: string       // Enumeration value definition
>         | 'p' VALUE: short        // index to typed parameters needed for values of select data types, recursive definition
>         | ( '1'         // instance-ref inside this SdaiModel
>             POPULATED_COMPLEX_ENTITY_INDEX: short      // index of populated complex entity type
>             INSTANCE_INDEX: integer                    // instance index
>           )
>         | ( '2'         // instance reference inside this SdaiRepository with SdaiModel name
>             SDAI_MODEL_NAME: string                    // SdaiModel name
>             ENTITY_TYPE: entity_type_reference         // entity type
>             PERSISTENT_LABEL: long                     // persistent label
>           )
>         | ( '3'         // instance reference inside this SdaiRepository with SdaiModel index
>             SDAI_MODEL_INDEX: short                    // SdaiModel index
>             ENTITY_TYPE: entity_type_reference         // entity type
>             PERSISTENT_LABEL: long                     // persistent label
>           )
>         | ( '4'         // instance reference with SdaiRepository name and SdaiModel name
>             SDAI_REPOSITORY_NAME: string               // SdaiRepository name
>             SDAI_MODEL_NAME: string                    // SdaiModel name
>             ENTITY_TYPE: entity_type_reference         // entity type
>             PERSISTENT_LABEL: long                     // persistent label
>           )
>         | ( '5'         // instance reference with SdaiRepository index and SdaiModel name
>             SDAI_REPOSITORY_INDEX: short               // SdaiRepository index
>             SDAI_MODEL_NAME: string                    // SdaiModel name
>             ENTITY_TYPE: entity_type_reference         // entity type
>             PERSISTENT_LABEL: long                     // persistent label
>           )
>         | ( '6'         // instance reference with SdaiRepository index and SdaiModel index
>             SDAI_REPOSITORY_INDEX: short              // SdaiRepository index
>             SDAI_MODEL_INDEX: short                   // SdaiModel index
>             ENTITY_TYPE: entity_type_reference        // entity type
>             PERSISTENT_LABEL: long                    // persistent label
>           )
>        | '(' { value } ')' // for all aggregates, starting with first member or valid index position
>        )

>     entity_type_reference :=
>         (
>           ( '1' // types from the current data dictionary are used
>            POPULATED_COMPLEX_ENTITY_INDEX: short // index of populated complex entity type
>           )
>         | ( '2' // type is not found in the current data dictionary
>            POPULATED_COMPLEX_ENTITY_NAME: string // name of populated complex entity type
>           )
>         | ( '3' // type is not found in the current data dictionary
>            POPULATED_COMPLEX_ENTITY_INDEX: short // index of populated complex entity type
>           )
>         )

>     aim2arm_link_definition :=
>         ( 'l'
>            SDAI_REPOSITORY_NAME: string  // ARM SdaiRepository name (empty string "" indicates current SdaiRepository)
>            SDAI_MODEL_NAME: string       // ARM SdaiModel name
>            PERSISTENT_LABEL: long        // ARM instance persistent label
>         )
>         | ( 'k'
>            SDAI_MODEL_INDEX: short       // ARM SdaiModel index
>            PERSISTENT_LABEL: long        // ARM instance persistent label
>         )