expressir 2.4.39 → 2.4.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/TODO.eengine/01-resolution-diagnostics.md +6 -0
  3. data/TODO.eengine/03-entity-computations.md +6 -0
  4. data/TODO.eengine/04-shtolo-rule-audit.md +6 -0
  5. data/TODO.eengine/05-shtolo-longform-flatten.md +7 -0
  6. data/TODO.eengine/08-official-corpus-gate.md +7 -0
  7. data/TODO.eengine/09-mim-mapping-parser.md +7 -0
  8. data/TODO.max-perf/01-restore-ci-green.md +4 -0
  9. data/TODO.max-perf/02-streaming-parse-path.md +4 -0
  10. data/TODO.max-perf/03-cli-parallel-opt-in.md +4 -0
  11. data/TODO.max-perf/04-benchmark-harness.md +4 -0
  12. data/TODO.max-perf/05-parallel-fidelity-specs.md +4 -0
  13. data/TODO.max-perf/06-builder-cpu-audit.md +4 -0
  14. data/TODO.max-perf/07-upstream-parsanol-roadmap.md +4 -0
  15. data/TODO.max-perf/08-builder-build-perf.md +4 -0
  16. data/TODO.max-perf/09-grammar-cold-start.md +4 -0
  17. data/TODO.max-perf/10-parser-facade-hygiene.md +4 -0
  18. data/TODO.max-perf/11-ci-green-closeout.md +4 -0
  19. data/TODO.max-perf/12-require-boot-profile.md +12 -0
  20. data/TODO.max-perf/13-key-conversion-specs.md +11 -0
  21. data/TODO.max-perf/14-builder-call-handler-audit.md +14 -0
  22. data/TODO.p28/00-overview.md +37 -0
  23. data/TODO.p28/01-uos-writer.md +54 -0
  24. data/TODO.p28/02-uos-reader.md +50 -0
  25. data/TODO.p28/03-default-xsd.md +68 -0
  26. data/TODO.p28/04-document-envelope.md +62 -0
  27. data/TODO.sota/02-evaluator.md +0 -1
  28. data/lib/expressir/p28/document.rb +138 -0
  29. data/lib/expressir/p28/uos.rb +452 -0
  30. data/lib/expressir/p28/xsd.rb +526 -0
  31. data/lib/expressir/p28.rb +29 -0
  32. data/lib/expressir/version.rb +1 -1
  33. data/lib/expressir.rb +1 -0
  34. metadata +10 -1
