sandflow / regxmllib

Convert MXF to XML: RegXML (SMPTE ST 2001-1) tools and libraries
BSD 2-Clause "Simplified" License
35 stars 14 forks source link

Do not throw exception when importing a bad enum #120

Closed palemieux closed 6 years ago

palemieux commented 6 years ago

Closes #119

thomasheritage commented 6 years ago

In this code, when creating dictionaries from Registers, the only "Enumeration" Types that are included in the output dictionaries are those with an "approved" BaseType. All others are simply omitted from the output dictionary. This is regardless of whether the Type has any Facets or not.

This means that dictionaries are created in which some PropertyDefinitions reference non-existent TypeDefinitions. When regxmllib is used to generate schemas from these dictionaries an exception is thrown. I've not tested what happens if you try to process an MXF file using these dictionaries (although presumably that's OK as that issue would have shown-up in the regxmllib test suite).

Either:

  1. "Invalid" dictionaries should not be generated. To achieve this any references to the affected Types would need to be removed (can you leave "Type" unspecified for affected Properties?)
  2. regxmllib should be able to handle "invalid" dictionaries.

(Note: perhaps "incomplete" would be more accurate here than "invalid"?)

This situation affects even currently "published" Registers. This is because they contain some Enumeration Types with a BaseType of "ISO7" (which is a string). These were not found earlier because none of these Types specify any Facets and therefore they have never caused any problems.

On a related note: this suggests that conversion of dictionaries to schemas is not included in the regxmllib test suite -- perhaps it should be added?

palemieux commented 6 years ago

regxmllib should be able to handle "invalid" dictionaries.

Well, let's figure out how to actually support ISO7 enumerations, and regxmllib will support them.

palemieux commented 6 years ago

@thomasheritage For enumeration, ST 2001-1 states:

Elements: specifies the name, value and description associated with each enumerated value. Each value is a positive integer value. Each name and value is unique within the enumeration type definition. The description is optional and may be omitted.

Why couldn't ISO7 enumerations be turned into byte enumerations?

thomasheritage commented 6 years ago

To clarify:

1) As this code stands, dictionaries are produced from the "published" Registers which cause regxmllib to raise an Exception when trying to convert these dictionaries to XML Schemas:

Exception in thread "main" com.sandflow.smpte.regxml.XMLSchemaBuilder$RuleException: Type UL does not resolve at Element urn:smpte:ul:060e2b34.01010103.02300501.02000000
        at com.sandflow.smpte.regxml.XMLSchemaBuilder.applyRule5(XMLSchemaBuilder.java:416)
        at com.sandflow.smpte.regxml.XMLSchemaBuilder.fromDictionary(XMLSchemaBuilder.java:291)
        at com.sandflow.smpte.tools.GenerateDictionaryXMLSchema.main(GenerateDictionaryXMLSchema.java:173)

2) To resolve the above, I suggest that either regxmllib should be tolerant of unresolved Type references within dictionaries, or dictionaries should be "pruned" during generation such that no unresolved Type references exist.

3) To guard against this happening in the future I suggest adding XML Schema generation to the regxmllib test suite.

palemieux commented 6 years ago

@thomasheritage Thanks for the detailed report. This is a bug. Will fix.

palemieux commented 6 years ago

@thomasheritage Please review updated pull request. Elements referencing undefined types are now pruned. XSD generation tests have been added.

thomasheritage commented 6 years ago

I've tested this. All looks good. This should now be ready for merging.