@@ -0,0 +1,526 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Expressir
4
+ module P28
5
+ # The default-binding derived XML schema (TODO.p28/03): an EXPRESS
6
+ # schema rendered per ISO 10303-28:2007 clause 7 so that clause 9
7
+ # instance documents (P28::Uos.emit) validate against it.
8
+ #
9
+ # Normative anchors, per rule:
10
+ # - 7.7/7.7.3: one xs:schema with targetNamespace; xmlns for the
11
+ # target namespace, xs and the Base XML Schema; if present,
12
+ # elementFormDefault/attributeFormDefault shall be "unqualified"
13
+ # — which is what makes the clause 9 instance shape (qualified
14
+ # instance elements, unqualified accessors) validate.
15
+ # - 7.7.4: xs:import for the Base XML Schema (exp:) and for each
16
+ # interfaced schema.
17
+ # - 7.1.2: identifiers map with the initial letter upper case and
18
+ # all other letters lower case.
19
+ # - 7.2: BINARY → exp:hexBinary (base-schema complexType with
20
+ # extraBits), the other simple types per 7.2.1.
21
+ # - 7.3: defined types → named simpleType/complexType per the
22
+ # underlying type; enumerations keep their EXPRESS item texts.
23
+ # - 7.6.2: explicit attributes only — DERIVEd and INVERSE
24
+ # attributes are not mapped.
25
+ # - 7.6.4: the entity complexType extends exp:Entity, holds the
26
+ # accessor declarations of the whole supertype closure (union,
27
+ # redeclarations winning) inside xs:all, and is abstract when
28
+ # the entity is ABSTRACT.
29
+ # - 7.6.5/7.5.3: one global instance element per entity, in the
30
+ # substitution group headed by exp:Entity.
31
+ # - 7.8: a context-schema specific uos element declaration.
32
+ #
33
+ # v1 boundary, stated: constrained widths/precisions do not emit
34
+ # facet restrictions; SELECT accessors map their declared members
35
+ # as a choice (the full 7.4 select machinery, including
36
+ # extensible-select fallbacks, is future work); cross-schema
37
+ # supertypes raise rather than silently dropping attributes.
38
+ module Xsd
39
+ XS = "http://www.w3.org/2001/XMLSchema"
40
+
41
+ module_function
42
+
43
+ # The Base XML Schema (annex C) components the default binding
44
+ # relies on, emitted from the normative snippets in clause 7
45
+ # (7.5.3.1 exp:Entity, 7.2.1.1 exp:hexBinary) and the logical
46
+ # value domain of 9.5.4.
47
+ def base_schema
48
+ <<~XSD
49
+ <xs:schema xmlns:xs="#{XS}"
50
+ targetNamespace="#{COMMON_NS}"
51
+ xmlns:exp="#{COMMON_NS}"
52
+ elementFormDefault="qualified"
53
+ attributeFormDefault="unqualified">
54
+ <xs:attributeGroup name="instanceAttributes">
55
+ <xs:attribute name="id" type="xs:ID" use="optional"/>
56
+ </xs:attributeGroup>
57
+ <xs:complexType name="Entity" abstract="true">
58
+ <xs:attribute name="href" type="xs:anyURI" use="optional"/>
59
+ <xs:attribute name="ref" type="xs:IDREF" use="optional"/>
60
+ <xs:attribute name="proxy" type="xs:IDREF" use="optional"/>
61
+ <xs:attribute name="edo" type="xs:anyURI" use="optional"/>
62
+ <xs:attributeGroup ref="exp:instanceAttributes"/>
63
+ </xs:complexType>
64
+ <xs:element name="Entity" type="exp:Entity" abstract="true"/>
65
+ <xs:complexType name="hexBinary">
66
+ <xs:simpleContent>
67
+ <xs:extension base="xs:hexBinary">
68
+ <xs:attribute name="extraBits" type="xs:integer"
69
+ use="optional"/>
70
+ </xs:extension>
71
+ </xs:simpleContent>
72
+ </xs:complexType>
73
+ <xs:simpleType name="logical">
74
+ <xs:restriction base="xs:string">
75
+ <xs:enumeration value="true"/>
76
+ <xs:enumeration value="false"/>
77
+ <xs:enumeration value="unknown"/>
78
+ </xs:restriction>
79
+ </xs:simpleType>
80
+ <xs:complexType name="complexEntity">
81
+ <xs:sequence>
82
+ <xs:any namespace="##other" processContents="lax"
83
+ maxOccurs="unbounded"/>
84
+ </xs:sequence>
85
+ <xs:attributeGroup ref="exp:instanceAttributes"/>
86
+ </xs:complexType>
87
+ <xs:element name="complexEntity" type="exp:complexEntity"/>
88
+ <xs:complexType name="uos" abstract="true">
89
+ <xs:attribute name="id" type="xs:ID" use="optional"/>
90
+ <xs:attribute name="express" type="xs:string"
91
+ use="optional"/>
92
+ <xs:attribute name="edo" type="xs:anyURI" use="optional"/>
93
+ </xs:complexType>
94
+ <xs:element name="uos" type="exp:uos" abstract="true"/>
95
+ <xs:element name="edokey" type="exp:Entity"/>
96
+ </xs:schema>
97
+ XSD
98
+ end
99
+
100
+ # @param schema [Model::Declarations::Schema]
101
+ # @param target_namespace [String] the 7.7.2 namespace URI
102
+ # @param prefix [String] the preprocessor-chosen target-namespace
103
+ # prefix (7.7.1)
104
+ # @return [String] the serialized derived XML schema
105
+ def format(schema, target_namespace: P28.default_target_namespace(schema.id),
106
+ prefix: Uos.default_prefix(schema),
107
+ base_schema_location: "iso-10303-28-base.xsd",
108
+ inline_base: false)
109
+ ctx = Moxml::Context.new
110
+ doc = ctx.create_document
111
+ root = doc.create_element("xs:schema")
112
+ root.set_attributes(
113
+ "targetNamespace" => target_namespace,
114
+ "xmlns:#{prefix}" => target_namespace,
115
+ "xmlns:xs" => XS,
116
+ "xmlns:exp" => COMMON_NS,
117
+ "elementFormDefault" => "unqualified",
118
+ "attributeFormDefault" => "unqualified",
119
+ )
120
+ doc.add_child(root)
121
+ # inline_base: toolchains that cannot resolve xs:import from
122
+ # an in-memory compilation get the base components inlined
123
+ # (same content, local names); the default emits the
124
+ # normative 7.7.4 import.
125
+ if inline_base
126
+ inline_base_components(doc, prefix)
127
+ else
128
+ root.add_child(import_node(doc, COMMON_NS, base_schema_location))
129
+ end
130
+ schema.types.to_a.each do |type|
131
+ node = defined_type_node(doc, schema, prefix, type, inline_base)
132
+ root.add_child(node) if node
133
+ end
134
+ schema.entities.to_a.each do |entity|
135
+ root.add_child(entity_type_node(doc, schema, prefix, entity,
136
+ inline_base))
137
+ root.add_child(entity_element_node(doc, prefix, entity, inline_base))
138
+ end
139
+ uos_node(doc, schema, prefix, inline_base).each do |node|
140
+ root.add_child(node)
141
+ end
142
+ doc.to_xml
143
+ end
144
+
145
+ # exp: in the normative import form; the target-namespace
146
+ # prefix when inlined — an unprefixed QName in a schema with a
147
+ # targetNamespace resolves to the empty namespace (XSD QName
148
+ # rules), which stricter engines reject at compile time.
149
+ def exp_name(name, inline, prefix = "exp")
150
+ inline ? "#{prefix}:#{name}" : "exp:#{name}"
151
+ end
152
+
153
+ def inline_base_components(doc, prefix)
154
+ root = doc.root
155
+ group = doc.create_element("xs:attributeGroup")
156
+ group.set_attributes("name" => "instanceAttributes")
157
+ id_attr = doc.create_element("xs:attribute")
158
+ id_attr.set_attributes("name" => "id", "type" => "xs:ID",
159
+ "use" => "optional")
160
+ group.add_child(id_attr)
161
+ root.add_child(group)
162
+ entity = doc.create_element("xs:complexType")
163
+ entity.set_attributes("name" => "Entity", "abstract" => "true")
164
+ { "href" => "xs:anyURI", "ref" => "xs:IDREF",
165
+ "proxy" => "xs:IDREF", "edo" => "xs:anyURI" }.each do |name, type|
166
+ attr = doc.create_element("xs:attribute")
167
+ attr.set_attributes("name" => name, "type" => type,
168
+ "use" => "optional")
169
+ entity.add_child(attr)
170
+ end
171
+ group_ref = doc.create_element("xs:attributeGroup")
172
+ group_ref.set_attributes("ref" => exp_name("instanceAttributes", true,
173
+ prefix))
174
+ entity.add_child(group_ref)
175
+ root.add_child(entity)
176
+ entity_el = doc.create_element("xs:element")
177
+ entity_el.set_attributes(
178
+ "name" => "Entity", "type" => exp_name("Entity", true, prefix),
179
+ "abstract" => "true"
180
+ )
181
+ root.add_child(entity_el)
182
+ hex = doc.create_element("xs:complexType")
183
+ hex.set_attributes("name" => "hexBinary")
184
+ content = doc.create_element("xs:simpleContent")
185
+ extension = doc.create_element("xs:extension")
186
+ extension.set_attributes("base" => "xs:hexBinary")
187
+ extra = doc.create_element("xs:attribute")
188
+ extra.set_attributes("name" => "extraBits", "type" => "xs:integer",
189
+ "use" => "optional")
190
+ extension.add_child(extra)
191
+ content.add_child(extension)
192
+ hex.add_child(content)
193
+ root.add_child(hex)
194
+ logical = doc.create_element("xs:simpleType")
195
+ logical.set_attributes("name" => "logical")
196
+ restriction = doc.create_element("xs:restriction")
197
+ restriction.set_attributes("base" => "xs:string")
198
+ %w[true false unknown].each do |value|
199
+ facet = doc.create_element("xs:enumeration")
200
+ facet.set_attributes("value" => value)
201
+ restriction.add_child(facet)
202
+ end
203
+ logical.add_child(restriction)
204
+ root.add_child(logical)
205
+ complex = doc.create_element("xs:complexType")
206
+ complex.set_attributes("name" => "complexEntity")
207
+ seq = doc.create_element("xs:sequence")
208
+ any = doc.create_element("xs:any")
209
+ any.set_attributes("namespace" => "##targetNamespace",
210
+ "processContents" => "lax",
211
+ "maxOccurs" => "unbounded")
212
+ seq.add_child(any)
213
+ complex.add_child(seq)
214
+ group_ref2 = doc.create_element("xs:attributeGroup")
215
+ group_ref2.set_attributes("ref" => exp_name("instanceAttributes", true,
216
+ prefix))
217
+ complex.add_child(group_ref2)
218
+ root.add_child(complex)
219
+ complex_el = doc.create_element("xs:element")
220
+ complex_el.set_attributes(
221
+ "name" => "complexEntity",
222
+ "type" => exp_name("complexEntity", true, prefix),
223
+ )
224
+ root.add_child(complex_el)
225
+ # distinct name: the derived schema declares its own uos type
226
+ # extending this carrier, so a second global "uos" here would
227
+ # be a duplicate declaration
228
+ uos_type = doc.create_element("xs:complexType")
229
+ uos_type.set_attributes("name" => "uos_base", "abstract" => "true")
230
+ %w[id express edo].zip(%w[xs:ID xs:string xs:anyURI])
231
+ .each do |(name, type)|
232
+ attr = doc.create_element("xs:attribute")
233
+ attr.set_attributes("name" => name, "type" => type,
234
+ "use" => "optional")
235
+ uos_type.add_child(attr)
236
+ end
237
+ root.add_child(uos_type)
238
+ uos_el = doc.create_element("xs:element")
239
+ uos_el.set_attributes("name" => "uos_base", "type" => "uos_base",
240
+ "abstract" => "true")
241
+ root.add_child(uos_el)
242
+ edokey = doc.create_element("xs:element")
243
+ edokey.set_attributes("name" => "edokey",
244
+ "type" => exp_name("Entity", true, prefix))
245
+ root.add_child(edokey)
246
+ end
247
+
248
+ def import_node(doc, namespace, location)
249
+ node = doc.create_element("xs:import")
250
+ node.set_attributes("namespace" => namespace,
251
+ "schemaLocation" => location)
252
+ node
253
+ end
254
+
255
+ # 7.1.2 identifier mapping.
256
+ def mapped(express_id)
257
+ express_id.to_s.sub(/\A./, &:upcase)
258
+ end
259
+
260
+ # 7.3: defined types over simple/enum/aggregates.
261
+ def defined_type_node(doc, schema, prefix, type, inline)
262
+ underlying = type.underlying_type
263
+ case kind_of(schema, underlying)
264
+ when :enumeration
265
+ simple_type_node(doc, prefix, type.id, "xs:string") do |restriction|
266
+ underlying.items.to_a.each do |item|
267
+ facet = doc.create_element("xs:enumeration")
268
+ facet.set_attributes("value" => item.id.to_s)
269
+ restriction.add_child(facet)
270
+ end
271
+ end
272
+ when :simple
273
+ simple_type_node(doc, prefix, type.id,
274
+ simple_type_name(schema, underlying, inline))
275
+ when :aggregate
276
+ list_type_node(doc, schema, prefix, type.id, underlying, inline)
277
+ end
278
+ end
279
+
280
+ def simple_type_node(doc, _prefix, express_id, base)
281
+ node = doc.create_element("xs:simpleType")
282
+ node.set_attributes("name" => mapped(express_id))
283
+ restriction = doc.create_element("xs:restriction")
284
+ restriction.set_attributes("base" => base)
285
+ node.add_child(restriction)
286
+ if block_given?
287
+ yield restriction
288
+ end
289
+ node
290
+ end
291
+
292
+ # 7.3.2/8.2.2.3: aggregates of simple base types derive from
293
+ # xs:list over the base's item type.
294
+ def list_type_node(doc, schema, _prefix, express_id, aggregate, inline)
295
+ node = doc.create_element("xs:simpleType")
296
+ node.set_attributes("name" => mapped(express_id))
297
+ list = doc.create_element("xs:list")
298
+ base = aggregate.base_type
299
+ list.set_attributes("itemType" => simple_type_name(schema, base, inline))
300
+ node.add_child(list)
301
+ node
302
+ end
303
+
304
+ # 7.6.4: extension of exp:Entity, xs:all over the closure
305
+ # union, abstract per ABSTRACT SUPERTYPE.
306
+ def entity_type_node(doc, schema, prefix, entity, inline)
307
+ node = doc.create_element("xs:complexType")
308
+ node.set_attributes("name" => mapped(entity.id))
309
+ node.set_attributes("abstract" => "true") if entity.abstract
310
+ content = doc.create_element("xs:complexContent")
311
+ extension = doc.create_element("xs:extension")
312
+ extension.set_attributes("base" => exp_name("Entity", inline, prefix))
313
+ all_node = doc.create_element("xs:all")
314
+ closure_attributes(entity).each do |attribute|
315
+ accessor = accessor_node(doc, schema, prefix, attribute, inline)
316
+ all_node.add_child(accessor) if accessor
317
+ end
318
+ extension.add_child(all_node)
319
+ content.add_child(extension)
320
+ node.add_child(content)
321
+ node
322
+ end
323
+
324
+ # 7.6.5: the global instance element, in the exp:Entity
325
+ # substitution group.
326
+ def entity_element_node(doc, prefix, entity, inline)
327
+ node = doc.create_element("xs:element")
328
+ node.set_attributes(
329
+ "name" => mapped(entity.id),
330
+ "type" => "#{prefix}:#{mapped(entity.id)}",
331
+ "substitutionGroup" => exp_name("Entity", inline, prefix),
332
+ )
333
+ node
334
+ end
335
+
336
+ # 7.6.3: one accessor element per mapped attribute; OPTIONAL
337
+ # attributes are minOccurs="0"; aggregates carry their
338
+ # occurrence bounds.
339
+ def accessor_node(doc, schema, prefix, attribute, inline)
340
+ type = attribute.type
341
+ optional = attribute.respond_to?(:optional) && attribute.optional
342
+ kind = kind_of(schema, type)
343
+ node = doc.create_element("xs:element")
344
+ node.set_attributes("name" => mapped(attribute.id))
345
+ node.set_attributes("minOccurs" => "0") if optional
346
+ case kind
347
+ when :entity
348
+ target = entity_id_of(schema, type)
349
+ node.set_attributes("type" => "#{prefix}:#{mapped(target)}")
350
+ when :entity_aggregate
351
+ node.add_child(aggregate_content_node(doc, schema, prefix, type))
352
+ when :aggregate
353
+ node.add_child(inline_list_node(doc, schema, type, inline))
354
+ when :select
355
+ raise Expressir::Error,
356
+ "SELECT accessor '#{attribute.id}' is outside the v1 " \
357
+ "default derivation (TODO.p28/03 boundary)"
358
+ else
359
+ node.set_attributes("type" => simple_type_name(schema, type, inline))
360
+ end
361
+ node
362
+ end
363
+
364
+ # An aggregate declared directly on the attribute (no defined
365
+ # TYPE): an inline xs:list over the base item type.
366
+ def inline_list_node(doc, schema, aggregate, inline)
367
+ base = aggregate.base_type
368
+ node = doc.create_element("xs:simpleType")
369
+ list = doc.create_element("xs:list")
370
+ list.set_attributes("itemType" => simple_type_name(schema, base, inline))
371
+ node.add_child(list)
372
+ node
373
+ end
374
+
375
+ # Aggregates of entity base: the accessor wraps unqualified
376
+ # component elements typed by the component entity (9.2.6.1
377
+ # worked example shape).
378
+ def aggregate_content_node(doc, schema, prefix, aggregate)
379
+ base = aggregate.base_type
380
+ target = entity_id_of(schema, base)
381
+ content = doc.create_element("xs:complexType")
382
+ sequence = doc.create_element("xs:sequence")
383
+ component = doc.create_element("xs:element")
384
+ component.set_attributes(
385
+ "name" => mapped(target),
386
+ "type" => "#{prefix}:#{mapped(target)}",
387
+ "minOccurs" => "0",
388
+ "maxOccurs" => "unbounded",
389
+ )
390
+ sequence.add_child(component)
391
+ content.add_child(sequence)
392
+ content
393
+ end
394
+
395
+ # 7.8: the context-schema specific uos element — in the
396
+ # exp:uos substitution group, extending the exp:uos carrier,
397
+ # with a repeating choice over the exp:Entity substitution
398
+ # head (every entity instance element) and the complexEntity
399
+ # carrier.
400
+ def uos_node(doc, _schema, prefix, inline)
401
+ # inline mode names the carrier uos_base (the derived type
402
+ # is uos); the imported base schema names it exp:uos
403
+ carrier = inline ? "#{prefix}:uos_base" : "exp:uos"
404
+ element = doc.create_element("xs:element")
405
+ element.set_attributes(
406
+ "name" => "uos",
407
+ "type" => "#{prefix}:uos",
408
+ "substitutionGroup" => carrier,
409
+ )
410
+ node = doc.create_element("xs:complexType")
411
+ node.set_attributes("name" => "uos")
412
+ complex_content = doc.create_element("xs:complexContent")
413
+ extension = doc.create_element("xs:extension")
414
+ extension.set_attributes("base" => carrier)
415
+ choice = doc.create_element("xs:choice")
416
+ choice.set_attributes("minOccurs" => "0", "maxOccurs" => "unbounded")
417
+ head = doc.create_element("xs:element")
418
+ head.set_attributes("ref" => exp_name("Entity", inline, prefix))
419
+ choice.add_child(head)
420
+ complex = doc.create_element("xs:element")
421
+ complex.set_attributes("ref" => exp_name("complexEntity", inline, prefix))
422
+ choice.add_child(complex)
423
+ extension.add_child(choice)
424
+ complex_content.add_child(extension)
425
+ node.add_child(complex_content)
426
+ [element, node]
427
+ end
428
+
429
+ def closure_attributes(entity)
430
+ (entity.supertype_closure.to_a + [entity])
431
+ .flat_map { |decl| Array(decl.attributes) }
432
+ .select { |attr| attr.instance_of?(Model::Declarations::Attribute) }
433
+ .reject do |attr|
434
+ attr.respond_to?(:kind) &&
435
+ [Model::Declarations::Attribute::DERIVED,
436
+ Model::Declarations::Attribute::INVERSE].include?(attr.kind)
437
+ end
438
+ .uniq { |attr| attr.id&.safe_downcase }
439
+ end
440
+
441
+ # 7.2/7.3 kind resolution over the type face.
442
+ def kind_of(schema, type)
443
+ case type
444
+ when Model::DataTypes::Enumeration
445
+ :enumeration
446
+ when Model::DataTypes::Boolean, Model::DataTypes::Logical,
447
+ Model::DataTypes::Binary, Model::DataTypes::Integer,
448
+ Model::DataTypes::Real, Model::DataTypes::Number,
449
+ Model::DataTypes::String
450
+ :simple
451
+ when Model::DataTypes::Select
452
+ :select
453
+ else
454
+ if type.respond_to?(:base_type) && type.base_type
455
+ base = type.base_type
456
+ if entity_type?(schema, base)
457
+ :entity_aggregate
458
+ else
459
+ :aggregate
460
+ end
461
+ elsif entity_type?(schema, type)
462
+ :entity
463
+ else
464
+ defined_kind(schema, type)
465
+ end
466
+ end
467
+ end
468
+
469
+ def defined_kind(schema, type)
470
+ return :string unless type.is_a?(Model::References::SimpleReference)
471
+
472
+ id = type.respond_to?(:base_path) && type.base_path ? type.base_path.to_s.split(".").last : type.id
473
+ decl = id &&
474
+ Array(schema.types).find do |candidate|
475
+ candidate.id&.safe_downcase == id
476
+ end
477
+ return :string unless decl
478
+
479
+ kind_of(schema, decl.underlying_type)
480
+ end
481
+
482
+ def entity_type?(schema, type)
483
+ return false unless type.is_a?(Model::References::SimpleReference)
484
+
485
+ id = type.respond_to?(:base_path) && type.base_path ? type.base_path.to_s.split(".").last : type.id
486
+ id && Array(schema.entities)
487
+ .any? { |entity| entity.id&.safe_downcase == id }
488
+ end
489
+
490
+ def entity_id_of(schema, type)
491
+ id = type.respond_to?(:base_path) && type.base_path ? type.base_path.to_s.split(".").last : type.id
492
+ decl = Array(schema.entities).find do |entity|
493
+ entity.id&.safe_downcase == id
494
+ end
495
+ raise Expressir::Error, "no entity '#{id}' in '#{schema.id}'" unless decl
496
+
497
+ decl.id
498
+ end
499
+
500
+ def type_id(type)
501
+ type.respond_to?(:base_path) && type.base_path ? type.base_path.to_s.split(".").last : type.id
502
+ end
503
+
504
+ # 7.2.1: the XML Schema data type for a simple/defined face.
505
+ def simple_type_name(_schema, type, inline)
506
+ case type
507
+ when Model::DataTypes::Boolean then "xs:boolean"
508
+ when Model::DataTypes::Logical then exp_name("logical", inline)
509
+ when Model::DataTypes::Binary then exp_name("hexBinary", inline)
510
+ when Model::DataTypes::Integer then "xs:integer"
511
+ when Model::DataTypes::Real, Model::DataTypes::Number then "xs:double"
512
+ when Model::DataTypes::String then "xs:string"
513
+ when Model::DataTypes::Enumeration
514
+ raise Expressir::Error,
515
+ "anonymous enumeration type needs a defined TYPE wrapper"
516
+ else
517
+ if type.respond_to?(:base_type) && type.base_type
518
+ return "xs:string" # xs:list-derived aggregate
519
+ end
520
+
521
+ mapped(type_id(type)).to_s
522
+ end
523
+ end
524
+ end
525
+ end
526
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Expressir
4
+ module P28
5
+ autoload :Uos, "#{__dir__}/p28/uos"
6
+ autoload :Xsd, "#{__dir__}/p28/xsd"
7
+ autoload :Document, "#{__dir__}/p28/document"
8
+
9
+ # ISO 10303-28:2007 XML representation of EXPRESS-driven data.
10
+ #
11
+ # The common namespace shared by every -28 binding (annex C base
12
+ # schema; clause 9 examples).
13
+ COMMON_NS = "urn:iso:std:iso:10303:-28:ed-2:tech:XMLschema:common"
14
+
15
+ # The default target-namespace URN for a schema registered as an
16
+ # International Standard (clause 7, "URI for the target namespace
17
+ # of the derived XML schema" + annex A URN form).
18
+ module_function
19
+
20
+ def default_target_namespace(schema_name, part: nil, version: nil)
21
+ if part && version
22
+ "urn:iso.org:standard:10303:part(#{part}):version(#{version}):" \
23
+ "defaultXML:#{schema_name}"
24
+ else
25
+ "URN:my_company.com:iso_10303_28/#{schema_name}"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -3,6 +3,6 @@ module Expressir
3
3
  # autoload it (Ruby autoload only works for module/class constants, not
4
4
  # for string constants like `Expressir::VERSION`).
5
5
  module Version
6
- VERSION = "2.4.39".freeze
6
+ VERSION = "2.4.40".freeze
7
7
  end
8
8
  end
data/lib/expressir.rb CHANGED
@@ -31,6 +31,7 @@ module Expressir
31
31
  autoload :Version, "#{__dir__}/expressir/version"
32
32
  autoload :Mapping, "#{__dir__}/expressir/mapping"
33
33
  autoload :P21, "#{__dir__}/expressir/p21"
34
+ autoload :P28, "#{__dir__}/expressir/p28"
34
35
  autoload :Reference, "#{__dir__}/expressir/reference"
35
36
 
36
37
  # Error classes — autoload the same errors.rb file from each name.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expressir
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.39
4
+ version: 2.4.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -334,6 +334,11 @@ files:
334
334
  - TODO.max-perf/12-require-boot-profile.md
335
335
  - TODO.max-perf/13-key-conversion-specs.md
336
336
  - TODO.max-perf/14-builder-call-handler-audit.md
337
+ - TODO.p28/00-overview.md
338
+ - TODO.p28/01-uos-writer.md
339
+ - TODO.p28/02-uos-reader.md
340
+ - TODO.p28/03-default-xsd.md
341
+ - TODO.p28/04-document-envelope.md
337
342
  - TODO.parity-ee/00-overview.md
338
343
  - TODO.parity-ee/01-annex-g-rule-extraction.md
339
344
  - TODO.parity-ee/02-eeng-algorithm-inventory.md
@@ -735,6 +740,10 @@ files:
735
740
  - lib/expressir/p21/typing.rb
736
741
  - lib/expressir/p21/validator.rb
737
742
  - lib/expressir/p21/writer.rb
743
+ - lib/expressir/p28.rb
744
+ - lib/expressir/p28/document.rb
745
+ - lib/expressir/p28/uos.rb
746
+ - lib/expressir/p28/xsd.rb
738
747
  - lib/expressir/package.rb
739
748
  - lib/expressir/package/builder.rb
740
749
  - lib/expressir/package/metadata.rb