UNPKG

158 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3 typeof define === 'function' && define.amd ? define(factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.BpmnModdle = factory());
5})(this, (function () { 'use strict';
6
7 /**
8 * Flatten array, one level deep.
9 *
10 * @param {Array<?>} arr
11 *
12 * @return {Array<?>}
13 */
14
15 var nativeToString = Object.prototype.toString;
16 var nativeHasOwnProperty = Object.prototype.hasOwnProperty;
17 function isUndefined$1(obj) {
18 return obj === undefined;
19 }
20 function isArray(obj) {
21 return nativeToString.call(obj) === '[object Array]';
22 }
23 function isObject(obj) {
24 return nativeToString.call(obj) === '[object Object]';
25 }
26 function isFunction(obj) {
27 var tag = nativeToString.call(obj);
28 return tag === '[object Function]' || tag === '[object AsyncFunction]' || tag === '[object GeneratorFunction]' || tag === '[object AsyncGeneratorFunction]' || tag === '[object Proxy]';
29 }
30 function isString(obj) {
31 return nativeToString.call(obj) === '[object String]';
32 }
33 /**
34 * Return true, if target owns a property with the given key.
35 *
36 * @param {Object} target
37 * @param {String} key
38 *
39 * @return {Boolean}
40 */
41
42 function has(target, key) {
43 return nativeHasOwnProperty.call(target, key);
44 }
45
46 /**
47 * Find element in collection.
48 *
49 * @param {Array|Object} collection
50 * @param {Function|Object} matcher
51 *
52 * @return {Object}
53 */
54
55 function find(collection, matcher) {
56 matcher = toMatcher(matcher);
57 var match;
58 forEach(collection, function (val, key) {
59 if (matcher(val, key)) {
60 match = val;
61 return false;
62 }
63 });
64 return match;
65 }
66 /**
67 * Find element index in collection.
68 *
69 * @param {Array|Object} collection
70 * @param {Function} matcher
71 *
72 * @return {Object}
73 */
74
75 function findIndex(collection, matcher) {
76 matcher = toMatcher(matcher);
77 var idx = isArray(collection) ? -1 : undefined;
78 forEach(collection, function (val, key) {
79 if (matcher(val, key)) {
80 idx = key;
81 return false;
82 }
83 });
84 return idx;
85 }
86 /**
87 * Find element in collection.
88 *
89 * @param {Array|Object} collection
90 * @param {Function} matcher
91 *
92 * @return {Array} result
93 */
94
95 function filter(collection, matcher) {
96 var result = [];
97 forEach(collection, function (val, key) {
98 if (matcher(val, key)) {
99 result.push(val);
100 }
101 });
102 return result;
103 }
104 /**
105 * Iterate over collection; returning something
106 * (non-undefined) will stop iteration.
107 *
108 * @param {Array|Object} collection
109 * @param {Function} iterator
110 *
111 * @return {Object} return result that stopped the iteration
112 */
113
114 function forEach(collection, iterator) {
115 var val, result;
116
117 if (isUndefined$1(collection)) {
118 return;
119 }
120
121 var convertKey = isArray(collection) ? toNum : identity;
122
123 for (var key in collection) {
124 if (has(collection, key)) {
125 val = collection[key];
126 result = iterator(val, convertKey(key));
127
128 if (result === false) {
129 return val;
130 }
131 }
132 }
133 }
134
135 function toMatcher(matcher) {
136 return isFunction(matcher) ? matcher : function (e) {
137 return e === matcher;
138 };
139 }
140
141 function identity(arg) {
142 return arg;
143 }
144
145 function toNum(arg) {
146 return Number(arg);
147 }
148 /**
149 * Bind function against target <this>.
150 *
151 * @param {Function} fn
152 * @param {Object} target
153 *
154 * @return {Function} bound function
155 */
156
157 function bind(fn, target) {
158 return fn.bind(target);
159 }
160
161 function _extends() {
162 _extends = Object.assign || function (target) {
163 for (var i = 1; i < arguments.length; i++) {
164 var source = arguments[i];
165
166 for (var key in source) {
167 if (Object.prototype.hasOwnProperty.call(source, key)) {
168 target[key] = source[key];
169 }
170 }
171 }
172
173 return target;
174 };
175
176 return _extends.apply(this, arguments);
177 }
178
179 /**
180 * Convenience wrapper for `Object.assign`.
181 *
182 * @param {Object} target
183 * @param {...Object} others
184 *
185 * @return {Object} the target
186 */
187
188 function assign(target) {
189 for (var _len = arguments.length, others = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
190 others[_key - 1] = arguments[_key];
191 }
192
193 return _extends.apply(void 0, [target].concat(others));
194 }
195 /**
196 * Pick given properties from the target object.
197 *
198 * @param {Object} target
199 * @param {Array} properties
200 *
201 * @return {Object} target
202 */
203
204 function pick(target, properties) {
205 var result = {};
206 var obj = Object(target);
207 forEach(properties, function (prop) {
208 if (prop in obj) {
209 result[prop] = target[prop];
210 }
211 });
212 return result;
213 }
214
215 /**
216 * Moddle base element.
217 */
218 function Base() { }
219
220 Base.prototype.get = function(name) {
221 return this.$model.properties.get(this, name);
222 };
223
224 Base.prototype.set = function(name, value) {
225 this.$model.properties.set(this, name, value);
226 };
227
228 /**
229 * A model element factory.
230 *
231 * @param {Moddle} model
232 * @param {Properties} properties
233 */
234 function Factory(model, properties) {
235 this.model = model;
236 this.properties = properties;
237 }
238
239
240 Factory.prototype.createType = function(descriptor) {
241
242 var model = this.model;
243
244 var props = this.properties,
245 prototype = Object.create(Base.prototype);
246
247 // initialize default values
248 forEach(descriptor.properties, function(p) {
249 if (!p.isMany && p.default !== undefined) {
250 prototype[p.name] = p.default;
251 }
252 });
253
254 props.defineModel(prototype, model);
255 props.defineDescriptor(prototype, descriptor);
256
257 var name = descriptor.ns.name;
258
259 /**
260 * The new type constructor
261 */
262 function ModdleElement(attrs) {
263 props.define(this, '$type', { value: name, enumerable: true });
264 props.define(this, '$attrs', { value: {} });
265 props.define(this, '$parent', { writable: true });
266
267 forEach(attrs, bind(function(val, key) {
268 this.set(key, val);
269 }, this));
270 }
271
272 ModdleElement.prototype = prototype;
273
274 ModdleElement.hasType = prototype.$instanceOf = this.model.hasType;
275
276 // static links
277 props.defineModel(ModdleElement, model);
278 props.defineDescriptor(ModdleElement, descriptor);
279
280 return ModdleElement;
281 };
282
283 /**
284 * Built-in moddle types
285 */
286 var BUILTINS = {
287 String: true,
288 Boolean: true,
289 Integer: true,
290 Real: true,
291 Element: true
292 };
293
294 /**
295 * Converters for built in types from string representations
296 */
297 var TYPE_CONVERTERS = {
298 String: function(s) { return s; },
299 Boolean: function(s) { return s === 'true'; },
300 Integer: function(s) { return parseInt(s, 10); },
301 Real: function(s) { return parseFloat(s); }
302 };
303
304 /**
305 * Convert a type to its real representation
306 */
307 function coerceType(type, value) {
308
309 var converter = TYPE_CONVERTERS[type];
310
311 if (converter) {
312 return converter(value);
313 } else {
314 return value;
315 }
316 }
317
318 /**
319 * Return whether the given type is built-in
320 */
321 function isBuiltIn(type) {
322 return !!BUILTINS[type];
323 }
324
325 /**
326 * Return whether the given type is simple
327 */
328 function isSimple(type) {
329 return !!TYPE_CONVERTERS[type];
330 }
331
332 /**
333 * Parses a namespaced attribute name of the form (ns:)localName to an object,
334 * given a default prefix to assume in case no explicit namespace is given.
335 *
336 * @param {String} name
337 * @param {String} [defaultPrefix] the default prefix to take, if none is present.
338 *
339 * @return {Object} the parsed name
340 */
341 function parseName(name, defaultPrefix) {
342 var parts = name.split(/:/),
343 localName, prefix;
344
345 // no prefix (i.e. only local name)
346 if (parts.length === 1) {
347 localName = name;
348 prefix = defaultPrefix;
349 } else
350 // prefix + local name
351 if (parts.length === 2) {
352 localName = parts[1];
353 prefix = parts[0];
354 } else {
355 throw new Error('expected <prefix:localName> or <localName>, got ' + name);
356 }
357
358 name = (prefix ? prefix + ':' : '') + localName;
359
360 return {
361 name: name,
362 prefix: prefix,
363 localName: localName
364 };
365 }
366
367 /**
368 * A utility to build element descriptors.
369 */
370 function DescriptorBuilder(nameNs) {
371 this.ns = nameNs;
372 this.name = nameNs.name;
373 this.allTypes = [];
374 this.allTypesByName = {};
375 this.properties = [];
376 this.propertiesByName = {};
377 }
378
379
380 DescriptorBuilder.prototype.build = function() {
381 return pick(this, [
382 'ns',
383 'name',
384 'allTypes',
385 'allTypesByName',
386 'properties',
387 'propertiesByName',
388 'bodyProperty',
389 'idProperty'
390 ]);
391 };
392
393 /**
394 * Add property at given index.
395 *
396 * @param {Object} p
397 * @param {Number} [idx]
398 * @param {Boolean} [validate=true]
399 */
400 DescriptorBuilder.prototype.addProperty = function(p, idx, validate) {
401
402 if (typeof idx === 'boolean') {
403 validate = idx;
404 idx = undefined;
405 }
406
407 this.addNamedProperty(p, validate !== false);
408
409 var properties = this.properties;
410
411 if (idx !== undefined) {
412 properties.splice(idx, 0, p);
413 } else {
414 properties.push(p);
415 }
416 };
417
418
419 DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty, replace) {
420 var oldNameNs = oldProperty.ns;
421
422 var props = this.properties,
423 propertiesByName = this.propertiesByName,
424 rename = oldProperty.name !== newProperty.name;
425
426 if (oldProperty.isId) {
427 if (!newProperty.isId) {
428 throw new Error(
429 'property <' + newProperty.ns.name + '> must be id property ' +
430 'to refine <' + oldProperty.ns.name + '>');
431 }
432
433 this.setIdProperty(newProperty, false);
434 }
435
436 if (oldProperty.isBody) {
437
438 if (!newProperty.isBody) {
439 throw new Error(
440 'property <' + newProperty.ns.name + '> must be body property ' +
441 'to refine <' + oldProperty.ns.name + '>');
442 }
443
444 // TODO: Check compatibility
445 this.setBodyProperty(newProperty, false);
446 }
447
448 // validate existence and get location of old property
449 var idx = props.indexOf(oldProperty);
450 if (idx === -1) {
451 throw new Error('property <' + oldNameNs.name + '> not found in property list');
452 }
453
454 // remove old property
455 props.splice(idx, 1);
456
457 // replacing the named property is intentional
458 //
459 // * validate only if this is a "rename" operation
460 // * add at specific index unless we "replace"
461 //
462 this.addProperty(newProperty, replace ? undefined : idx, rename);
463
464 // make new property available under old name
465 propertiesByName[oldNameNs.name] = propertiesByName[oldNameNs.localName] = newProperty;
466 };
467
468
469 DescriptorBuilder.prototype.redefineProperty = function(p, targetPropertyName, replace) {
470
471 var nsPrefix = p.ns.prefix;
472 var parts = targetPropertyName.split('#');
473
474 var name = parseName(parts[0], nsPrefix);
475 var attrName = parseName(parts[1], name.prefix).name;
476
477 var redefinedProperty = this.propertiesByName[attrName];
478 if (!redefinedProperty) {
479 throw new Error('refined property <' + attrName + '> not found');
480 } else {
481 this.replaceProperty(redefinedProperty, p, replace);
482 }
483
484 delete p.redefines;
485 };
486
487 DescriptorBuilder.prototype.addNamedProperty = function(p, validate) {
488 var ns = p.ns,
489 propsByName = this.propertiesByName;
490
491 if (validate) {
492 this.assertNotDefined(p, ns.name);
493 this.assertNotDefined(p, ns.localName);
494 }
495
496 propsByName[ns.name] = propsByName[ns.localName] = p;
497 };
498
499 DescriptorBuilder.prototype.removeNamedProperty = function(p) {
500 var ns = p.ns,
501 propsByName = this.propertiesByName;
502
503 delete propsByName[ns.name];
504 delete propsByName[ns.localName];
505 };
506
507 DescriptorBuilder.prototype.setBodyProperty = function(p, validate) {
508
509 if (validate && this.bodyProperty) {
510 throw new Error(
511 'body property defined multiple times ' +
512 '(<' + this.bodyProperty.ns.name + '>, <' + p.ns.name + '>)');
513 }
514
515 this.bodyProperty = p;
516 };
517
518 DescriptorBuilder.prototype.setIdProperty = function(p, validate) {
519
520 if (validate && this.idProperty) {
521 throw new Error(
522 'id property defined multiple times ' +
523 '(<' + this.idProperty.ns.name + '>, <' + p.ns.name + '>)');
524 }
525
526 this.idProperty = p;
527 };
528
529 DescriptorBuilder.prototype.assertNotDefined = function(p, name) {
530 var propertyName = p.name,
531 definedProperty = this.propertiesByName[propertyName];
532
533 if (definedProperty) {
534 throw new Error(
535 'property <' + propertyName + '> already defined; ' +
536 'override of <' + definedProperty.definedBy.ns.name + '#' + definedProperty.ns.name + '> by ' +
537 '<' + p.definedBy.ns.name + '#' + p.ns.name + '> not allowed without redefines');
538 }
539 };
540
541 DescriptorBuilder.prototype.hasProperty = function(name) {
542 return this.propertiesByName[name];
543 };
544
545 DescriptorBuilder.prototype.addTrait = function(t, inherited) {
546
547 var typesByName = this.allTypesByName,
548 types = this.allTypes;
549
550 var typeName = t.name;
551
552 if (typeName in typesByName) {
553 return;
554 }
555
556 forEach(t.properties, bind(function(p) {
557
558 // clone property to allow extensions
559 p = assign({}, p, {
560 name: p.ns.localName,
561 inherited: inherited
562 });
563
564 Object.defineProperty(p, 'definedBy', {
565 value: t
566 });
567
568 var replaces = p.replaces,
569 redefines = p.redefines;
570
571 // add replace/redefine support
572 if (replaces || redefines) {
573 this.redefineProperty(p, replaces || redefines, replaces);
574 } else {
575 if (p.isBody) {
576 this.setBodyProperty(p);
577 }
578 if (p.isId) {
579 this.setIdProperty(p);
580 }
581 this.addProperty(p);
582 }
583 }, this));
584
585 types.push(t);
586 typesByName[typeName] = t;
587 };
588
589 /**
590 * A registry of Moddle packages.
591 *
592 * @param {Array<Package>} packages
593 * @param {Properties} properties
594 */
595 function Registry(packages, properties) {
596 this.packageMap = {};
597 this.typeMap = {};
598
599 this.packages = [];
600
601 this.properties = properties;
602
603 forEach(packages, bind(this.registerPackage, this));
604 }
605
606
607 Registry.prototype.getPackage = function(uriOrPrefix) {
608 return this.packageMap[uriOrPrefix];
609 };
610
611 Registry.prototype.getPackages = function() {
612 return this.packages;
613 };
614
615
616 Registry.prototype.registerPackage = function(pkg) {
617
618 // copy package
619 pkg = assign({}, pkg);
620
621 var pkgMap = this.packageMap;
622
623 ensureAvailable(pkgMap, pkg, 'prefix');
624 ensureAvailable(pkgMap, pkg, 'uri');
625
626 // register types
627 forEach(pkg.types, bind(function(descriptor) {
628 this.registerType(descriptor, pkg);
629 }, this));
630
631 pkgMap[pkg.uri] = pkgMap[pkg.prefix] = pkg;
632 this.packages.push(pkg);
633 };
634
635
636 /**
637 * Register a type from a specific package with us
638 */
639 Registry.prototype.registerType = function(type, pkg) {
640
641 type = assign({}, type, {
642 superClass: (type.superClass || []).slice(),
643 extends: (type.extends || []).slice(),
644 properties: (type.properties || []).slice(),
645 meta: assign((type.meta || {}))
646 });
647
648 var ns = parseName(type.name, pkg.prefix),
649 name = ns.name,
650 propertiesByName = {};
651
652 // parse properties
653 forEach(type.properties, bind(function(p) {
654
655 // namespace property names
656 var propertyNs = parseName(p.name, ns.prefix),
657 propertyName = propertyNs.name;
658
659 // namespace property types
660 if (!isBuiltIn(p.type)) {
661 p.type = parseName(p.type, propertyNs.prefix).name;
662 }
663
664 assign(p, {
665 ns: propertyNs,
666 name: propertyName
667 });
668
669 propertiesByName[propertyName] = p;
670 }, this));
671
672 // update ns + name
673 assign(type, {
674 ns: ns,
675 name: name,
676 propertiesByName: propertiesByName
677 });
678
679 forEach(type.extends, bind(function(extendsName) {
680 var extended = this.typeMap[extendsName];
681
682 extended.traits = extended.traits || [];
683 extended.traits.push(name);
684 }, this));
685
686 // link to package
687 this.definePackage(type, pkg);
688
689 // register
690 this.typeMap[name] = type;
691 };
692
693
694 /**
695 * Traverse the type hierarchy from bottom to top,
696 * calling iterator with (type, inherited) for all elements in
697 * the inheritance chain.
698 *
699 * @param {Object} nsName
700 * @param {Function} iterator
701 * @param {Boolean} [trait=false]
702 */
703 Registry.prototype.mapTypes = function(nsName, iterator, trait) {
704
705 var type = isBuiltIn(nsName.name) ? { name: nsName.name } : this.typeMap[nsName.name];
706
707 var self = this;
708
709 /**
710 * Traverse the selected trait.
711 *
712 * @param {String} cls
713 */
714 function traverseTrait(cls) {
715 return traverseSuper(cls, true);
716 }
717
718 /**
719 * Traverse the selected super type or trait
720 *
721 * @param {String} cls
722 * @param {Boolean} [trait=false]
723 */
724 function traverseSuper(cls, trait) {
725 var parentNs = parseName(cls, isBuiltIn(cls) ? '' : nsName.prefix);
726 self.mapTypes(parentNs, iterator, trait);
727 }
728
729 if (!type) {
730 throw new Error('unknown type <' + nsName.name + '>');
731 }
732
733 forEach(type.superClass, trait ? traverseTrait : traverseSuper);
734
735 // call iterator with (type, inherited=!trait)
736 iterator(type, !trait);
737
738 forEach(type.traits, traverseTrait);
739 };
740
741
742 /**
743 * Returns the effective descriptor for a type.
744 *
745 * @param {String} type the namespaced name (ns:localName) of the type
746 *
747 * @return {Descriptor} the resulting effective descriptor
748 */
749 Registry.prototype.getEffectiveDescriptor = function(name) {
750
751 var nsName = parseName(name);
752
753 var builder = new DescriptorBuilder(nsName);
754
755 this.mapTypes(nsName, function(type, inherited) {
756 builder.addTrait(type, inherited);
757 });
758
759 var descriptor = builder.build();
760
761 // define package link
762 this.definePackage(descriptor, descriptor.allTypes[descriptor.allTypes.length - 1].$pkg);
763
764 return descriptor;
765 };
766
767
768 Registry.prototype.definePackage = function(target, pkg) {
769 this.properties.define(target, '$pkg', { value: pkg });
770 };
771
772
773
774 ///////// helpers ////////////////////////////
775
776 function ensureAvailable(packageMap, pkg, identifierKey) {
777
778 var value = pkg[identifierKey];
779
780 if (value in packageMap) {
781 throw new Error('package with ' + identifierKey + ' <' + value + '> already defined');
782 }
783 }
784
785 /**
786 * A utility that gets and sets properties of model elements.
787 *
788 * @param {Model} model
789 */
790 function Properties(model) {
791 this.model = model;
792 }
793
794
795 /**
796 * Sets a named property on the target element.
797 * If the value is undefined, the property gets deleted.
798 *
799 * @param {Object} target
800 * @param {String} name
801 * @param {Object} value
802 */
803 Properties.prototype.set = function(target, name, value) {
804
805 var property = this.model.getPropertyDescriptor(target, name);
806
807 var propertyName = property && property.name;
808
809 if (isUndefined(value)) {
810 // unset the property, if the specified value is undefined;
811 // delete from $attrs (for extensions) or the target itself
812 if (property) {
813 delete target[propertyName];
814 } else {
815 delete target.$attrs[name];
816 }
817 } else {
818 // set the property, defining well defined properties on the fly
819 // or simply updating them in target.$attrs (for extensions)
820 if (property) {
821 if (propertyName in target) {
822 target[propertyName] = value;
823 } else {
824 defineProperty(target, property, value);
825 }
826 } else {
827 target.$attrs[name] = value;
828 }
829 }
830 };
831
832 /**
833 * Returns the named property of the given element
834 *
835 * @param {Object} target
836 * @param {String} name
837 *
838 * @return {Object}
839 */
840 Properties.prototype.get = function(target, name) {
841
842 var property = this.model.getPropertyDescriptor(target, name);
843
844 if (!property) {
845 return target.$attrs[name];
846 }
847
848 var propertyName = property.name;
849
850 // check if access to collection property and lazily initialize it
851 if (!target[propertyName] && property.isMany) {
852 defineProperty(target, property, []);
853 }
854
855 return target[propertyName];
856 };
857
858
859 /**
860 * Define a property on the target element
861 *
862 * @param {Object} target
863 * @param {String} name
864 * @param {Object} options
865 */
866 Properties.prototype.define = function(target, name, options) {
867 Object.defineProperty(target, name, options);
868 };
869
870
871 /**
872 * Define the descriptor for an element
873 */
874 Properties.prototype.defineDescriptor = function(target, descriptor) {
875 this.define(target, '$descriptor', { value: descriptor });
876 };
877
878 /**
879 * Define the model for an element
880 */
881 Properties.prototype.defineModel = function(target, model) {
882 this.define(target, '$model', { value: model });
883 };
884
885
886 function isUndefined(val) {
887 return typeof val === 'undefined';
888 }
889
890 function defineProperty(target, property, value) {
891 Object.defineProperty(target, property.name, {
892 enumerable: !property.isReference,
893 writable: true,
894 value: value,
895 configurable: true
896 });
897 }
898
899 //// Moddle implementation /////////////////////////////////////////////////
900
901 /**
902 * @class Moddle
903 *
904 * A model that can be used to create elements of a specific type.
905 *
906 * @example
907 *
908 * var Moddle = require('moddle');
909 *
910 * var pkg = {
911 * name: 'mypackage',
912 * prefix: 'my',
913 * types: [
914 * { name: 'Root' }
915 * ]
916 * };
917 *
918 * var moddle = new Moddle([pkg]);
919 *
920 * @param {Array<Package>} packages the packages to contain
921 */
922 function Moddle(packages) {
923
924 this.properties = new Properties(this);
925
926 this.factory = new Factory(this, this.properties);
927 this.registry = new Registry(packages, this.properties);
928
929 this.typeCache = {};
930 }
931
932
933 /**
934 * Create an instance of the specified type.
935 *
936 * @method Moddle#create
937 *
938 * @example
939 *
940 * var foo = moddle.create('my:Foo');
941 * var bar = moddle.create('my:Bar', { id: 'BAR_1' });
942 *
943 * @param {String|Object} descriptor the type descriptor or name know to the model
944 * @param {Object} attrs a number of attributes to initialize the model instance with
945 * @return {Object} model instance
946 */
947 Moddle.prototype.create = function(descriptor, attrs) {
948 var Type = this.getType(descriptor);
949
950 if (!Type) {
951 throw new Error('unknown type <' + descriptor + '>');
952 }
953
954 return new Type(attrs);
955 };
956
957
958 /**
959 * Returns the type representing a given descriptor
960 *
961 * @method Moddle#getType
962 *
963 * @example
964 *
965 * var Foo = moddle.getType('my:Foo');
966 * var foo = new Foo({ 'id' : 'FOO_1' });
967 *
968 * @param {String|Object} descriptor the type descriptor or name know to the model
969 * @return {Object} the type representing the descriptor
970 */
971 Moddle.prototype.getType = function(descriptor) {
972
973 var cache = this.typeCache;
974
975 var name = isString(descriptor) ? descriptor : descriptor.ns.name;
976
977 var type = cache[name];
978
979 if (!type) {
980 descriptor = this.registry.getEffectiveDescriptor(name);
981 type = cache[name] = this.factory.createType(descriptor);
982 }
983
984 return type;
985 };
986
987
988 /**
989 * Creates an any-element type to be used within model instances.
990 *
991 * This can be used to create custom elements that lie outside the meta-model.
992 * The created element contains all the meta-data required to serialize it
993 * as part of meta-model elements.
994 *
995 * @method Moddle#createAny
996 *
997 * @example
998 *
999 * var foo = moddle.createAny('vendor:Foo', 'http://vendor', {
1000 * value: 'bar'
1001 * });
1002 *
1003 * var container = moddle.create('my:Container', 'http://my', {
1004 * any: [ foo ]
1005 * });
1006 *
1007 * // go ahead and serialize the stuff
1008 *
1009 *
1010 * @param {String} name the name of the element
1011 * @param {String} nsUri the namespace uri of the element
1012 * @param {Object} [properties] a map of properties to initialize the instance with
1013 * @return {Object} the any type instance
1014 */
1015 Moddle.prototype.createAny = function(name, nsUri, properties) {
1016
1017 var nameNs = parseName(name);
1018
1019 var element = {
1020 $type: name,
1021 $instanceOf: function(type) {
1022 return type === this.$type;
1023 }
1024 };
1025
1026 var descriptor = {
1027 name: name,
1028 isGeneric: true,
1029 ns: {
1030 prefix: nameNs.prefix,
1031 localName: nameNs.localName,
1032 uri: nsUri
1033 }
1034 };
1035
1036 this.properties.defineDescriptor(element, descriptor);
1037 this.properties.defineModel(element, this);
1038 this.properties.define(element, '$parent', { enumerable: false, writable: true });
1039 this.properties.define(element, '$instanceOf', { enumerable: false, writable: true });
1040
1041 forEach(properties, function(a, key) {
1042 if (isObject(a) && a.value !== undefined) {
1043 element[a.name] = a.value;
1044 } else {
1045 element[key] = a;
1046 }
1047 });
1048
1049 return element;
1050 };
1051
1052 /**
1053 * Returns a registered package by uri or prefix
1054 *
1055 * @return {Object} the package
1056 */
1057 Moddle.prototype.getPackage = function(uriOrPrefix) {
1058 return this.registry.getPackage(uriOrPrefix);
1059 };
1060
1061 /**
1062 * Returns a snapshot of all known packages
1063 *
1064 * @return {Object} the package
1065 */
1066 Moddle.prototype.getPackages = function() {
1067 return this.registry.getPackages();
1068 };
1069
1070 /**
1071 * Returns the descriptor for an element
1072 */
1073 Moddle.prototype.getElementDescriptor = function(element) {
1074 return element.$descriptor;
1075 };
1076
1077 /**
1078 * Returns true if the given descriptor or instance
1079 * represents the given type.
1080 *
1081 * May be applied to this, if element is omitted.
1082 */
1083 Moddle.prototype.hasType = function(element, type) {
1084 if (type === undefined) {
1085 type = element;
1086 element = this;
1087 }
1088
1089 var descriptor = element.$model.getElementDescriptor(element);
1090
1091 return (type in descriptor.allTypesByName);
1092 };
1093
1094 /**
1095 * Returns the descriptor of an elements named property
1096 */
1097 Moddle.prototype.getPropertyDescriptor = function(element, property) {
1098 return this.getElementDescriptor(element).propertiesByName[property];
1099 };
1100
1101 /**
1102 * Returns a mapped type's descriptor
1103 */
1104 Moddle.prototype.getTypeDescriptor = function(type) {
1105 return this.registry.typeMap[type];
1106 };
1107
1108 var fromCharCode = String.fromCharCode;
1109
1110 var hasOwnProperty = Object.prototype.hasOwnProperty;
1111
1112 var ENTITY_PATTERN = /&#(\d+);|&#x([0-9a-f]+);|&(\w+);/ig;
1113
1114 var ENTITY_MAPPING = {
1115 'amp': '&',
1116 'apos': '\'',
1117 'gt': '>',
1118 'lt': '<',
1119 'quot': '"'
1120 };
1121
1122 // map UPPERCASE variants of supported special chars
1123 Object.keys(ENTITY_MAPPING).forEach(function(k) {
1124 ENTITY_MAPPING[k.toUpperCase()] = ENTITY_MAPPING[k];
1125 });
1126
1127
1128 function replaceEntities(_, d, x, z) {
1129
1130 // reserved names, i.e. &nbsp;
1131 if (z) {
1132 if (hasOwnProperty.call(ENTITY_MAPPING, z)) {
1133 return ENTITY_MAPPING[z];
1134 } else {
1135
1136 // fall back to original value
1137 return '&' + z + ';';
1138 }
1139 }
1140
1141 // decimal encoded char
1142 if (d) {
1143 return fromCharCode(d);
1144 }
1145
1146 // hex encoded char
1147 return fromCharCode(parseInt(x, 16));
1148 }
1149
1150
1151 /**
1152 * A basic entity decoder that can decode a minimal
1153 * sub-set of reserved names (&amp;) as well as
1154 * hex (&#xaaf;) and decimal (&#1231;) encoded characters.
1155 *
1156 * @param {string} str
1157 *
1158 * @return {string} decoded string
1159 */
1160 function decodeEntities(s) {
1161 if (s.length > 3 && s.indexOf('&') !== -1) {
1162 return s.replace(ENTITY_PATTERN, replaceEntities);
1163 }
1164
1165 return s;
1166 }
1167
1168 var XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance';
1169 var XSI_PREFIX = 'xsi';
1170 var XSI_TYPE$1 = 'xsi:type';
1171
1172 var NON_WHITESPACE_OUTSIDE_ROOT_NODE = 'non-whitespace outside of root node';
1173
1174 function error$1(msg) {
1175 return new Error(msg);
1176 }
1177
1178 function missingNamespaceForPrefix(prefix) {
1179 return 'missing namespace for prefix <' + prefix + '>';
1180 }
1181
1182 function getter(getFn) {
1183 return {
1184 'get': getFn,
1185 'enumerable': true
1186 };
1187 }
1188
1189 function cloneNsMatrix(nsMatrix) {
1190 var clone = {}, key;
1191 for (key in nsMatrix) {
1192 clone[key] = nsMatrix[key];
1193 }
1194 return clone;
1195 }
1196
1197 function uriPrefix(prefix) {
1198 return prefix + '$uri';
1199 }
1200
1201 function buildNsMatrix(nsUriToPrefix) {
1202 var nsMatrix = {},
1203 uri,
1204 prefix;
1205
1206 for (uri in nsUriToPrefix) {
1207 prefix = nsUriToPrefix[uri];
1208 nsMatrix[prefix] = prefix;
1209 nsMatrix[uriPrefix(prefix)] = uri;
1210 }
1211
1212 return nsMatrix;
1213 }
1214
1215 function noopGetContext() {
1216 return { 'line': 0, 'column': 0 };
1217 }
1218
1219 function throwFunc(err) {
1220 throw err;
1221 }
1222
1223 /**
1224 * Creates a new parser with the given options.
1225 *
1226 * @constructor
1227 *
1228 * @param {!Object<string, ?>=} options
1229 */
1230 function Parser(options) {
1231
1232 if (!this) {
1233 return new Parser(options);
1234 }
1235
1236 var proxy = options && options['proxy'];
1237
1238 var onText,
1239 onOpenTag,
1240 onCloseTag,
1241 onCDATA,
1242 onError = throwFunc,
1243 onWarning,
1244 onComment,
1245 onQuestion,
1246 onAttention;
1247
1248 var getContext = noopGetContext;
1249
1250 /**
1251 * Do we need to parse the current elements attributes for namespaces?
1252 *
1253 * @type {boolean}
1254 */
1255 var maybeNS = false;
1256
1257 /**
1258 * Do we process namespaces at all?
1259 *
1260 * @type {boolean}
1261 */
1262 var isNamespace = false;
1263
1264 /**
1265 * The caught error returned on parse end
1266 *
1267 * @type {Error}
1268 */
1269 var returnError = null;
1270
1271 /**
1272 * Should we stop parsing?
1273 *
1274 * @type {boolean}
1275 */
1276 var parseStop = false;
1277
1278 /**
1279 * A map of { uri: prefix } used by the parser.
1280 *
1281 * This map will ensure we can normalize prefixes during processing;
1282 * for each uri, only one prefix will be exposed to the handlers.
1283 *
1284 * @type {!Object<string, string>}}
1285 */
1286 var nsUriToPrefix;
1287
1288 /**
1289 * Handle parse error.
1290 *
1291 * @param {string|Error} err
1292 */
1293 function handleError(err) {
1294 if (!(err instanceof Error)) {
1295 err = error$1(err);
1296 }
1297
1298 returnError = err;
1299
1300 onError(err, getContext);
1301 }
1302
1303 /**
1304 * Handle parse error.
1305 *
1306 * @param {string|Error} err
1307 */
1308 function handleWarning(err) {
1309
1310 if (!onWarning) {
1311 return;
1312 }
1313
1314 if (!(err instanceof Error)) {
1315 err = error$1(err);
1316 }
1317
1318 onWarning(err, getContext);
1319 }
1320
1321 /**
1322 * Register parse listener.
1323 *
1324 * @param {string} name
1325 * @param {Function} cb
1326 *
1327 * @return {Parser}
1328 */
1329 this['on'] = function(name, cb) {
1330
1331 if (typeof cb !== 'function') {
1332 throw error$1('required args <name, cb>');
1333 }
1334
1335 switch (name) {
1336 case 'openTag': onOpenTag = cb; break;
1337 case 'text': onText = cb; break;
1338 case 'closeTag': onCloseTag = cb; break;
1339 case 'error': onError = cb; break;
1340 case 'warn': onWarning = cb; break;
1341 case 'cdata': onCDATA = cb; break;
1342 case 'attention': onAttention = cb; break; // <!XXXXX zzzz="eeee">
1343 case 'question': onQuestion = cb; break; // <? .... ?>
1344 case 'comment': onComment = cb; break;
1345 default:
1346 throw error$1('unsupported event: ' + name);
1347 }
1348
1349 return this;
1350 };
1351
1352 /**
1353 * Set the namespace to prefix mapping.
1354 *
1355 * @example
1356 *
1357 * parser.ns({
1358 * 'http://foo': 'foo',
1359 * 'http://bar': 'bar'
1360 * });
1361 *
1362 * @param {!Object<string, string>} nsMap
1363 *
1364 * @return {Parser}
1365 */
1366 this['ns'] = function(nsMap) {
1367
1368 if (typeof nsMap === 'undefined') {
1369 nsMap = {};
1370 }
1371
1372 if (typeof nsMap !== 'object') {
1373 throw error$1('required args <nsMap={}>');
1374 }
1375
1376 var _nsUriToPrefix = {}, k;
1377
1378 for (k in nsMap) {
1379 _nsUriToPrefix[k] = nsMap[k];
1380 }
1381
1382 // FORCE default mapping for schema instance
1383 _nsUriToPrefix[XSI_URI] = XSI_PREFIX;
1384
1385 isNamespace = true;
1386 nsUriToPrefix = _nsUriToPrefix;
1387
1388 return this;
1389 };
1390
1391 /**
1392 * Parse xml string.
1393 *
1394 * @param {string} xml
1395 *
1396 * @return {Error} returnError, if not thrown
1397 */
1398 this['parse'] = function(xml) {
1399 if (typeof xml !== 'string') {
1400 throw error$1('required args <xml=string>');
1401 }
1402
1403 returnError = null;
1404
1405 parse(xml);
1406
1407 getContext = noopGetContext;
1408 parseStop = false;
1409
1410 return returnError;
1411 };
1412
1413 /**
1414 * Stop parsing.
1415 */
1416 this['stop'] = function() {
1417 parseStop = true;
1418 };
1419
1420 /**
1421 * Parse string, invoking configured listeners on element.
1422 *
1423 * @param {string} xml
1424 */
1425 function parse(xml) {
1426 var nsMatrixStack = isNamespace ? [] : null,
1427 nsMatrix = isNamespace ? buildNsMatrix(nsUriToPrefix) : null,
1428 _nsMatrix,
1429 nodeStack = [],
1430 anonymousNsCount = 0,
1431 tagStart = false,
1432 tagEnd = false,
1433 i = 0, j = 0,
1434 x, y, q, w, v,
1435 xmlns,
1436 elementName,
1437 _elementName,
1438 elementProxy
1439 ;
1440
1441 var attrsString = '',
1442 attrsStart = 0,
1443 cachedAttrs // false = parsed with errors, null = needs parsing
1444 ;
1445
1446 /**
1447 * Parse attributes on demand and returns the parsed attributes.
1448 *
1449 * Return semantics: (1) `false` on attribute parse error,
1450 * (2) object hash on extracted attrs.
1451 *
1452 * @return {boolean|Object}
1453 */
1454 function getAttrs() {
1455 if (cachedAttrs !== null) {
1456 return cachedAttrs;
1457 }
1458
1459 var nsUri,
1460 nsUriPrefix,
1461 nsName,
1462 defaultAlias = isNamespace && nsMatrix['xmlns'],
1463 attrList = isNamespace && maybeNS ? [] : null,
1464 i = attrsStart,
1465 s = attrsString,
1466 l = s.length,
1467 hasNewMatrix,
1468 newalias,
1469 value,
1470 alias,
1471 name,
1472 attrs = {},
1473 seenAttrs = {},
1474 skipAttr,
1475 w,
1476 j;
1477
1478 parseAttr:
1479 for (; i < l; i++) {
1480 skipAttr = false;
1481 w = s.charCodeAt(i);
1482
1483 if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE={ \f\n\r\t\v}
1484 continue;
1485 }
1486
1487 // wait for non whitespace character
1488 if (w < 65 || w > 122 || (w > 90 && w < 97)) {
1489 if (w !== 95 && w !== 58) { // char 95"_" 58":"
1490 handleWarning('illegal first char attribute name');
1491 skipAttr = true;
1492 }
1493 }
1494
1495 // parse attribute name
1496 for (j = i + 1; j < l; j++) {
1497 w = s.charCodeAt(j);
1498
1499 if (
1500 w > 96 && w < 123 ||
1501 w > 64 && w < 91 ||
1502 w > 47 && w < 59 ||
1503 w === 46 || // '.'
1504 w === 45 || // '-'
1505 w === 95 // '_'
1506 ) {
1507 continue;
1508 }
1509
1510 // unexpected whitespace
1511 if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
1512 handleWarning('missing attribute value');
1513 i = j;
1514
1515 continue parseAttr;
1516 }
1517
1518 // expected "="
1519 if (w === 61) { // "=" == 61
1520 break;
1521 }
1522
1523 handleWarning('illegal attribute name char');
1524 skipAttr = true;
1525 }
1526
1527 name = s.substring(i, j);
1528
1529 if (name === 'xmlns:xmlns') {
1530 handleWarning('illegal declaration of xmlns');
1531 skipAttr = true;
1532 }
1533
1534 w = s.charCodeAt(j + 1);
1535
1536 if (w === 34) { // '"'
1537 j = s.indexOf('"', i = j + 2);
1538
1539 if (j === -1) {
1540 j = s.indexOf('\'', i);
1541
1542 if (j !== -1) {
1543 handleWarning('attribute value quote missmatch');
1544 skipAttr = true;
1545 }
1546 }
1547
1548 } else if (w === 39) { // "'"
1549 j = s.indexOf('\'', i = j + 2);
1550
1551 if (j === -1) {
1552 j = s.indexOf('"', i);
1553
1554 if (j !== -1) {
1555 handleWarning('attribute value quote missmatch');
1556 skipAttr = true;
1557 }
1558 }
1559
1560 } else {
1561 handleWarning('missing attribute value quotes');
1562 skipAttr = true;
1563
1564 // skip to next space
1565 for (j = j + 1; j < l; j++) {
1566 w = s.charCodeAt(j + 1);
1567
1568 if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
1569 break;
1570 }
1571 }
1572
1573 }
1574
1575 if (j === -1) {
1576 handleWarning('missing closing quotes');
1577
1578 j = l;
1579 skipAttr = true;
1580 }
1581
1582 if (!skipAttr) {
1583 value = s.substring(i, j);
1584 }
1585
1586 i = j;
1587
1588 // ensure SPACE follows attribute
1589 // skip illegal content otherwise
1590 // example a="b"c
1591 for (; j + 1 < l; j++) {
1592 w = s.charCodeAt(j + 1);
1593
1594 if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
1595 break;
1596 }
1597
1598 // FIRST ILLEGAL CHAR
1599 if (i === j) {
1600 handleWarning('illegal character after attribute end');
1601 skipAttr = true;
1602 }
1603 }
1604
1605 // advance cursor to next attribute
1606 i = j + 1;
1607
1608 if (skipAttr) {
1609 continue parseAttr;
1610 }
1611
1612 // check attribute re-declaration
1613 if (name in seenAttrs) {
1614 handleWarning('attribute <' + name + '> already defined');
1615 continue;
1616 }
1617
1618 seenAttrs[name] = true;
1619
1620 if (!isNamespace) {
1621 attrs[name] = value;
1622 continue;
1623 }
1624
1625 // try to extract namespace information
1626 if (maybeNS) {
1627 newalias = (
1628 name === 'xmlns'
1629 ? 'xmlns'
1630 : (name.charCodeAt(0) === 120 && name.substr(0, 6) === 'xmlns:')
1631 ? name.substr(6)
1632 : null
1633 );
1634
1635 // handle xmlns(:alias) assignment
1636 if (newalias !== null) {
1637 nsUri = decodeEntities(value);
1638 nsUriPrefix = uriPrefix(newalias);
1639
1640 alias = nsUriToPrefix[nsUri];
1641
1642 if (!alias) {
1643
1644 // no prefix defined or prefix collision
1645 if (
1646 (newalias === 'xmlns') ||
1647 (nsUriPrefix in nsMatrix && nsMatrix[nsUriPrefix] !== nsUri)
1648 ) {
1649
1650 // alocate free ns prefix
1651 do {
1652 alias = 'ns' + (anonymousNsCount++);
1653 } while (typeof nsMatrix[alias] !== 'undefined');
1654 } else {
1655 alias = newalias;
1656 }
1657
1658 nsUriToPrefix[nsUri] = alias;
1659 }
1660
1661 if (nsMatrix[newalias] !== alias) {
1662 if (!hasNewMatrix) {
1663 nsMatrix = cloneNsMatrix(nsMatrix);
1664 hasNewMatrix = true;
1665 }
1666
1667 nsMatrix[newalias] = alias;
1668 if (newalias === 'xmlns') {
1669 nsMatrix[uriPrefix(alias)] = nsUri;
1670 defaultAlias = alias;
1671 }
1672
1673 nsMatrix[nsUriPrefix] = nsUri;
1674 }
1675
1676 // expose xmlns(:asd)="..." in attributes
1677 attrs[name] = value;
1678 continue;
1679 }
1680
1681 // collect attributes until all namespace
1682 // declarations are processed
1683 attrList.push(name, value);
1684 continue;
1685
1686 } /** end if (maybeNs) */
1687
1688 // handle attributes on element without
1689 // namespace declarations
1690 w = name.indexOf(':');
1691 if (w === -1) {
1692 attrs[name] = value;
1693 continue;
1694 }
1695
1696 // normalize ns attribute name
1697 if (!(nsName = nsMatrix[name.substring(0, w)])) {
1698 handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
1699 continue;
1700 }
1701
1702 name = defaultAlias === nsName
1703 ? name.substr(w + 1)
1704 : nsName + name.substr(w);
1705
1706 // end: normalize ns attribute name
1707
1708 // normalize xsi:type ns attribute value
1709 if (name === XSI_TYPE$1) {
1710 w = value.indexOf(':');
1711
1712 if (w !== -1) {
1713 nsName = value.substring(0, w);
1714
1715 // handle default prefixes, i.e. xs:String gracefully
1716 nsName = nsMatrix[nsName] || nsName;
1717 value = nsName + value.substring(w);
1718 } else {
1719 value = defaultAlias + ':' + value;
1720 }
1721 }
1722
1723 // end: normalize xsi:type ns attribute value
1724
1725 attrs[name] = value;
1726 }
1727
1728
1729 // handle deferred, possibly namespaced attributes
1730 if (maybeNS) {
1731
1732 // normalize captured attributes
1733 for (i = 0, l = attrList.length; i < l; i++) {
1734
1735 name = attrList[i++];
1736 value = attrList[i];
1737
1738 w = name.indexOf(':');
1739
1740 if (w !== -1) {
1741
1742 // normalize ns attribute name
1743 if (!(nsName = nsMatrix[name.substring(0, w)])) {
1744 handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
1745 continue;
1746 }
1747
1748 name = defaultAlias === nsName
1749 ? name.substr(w + 1)
1750 : nsName + name.substr(w);
1751
1752 // end: normalize ns attribute name
1753
1754 // normalize xsi:type ns attribute value
1755 if (name === XSI_TYPE$1) {
1756 w = value.indexOf(':');
1757
1758 if (w !== -1) {
1759 nsName = value.substring(0, w);
1760
1761 // handle default prefixes, i.e. xs:String gracefully
1762 nsName = nsMatrix[nsName] || nsName;
1763 value = nsName + value.substring(w);
1764 } else {
1765 value = defaultAlias + ':' + value;
1766 }
1767 }
1768
1769 // end: normalize xsi:type ns attribute value
1770 }
1771
1772 attrs[name] = value;
1773 }
1774
1775 // end: normalize captured attributes
1776 }
1777
1778 return cachedAttrs = attrs;
1779 }
1780
1781 /**
1782 * Extract the parse context { line, column, part }
1783 * from the current parser position.
1784 *
1785 * @return {Object} parse context
1786 */
1787 function getParseContext() {
1788 var splitsRe = /(\r\n|\r|\n)/g;
1789
1790 var line = 0;
1791 var column = 0;
1792 var startOfLine = 0;
1793 var endOfLine = j;
1794 var match;
1795 var data;
1796
1797 while (i >= startOfLine) {
1798
1799 match = splitsRe.exec(xml);
1800
1801 if (!match) {
1802 break;
1803 }
1804
1805 // end of line = (break idx + break chars)
1806 endOfLine = match[0].length + match.index;
1807
1808 if (endOfLine > i) {
1809 break;
1810 }
1811
1812 // advance to next line
1813 line += 1;
1814
1815 startOfLine = endOfLine;
1816 }
1817
1818 // EOF errors
1819 if (i == -1) {
1820 column = endOfLine;
1821 data = xml.substring(j);
1822 } else
1823
1824 // start errors
1825 if (j === 0) {
1826 data = xml.substring(j, i);
1827 }
1828
1829 // other errors
1830 else {
1831 column = i - startOfLine;
1832 data = (j == -1 ? xml.substring(i) : xml.substring(i, j + 1));
1833 }
1834
1835 return {
1836 'data': data,
1837 'line': line,
1838 'column': column
1839 };
1840 }
1841
1842 getContext = getParseContext;
1843
1844
1845 if (proxy) {
1846 elementProxy = Object.create({}, {
1847 'name': getter(function() {
1848 return elementName;
1849 }),
1850 'originalName': getter(function() {
1851 return _elementName;
1852 }),
1853 'attrs': getter(getAttrs),
1854 'ns': getter(function() {
1855 return nsMatrix;
1856 })
1857 });
1858 }
1859
1860 // actual parse logic
1861 while (j !== -1) {
1862
1863 if (xml.charCodeAt(j) === 60) { // "<"
1864 i = j;
1865 } else {
1866 i = xml.indexOf('<', j);
1867 }
1868
1869 // parse end
1870 if (i === -1) {
1871 if (nodeStack.length) {
1872 return handleError('unexpected end of file');
1873 }
1874
1875 if (j === 0) {
1876 return handleError('missing start tag');
1877 }
1878
1879 if (j < xml.length) {
1880 if (xml.substring(j).trim()) {
1881 handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
1882 }
1883 }
1884
1885 return;
1886 }
1887
1888 // parse text
1889 if (j !== i) {
1890
1891 if (nodeStack.length) {
1892 if (onText) {
1893 onText(xml.substring(j, i), decodeEntities, getContext);
1894
1895 if (parseStop) {
1896 return;
1897 }
1898 }
1899 } else {
1900 if (xml.substring(j, i).trim()) {
1901 handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
1902
1903 if (parseStop) {
1904 return;
1905 }
1906 }
1907 }
1908 }
1909
1910 w = xml.charCodeAt(i+1);
1911
1912 // parse comments + CDATA
1913 if (w === 33) { // "!"
1914 q = xml.charCodeAt(i+2);
1915
1916 // CDATA section
1917 if (q === 91 && xml.substr(i + 3, 6) === 'CDATA[') { // 91 == "["
1918 j = xml.indexOf(']]>', i);
1919 if (j === -1) {
1920 return handleError('unclosed cdata');
1921 }
1922
1923 if (onCDATA) {
1924 onCDATA(xml.substring(i + 9, j), getContext);
1925 if (parseStop) {
1926 return;
1927 }
1928 }
1929
1930 j += 3;
1931 continue;
1932 }
1933
1934 // comment
1935 if (q === 45 && xml.charCodeAt(i + 3) === 45) { // 45 == "-"
1936 j = xml.indexOf('-->', i);
1937 if (j === -1) {
1938 return handleError('unclosed comment');
1939 }
1940
1941
1942 if (onComment) {
1943 onComment(xml.substring(i + 4, j), decodeEntities, getContext);
1944 if (parseStop) {
1945 return;
1946 }
1947 }
1948
1949 j += 3;
1950 continue;
1951 }
1952 }
1953
1954 // parse question <? ... ?>
1955 if (w === 63) { // "?"
1956 j = xml.indexOf('?>', i);
1957 if (j === -1) {
1958 return handleError('unclosed question');
1959 }
1960
1961 if (onQuestion) {
1962 onQuestion(xml.substring(i, j + 2), getContext);
1963 if (parseStop) {
1964 return;
1965 }
1966 }
1967
1968 j += 2;
1969 continue;
1970 }
1971
1972 // find matching closing tag for attention or standard tags
1973 // for that we must skip through attribute values
1974 // (enclosed in single or double quotes)
1975 for (x = i + 1; ; x++) {
1976 v = xml.charCodeAt(x);
1977 if (isNaN(v)) {
1978 j = -1;
1979 return handleError('unclosed tag');
1980 }
1981
1982 // [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
1983 // skips the quoted string
1984 // (double quotes) does not appear in a literal enclosed by (double quotes)
1985 // (single quote) does not appear in a literal enclosed by (single quote)
1986 if (v === 34) { // '"'
1987 q = xml.indexOf('"', x + 1);
1988 x = q !== -1 ? q : x;
1989 } else if (v === 39) { // "'"
1990 q = xml.indexOf("'", x + 1);
1991 x = q !== -1 ? q : x;
1992 } else if (v === 62) { // '>'
1993 j = x;
1994 break;
1995 }
1996 }
1997
1998
1999 // parse attention <! ...>
2000 // previously comment and CDATA have already been parsed
2001 if (w === 33) { // "!"
2002
2003 if (onAttention) {
2004 onAttention(xml.substring(i, j + 1), decodeEntities, getContext);
2005 if (parseStop) {
2006 return;
2007 }
2008 }
2009
2010 j += 1;
2011 continue;
2012 }
2013
2014 // don't process attributes;
2015 // there are none
2016 cachedAttrs = {};
2017
2018 // if (xml.charCodeAt(i+1) === 47) { // </...
2019 if (w === 47) { // </...
2020 tagStart = false;
2021 tagEnd = true;
2022
2023 if (!nodeStack.length) {
2024 return handleError('missing open tag');
2025 }
2026
2027 // verify open <-> close tag match
2028 x = elementName = nodeStack.pop();
2029 q = i + 2 + x.length;
2030
2031 if (xml.substring(i + 2, q) !== x) {
2032 return handleError('closing tag mismatch');
2033 }
2034
2035 // verify chars in close tag
2036 for (; q < j; q++) {
2037 w = xml.charCodeAt(q);
2038
2039 if (w === 32 || (w > 8 && w < 14)) { // \f\n\r\t\v space
2040 continue;
2041 }
2042
2043 return handleError('close tag');
2044 }
2045
2046 } else {
2047 if (xml.charCodeAt(j - 1) === 47) { // .../>
2048 x = elementName = xml.substring(i + 1, j - 1);
2049
2050 tagStart = true;
2051 tagEnd = true;
2052
2053 } else {
2054 x = elementName = xml.substring(i + 1, j);
2055
2056 tagStart = true;
2057 tagEnd = false;
2058 }
2059
2060 if (!(w > 96 && w < 123 || w > 64 && w < 91 || w === 95 || w === 58)) { // char 95"_" 58":"
2061 return handleError('illegal first char nodeName');
2062 }
2063
2064 for (q = 1, y = x.length; q < y; q++) {
2065 w = x.charCodeAt(q);
2066
2067 if (w > 96 && w < 123 || w > 64 && w < 91 || w > 47 && w < 59 || w === 45 || w === 95 || w == 46) {
2068 continue;
2069 }
2070
2071 if (w === 32 || (w < 14 && w > 8)) { // \f\n\r\t\v space
2072 elementName = x.substring(0, q);
2073
2074 // maybe there are attributes
2075 cachedAttrs = null;
2076 break;
2077 }
2078
2079 return handleError('invalid nodeName');
2080 }
2081
2082 if (!tagEnd) {
2083 nodeStack.push(elementName);
2084 }
2085 }
2086
2087 if (isNamespace) {
2088
2089 _nsMatrix = nsMatrix;
2090
2091 if (tagStart) {
2092
2093 // remember old namespace
2094 // unless we're self-closing
2095 if (!tagEnd) {
2096 nsMatrixStack.push(_nsMatrix);
2097 }
2098
2099 if (cachedAttrs === null) {
2100
2101 // quick check, whether there may be namespace
2102 // declarations on the node; if that is the case
2103 // we need to eagerly parse the node attributes
2104 if ((maybeNS = x.indexOf('xmlns', q) !== -1)) {
2105 attrsStart = q;
2106 attrsString = x;
2107
2108 getAttrs();
2109
2110 maybeNS = false;
2111 }
2112 }
2113 }
2114
2115 _elementName = elementName;
2116
2117 w = elementName.indexOf(':');
2118 if (w !== -1) {
2119 xmlns = nsMatrix[elementName.substring(0, w)];
2120
2121 // prefix given; namespace must exist
2122 if (!xmlns) {
2123 return handleError('missing namespace on <' + _elementName + '>');
2124 }
2125
2126 elementName = elementName.substr(w + 1);
2127 } else {
2128 xmlns = nsMatrix['xmlns'];
2129
2130 // if no default namespace is defined,
2131 // we'll import the element as anonymous.
2132 //
2133 // it is up to users to correct that to the document defined
2134 // targetNamespace, or whatever their undersanding of the
2135 // XML spec mandates.
2136 }
2137
2138 // adjust namespace prefixs as configured
2139 if (xmlns) {
2140 elementName = xmlns + ':' + elementName;
2141 }
2142
2143 }
2144
2145 if (tagStart) {
2146 attrsStart = q;
2147 attrsString = x;
2148
2149 if (onOpenTag) {
2150 if (proxy) {
2151 onOpenTag(elementProxy, decodeEntities, tagEnd, getContext);
2152 } else {
2153 onOpenTag(elementName, getAttrs, decodeEntities, tagEnd, getContext);
2154 }
2155
2156 if (parseStop) {
2157 return;
2158 }
2159 }
2160
2161 }
2162
2163 if (tagEnd) {
2164
2165 if (onCloseTag) {
2166 onCloseTag(proxy ? elementProxy : elementName, decodeEntities, tagStart, getContext);
2167
2168 if (parseStop) {
2169 return;
2170 }
2171 }
2172
2173 // restore old namespace
2174 if (isNamespace) {
2175 if (!tagStart) {
2176 nsMatrix = nsMatrixStack.pop();
2177 } else {
2178 nsMatrix = _nsMatrix;
2179 }
2180 }
2181 }
2182
2183 j += 1;
2184 }
2185 } /** end parse */
2186
2187 }
2188
2189 function hasLowerCaseAlias(pkg) {
2190 return pkg.xml && pkg.xml.tagAlias === 'lowerCase';
2191 }
2192
2193 var DEFAULT_NS_MAP = {
2194 'xsi': 'http://www.w3.org/2001/XMLSchema-instance',
2195 'xml': 'http://www.w3.org/XML/1998/namespace'
2196 };
2197
2198 var XSI_TYPE = 'xsi:type';
2199
2200 function serializeFormat(element) {
2201 return element.xml && element.xml.serialize;
2202 }
2203
2204 function serializeAsType(element) {
2205 return serializeFormat(element) === XSI_TYPE;
2206 }
2207
2208 function serializeAsProperty(element) {
2209 return serializeFormat(element) === 'property';
2210 }
2211
2212 function capitalize(str) {
2213 return str.charAt(0).toUpperCase() + str.slice(1);
2214 }
2215
2216 function aliasToName(aliasNs, pkg) {
2217
2218 if (!hasLowerCaseAlias(pkg)) {
2219 return aliasNs.name;
2220 }
2221
2222 return aliasNs.prefix + ':' + capitalize(aliasNs.localName);
2223 }
2224
2225 function prefixedToName(nameNs, pkg) {
2226
2227 var name = nameNs.name,
2228 localName = nameNs.localName;
2229
2230 var typePrefix = pkg.xml && pkg.xml.typePrefix;
2231
2232 if (typePrefix && localName.indexOf(typePrefix) === 0) {
2233 return nameNs.prefix + ':' + localName.slice(typePrefix.length);
2234 } else {
2235 return name;
2236 }
2237 }
2238
2239 function normalizeXsiTypeName(name, model) {
2240
2241 var nameNs = parseName(name);
2242 var pkg = model.getPackage(nameNs.prefix);
2243
2244 return prefixedToName(nameNs, pkg);
2245 }
2246
2247 function error(message) {
2248 return new Error(message);
2249 }
2250
2251 /**
2252 * Get the moddle descriptor for a given instance or type.
2253 *
2254 * @param {ModdleElement|Function} element
2255 *
2256 * @return {Object} the moddle descriptor
2257 */
2258 function getModdleDescriptor(element) {
2259 return element.$descriptor;
2260 }
2261
2262
2263 /**
2264 * A parse context.
2265 *
2266 * @class
2267 *
2268 * @param {Object} options
2269 * @param {ElementHandler} options.rootHandler the root handler for parsing a document
2270 * @param {boolean} [options.lax=false] whether or not to ignore invalid elements
2271 */
2272 function Context(options) {
2273
2274 /**
2275 * @property {ElementHandler} rootHandler
2276 */
2277
2278 /**
2279 * @property {Boolean} lax
2280 */
2281
2282 assign(this, options);
2283
2284 this.elementsById = {};
2285 this.references = [];
2286 this.warnings = [];
2287
2288 /**
2289 * Add an unresolved reference.
2290 *
2291 * @param {Object} reference
2292 */
2293 this.addReference = function(reference) {
2294 this.references.push(reference);
2295 };
2296
2297 /**
2298 * Add a processed element.
2299 *
2300 * @param {ModdleElement} element
2301 */
2302 this.addElement = function(element) {
2303
2304 if (!element) {
2305 throw error('expected element');
2306 }
2307
2308 var elementsById = this.elementsById;
2309
2310 var descriptor = getModdleDescriptor(element);
2311
2312 var idProperty = descriptor.idProperty,
2313 id;
2314
2315 if (idProperty) {
2316 id = element.get(idProperty.name);
2317
2318 if (id) {
2319
2320 // for QName validation as per http://www.w3.org/TR/REC-xml/#NT-NameChar
2321 if (!/^([a-z][\w-.]*:)?[a-z_][\w-.]*$/i.test(id)) {
2322 throw new Error('illegal ID <' + id + '>');
2323 }
2324
2325 if (elementsById[id]) {
2326 throw error('duplicate ID <' + id + '>');
2327 }
2328
2329 elementsById[id] = element;
2330 }
2331 }
2332 };
2333
2334 /**
2335 * Add an import warning.
2336 *
2337 * @param {Object} warning
2338 * @param {String} warning.message
2339 * @param {Error} [warning.error]
2340 */
2341 this.addWarning = function(warning) {
2342 this.warnings.push(warning);
2343 };
2344 }
2345
2346 function BaseHandler() {}
2347
2348 BaseHandler.prototype.handleEnd = function() {};
2349 BaseHandler.prototype.handleText = function() {};
2350 BaseHandler.prototype.handleNode = function() {};
2351
2352
2353 /**
2354 * A simple pass through handler that does nothing except for
2355 * ignoring all input it receives.
2356 *
2357 * This is used to ignore unknown elements and
2358 * attributes.
2359 */
2360 function NoopHandler() { }
2361
2362 NoopHandler.prototype = Object.create(BaseHandler.prototype);
2363
2364 NoopHandler.prototype.handleNode = function() {
2365 return this;
2366 };
2367
2368 function BodyHandler() {}
2369
2370 BodyHandler.prototype = Object.create(BaseHandler.prototype);
2371
2372 BodyHandler.prototype.handleText = function(text) {
2373 this.body = (this.body || '') + text;
2374 };
2375
2376 function ReferenceHandler(property, context) {
2377 this.property = property;
2378 this.context = context;
2379 }
2380
2381 ReferenceHandler.prototype = Object.create(BodyHandler.prototype);
2382
2383 ReferenceHandler.prototype.handleNode = function(node) {
2384
2385 if (this.element) {
2386 throw error('expected no sub nodes');
2387 } else {
2388 this.element = this.createReference(node);
2389 }
2390
2391 return this;
2392 };
2393
2394 ReferenceHandler.prototype.handleEnd = function() {
2395 this.element.id = this.body;
2396 };
2397
2398 ReferenceHandler.prototype.createReference = function(node) {
2399 return {
2400 property: this.property.ns.name,
2401 id: ''
2402 };
2403 };
2404
2405 function ValueHandler(propertyDesc, element) {
2406 this.element = element;
2407 this.propertyDesc = propertyDesc;
2408 }
2409
2410 ValueHandler.prototype = Object.create(BodyHandler.prototype);
2411
2412 ValueHandler.prototype.handleEnd = function() {
2413
2414 var value = this.body || '',
2415 element = this.element,
2416 propertyDesc = this.propertyDesc;
2417
2418 value = coerceType(propertyDesc.type, value);
2419
2420 if (propertyDesc.isMany) {
2421 element.get(propertyDesc.name).push(value);
2422 } else {
2423 element.set(propertyDesc.name, value);
2424 }
2425 };
2426
2427
2428 function BaseElementHandler() {}
2429
2430 BaseElementHandler.prototype = Object.create(BodyHandler.prototype);
2431
2432 BaseElementHandler.prototype.handleNode = function(node) {
2433 var parser = this,
2434 element = this.element;
2435
2436 if (!element) {
2437 element = this.element = this.createElement(node);
2438
2439 this.context.addElement(element);
2440 } else {
2441 parser = this.handleChild(node);
2442 }
2443
2444 return parser;
2445 };
2446
2447 /**
2448 * @class Reader.ElementHandler
2449 *
2450 */
2451 function ElementHandler(model, typeName, context) {
2452 this.model = model;
2453 this.type = model.getType(typeName);
2454 this.context = context;
2455 }
2456
2457 ElementHandler.prototype = Object.create(BaseElementHandler.prototype);
2458
2459 ElementHandler.prototype.addReference = function(reference) {
2460 this.context.addReference(reference);
2461 };
2462
2463 ElementHandler.prototype.handleText = function(text) {
2464
2465 var element = this.element,
2466 descriptor = getModdleDescriptor(element),
2467 bodyProperty = descriptor.bodyProperty;
2468
2469 if (!bodyProperty) {
2470 throw error('unexpected body text <' + text + '>');
2471 }
2472
2473 BodyHandler.prototype.handleText.call(this, text);
2474 };
2475
2476 ElementHandler.prototype.handleEnd = function() {
2477
2478 var value = this.body,
2479 element = this.element,
2480 descriptor = getModdleDescriptor(element),
2481 bodyProperty = descriptor.bodyProperty;
2482
2483 if (bodyProperty && value !== undefined) {
2484 value = coerceType(bodyProperty.type, value);
2485 element.set(bodyProperty.name, value);
2486 }
2487 };
2488
2489 /**
2490 * Create an instance of the model from the given node.
2491 *
2492 * @param {Element} node the xml node
2493 */
2494 ElementHandler.prototype.createElement = function(node) {
2495 var attributes = node.attributes,
2496 Type = this.type,
2497 descriptor = getModdleDescriptor(Type),
2498 context = this.context,
2499 instance = new Type({}),
2500 model = this.model,
2501 propNameNs;
2502
2503 forEach(attributes, function(value, name) {
2504
2505 var prop = descriptor.propertiesByName[name],
2506 values;
2507
2508 if (prop && prop.isReference) {
2509
2510 if (!prop.isMany) {
2511 context.addReference({
2512 element: instance,
2513 property: prop.ns.name,
2514 id: value
2515 });
2516 } else {
2517
2518 // IDREFS: parse references as whitespace-separated list
2519 values = value.split(' ');
2520
2521 forEach(values, function(v) {
2522 context.addReference({
2523 element: instance,
2524 property: prop.ns.name,
2525 id: v
2526 });
2527 });
2528 }
2529
2530 } else {
2531 if (prop) {
2532 value = coerceType(prop.type, value);
2533 } else
2534 if (name !== 'xmlns') {
2535 propNameNs = parseName(name, descriptor.ns.prefix);
2536
2537 // check whether attribute is defined in a well-known namespace
2538 // if that is the case we emit a warning to indicate potential misuse
2539 if (model.getPackage(propNameNs.prefix)) {
2540
2541 context.addWarning({
2542 message: 'unknown attribute <' + name + '>',
2543 element: instance,
2544 property: name,
2545 value: value
2546 });
2547 }
2548 }
2549
2550 instance.set(name, value);
2551 }
2552 });
2553
2554 return instance;
2555 };
2556
2557 ElementHandler.prototype.getPropertyForNode = function(node) {
2558
2559 var name = node.name;
2560 var nameNs = parseName(name);
2561
2562 var type = this.type,
2563 model = this.model,
2564 descriptor = getModdleDescriptor(type);
2565
2566 var propertyName = nameNs.name,
2567 property = descriptor.propertiesByName[propertyName],
2568 elementTypeName,
2569 elementType;
2570
2571 // search for properties by name first
2572
2573 if (property && !property.isAttr) {
2574
2575 if (serializeAsType(property)) {
2576 elementTypeName = node.attributes[XSI_TYPE];
2577
2578 // xsi type is optional, if it does not exists the
2579 // default type is assumed
2580 if (elementTypeName) {
2581
2582 // take possible type prefixes from XML
2583 // into account, i.e.: xsi:type="t{ActualType}"
2584 elementTypeName = normalizeXsiTypeName(elementTypeName, model);
2585
2586 elementType = model.getType(elementTypeName);
2587
2588 return assign({}, property, {
2589 effectiveType: getModdleDescriptor(elementType).name
2590 });
2591 }
2592 }
2593
2594 // search for properties by name first
2595 return property;
2596 }
2597
2598 var pkg = model.getPackage(nameNs.prefix);
2599
2600 if (pkg) {
2601 elementTypeName = aliasToName(nameNs, pkg);
2602 elementType = model.getType(elementTypeName);
2603
2604 // search for collection members later
2605 property = find(descriptor.properties, function(p) {
2606 return !p.isVirtual && !p.isReference && !p.isAttribute && elementType.hasType(p.type);
2607 });
2608
2609 if (property) {
2610 return assign({}, property, {
2611 effectiveType: getModdleDescriptor(elementType).name
2612 });
2613 }
2614 } else {
2615
2616 // parse unknown element (maybe extension)
2617 property = find(descriptor.properties, function(p) {
2618 return !p.isReference && !p.isAttribute && p.type === 'Element';
2619 });
2620
2621 if (property) {
2622 return property;
2623 }
2624 }
2625
2626 throw error('unrecognized element <' + nameNs.name + '>');
2627 };
2628
2629 ElementHandler.prototype.toString = function() {
2630 return 'ElementDescriptor[' + getModdleDescriptor(this.type).name + ']';
2631 };
2632
2633 ElementHandler.prototype.valueHandler = function(propertyDesc, element) {
2634 return new ValueHandler(propertyDesc, element);
2635 };
2636
2637 ElementHandler.prototype.referenceHandler = function(propertyDesc) {
2638 return new ReferenceHandler(propertyDesc, this.context);
2639 };
2640
2641 ElementHandler.prototype.handler = function(type) {
2642 if (type === 'Element') {
2643 return new GenericElementHandler(this.model, type, this.context);
2644 } else {
2645 return new ElementHandler(this.model, type, this.context);
2646 }
2647 };
2648
2649 /**
2650 * Handle the child element parsing
2651 *
2652 * @param {Element} node the xml node
2653 */
2654 ElementHandler.prototype.handleChild = function(node) {
2655 var propertyDesc, type, element, childHandler;
2656
2657 propertyDesc = this.getPropertyForNode(node);
2658 element = this.element;
2659
2660 type = propertyDesc.effectiveType || propertyDesc.type;
2661
2662 if (isSimple(type)) {
2663 return this.valueHandler(propertyDesc, element);
2664 }
2665
2666 if (propertyDesc.isReference) {
2667 childHandler = this.referenceHandler(propertyDesc).handleNode(node);
2668 } else {
2669 childHandler = this.handler(type).handleNode(node);
2670 }
2671
2672 var newElement = childHandler.element;
2673
2674 // child handles may decide to skip elements
2675 // by not returning anything
2676 if (newElement !== undefined) {
2677
2678 if (propertyDesc.isMany) {
2679 element.get(propertyDesc.name).push(newElement);
2680 } else {
2681 element.set(propertyDesc.name, newElement);
2682 }
2683
2684 if (propertyDesc.isReference) {
2685 assign(newElement, {
2686 element: element
2687 });
2688
2689 this.context.addReference(newElement);
2690 } else {
2691
2692 // establish child -> parent relationship
2693 newElement.$parent = element;
2694 }
2695 }
2696
2697 return childHandler;
2698 };
2699
2700 /**
2701 * An element handler that performs special validation
2702 * to ensure the node it gets initialized with matches
2703 * the handlers type (namespace wise).
2704 *
2705 * @param {Moddle} model
2706 * @param {String} typeName
2707 * @param {Context} context
2708 */
2709 function RootElementHandler(model, typeName, context) {
2710 ElementHandler.call(this, model, typeName, context);
2711 }
2712
2713 RootElementHandler.prototype = Object.create(ElementHandler.prototype);
2714
2715 RootElementHandler.prototype.createElement = function(node) {
2716
2717 var name = node.name,
2718 nameNs = parseName(name),
2719 model = this.model,
2720 type = this.type,
2721 pkg = model.getPackage(nameNs.prefix),
2722 typeName = pkg && aliasToName(nameNs, pkg) || name;
2723
2724 // verify the correct namespace if we parse
2725 // the first element in the handler tree
2726 //
2727 // this ensures we don't mistakenly import wrong namespace elements
2728 if (!type.hasType(typeName)) {
2729 throw error('unexpected element <' + node.originalName + '>');
2730 }
2731
2732 return ElementHandler.prototype.createElement.call(this, node);
2733 };
2734
2735
2736 function GenericElementHandler(model, typeName, context) {
2737 this.model = model;
2738 this.context = context;
2739 }
2740
2741 GenericElementHandler.prototype = Object.create(BaseElementHandler.prototype);
2742
2743 GenericElementHandler.prototype.createElement = function(node) {
2744
2745 var name = node.name,
2746 ns = parseName(name),
2747 prefix = ns.prefix,
2748 uri = node.ns[prefix + '$uri'],
2749 attributes = node.attributes;
2750
2751 return this.model.createAny(name, uri, attributes);
2752 };
2753
2754 GenericElementHandler.prototype.handleChild = function(node) {
2755
2756 var handler = new GenericElementHandler(this.model, 'Element', this.context).handleNode(node),
2757 element = this.element;
2758
2759 var newElement = handler.element,
2760 children;
2761
2762 if (newElement !== undefined) {
2763 children = element.$children = element.$children || [];
2764 children.push(newElement);
2765
2766 // establish child -> parent relationship
2767 newElement.$parent = element;
2768 }
2769
2770 return handler;
2771 };
2772
2773 GenericElementHandler.prototype.handleEnd = function() {
2774 if (this.body) {
2775 this.element.$body = this.body;
2776 }
2777 };
2778
2779 /**
2780 * A reader for a meta-model
2781 *
2782 * @param {Object} options
2783 * @param {Model} options.model used to read xml files
2784 * @param {Boolean} options.lax whether to make parse errors warnings
2785 */
2786 function Reader(options) {
2787
2788 if (options instanceof Moddle) {
2789 options = {
2790 model: options
2791 };
2792 }
2793
2794 assign(this, { lax: false }, options);
2795 }
2796
2797 /**
2798 * The fromXML result.
2799 *
2800 * @typedef {Object} ParseResult
2801 *
2802 * @property {ModdleElement} rootElement
2803 * @property {Array<Object>} references
2804 * @property {Array<Error>} warnings
2805 * @property {Object} elementsById - a mapping containing each ID -> ModdleElement
2806 */
2807
2808 /**
2809 * The fromXML result.
2810 *
2811 * @typedef {Error} ParseError
2812 *
2813 * @property {Array<Error>} warnings
2814 */
2815
2816 /**
2817 * Parse the given XML into a moddle document tree.
2818 *
2819 * @param {String} xml
2820 * @param {ElementHandler|Object} options or rootHandler
2821 *
2822 * @returns {Promise<ParseResult, ParseError>}
2823 */
2824 Reader.prototype.fromXML = function(xml, options, done) {
2825
2826 var rootHandler = options.rootHandler;
2827
2828 if (options instanceof ElementHandler) {
2829
2830 // root handler passed via (xml, { rootHandler: ElementHandler }, ...)
2831 rootHandler = options;
2832 options = {};
2833 } else {
2834 if (typeof options === 'string') {
2835
2836 // rootHandler passed via (xml, 'someString', ...)
2837 rootHandler = this.handler(options);
2838 options = {};
2839 } else if (typeof rootHandler === 'string') {
2840
2841 // rootHandler passed via (xml, { rootHandler: 'someString' }, ...)
2842 rootHandler = this.handler(rootHandler);
2843 }
2844 }
2845
2846 var model = this.model,
2847 lax = this.lax;
2848
2849 var context = new Context(assign({}, options, { rootHandler: rootHandler })),
2850 parser = new Parser({ proxy: true }),
2851 stack = createStack();
2852
2853 rootHandler.context = context;
2854
2855 // push root handler
2856 stack.push(rootHandler);
2857
2858
2859 /**
2860 * Handle error.
2861 *
2862 * @param {Error} err
2863 * @param {Function} getContext
2864 * @param {boolean} lax
2865 *
2866 * @return {boolean} true if handled
2867 */
2868 function handleError(err, getContext, lax) {
2869
2870 var ctx = getContext();
2871
2872 var line = ctx.line,
2873 column = ctx.column,
2874 data = ctx.data;
2875
2876 // we receive the full context data here,
2877 // for elements trim down the information
2878 // to the tag name, only
2879 if (data.charAt(0) === '<' && data.indexOf(' ') !== -1) {
2880 data = data.slice(0, data.indexOf(' ')) + '>';
2881 }
2882
2883 var message =
2884 'unparsable content ' + (data ? data + ' ' : '') + 'detected\n\t' +
2885 'line: ' + line + '\n\t' +
2886 'column: ' + column + '\n\t' +
2887 'nested error: ' + err.message;
2888
2889 if (lax) {
2890 context.addWarning({
2891 message: message,
2892 error: err
2893 });
2894
2895 return true;
2896 } else {
2897 throw error(message);
2898 }
2899 }
2900
2901 function handleWarning(err, getContext) {
2902
2903 // just like handling errors in <lax=true> mode
2904 return handleError(err, getContext, true);
2905 }
2906
2907 /**
2908 * Resolve collected references on parse end.
2909 */
2910 function resolveReferences() {
2911
2912 var elementsById = context.elementsById;
2913 var references = context.references;
2914
2915 var i, r;
2916
2917 for (i = 0; (r = references[i]); i++) {
2918 var element = r.element;
2919 var reference = elementsById[r.id];
2920 var property = getModdleDescriptor(element).propertiesByName[r.property];
2921
2922 if (!reference) {
2923 context.addWarning({
2924 message: 'unresolved reference <' + r.id + '>',
2925 element: r.element,
2926 property: r.property,
2927 value: r.id
2928 });
2929 }
2930
2931 if (property.isMany) {
2932 var collection = element.get(property.name),
2933 idx = collection.indexOf(r);
2934
2935 // we replace an existing place holder (idx != -1) or
2936 // append to the collection instead
2937 if (idx === -1) {
2938 idx = collection.length;
2939 }
2940
2941 if (!reference) {
2942
2943 // remove unresolvable reference
2944 collection.splice(idx, 1);
2945 } else {
2946
2947 // add or update reference in collection
2948 collection[idx] = reference;
2949 }
2950 } else {
2951 element.set(property.name, reference);
2952 }
2953 }
2954 }
2955
2956 function handleClose() {
2957 stack.pop().handleEnd();
2958 }
2959
2960 var PREAMBLE_START_PATTERN = /^<\?xml /i;
2961
2962 var ENCODING_PATTERN = / encoding="([^"]+)"/i;
2963
2964 var UTF_8_PATTERN = /^utf-8$/i;
2965
2966 function handleQuestion(question) {
2967
2968 if (!PREAMBLE_START_PATTERN.test(question)) {
2969 return;
2970 }
2971
2972 var match = ENCODING_PATTERN.exec(question);
2973 var encoding = match && match[1];
2974
2975 if (!encoding || UTF_8_PATTERN.test(encoding)) {
2976 return;
2977 }
2978
2979 context.addWarning({
2980 message:
2981 'unsupported document encoding <' + encoding + '>, ' +
2982 'falling back to UTF-8'
2983 });
2984 }
2985
2986 function handleOpen(node, getContext) {
2987 var handler = stack.peek();
2988
2989 try {
2990 stack.push(handler.handleNode(node));
2991 } catch (err) {
2992
2993 if (handleError(err, getContext, lax)) {
2994 stack.push(new NoopHandler());
2995 }
2996 }
2997 }
2998
2999 function handleCData(text, getContext) {
3000
3001 try {
3002 stack.peek().handleText(text);
3003 } catch (err) {
3004 handleWarning(err, getContext);
3005 }
3006 }
3007
3008 function handleText(text, getContext) {
3009
3010 // strip whitespace only nodes, i.e. before
3011 // <!CDATA[ ... ]> sections and in between tags
3012
3013 if (!text.trim()) {
3014 return;
3015 }
3016
3017 handleCData(text, getContext);
3018 }
3019
3020 var uriMap = model.getPackages().reduce(function(uriMap, p) {
3021 uriMap[p.uri] = p.prefix;
3022
3023 return uriMap;
3024 }, {
3025 'http://www.w3.org/XML/1998/namespace': 'xml' // add default xml ns
3026 });
3027 parser
3028 .ns(uriMap)
3029 .on('openTag', function(obj, decodeStr, selfClosing, getContext) {
3030
3031 // gracefully handle unparsable attributes (attrs=false)
3032 var attrs = obj.attrs || {};
3033
3034 var decodedAttrs = Object.keys(attrs).reduce(function(d, key) {
3035 var value = decodeStr(attrs[key]);
3036
3037 d[key] = value;
3038
3039 return d;
3040 }, {});
3041
3042 var node = {
3043 name: obj.name,
3044 originalName: obj.originalName,
3045 attributes: decodedAttrs,
3046 ns: obj.ns
3047 };
3048
3049 handleOpen(node, getContext);
3050 })
3051 .on('question', handleQuestion)
3052 .on('closeTag', handleClose)
3053 .on('cdata', handleCData)
3054 .on('text', function(text, decodeEntities, getContext) {
3055 handleText(decodeEntities(text), getContext);
3056 })
3057 .on('error', handleError)
3058 .on('warn', handleWarning);
3059
3060 // async XML parsing to make sure the execution environment
3061 // (node or brower) is kept responsive and that certain optimization
3062 // strategies can kick in.
3063 return new Promise(function(resolve, reject) {
3064
3065 var err;
3066
3067 try {
3068 parser.parse(xml);
3069
3070 resolveReferences();
3071 } catch (e) {
3072 err = e;
3073 }
3074
3075 var rootElement = rootHandler.element;
3076
3077 if (!err && !rootElement) {
3078 err = error('failed to parse document as <' + rootHandler.type.$descriptor.name + '>');
3079 }
3080
3081 var warnings = context.warnings;
3082 var references = context.references;
3083 var elementsById = context.elementsById;
3084
3085 if (err) {
3086 err.warnings = warnings;
3087
3088 return reject(err);
3089 } else {
3090 return resolve({
3091 rootElement: rootElement,
3092 elementsById: elementsById,
3093 references: references,
3094 warnings: warnings
3095 });
3096 }
3097 });
3098 };
3099
3100 Reader.prototype.handler = function(name) {
3101 return new RootElementHandler(this.model, name);
3102 };
3103
3104
3105 // helpers //////////////////////////
3106
3107 function createStack() {
3108 var stack = [];
3109
3110 Object.defineProperty(stack, 'peek', {
3111 value: function() {
3112 return this[this.length - 1];
3113 }
3114 });
3115
3116 return stack;
3117 }
3118
3119 var XML_PREAMBLE = '<?xml version="1.0" encoding="UTF-8"?>\n';
3120
3121 var ESCAPE_ATTR_CHARS = /<|>|'|"|&|\n\r|\n/g;
3122 var ESCAPE_CHARS = /<|>|&/g;
3123
3124
3125 function Namespaces(parent) {
3126
3127 var prefixMap = {};
3128 var uriMap = {};
3129 var used = {};
3130
3131 var wellknown = [];
3132 var custom = [];
3133
3134 // API
3135
3136 this.byUri = function(uri) {
3137 return uriMap[uri] || (
3138 parent && parent.byUri(uri)
3139 );
3140 };
3141
3142 this.add = function(ns, isWellknown) {
3143
3144 uriMap[ns.uri] = ns;
3145
3146 if (isWellknown) {
3147 wellknown.push(ns);
3148 } else {
3149 custom.push(ns);
3150 }
3151
3152 this.mapPrefix(ns.prefix, ns.uri);
3153 };
3154
3155 this.uriByPrefix = function(prefix) {
3156 return prefixMap[prefix || 'xmlns'];
3157 };
3158
3159 this.mapPrefix = function(prefix, uri) {
3160 prefixMap[prefix || 'xmlns'] = uri;
3161 };
3162
3163 this.getNSKey = function(ns) {
3164 return (ns.prefix !== undefined) ? (ns.uri + '|' + ns.prefix) : ns.uri;
3165 };
3166
3167 this.logUsed = function(ns) {
3168
3169 var uri = ns.uri;
3170 var nsKey = this.getNSKey(ns);
3171
3172 used[nsKey] = this.byUri(uri);
3173
3174 // Inform parent recursively about the usage of this NS
3175 if (parent) {
3176 parent.logUsed(ns);
3177 }
3178 };
3179
3180 this.getUsed = function(ns) {
3181
3182 function isUsed(ns) {
3183 var nsKey = self.getNSKey(ns);
3184
3185 return used[nsKey];
3186 }
3187
3188 var self = this;
3189
3190 var allNs = [].concat(wellknown, custom);
3191
3192 return allNs.filter(isUsed);
3193 };
3194
3195 }
3196
3197 function lower(string) {
3198 return string.charAt(0).toLowerCase() + string.slice(1);
3199 }
3200
3201 function nameToAlias(name, pkg) {
3202 if (hasLowerCaseAlias(pkg)) {
3203 return lower(name);
3204 } else {
3205 return name;
3206 }
3207 }
3208
3209 function inherits(ctor, superCtor) {
3210 ctor.super_ = superCtor;
3211 ctor.prototype = Object.create(superCtor.prototype, {
3212 constructor: {
3213 value: ctor,
3214 enumerable: false,
3215 writable: true,
3216 configurable: true
3217 }
3218 });
3219 }
3220
3221 function nsName(ns) {
3222 if (isString(ns)) {
3223 return ns;
3224 } else {
3225 return (ns.prefix ? ns.prefix + ':' : '') + ns.localName;
3226 }
3227 }
3228
3229 function getNsAttrs(namespaces) {
3230
3231 return namespaces.getUsed().filter(function(ns) {
3232
3233 // do not serialize built in <xml> namespace
3234 return ns.prefix !== 'xml';
3235 }).map(function(ns) {
3236 var name = 'xmlns' + (ns.prefix ? ':' + ns.prefix : '');
3237 return { name: name, value: ns.uri };
3238 });
3239
3240 }
3241
3242 function getElementNs(ns, descriptor) {
3243 if (descriptor.isGeneric) {
3244 return assign({ localName: descriptor.ns.localName }, ns);
3245 } else {
3246 return assign({ localName: nameToAlias(descriptor.ns.localName, descriptor.$pkg) }, ns);
3247 }
3248 }
3249
3250 function getPropertyNs(ns, descriptor) {
3251 return assign({ localName: descriptor.ns.localName }, ns);
3252 }
3253
3254 function getSerializableProperties(element) {
3255 var descriptor = element.$descriptor;
3256
3257 return filter(descriptor.properties, function(p) {
3258 var name = p.name;
3259
3260 if (p.isVirtual) {
3261 return false;
3262 }
3263
3264 // do not serialize defaults
3265 if (!has(element, name)) {
3266 return false;
3267 }
3268
3269 var value = element[name];
3270
3271 // do not serialize default equals
3272 if (value === p.default) {
3273 return false;
3274 }
3275
3276 // do not serialize null properties
3277 if (value === null) {
3278 return false;
3279 }
3280
3281 return p.isMany ? value.length : true;
3282 });
3283 }
3284
3285 var ESCAPE_ATTR_MAP = {
3286 '\n': '#10',
3287 '\n\r': '#10',
3288 '"': '#34',
3289 '\'': '#39',
3290 '<': '#60',
3291 '>': '#62',
3292 '&': '#38'
3293 };
3294
3295 var ESCAPE_MAP = {
3296 '<': 'lt',
3297 '>': 'gt',
3298 '&': 'amp'
3299 };
3300
3301 function escape(str, charPattern, replaceMap) {
3302
3303 // ensure we are handling strings here
3304 str = isString(str) ? str : '' + str;
3305
3306 return str.replace(charPattern, function(s) {
3307 return '&' + replaceMap[s] + ';';
3308 });
3309 }
3310
3311 /**
3312 * Escape a string attribute to not contain any bad values (line breaks, '"', ...)
3313 *
3314 * @param {String} str the string to escape
3315 * @return {String} the escaped string
3316 */
3317 function escapeAttr(str) {
3318 return escape(str, ESCAPE_ATTR_CHARS, ESCAPE_ATTR_MAP);
3319 }
3320
3321 function escapeBody(str) {
3322 return escape(str, ESCAPE_CHARS, ESCAPE_MAP);
3323 }
3324
3325 function filterAttributes(props) {
3326 return filter(props, function(p) { return p.isAttr; });
3327 }
3328
3329 function filterContained(props) {
3330 return filter(props, function(p) { return !p.isAttr; });
3331 }
3332
3333
3334 function ReferenceSerializer(tagName) {
3335 this.tagName = tagName;
3336 }
3337
3338 ReferenceSerializer.prototype.build = function(element) {
3339 this.element = element;
3340 return this;
3341 };
3342
3343 ReferenceSerializer.prototype.serializeTo = function(writer) {
3344 writer
3345 .appendIndent()
3346 .append('<' + this.tagName + '>' + this.element.id + '</' + this.tagName + '>')
3347 .appendNewLine();
3348 };
3349
3350 function BodySerializer() {}
3351
3352 BodySerializer.prototype.serializeValue =
3353 BodySerializer.prototype.serializeTo = function(writer) {
3354 writer.append(
3355 this.escape
3356 ? escapeBody(this.value)
3357 : this.value
3358 );
3359 };
3360
3361 BodySerializer.prototype.build = function(prop, value) {
3362 this.value = value;
3363
3364 if (prop.type === 'String' && value.search(ESCAPE_CHARS) !== -1) {
3365 this.escape = true;
3366 }
3367
3368 return this;
3369 };
3370
3371 function ValueSerializer(tagName) {
3372 this.tagName = tagName;
3373 }
3374
3375 inherits(ValueSerializer, BodySerializer);
3376
3377 ValueSerializer.prototype.serializeTo = function(writer) {
3378
3379 writer
3380 .appendIndent()
3381 .append('<' + this.tagName + '>');
3382
3383 this.serializeValue(writer);
3384
3385 writer
3386 .append('</' + this.tagName + '>')
3387 .appendNewLine();
3388 };
3389
3390 function ElementSerializer(parent, propertyDescriptor) {
3391 this.body = [];
3392 this.attrs = [];
3393
3394 this.parent = parent;
3395 this.propertyDescriptor = propertyDescriptor;
3396 }
3397
3398 ElementSerializer.prototype.build = function(element) {
3399 this.element = element;
3400
3401 var elementDescriptor = element.$descriptor,
3402 propertyDescriptor = this.propertyDescriptor;
3403
3404 var otherAttrs,
3405 properties;
3406
3407 var isGeneric = elementDescriptor.isGeneric;
3408
3409 if (isGeneric) {
3410 otherAttrs = this.parseGeneric(element);
3411 } else {
3412 otherAttrs = this.parseNsAttributes(element);
3413 }
3414
3415 if (propertyDescriptor) {
3416 this.ns = this.nsPropertyTagName(propertyDescriptor);
3417 } else {
3418 this.ns = this.nsTagName(elementDescriptor);
3419 }
3420
3421 // compute tag name
3422 this.tagName = this.addTagName(this.ns);
3423
3424 if (!isGeneric) {
3425 properties = getSerializableProperties(element);
3426
3427 this.parseAttributes(filterAttributes(properties));
3428 this.parseContainments(filterContained(properties));
3429 }
3430
3431 this.parseGenericAttributes(element, otherAttrs);
3432
3433 return this;
3434 };
3435
3436 ElementSerializer.prototype.nsTagName = function(descriptor) {
3437 var effectiveNs = this.logNamespaceUsed(descriptor.ns);
3438 return getElementNs(effectiveNs, descriptor);
3439 };
3440
3441 ElementSerializer.prototype.nsPropertyTagName = function(descriptor) {
3442 var effectiveNs = this.logNamespaceUsed(descriptor.ns);
3443 return getPropertyNs(effectiveNs, descriptor);
3444 };
3445
3446 ElementSerializer.prototype.isLocalNs = function(ns) {
3447 return ns.uri === this.ns.uri;
3448 };
3449
3450 /**
3451 * Get the actual ns attribute name for the given element.
3452 *
3453 * @param {Object} element
3454 * @param {Boolean} [element.inherited=false]
3455 *
3456 * @return {Object} nsName
3457 */
3458 ElementSerializer.prototype.nsAttributeName = function(element) {
3459
3460 var ns;
3461
3462 if (isString(element)) {
3463 ns = parseName(element);
3464 } else {
3465 ns = element.ns;
3466 }
3467
3468 // return just local name for inherited attributes
3469 if (element.inherited) {
3470 return { localName: ns.localName };
3471 }
3472
3473 // parse + log effective ns
3474 var effectiveNs = this.logNamespaceUsed(ns);
3475
3476 // LOG ACTUAL namespace use
3477 this.getNamespaces().logUsed(effectiveNs);
3478
3479 // strip prefix if same namespace like parent
3480 if (this.isLocalNs(effectiveNs)) {
3481 return { localName: ns.localName };
3482 } else {
3483 return assign({ localName: ns.localName }, effectiveNs);
3484 }
3485 };
3486
3487 ElementSerializer.prototype.parseGeneric = function(element) {
3488
3489 var self = this,
3490 body = this.body;
3491
3492 var attributes = [];
3493
3494 forEach(element, function(val, key) {
3495
3496 var nonNsAttr;
3497
3498 if (key === '$body') {
3499 body.push(new BodySerializer().build({ type: 'String' }, val));
3500 } else
3501 if (key === '$children') {
3502 forEach(val, function(child) {
3503 body.push(new ElementSerializer(self).build(child));
3504 });
3505 } else
3506 if (key.indexOf('$') !== 0) {
3507 nonNsAttr = self.parseNsAttribute(element, key, val);
3508
3509 if (nonNsAttr) {
3510 attributes.push({ name: key, value: val });
3511 }
3512 }
3513 });
3514
3515 return attributes;
3516 };
3517
3518 ElementSerializer.prototype.parseNsAttribute = function(element, name, value) {
3519 var model = element.$model;
3520
3521 var nameNs = parseName(name);
3522
3523 var ns;
3524
3525 // parse xmlns:foo="http://foo.bar"
3526 if (nameNs.prefix === 'xmlns') {
3527 ns = { prefix: nameNs.localName, uri: value };
3528 }
3529
3530 // parse xmlns="http://foo.bar"
3531 if (!nameNs.prefix && nameNs.localName === 'xmlns') {
3532 ns = { uri: value };
3533 }
3534
3535 if (!ns) {
3536 return {
3537 name: name,
3538 value: value
3539 };
3540 }
3541
3542 if (model && model.getPackage(value)) {
3543
3544 // register well known namespace
3545 this.logNamespace(ns, true, true);
3546 } else {
3547
3548 // log custom namespace directly as used
3549 var actualNs = this.logNamespaceUsed(ns, true);
3550
3551 this.getNamespaces().logUsed(actualNs);
3552 }
3553 };
3554
3555
3556 /**
3557 * Parse namespaces and return a list of left over generic attributes
3558 *
3559 * @param {Object} element
3560 * @return {Array<Object>}
3561 */
3562 ElementSerializer.prototype.parseNsAttributes = function(element, attrs) {
3563 var self = this;
3564
3565 var genericAttrs = element.$attrs;
3566
3567 var attributes = [];
3568
3569 // parse namespace attributes first
3570 // and log them. push non namespace attributes to a list
3571 // and process them later
3572 forEach(genericAttrs, function(value, name) {
3573
3574 var nonNsAttr = self.parseNsAttribute(element, name, value);
3575
3576 if (nonNsAttr) {
3577 attributes.push(nonNsAttr);
3578 }
3579 });
3580
3581 return attributes;
3582 };
3583
3584 ElementSerializer.prototype.parseGenericAttributes = function(element, attributes) {
3585
3586 var self = this;
3587
3588 forEach(attributes, function(attr) {
3589
3590 // do not serialize xsi:type attribute
3591 // it is set manually based on the actual implementation type
3592 if (attr.name === XSI_TYPE) {
3593 return;
3594 }
3595
3596 try {
3597 self.addAttribute(self.nsAttributeName(attr.name), attr.value);
3598 } catch (e) {
3599 console.warn(
3600 'missing namespace information for ',
3601 attr.name, '=', attr.value, 'on', element,
3602 e);
3603 }
3604 });
3605 };
3606
3607 ElementSerializer.prototype.parseContainments = function(properties) {
3608
3609 var self = this,
3610 body = this.body,
3611 element = this.element;
3612
3613 forEach(properties, function(p) {
3614 var value = element.get(p.name),
3615 isReference = p.isReference,
3616 isMany = p.isMany;
3617
3618 if (!isMany) {
3619 value = [ value ];
3620 }
3621
3622 if (p.isBody) {
3623 body.push(new BodySerializer().build(p, value[0]));
3624 } else
3625 if (isSimple(p.type)) {
3626 forEach(value, function(v) {
3627 body.push(new ValueSerializer(self.addTagName(self.nsPropertyTagName(p))).build(p, v));
3628 });
3629 } else
3630 if (isReference) {
3631 forEach(value, function(v) {
3632 body.push(new ReferenceSerializer(self.addTagName(self.nsPropertyTagName(p))).build(v));
3633 });
3634 } else {
3635
3636 // allow serialization via type
3637 // rather than element name
3638 var asType = serializeAsType(p),
3639 asProperty = serializeAsProperty(p);
3640
3641 forEach(value, function(v) {
3642 var serializer;
3643
3644 if (asType) {
3645 serializer = new TypeSerializer(self, p);
3646 } else
3647 if (asProperty) {
3648 serializer = new ElementSerializer(self, p);
3649 } else {
3650 serializer = new ElementSerializer(self);
3651 }
3652
3653 body.push(serializer.build(v));
3654 });
3655 }
3656 });
3657 };
3658
3659 ElementSerializer.prototype.getNamespaces = function(local) {
3660
3661 var namespaces = this.namespaces,
3662 parent = this.parent,
3663 parentNamespaces;
3664
3665 if (!namespaces) {
3666 parentNamespaces = parent && parent.getNamespaces();
3667
3668 if (local || !parentNamespaces) {
3669 this.namespaces = namespaces = new Namespaces(parentNamespaces);
3670 } else {
3671 namespaces = parentNamespaces;
3672 }
3673 }
3674
3675 return namespaces;
3676 };
3677
3678 ElementSerializer.prototype.logNamespace = function(ns, wellknown, local) {
3679 var namespaces = this.getNamespaces(local);
3680
3681 var nsUri = ns.uri,
3682 nsPrefix = ns.prefix;
3683
3684 var existing = namespaces.byUri(nsUri);
3685
3686 if (!existing || local) {
3687 namespaces.add(ns, wellknown);
3688 }
3689
3690 namespaces.mapPrefix(nsPrefix, nsUri);
3691
3692 return ns;
3693 };
3694
3695 ElementSerializer.prototype.logNamespaceUsed = function(ns, local) {
3696 var element = this.element,
3697 model = element.$model,
3698 namespaces = this.getNamespaces(local);
3699
3700 // ns may be
3701 //
3702 // * prefix only
3703 // * prefix:uri
3704 // * localName only
3705
3706 var prefix = ns.prefix,
3707 uri = ns.uri,
3708 newPrefix, idx,
3709 wellknownUri;
3710
3711 // handle anonymous namespaces (elementForm=unqualified), cf. #23
3712 if (!prefix && !uri) {
3713 return { localName: ns.localName };
3714 }
3715
3716 wellknownUri = DEFAULT_NS_MAP[prefix] || model && (model.getPackage(prefix) || {}).uri;
3717
3718 uri = uri || wellknownUri || namespaces.uriByPrefix(prefix);
3719
3720 if (!uri) {
3721 throw new Error('no namespace uri given for prefix <' + prefix + '>');
3722 }
3723
3724 ns = namespaces.byUri(uri);
3725
3726 if (!ns) {
3727 newPrefix = prefix;
3728 idx = 1;
3729
3730 // find a prefix that is not mapped yet
3731 while (namespaces.uriByPrefix(newPrefix)) {
3732 newPrefix = prefix + '_' + idx++;
3733 }
3734
3735 ns = this.logNamespace({ prefix: newPrefix, uri: uri }, wellknownUri === uri);
3736 }
3737
3738 if (prefix) {
3739 namespaces.mapPrefix(prefix, uri);
3740 }
3741
3742 return ns;
3743 };
3744
3745 ElementSerializer.prototype.parseAttributes = function(properties) {
3746 var self = this,
3747 element = this.element;
3748
3749 forEach(properties, function(p) {
3750
3751 var value = element.get(p.name);
3752
3753 if (p.isReference) {
3754
3755 if (!p.isMany) {
3756 value = value.id;
3757 }
3758 else {
3759 var values = [];
3760 forEach(value, function(v) {
3761 values.push(v.id);
3762 });
3763
3764 // IDREFS is a whitespace-separated list of references.
3765 value = values.join(' ');
3766 }
3767
3768 }
3769
3770 self.addAttribute(self.nsAttributeName(p), value);
3771 });
3772 };
3773
3774 ElementSerializer.prototype.addTagName = function(nsTagName) {
3775 var actualNs = this.logNamespaceUsed(nsTagName);
3776
3777 this.getNamespaces().logUsed(actualNs);
3778
3779 return nsName(nsTagName);
3780 };
3781
3782 ElementSerializer.prototype.addAttribute = function(name, value) {
3783 var attrs = this.attrs;
3784
3785 if (isString(value)) {
3786 value = escapeAttr(value);
3787 }
3788
3789 // de-duplicate attributes
3790 // https://github.com/bpmn-io/moddle-xml/issues/66
3791 var idx = findIndex(attrs, function(element) {
3792 return (
3793 element.name.localName === name.localName &&
3794 element.name.uri === name.uri &&
3795 element.name.prefix === name.prefix
3796 );
3797 });
3798
3799 var attr = { name: name, value: value };
3800
3801 if (idx !== -1) {
3802 attrs.splice(idx, 1, attr);
3803 } else {
3804 attrs.push(attr);
3805 }
3806 };
3807
3808 ElementSerializer.prototype.serializeAttributes = function(writer) {
3809 var attrs = this.attrs,
3810 namespaces = this.namespaces;
3811
3812 if (namespaces) {
3813 attrs = getNsAttrs(namespaces).concat(attrs);
3814 }
3815
3816 forEach(attrs, function(a) {
3817 writer
3818 .append(' ')
3819 .append(nsName(a.name)).append('="').append(a.value).append('"');
3820 });
3821 };
3822
3823 ElementSerializer.prototype.serializeTo = function(writer) {
3824 var firstBody = this.body[0],
3825 indent = firstBody && firstBody.constructor !== BodySerializer;
3826
3827 writer
3828 .appendIndent()
3829 .append('<' + this.tagName);
3830
3831 this.serializeAttributes(writer);
3832
3833 writer.append(firstBody ? '>' : ' />');
3834
3835 if (firstBody) {
3836
3837 if (indent) {
3838 writer
3839 .appendNewLine()
3840 .indent();
3841 }
3842
3843 forEach(this.body, function(b) {
3844 b.serializeTo(writer);
3845 });
3846
3847 if (indent) {
3848 writer
3849 .unindent()
3850 .appendIndent();
3851 }
3852
3853 writer.append('</' + this.tagName + '>');
3854 }
3855
3856 writer.appendNewLine();
3857 };
3858
3859 /**
3860 * A serializer for types that handles serialization of data types
3861 */
3862 function TypeSerializer(parent, propertyDescriptor) {
3863 ElementSerializer.call(this, parent, propertyDescriptor);
3864 }
3865
3866 inherits(TypeSerializer, ElementSerializer);
3867
3868 TypeSerializer.prototype.parseNsAttributes = function(element) {
3869
3870 // extracted attributes
3871 var attributes = ElementSerializer.prototype.parseNsAttributes.call(this, element);
3872
3873 var descriptor = element.$descriptor;
3874
3875 // only serialize xsi:type if necessary
3876 if (descriptor.name === this.propertyDescriptor.type) {
3877 return attributes;
3878 }
3879
3880 var typeNs = this.typeNs = this.nsTagName(descriptor);
3881 this.getNamespaces().logUsed(this.typeNs);
3882
3883 // add xsi:type attribute to represent the elements
3884 // actual type
3885
3886 var pkg = element.$model.getPackage(typeNs.uri),
3887 typePrefix = (pkg.xml && pkg.xml.typePrefix) || '';
3888
3889 this.addAttribute(
3890 this.nsAttributeName(XSI_TYPE),
3891 (typeNs.prefix ? typeNs.prefix + ':' : '') + typePrefix + descriptor.ns.localName
3892 );
3893
3894 return attributes;
3895 };
3896
3897 TypeSerializer.prototype.isLocalNs = function(ns) {
3898 return ns.uri === (this.typeNs || this.ns).uri;
3899 };
3900
3901 function SavingWriter() {
3902 this.value = '';
3903
3904 this.write = function(str) {
3905 this.value += str;
3906 };
3907 }
3908
3909 function FormatingWriter(out, format) {
3910
3911 var indent = [''];
3912
3913 this.append = function(str) {
3914 out.write(str);
3915
3916 return this;
3917 };
3918
3919 this.appendNewLine = function() {
3920 if (format) {
3921 out.write('\n');
3922 }
3923
3924 return this;
3925 };
3926
3927 this.appendIndent = function() {
3928 if (format) {
3929 out.write(indent.join(' '));
3930 }
3931
3932 return this;
3933 };
3934
3935 this.indent = function() {
3936 indent.push('');
3937 return this;
3938 };
3939
3940 this.unindent = function() {
3941 indent.pop();
3942 return this;
3943 };
3944 }
3945
3946 /**
3947 * A writer for meta-model backed document trees
3948 *
3949 * @param {Object} options output options to pass into the writer
3950 */
3951 function Writer(options) {
3952
3953 options = assign({ format: false, preamble: true }, options || {});
3954
3955 function toXML(tree, writer) {
3956 var internalWriter = writer || new SavingWriter();
3957 var formatingWriter = new FormatingWriter(internalWriter, options.format);
3958
3959 if (options.preamble) {
3960 formatingWriter.append(XML_PREAMBLE);
3961 }
3962
3963 new ElementSerializer().build(tree).serializeTo(formatingWriter);
3964
3965 if (!writer) {
3966 return internalWriter.value;
3967 }
3968 }
3969
3970 return {
3971 toXML: toXML
3972 };
3973 }
3974
3975 /**
3976 * A sub class of {@link Moddle} with support for import and export of BPMN 2.0 xml files.
3977 *
3978 * @class BpmnModdle
3979 * @extends Moddle
3980 *
3981 * @param {Object|Array} packages to use for instantiating the model
3982 * @param {Object} [options] additional options to pass over
3983 */
3984 function BpmnModdle(packages, options) {
3985 Moddle.call(this, packages, options);
3986 }
3987
3988 BpmnModdle.prototype = Object.create(Moddle.prototype);
3989
3990 /**
3991 * The fromXML result.
3992 *
3993 * @typedef {Object} ParseResult
3994 *
3995 * @property {ModdleElement} rootElement
3996 * @property {Array<Object>} references
3997 * @property {Array<Error>} warnings
3998 * @property {Object} elementsById - a mapping containing each ID -> ModdleElement
3999 */
4000
4001 /**
4002 * The fromXML error.
4003 *
4004 * @typedef {Error} ParseError
4005 *
4006 * @property {Array<Error>} warnings
4007 */
4008
4009 /**
4010 * Instantiates a BPMN model tree from a given xml string.
4011 *
4012 * @param {String} xmlStr
4013 * @param {String} [typeName='bpmn:Definitions'] name of the root element
4014 * @param {Object} [options] options to pass to the underlying reader
4015 *
4016 * @returns {Promise<ParseResult, ParseError>}
4017 */
4018 BpmnModdle.prototype.fromXML = function(xmlStr, typeName, options) {
4019
4020 if (!isString(typeName)) {
4021 options = typeName;
4022 typeName = 'bpmn:Definitions';
4023 }
4024
4025 var reader = new Reader(assign({ model: this, lax: true }, options));
4026 var rootHandler = reader.handler(typeName);
4027
4028 return reader.fromXML(xmlStr, rootHandler);
4029 };
4030
4031
4032 /**
4033 * The toXML result.
4034 *
4035 * @typedef {Object} SerializationResult
4036 *
4037 * @property {String} xml
4038 */
4039
4040 /**
4041 * Serializes a BPMN 2.0 object tree to XML.
4042 *
4043 * @param {String} element the root element, typically an instance of `bpmn:Definitions`
4044 * @param {Object} [options] to pass to the underlying writer
4045 *
4046 * @returns {Promise<SerializationResult, Error>}
4047 */
4048 BpmnModdle.prototype.toXML = function(element, options) {
4049
4050 var writer = new Writer(options);
4051
4052 return new Promise(function(resolve, reject) {
4053 try {
4054 var result = writer.toXML(element);
4055
4056 return resolve({
4057 xml: result
4058 });
4059 } catch (err) {
4060 return reject(err);
4061 }
4062 });
4063 };
4064
4065 var name$5 = "BPMN20";
4066 var uri$5 = "http://www.omg.org/spec/BPMN/20100524/MODEL";
4067 var prefix$5 = "bpmn";
4068 var associations$5 = [
4069 ];
4070 var types$5 = [
4071 {
4072 name: "Interface",
4073 superClass: [
4074 "RootElement"
4075 ],
4076 properties: [
4077 {
4078 name: "name",
4079 isAttr: true,
4080 type: "String"
4081 },
4082 {
4083 name: "operations",
4084 type: "Operation",
4085 isMany: true
4086 },
4087 {
4088 name: "implementationRef",
4089 isAttr: true,
4090 type: "String"
4091 }
4092 ]
4093 },
4094 {
4095 name: "Operation",
4096 superClass: [
4097 "BaseElement"
4098 ],
4099 properties: [
4100 {
4101 name: "name",
4102 isAttr: true,
4103 type: "String"
4104 },
4105 {
4106 name: "inMessageRef",
4107 type: "Message",
4108 isReference: true
4109 },
4110 {
4111 name: "outMessageRef",
4112 type: "Message",
4113 isReference: true
4114 },
4115 {
4116 name: "errorRef",
4117 type: "Error",
4118 isMany: true,
4119 isReference: true
4120 },
4121 {
4122 name: "implementationRef",
4123 isAttr: true,
4124 type: "String"
4125 }
4126 ]
4127 },
4128 {
4129 name: "EndPoint",
4130 superClass: [
4131 "RootElement"
4132 ]
4133 },
4134 {
4135 name: "Auditing",
4136 superClass: [
4137 "BaseElement"
4138 ]
4139 },
4140 {
4141 name: "GlobalTask",
4142 superClass: [
4143 "CallableElement"
4144 ],
4145 properties: [
4146 {
4147 name: "resources",
4148 type: "ResourceRole",
4149 isMany: true
4150 }
4151 ]
4152 },
4153 {
4154 name: "Monitoring",
4155 superClass: [
4156 "BaseElement"
4157 ]
4158 },
4159 {
4160 name: "Performer",
4161 superClass: [
4162 "ResourceRole"
4163 ]
4164 },
4165 {
4166 name: "Process",
4167 superClass: [
4168 "FlowElementsContainer",
4169 "CallableElement"
4170 ],
4171 properties: [
4172 {
4173 name: "processType",
4174 type: "ProcessType",
4175 isAttr: true
4176 },
4177 {
4178 name: "isClosed",
4179 isAttr: true,
4180 type: "Boolean"
4181 },
4182 {
4183 name: "auditing",
4184 type: "Auditing"
4185 },
4186 {
4187 name: "monitoring",
4188 type: "Monitoring"
4189 },
4190 {
4191 name: "properties",
4192 type: "Property",
4193 isMany: true
4194 },
4195 {
4196 name: "laneSets",
4197 isMany: true,
4198 replaces: "FlowElementsContainer#laneSets",
4199 type: "LaneSet"
4200 },
4201 {
4202 name: "flowElements",
4203 isMany: true,
4204 replaces: "FlowElementsContainer#flowElements",
4205 type: "FlowElement"
4206 },
4207 {
4208 name: "artifacts",
4209 type: "Artifact",
4210 isMany: true
4211 },
4212 {
4213 name: "resources",
4214 type: "ResourceRole",
4215 isMany: true
4216 },
4217 {
4218 name: "correlationSubscriptions",
4219 type: "CorrelationSubscription",
4220 isMany: true
4221 },
4222 {
4223 name: "supports",
4224 type: "Process",
4225 isMany: true,
4226 isReference: true
4227 },
4228 {
4229 name: "definitionalCollaborationRef",
4230 type: "Collaboration",
4231 isAttr: true,
4232 isReference: true
4233 },
4234 {
4235 name: "isExecutable",
4236 isAttr: true,
4237 type: "Boolean"
4238 }
4239 ]
4240 },
4241 {
4242 name: "LaneSet",
4243 superClass: [
4244 "BaseElement"
4245 ],
4246 properties: [
4247 {
4248 name: "lanes",
4249 type: "Lane",
4250 isMany: true
4251 },
4252 {
4253 name: "name",
4254 isAttr: true,
4255 type: "String"
4256 }
4257 ]
4258 },
4259 {
4260 name: "Lane",
4261 superClass: [
4262 "BaseElement"
4263 ],
4264 properties: [
4265 {
4266 name: "name",
4267 isAttr: true,
4268 type: "String"
4269 },
4270 {
4271 name: "partitionElementRef",
4272 type: "BaseElement",
4273 isAttr: true,
4274 isReference: true
4275 },
4276 {
4277 name: "partitionElement",
4278 type: "BaseElement"
4279 },
4280 {
4281 name: "flowNodeRef",
4282 type: "FlowNode",
4283 isMany: true,
4284 isReference: true
4285 },
4286 {
4287 name: "childLaneSet",
4288 type: "LaneSet",
4289 xml: {
4290 serialize: "xsi:type"
4291 }
4292 }
4293 ]
4294 },
4295 {
4296 name: "GlobalManualTask",
4297 superClass: [
4298 "GlobalTask"
4299 ]
4300 },
4301 {
4302 name: "ManualTask",
4303 superClass: [
4304 "Task"
4305 ]
4306 },
4307 {
4308 name: "UserTask",
4309 superClass: [
4310 "Task"
4311 ],
4312 properties: [
4313 {
4314 name: "renderings",
4315 type: "Rendering",
4316 isMany: true
4317 },
4318 {
4319 name: "implementation",
4320 isAttr: true,
4321 type: "String"
4322 }
4323 ]
4324 },
4325 {
4326 name: "Rendering",
4327 superClass: [
4328 "BaseElement"
4329 ]
4330 },
4331 {
4332 name: "HumanPerformer",
4333 superClass: [
4334 "Performer"
4335 ]
4336 },
4337 {
4338 name: "PotentialOwner",
4339 superClass: [
4340 "HumanPerformer"
4341 ]
4342 },
4343 {
4344 name: "GlobalUserTask",
4345 superClass: [
4346 "GlobalTask"
4347 ],
4348 properties: [
4349 {
4350 name: "implementation",
4351 isAttr: true,
4352 type: "String"
4353 },
4354 {
4355 name: "renderings",
4356 type: "Rendering",
4357 isMany: true
4358 }
4359 ]
4360 },
4361 {
4362 name: "Gateway",
4363 isAbstract: true,
4364 superClass: [
4365 "FlowNode"
4366 ],
4367 properties: [
4368 {
4369 name: "gatewayDirection",
4370 type: "GatewayDirection",
4371 "default": "Unspecified",
4372 isAttr: true
4373 }
4374 ]
4375 },
4376 {
4377 name: "EventBasedGateway",
4378 superClass: [
4379 "Gateway"
4380 ],
4381 properties: [
4382 {
4383 name: "instantiate",
4384 "default": false,
4385 isAttr: true,
4386 type: "Boolean"
4387 },
4388 {
4389 name: "eventGatewayType",
4390 type: "EventBasedGatewayType",
4391 isAttr: true,
4392 "default": "Exclusive"
4393 }
4394 ]
4395 },
4396 {
4397 name: "ComplexGateway",
4398 superClass: [
4399 "Gateway"
4400 ],
4401 properties: [
4402 {
4403 name: "activationCondition",
4404 type: "Expression",
4405 xml: {
4406 serialize: "xsi:type"
4407 }
4408 },
4409 {
4410 name: "default",
4411 type: "SequenceFlow",
4412 isAttr: true,
4413 isReference: true
4414 }
4415 ]
4416 },
4417 {
4418 name: "ExclusiveGateway",
4419 superClass: [
4420 "Gateway"
4421 ],
4422 properties: [
4423 {
4424 name: "default",
4425 type: "SequenceFlow",
4426 isAttr: true,
4427 isReference: true
4428 }
4429 ]
4430 },
4431 {
4432 name: "InclusiveGateway",
4433 superClass: [
4434 "Gateway"
4435 ],
4436 properties: [
4437 {
4438 name: "default",
4439 type: "SequenceFlow",
4440 isAttr: true,
4441 isReference: true
4442 }
4443 ]
4444 },
4445 {
4446 name: "ParallelGateway",
4447 superClass: [
4448 "Gateway"
4449 ]
4450 },
4451 {
4452 name: "RootElement",
4453 isAbstract: true,
4454 superClass: [
4455 "BaseElement"
4456 ]
4457 },
4458 {
4459 name: "Relationship",
4460 superClass: [
4461 "BaseElement"
4462 ],
4463 properties: [
4464 {
4465 name: "type",
4466 isAttr: true,
4467 type: "String"
4468 },
4469 {
4470 name: "direction",
4471 type: "RelationshipDirection",
4472 isAttr: true
4473 },
4474 {
4475 name: "source",
4476 isMany: true,
4477 isReference: true,
4478 type: "Element"
4479 },
4480 {
4481 name: "target",
4482 isMany: true,
4483 isReference: true,
4484 type: "Element"
4485 }
4486 ]
4487 },
4488 {
4489 name: "BaseElement",
4490 isAbstract: true,
4491 properties: [
4492 {
4493 name: "id",
4494 isAttr: true,
4495 type: "String",
4496 isId: true
4497 },
4498 {
4499 name: "documentation",
4500 type: "Documentation",
4501 isMany: true
4502 },
4503 {
4504 name: "extensionDefinitions",
4505 type: "ExtensionDefinition",
4506 isMany: true,
4507 isReference: true
4508 },
4509 {
4510 name: "extensionElements",
4511 type: "ExtensionElements"
4512 }
4513 ]
4514 },
4515 {
4516 name: "Extension",
4517 properties: [
4518 {
4519 name: "mustUnderstand",
4520 "default": false,
4521 isAttr: true,
4522 type: "Boolean"
4523 },
4524 {
4525 name: "definition",
4526 type: "ExtensionDefinition",
4527 isAttr: true,
4528 isReference: true
4529 }
4530 ]
4531 },
4532 {
4533 name: "ExtensionDefinition",
4534 properties: [
4535 {
4536 name: "name",
4537 isAttr: true,
4538 type: "String"
4539 },
4540 {
4541 name: "extensionAttributeDefinitions",
4542 type: "ExtensionAttributeDefinition",
4543 isMany: true
4544 }
4545 ]
4546 },
4547 {
4548 name: "ExtensionAttributeDefinition",
4549 properties: [
4550 {
4551 name: "name",
4552 isAttr: true,
4553 type: "String"
4554 },
4555 {
4556 name: "type",
4557 isAttr: true,
4558 type: "String"
4559 },
4560 {
4561 name: "isReference",
4562 "default": false,
4563 isAttr: true,
4564 type: "Boolean"
4565 },
4566 {
4567 name: "extensionDefinition",
4568 type: "ExtensionDefinition",
4569 isAttr: true,
4570 isReference: true
4571 }
4572 ]
4573 },
4574 {
4575 name: "ExtensionElements",
4576 properties: [
4577 {
4578 name: "valueRef",
4579 isAttr: true,
4580 isReference: true,
4581 type: "Element"
4582 },
4583 {
4584 name: "values",
4585 type: "Element",
4586 isMany: true
4587 },
4588 {
4589 name: "extensionAttributeDefinition",
4590 type: "ExtensionAttributeDefinition",
4591 isAttr: true,
4592 isReference: true
4593 }
4594 ]
4595 },
4596 {
4597 name: "Documentation",
4598 superClass: [
4599 "BaseElement"
4600 ],
4601 properties: [
4602 {
4603 name: "text",
4604 type: "String",
4605 isBody: true
4606 },
4607 {
4608 name: "textFormat",
4609 "default": "text/plain",
4610 isAttr: true,
4611 type: "String"
4612 }
4613 ]
4614 },
4615 {
4616 name: "Event",
4617 isAbstract: true,
4618 superClass: [
4619 "FlowNode",
4620 "InteractionNode"
4621 ],
4622 properties: [
4623 {
4624 name: "properties",
4625 type: "Property",
4626 isMany: true
4627 }
4628 ]
4629 },
4630 {
4631 name: "IntermediateCatchEvent",
4632 superClass: [
4633 "CatchEvent"
4634 ]
4635 },
4636 {
4637 name: "IntermediateThrowEvent",
4638 superClass: [
4639 "ThrowEvent"
4640 ]
4641 },
4642 {
4643 name: "EndEvent",
4644 superClass: [
4645 "ThrowEvent"
4646 ]
4647 },
4648 {
4649 name: "StartEvent",
4650 superClass: [
4651 "CatchEvent"
4652 ],
4653 properties: [
4654 {
4655 name: "isInterrupting",
4656 "default": true,
4657 isAttr: true,
4658 type: "Boolean"
4659 }
4660 ]
4661 },
4662 {
4663 name: "ThrowEvent",
4664 isAbstract: true,
4665 superClass: [
4666 "Event"
4667 ],
4668 properties: [
4669 {
4670 name: "dataInputs",
4671 type: "DataInput",
4672 isMany: true
4673 },
4674 {
4675 name: "dataInputAssociations",
4676 type: "DataInputAssociation",
4677 isMany: true
4678 },
4679 {
4680 name: "inputSet",
4681 type: "InputSet"
4682 },
4683 {
4684 name: "eventDefinitions",
4685 type: "EventDefinition",
4686 isMany: true
4687 },
4688 {
4689 name: "eventDefinitionRef",
4690 type: "EventDefinition",
4691 isMany: true,
4692 isReference: true
4693 }
4694 ]
4695 },
4696 {
4697 name: "CatchEvent",
4698 isAbstract: true,
4699 superClass: [
4700 "Event"
4701 ],
4702 properties: [
4703 {
4704 name: "parallelMultiple",
4705 isAttr: true,
4706 type: "Boolean",
4707 "default": false
4708 },
4709 {
4710 name: "dataOutputs",
4711 type: "DataOutput",
4712 isMany: true
4713 },
4714 {
4715 name: "dataOutputAssociations",
4716 type: "DataOutputAssociation",
4717 isMany: true
4718 },
4719 {
4720 name: "outputSet",
4721 type: "OutputSet"
4722 },
4723 {
4724 name: "eventDefinitions",
4725 type: "EventDefinition",
4726 isMany: true
4727 },
4728 {
4729 name: "eventDefinitionRef",
4730 type: "EventDefinition",
4731 isMany: true,
4732 isReference: true
4733 }
4734 ]
4735 },
4736 {
4737 name: "BoundaryEvent",
4738 superClass: [
4739 "CatchEvent"
4740 ],
4741 properties: [
4742 {
4743 name: "cancelActivity",
4744 "default": true,
4745 isAttr: true,
4746 type: "Boolean"
4747 },
4748 {
4749 name: "attachedToRef",
4750 type: "Activity",
4751 isAttr: true,
4752 isReference: true
4753 }
4754 ]
4755 },
4756 {
4757 name: "EventDefinition",
4758 isAbstract: true,
4759 superClass: [
4760 "RootElement"
4761 ]
4762 },
4763 {
4764 name: "CancelEventDefinition",
4765 superClass: [
4766 "EventDefinition"
4767 ]
4768 },
4769 {
4770 name: "ErrorEventDefinition",
4771 superClass: [
4772 "EventDefinition"
4773 ],
4774 properties: [
4775 {
4776 name: "errorRef",
4777 type: "Error",
4778 isAttr: true,
4779 isReference: true
4780 }
4781 ]
4782 },
4783 {
4784 name: "TerminateEventDefinition",
4785 superClass: [
4786 "EventDefinition"
4787 ]
4788 },
4789 {
4790 name: "EscalationEventDefinition",
4791 superClass: [
4792 "EventDefinition"
4793 ],
4794 properties: [
4795 {
4796 name: "escalationRef",
4797 type: "Escalation",
4798 isAttr: true,
4799 isReference: true
4800 }
4801 ]
4802 },
4803 {
4804 name: "Escalation",
4805 properties: [
4806 {
4807 name: "structureRef",
4808 type: "ItemDefinition",
4809 isAttr: true,
4810 isReference: true
4811 },
4812 {
4813 name: "name",
4814 isAttr: true,
4815 type: "String"
4816 },
4817 {
4818 name: "escalationCode",
4819 isAttr: true,
4820 type: "String"
4821 }
4822 ],
4823 superClass: [
4824 "RootElement"
4825 ]
4826 },
4827 {
4828 name: "CompensateEventDefinition",
4829 superClass: [
4830 "EventDefinition"
4831 ],
4832 properties: [
4833 {
4834 name: "waitForCompletion",
4835 isAttr: true,
4836 type: "Boolean",
4837 "default": true
4838 },
4839 {
4840 name: "activityRef",
4841 type: "Activity",
4842 isAttr: true,
4843 isReference: true
4844 }
4845 ]
4846 },
4847 {
4848 name: "TimerEventDefinition",
4849 superClass: [
4850 "EventDefinition"
4851 ],
4852 properties: [
4853 {
4854 name: "timeDate",
4855 type: "Expression",
4856 xml: {
4857 serialize: "xsi:type"
4858 }
4859 },
4860 {
4861 name: "timeCycle",
4862 type: "Expression",
4863 xml: {
4864 serialize: "xsi:type"
4865 }
4866 },
4867 {
4868 name: "timeDuration",
4869 type: "Expression",
4870 xml: {
4871 serialize: "xsi:type"
4872 }
4873 }
4874 ]
4875 },
4876 {
4877 name: "LinkEventDefinition",
4878 superClass: [
4879 "EventDefinition"
4880 ],
4881 properties: [
4882 {
4883 name: "name",
4884 isAttr: true,
4885 type: "String"
4886 },
4887 {
4888 name: "target",
4889 type: "LinkEventDefinition",
4890 isAttr: true,
4891 isReference: true
4892 },
4893 {
4894 name: "source",
4895 type: "LinkEventDefinition",
4896 isMany: true,
4897 isReference: true
4898 }
4899 ]
4900 },
4901 {
4902 name: "MessageEventDefinition",
4903 superClass: [
4904 "EventDefinition"
4905 ],
4906 properties: [
4907 {
4908 name: "messageRef",
4909 type: "Message",
4910 isAttr: true,
4911 isReference: true
4912 },
4913 {
4914 name: "operationRef",
4915 type: "Operation",
4916 isAttr: true,
4917 isReference: true
4918 }
4919 ]
4920 },
4921 {
4922 name: "ConditionalEventDefinition",
4923 superClass: [
4924 "EventDefinition"
4925 ],
4926 properties: [
4927 {
4928 name: "condition",
4929 type: "Expression",
4930 xml: {
4931 serialize: "xsi:type"
4932 }
4933 }
4934 ]
4935 },
4936 {
4937 name: "SignalEventDefinition",
4938 superClass: [
4939 "EventDefinition"
4940 ],
4941 properties: [
4942 {
4943 name: "signalRef",
4944 type: "Signal",
4945 isAttr: true,
4946 isReference: true
4947 }
4948 ]
4949 },
4950 {
4951 name: "Signal",
4952 superClass: [
4953 "RootElement"
4954 ],
4955 properties: [
4956 {
4957 name: "structureRef",
4958 type: "ItemDefinition",
4959 isAttr: true,
4960 isReference: true
4961 },
4962 {
4963 name: "name",
4964 isAttr: true,
4965 type: "String"
4966 }
4967 ]
4968 },
4969 {
4970 name: "ImplicitThrowEvent",
4971 superClass: [
4972 "ThrowEvent"
4973 ]
4974 },
4975 {
4976 name: "DataState",
4977 superClass: [
4978 "BaseElement"
4979 ],
4980 properties: [
4981 {
4982 name: "name",
4983 isAttr: true,
4984 type: "String"
4985 }
4986 ]
4987 },
4988 {
4989 name: "ItemAwareElement",
4990 superClass: [
4991 "BaseElement"
4992 ],
4993 properties: [
4994 {
4995 name: "itemSubjectRef",
4996 type: "ItemDefinition",
4997 isAttr: true,
4998 isReference: true
4999 },
5000 {
5001 name: "dataState",
5002 type: "DataState"
5003 }
5004 ]
5005 },
5006 {
5007 name: "DataAssociation",
5008 superClass: [
5009 "BaseElement"
5010 ],
5011 properties: [
5012 {
5013 name: "sourceRef",
5014 type: "ItemAwareElement",
5015 isMany: true,
5016 isReference: true
5017 },
5018 {
5019 name: "targetRef",
5020 type: "ItemAwareElement",
5021 isReference: true
5022 },
5023 {
5024 name: "transformation",
5025 type: "FormalExpression",
5026 xml: {
5027 serialize: "property"
5028 }
5029 },
5030 {
5031 name: "assignment",
5032 type: "Assignment",
5033 isMany: true
5034 }
5035 ]
5036 },
5037 {
5038 name: "DataInput",
5039 superClass: [
5040 "ItemAwareElement"
5041 ],
5042 properties: [
5043 {
5044 name: "name",
5045 isAttr: true,
5046 type: "String"
5047 },
5048 {
5049 name: "isCollection",
5050 "default": false,
5051 isAttr: true,
5052 type: "Boolean"
5053 },
5054 {
5055 name: "inputSetRef",
5056 type: "InputSet",
5057 isMany: true,
5058 isVirtual: true,
5059 isReference: true
5060 },
5061 {
5062 name: "inputSetWithOptional",
5063 type: "InputSet",
5064 isMany: true,
5065 isVirtual: true,
5066 isReference: true
5067 },
5068 {
5069 name: "inputSetWithWhileExecuting",
5070 type: "InputSet",
5071 isMany: true,
5072 isVirtual: true,
5073 isReference: true
5074 }
5075 ]
5076 },
5077 {
5078 name: "DataOutput",
5079 superClass: [
5080 "ItemAwareElement"
5081 ],
5082 properties: [
5083 {
5084 name: "name",
5085 isAttr: true,
5086 type: "String"
5087 },
5088 {
5089 name: "isCollection",
5090 "default": false,
5091 isAttr: true,
5092 type: "Boolean"
5093 },
5094 {
5095 name: "outputSetRef",
5096 type: "OutputSet",
5097 isMany: true,
5098 isVirtual: true,
5099 isReference: true
5100 },
5101 {
5102 name: "outputSetWithOptional",
5103 type: "OutputSet",
5104 isMany: true,
5105 isVirtual: true,
5106 isReference: true
5107 },
5108 {
5109 name: "outputSetWithWhileExecuting",
5110 type: "OutputSet",
5111 isMany: true,
5112 isVirtual: true,
5113 isReference: true
5114 }
5115 ]
5116 },
5117 {
5118 name: "InputSet",
5119 superClass: [
5120 "BaseElement"
5121 ],
5122 properties: [
5123 {
5124 name: "name",
5125 isAttr: true,
5126 type: "String"
5127 },
5128 {
5129 name: "dataInputRefs",
5130 type: "DataInput",
5131 isMany: true,
5132 isReference: true
5133 },
5134 {
5135 name: "optionalInputRefs",
5136 type: "DataInput",
5137 isMany: true,
5138 isReference: true
5139 },
5140 {
5141 name: "whileExecutingInputRefs",
5142 type: "DataInput",
5143 isMany: true,
5144 isReference: true
5145 },
5146 {
5147 name: "outputSetRefs",
5148 type: "OutputSet",
5149 isMany: true,
5150 isReference: true
5151 }
5152 ]
5153 },
5154 {
5155 name: "OutputSet",
5156 superClass: [
5157 "BaseElement"
5158 ],
5159 properties: [
5160 {
5161 name: "dataOutputRefs",
5162 type: "DataOutput",
5163 isMany: true,
5164 isReference: true
5165 },
5166 {
5167 name: "name",
5168 isAttr: true,
5169 type: "String"
5170 },
5171 {
5172 name: "inputSetRefs",
5173 type: "InputSet",
5174 isMany: true,
5175 isReference: true
5176 },
5177 {
5178 name: "optionalOutputRefs",
5179 type: "DataOutput",
5180 isMany: true,
5181 isReference: true
5182 },
5183 {
5184 name: "whileExecutingOutputRefs",
5185 type: "DataOutput",
5186 isMany: true,
5187 isReference: true
5188 }
5189 ]
5190 },
5191 {
5192 name: "Property",
5193 superClass: [
5194 "ItemAwareElement"
5195 ],
5196 properties: [
5197 {
5198 name: "name",
5199 isAttr: true,
5200 type: "String"
5201 }
5202 ]
5203 },
5204 {
5205 name: "DataInputAssociation",
5206 superClass: [
5207 "DataAssociation"
5208 ]
5209 },
5210 {
5211 name: "DataOutputAssociation",
5212 superClass: [
5213 "DataAssociation"
5214 ]
5215 },
5216 {
5217 name: "InputOutputSpecification",
5218 superClass: [
5219 "BaseElement"
5220 ],
5221 properties: [
5222 {
5223 name: "dataInputs",
5224 type: "DataInput",
5225 isMany: true
5226 },
5227 {
5228 name: "dataOutputs",
5229 type: "DataOutput",
5230 isMany: true
5231 },
5232 {
5233 name: "inputSets",
5234 type: "InputSet",
5235 isMany: true
5236 },
5237 {
5238 name: "outputSets",
5239 type: "OutputSet",
5240 isMany: true
5241 }
5242 ]
5243 },
5244 {
5245 name: "DataObject",
5246 superClass: [
5247 "FlowElement",
5248 "ItemAwareElement"
5249 ],
5250 properties: [
5251 {
5252 name: "isCollection",
5253 "default": false,
5254 isAttr: true,
5255 type: "Boolean"
5256 }
5257 ]
5258 },
5259 {
5260 name: "InputOutputBinding",
5261 properties: [
5262 {
5263 name: "inputDataRef",
5264 type: "InputSet",
5265 isAttr: true,
5266 isReference: true
5267 },
5268 {
5269 name: "outputDataRef",
5270 type: "OutputSet",
5271 isAttr: true,
5272 isReference: true
5273 },
5274 {
5275 name: "operationRef",
5276 type: "Operation",
5277 isAttr: true,
5278 isReference: true
5279 }
5280 ]
5281 },
5282 {
5283 name: "Assignment",
5284 superClass: [
5285 "BaseElement"
5286 ],
5287 properties: [
5288 {
5289 name: "from",
5290 type: "Expression",
5291 xml: {
5292 serialize: "xsi:type"
5293 }
5294 },
5295 {
5296 name: "to",
5297 type: "Expression",
5298 xml: {
5299 serialize: "xsi:type"
5300 }
5301 }
5302 ]
5303 },
5304 {
5305 name: "DataStore",
5306 superClass: [
5307 "RootElement",
5308 "ItemAwareElement"
5309 ],
5310 properties: [
5311 {
5312 name: "name",
5313 isAttr: true,
5314 type: "String"
5315 },
5316 {
5317 name: "capacity",
5318 isAttr: true,
5319 type: "Integer"
5320 },
5321 {
5322 name: "isUnlimited",
5323 "default": true,
5324 isAttr: true,
5325 type: "Boolean"
5326 }
5327 ]
5328 },
5329 {
5330 name: "DataStoreReference",
5331 superClass: [
5332 "ItemAwareElement",
5333 "FlowElement"
5334 ],
5335 properties: [
5336 {
5337 name: "dataStoreRef",
5338 type: "DataStore",
5339 isAttr: true,
5340 isReference: true
5341 }
5342 ]
5343 },
5344 {
5345 name: "DataObjectReference",
5346 superClass: [
5347 "ItemAwareElement",
5348 "FlowElement"
5349 ],
5350 properties: [
5351 {
5352 name: "dataObjectRef",
5353 type: "DataObject",
5354 isAttr: true,
5355 isReference: true
5356 }
5357 ]
5358 },
5359 {
5360 name: "ConversationLink",
5361 superClass: [
5362 "BaseElement"
5363 ],
5364 properties: [
5365 {
5366 name: "sourceRef",
5367 type: "InteractionNode",
5368 isAttr: true,
5369 isReference: true
5370 },
5371 {
5372 name: "targetRef",
5373 type: "InteractionNode",
5374 isAttr: true,
5375 isReference: true
5376 },
5377 {
5378 name: "name",
5379 isAttr: true,
5380 type: "String"
5381 }
5382 ]
5383 },
5384 {
5385 name: "ConversationAssociation",
5386 superClass: [
5387 "BaseElement"
5388 ],
5389 properties: [
5390 {
5391 name: "innerConversationNodeRef",
5392 type: "ConversationNode",
5393 isAttr: true,
5394 isReference: true
5395 },
5396 {
5397 name: "outerConversationNodeRef",
5398 type: "ConversationNode",
5399 isAttr: true,
5400 isReference: true
5401 }
5402 ]
5403 },
5404 {
5405 name: "CallConversation",
5406 superClass: [
5407 "ConversationNode"
5408 ],
5409 properties: [
5410 {
5411 name: "calledCollaborationRef",
5412 type: "Collaboration",
5413 isAttr: true,
5414 isReference: true
5415 },
5416 {
5417 name: "participantAssociations",
5418 type: "ParticipantAssociation",
5419 isMany: true
5420 }
5421 ]
5422 },
5423 {
5424 name: "Conversation",
5425 superClass: [
5426 "ConversationNode"
5427 ]
5428 },
5429 {
5430 name: "SubConversation",
5431 superClass: [
5432 "ConversationNode"
5433 ],
5434 properties: [
5435 {
5436 name: "conversationNodes",
5437 type: "ConversationNode",
5438 isMany: true
5439 }
5440 ]
5441 },
5442 {
5443 name: "ConversationNode",
5444 isAbstract: true,
5445 superClass: [
5446 "InteractionNode",
5447 "BaseElement"
5448 ],
5449 properties: [
5450 {
5451 name: "name",
5452 isAttr: true,
5453 type: "String"
5454 },
5455 {
5456 name: "participantRef",
5457 type: "Participant",
5458 isMany: true,
5459 isReference: true
5460 },
5461 {
5462 name: "messageFlowRefs",
5463 type: "MessageFlow",
5464 isMany: true,
5465 isReference: true
5466 },
5467 {
5468 name: "correlationKeys",
5469 type: "CorrelationKey",
5470 isMany: true
5471 }
5472 ]
5473 },
5474 {
5475 name: "GlobalConversation",
5476 superClass: [
5477 "Collaboration"
5478 ]
5479 },
5480 {
5481 name: "PartnerEntity",
5482 superClass: [
5483 "RootElement"
5484 ],
5485 properties: [
5486 {
5487 name: "name",
5488 isAttr: true,
5489 type: "String"
5490 },
5491 {
5492 name: "participantRef",
5493 type: "Participant",
5494 isMany: true,
5495 isReference: true
5496 }
5497 ]
5498 },
5499 {
5500 name: "PartnerRole",
5501 superClass: [
5502 "RootElement"
5503 ],
5504 properties: [
5505 {
5506 name: "name",
5507 isAttr: true,
5508 type: "String"
5509 },
5510 {
5511 name: "participantRef",
5512 type: "Participant",
5513 isMany: true,
5514 isReference: true
5515 }
5516 ]
5517 },
5518 {
5519 name: "CorrelationProperty",
5520 superClass: [
5521 "RootElement"
5522 ],
5523 properties: [
5524 {
5525 name: "correlationPropertyRetrievalExpression",
5526 type: "CorrelationPropertyRetrievalExpression",
5527 isMany: true
5528 },
5529 {
5530 name: "name",
5531 isAttr: true,
5532 type: "String"
5533 },
5534 {
5535 name: "type",
5536 type: "ItemDefinition",
5537 isAttr: true,
5538 isReference: true
5539 }
5540 ]
5541 },
5542 {
5543 name: "Error",
5544 superClass: [
5545 "RootElement"
5546 ],
5547 properties: [
5548 {
5549 name: "structureRef",
5550 type: "ItemDefinition",
5551 isAttr: true,
5552 isReference: true
5553 },
5554 {
5555 name: "name",
5556 isAttr: true,
5557 type: "String"
5558 },
5559 {
5560 name: "errorCode",
5561 isAttr: true,
5562 type: "String"
5563 }
5564 ]
5565 },
5566 {
5567 name: "CorrelationKey",
5568 superClass: [
5569 "BaseElement"
5570 ],
5571 properties: [
5572 {
5573 name: "correlationPropertyRef",
5574 type: "CorrelationProperty",
5575 isMany: true,
5576 isReference: true
5577 },
5578 {
5579 name: "name",
5580 isAttr: true,
5581 type: "String"
5582 }
5583 ]
5584 },
5585 {
5586 name: "Expression",
5587 superClass: [
5588 "BaseElement"
5589 ],
5590 isAbstract: false,
5591 properties: [
5592 {
5593 name: "body",
5594 isBody: true,
5595 type: "String"
5596 }
5597 ]
5598 },
5599 {
5600 name: "FormalExpression",
5601 superClass: [
5602 "Expression"
5603 ],
5604 properties: [
5605 {
5606 name: "language",
5607 isAttr: true,
5608 type: "String"
5609 },
5610 {
5611 name: "evaluatesToTypeRef",
5612 type: "ItemDefinition",
5613 isAttr: true,
5614 isReference: true
5615 }
5616 ]
5617 },
5618 {
5619 name: "Message",
5620 superClass: [
5621 "RootElement"
5622 ],
5623 properties: [
5624 {
5625 name: "name",
5626 isAttr: true,
5627 type: "String"
5628 },
5629 {
5630 name: "itemRef",
5631 type: "ItemDefinition",
5632 isAttr: true,
5633 isReference: true
5634 }
5635 ]
5636 },
5637 {
5638 name: "ItemDefinition",
5639 superClass: [
5640 "RootElement"
5641 ],
5642 properties: [
5643 {
5644 name: "itemKind",
5645 type: "ItemKind",
5646 isAttr: true
5647 },
5648 {
5649 name: "structureRef",
5650 isAttr: true,
5651 type: "String"
5652 },
5653 {
5654 name: "isCollection",
5655 "default": false,
5656 isAttr: true,
5657 type: "Boolean"
5658 },
5659 {
5660 name: "import",
5661 type: "Import",
5662 isAttr: true,
5663 isReference: true
5664 }
5665 ]
5666 },
5667 {
5668 name: "FlowElement",
5669 isAbstract: true,
5670 superClass: [
5671 "BaseElement"
5672 ],
5673 properties: [
5674 {
5675 name: "name",
5676 isAttr: true,
5677 type: "String"
5678 },
5679 {
5680 name: "auditing",
5681 type: "Auditing"
5682 },
5683 {
5684 name: "monitoring",
5685 type: "Monitoring"
5686 },
5687 {
5688 name: "categoryValueRef",
5689 type: "CategoryValue",
5690 isMany: true,
5691 isReference: true
5692 }
5693 ]
5694 },
5695 {
5696 name: "SequenceFlow",
5697 superClass: [
5698 "FlowElement"
5699 ],
5700 properties: [
5701 {
5702 name: "isImmediate",
5703 isAttr: true,
5704 type: "Boolean"
5705 },
5706 {
5707 name: "conditionExpression",
5708 type: "Expression",
5709 xml: {
5710 serialize: "xsi:type"
5711 }
5712 },
5713 {
5714 name: "sourceRef",
5715 type: "FlowNode",
5716 isAttr: true,
5717 isReference: true
5718 },
5719 {
5720 name: "targetRef",
5721 type: "FlowNode",
5722 isAttr: true,
5723 isReference: true
5724 }
5725 ]
5726 },
5727 {
5728 name: "FlowElementsContainer",
5729 isAbstract: true,
5730 superClass: [
5731 "BaseElement"
5732 ],
5733 properties: [
5734 {
5735 name: "laneSets",
5736 type: "LaneSet",
5737 isMany: true
5738 },
5739 {
5740 name: "flowElements",
5741 type: "FlowElement",
5742 isMany: true
5743 }
5744 ]
5745 },
5746 {
5747 name: "CallableElement",
5748 isAbstract: true,
5749 superClass: [
5750 "RootElement"
5751 ],
5752 properties: [
5753 {
5754 name: "name",
5755 isAttr: true,
5756 type: "String"
5757 },
5758 {
5759 name: "ioSpecification",
5760 type: "InputOutputSpecification",
5761 xml: {
5762 serialize: "property"
5763 }
5764 },
5765 {
5766 name: "supportedInterfaceRef",
5767 type: "Interface",
5768 isMany: true,
5769 isReference: true
5770 },
5771 {
5772 name: "ioBinding",
5773 type: "InputOutputBinding",
5774 isMany: true,
5775 xml: {
5776 serialize: "property"
5777 }
5778 }
5779 ]
5780 },
5781 {
5782 name: "FlowNode",
5783 isAbstract: true,
5784 superClass: [
5785 "FlowElement"
5786 ],
5787 properties: [
5788 {
5789 name: "incoming",
5790 type: "SequenceFlow",
5791 isMany: true,
5792 isReference: true
5793 },
5794 {
5795 name: "outgoing",
5796 type: "SequenceFlow",
5797 isMany: true,
5798 isReference: true
5799 },
5800 {
5801 name: "lanes",
5802 type: "Lane",
5803 isMany: true,
5804 isVirtual: true,
5805 isReference: true
5806 }
5807 ]
5808 },
5809 {
5810 name: "CorrelationPropertyRetrievalExpression",
5811 superClass: [
5812 "BaseElement"
5813 ],
5814 properties: [
5815 {
5816 name: "messagePath",
5817 type: "FormalExpression"
5818 },
5819 {
5820 name: "messageRef",
5821 type: "Message",
5822 isAttr: true,
5823 isReference: true
5824 }
5825 ]
5826 },
5827 {
5828 name: "CorrelationPropertyBinding",
5829 superClass: [
5830 "BaseElement"
5831 ],
5832 properties: [
5833 {
5834 name: "dataPath",
5835 type: "FormalExpression"
5836 },
5837 {
5838 name: "correlationPropertyRef",
5839 type: "CorrelationProperty",
5840 isAttr: true,
5841 isReference: true
5842 }
5843 ]
5844 },
5845 {
5846 name: "Resource",
5847 superClass: [
5848 "RootElement"
5849 ],
5850 properties: [
5851 {
5852 name: "name",
5853 isAttr: true,
5854 type: "String"
5855 },
5856 {
5857 name: "resourceParameters",
5858 type: "ResourceParameter",
5859 isMany: true
5860 }
5861 ]
5862 },
5863 {
5864 name: "ResourceParameter",
5865 superClass: [
5866 "BaseElement"
5867 ],
5868 properties: [
5869 {
5870 name: "name",
5871 isAttr: true,
5872 type: "String"
5873 },
5874 {
5875 name: "isRequired",
5876 isAttr: true,
5877 type: "Boolean"
5878 },
5879 {
5880 name: "type",
5881 type: "ItemDefinition",
5882 isAttr: true,
5883 isReference: true
5884 }
5885 ]
5886 },
5887 {
5888 name: "CorrelationSubscription",
5889 superClass: [
5890 "BaseElement"
5891 ],
5892 properties: [
5893 {
5894 name: "correlationKeyRef",
5895 type: "CorrelationKey",
5896 isAttr: true,
5897 isReference: true
5898 },
5899 {
5900 name: "correlationPropertyBinding",
5901 type: "CorrelationPropertyBinding",
5902 isMany: true
5903 }
5904 ]
5905 },
5906 {
5907 name: "MessageFlow",
5908 superClass: [
5909 "BaseElement"
5910 ],
5911 properties: [
5912 {
5913 name: "name",
5914 isAttr: true,
5915 type: "String"
5916 },
5917 {
5918 name: "sourceRef",
5919 type: "InteractionNode",
5920 isAttr: true,
5921 isReference: true
5922 },
5923 {
5924 name: "targetRef",
5925 type: "InteractionNode",
5926 isAttr: true,
5927 isReference: true
5928 },
5929 {
5930 name: "messageRef",
5931 type: "Message",
5932 isAttr: true,
5933 isReference: true
5934 }
5935 ]
5936 },
5937 {
5938 name: "MessageFlowAssociation",
5939 superClass: [
5940 "BaseElement"
5941 ],
5942 properties: [
5943 {
5944 name: "innerMessageFlowRef",
5945 type: "MessageFlow",
5946 isAttr: true,
5947 isReference: true
5948 },
5949 {
5950 name: "outerMessageFlowRef",
5951 type: "MessageFlow",
5952 isAttr: true,
5953 isReference: true
5954 }
5955 ]
5956 },
5957 {
5958 name: "InteractionNode",
5959 isAbstract: true,
5960 properties: [
5961 {
5962 name: "incomingConversationLinks",
5963 type: "ConversationLink",
5964 isMany: true,
5965 isVirtual: true,
5966 isReference: true
5967 },
5968 {
5969 name: "outgoingConversationLinks",
5970 type: "ConversationLink",
5971 isMany: true,
5972 isVirtual: true,
5973 isReference: true
5974 }
5975 ]
5976 },
5977 {
5978 name: "Participant",
5979 superClass: [
5980 "InteractionNode",
5981 "BaseElement"
5982 ],
5983 properties: [
5984 {
5985 name: "name",
5986 isAttr: true,
5987 type: "String"
5988 },
5989 {
5990 name: "interfaceRef",
5991 type: "Interface",
5992 isMany: true,
5993 isReference: true
5994 },
5995 {
5996 name: "participantMultiplicity",
5997 type: "ParticipantMultiplicity"
5998 },
5999 {
6000 name: "endPointRefs",
6001 type: "EndPoint",
6002 isMany: true,
6003 isReference: true
6004 },
6005 {
6006 name: "processRef",
6007 type: "Process",
6008 isAttr: true,
6009 isReference: true
6010 }
6011 ]
6012 },
6013 {
6014 name: "ParticipantAssociation",
6015 superClass: [
6016 "BaseElement"
6017 ],
6018 properties: [
6019 {
6020 name: "innerParticipantRef",
6021 type: "Participant",
6022 isAttr: true,
6023 isReference: true
6024 },
6025 {
6026 name: "outerParticipantRef",
6027 type: "Participant",
6028 isAttr: true,
6029 isReference: true
6030 }
6031 ]
6032 },
6033 {
6034 name: "ParticipantMultiplicity",
6035 properties: [
6036 {
6037 name: "minimum",
6038 "default": 0,
6039 isAttr: true,
6040 type: "Integer"
6041 },
6042 {
6043 name: "maximum",
6044 "default": 1,
6045 isAttr: true,
6046 type: "Integer"
6047 }
6048 ],
6049 superClass: [
6050 "BaseElement"
6051 ]
6052 },
6053 {
6054 name: "Collaboration",
6055 superClass: [
6056 "RootElement"
6057 ],
6058 properties: [
6059 {
6060 name: "name",
6061 isAttr: true,
6062 type: "String"
6063 },
6064 {
6065 name: "isClosed",
6066 isAttr: true,
6067 type: "Boolean"
6068 },
6069 {
6070 name: "participants",
6071 type: "Participant",
6072 isMany: true
6073 },
6074 {
6075 name: "messageFlows",
6076 type: "MessageFlow",
6077 isMany: true
6078 },
6079 {
6080 name: "artifacts",
6081 type: "Artifact",
6082 isMany: true
6083 },
6084 {
6085 name: "conversations",
6086 type: "ConversationNode",
6087 isMany: true
6088 },
6089 {
6090 name: "conversationAssociations",
6091 type: "ConversationAssociation"
6092 },
6093 {
6094 name: "participantAssociations",
6095 type: "ParticipantAssociation",
6096 isMany: true
6097 },
6098 {
6099 name: "messageFlowAssociations",
6100 type: "MessageFlowAssociation",
6101 isMany: true
6102 },
6103 {
6104 name: "correlationKeys",
6105 type: "CorrelationKey",
6106 isMany: true
6107 },
6108 {
6109 name: "choreographyRef",
6110 type: "Choreography",
6111 isMany: true,
6112 isReference: true
6113 },
6114 {
6115 name: "conversationLinks",
6116 type: "ConversationLink",
6117 isMany: true
6118 }
6119 ]
6120 },
6121 {
6122 name: "ChoreographyActivity",
6123 isAbstract: true,
6124 superClass: [
6125 "FlowNode"
6126 ],
6127 properties: [
6128 {
6129 name: "participantRef",
6130 type: "Participant",
6131 isMany: true,
6132 isReference: true
6133 },
6134 {
6135 name: "initiatingParticipantRef",
6136 type: "Participant",
6137 isAttr: true,
6138 isReference: true
6139 },
6140 {
6141 name: "correlationKeys",
6142 type: "CorrelationKey",
6143 isMany: true
6144 },
6145 {
6146 name: "loopType",
6147 type: "ChoreographyLoopType",
6148 "default": "None",
6149 isAttr: true
6150 }
6151 ]
6152 },
6153 {
6154 name: "CallChoreography",
6155 superClass: [
6156 "ChoreographyActivity"
6157 ],
6158 properties: [
6159 {
6160 name: "calledChoreographyRef",
6161 type: "Choreography",
6162 isAttr: true,
6163 isReference: true
6164 },
6165 {
6166 name: "participantAssociations",
6167 type: "ParticipantAssociation",
6168 isMany: true
6169 }
6170 ]
6171 },
6172 {
6173 name: "SubChoreography",
6174 superClass: [
6175 "ChoreographyActivity",
6176 "FlowElementsContainer"
6177 ],
6178 properties: [
6179 {
6180 name: "artifacts",
6181 type: "Artifact",
6182 isMany: true
6183 }
6184 ]
6185 },
6186 {
6187 name: "ChoreographyTask",
6188 superClass: [
6189 "ChoreographyActivity"
6190 ],
6191 properties: [
6192 {
6193 name: "messageFlowRef",
6194 type: "MessageFlow",
6195 isMany: true,
6196 isReference: true
6197 }
6198 ]
6199 },
6200 {
6201 name: "Choreography",
6202 superClass: [
6203 "Collaboration",
6204 "FlowElementsContainer"
6205 ]
6206 },
6207 {
6208 name: "GlobalChoreographyTask",
6209 superClass: [
6210 "Choreography"
6211 ],
6212 properties: [
6213 {
6214 name: "initiatingParticipantRef",
6215 type: "Participant",
6216 isAttr: true,
6217 isReference: true
6218 }
6219 ]
6220 },
6221 {
6222 name: "TextAnnotation",
6223 superClass: [
6224 "Artifact"
6225 ],
6226 properties: [
6227 {
6228 name: "text",
6229 type: "String"
6230 },
6231 {
6232 name: "textFormat",
6233 "default": "text/plain",
6234 isAttr: true,
6235 type: "String"
6236 }
6237 ]
6238 },
6239 {
6240 name: "Group",
6241 superClass: [
6242 "Artifact"
6243 ],
6244 properties: [
6245 {
6246 name: "categoryValueRef",
6247 type: "CategoryValue",
6248 isAttr: true,
6249 isReference: true
6250 }
6251 ]
6252 },
6253 {
6254 name: "Association",
6255 superClass: [
6256 "Artifact"
6257 ],
6258 properties: [
6259 {
6260 name: "associationDirection",
6261 type: "AssociationDirection",
6262 isAttr: true
6263 },
6264 {
6265 name: "sourceRef",
6266 type: "BaseElement",
6267 isAttr: true,
6268 isReference: true
6269 },
6270 {
6271 name: "targetRef",
6272 type: "BaseElement",
6273 isAttr: true,
6274 isReference: true
6275 }
6276 ]
6277 },
6278 {
6279 name: "Category",
6280 superClass: [
6281 "RootElement"
6282 ],
6283 properties: [
6284 {
6285 name: "categoryValue",
6286 type: "CategoryValue",
6287 isMany: true
6288 },
6289 {
6290 name: "name",
6291 isAttr: true,
6292 type: "String"
6293 }
6294 ]
6295 },
6296 {
6297 name: "Artifact",
6298 isAbstract: true,
6299 superClass: [
6300 "BaseElement"
6301 ]
6302 },
6303 {
6304 name: "CategoryValue",
6305 superClass: [
6306 "BaseElement"
6307 ],
6308 properties: [
6309 {
6310 name: "categorizedFlowElements",
6311 type: "FlowElement",
6312 isMany: true,
6313 isVirtual: true,
6314 isReference: true
6315 },
6316 {
6317 name: "value",
6318 isAttr: true,
6319 type: "String"
6320 }
6321 ]
6322 },
6323 {
6324 name: "Activity",
6325 isAbstract: true,
6326 superClass: [
6327 "FlowNode"
6328 ],
6329 properties: [
6330 {
6331 name: "isForCompensation",
6332 "default": false,
6333 isAttr: true,
6334 type: "Boolean"
6335 },
6336 {
6337 name: "default",
6338 type: "SequenceFlow",
6339 isAttr: true,
6340 isReference: true
6341 },
6342 {
6343 name: "ioSpecification",
6344 type: "InputOutputSpecification",
6345 xml: {
6346 serialize: "property"
6347 }
6348 },
6349 {
6350 name: "boundaryEventRefs",
6351 type: "BoundaryEvent",
6352 isMany: true,
6353 isReference: true
6354 },
6355 {
6356 name: "properties",
6357 type: "Property",
6358 isMany: true
6359 },
6360 {
6361 name: "dataInputAssociations",
6362 type: "DataInputAssociation",
6363 isMany: true
6364 },
6365 {
6366 name: "dataOutputAssociations",
6367 type: "DataOutputAssociation",
6368 isMany: true
6369 },
6370 {
6371 name: "startQuantity",
6372 "default": 1,
6373 isAttr: true,
6374 type: "Integer"
6375 },
6376 {
6377 name: "resources",
6378 type: "ResourceRole",
6379 isMany: true
6380 },
6381 {
6382 name: "completionQuantity",
6383 "default": 1,
6384 isAttr: true,
6385 type: "Integer"
6386 },
6387 {
6388 name: "loopCharacteristics",
6389 type: "LoopCharacteristics"
6390 }
6391 ]
6392 },
6393 {
6394 name: "ServiceTask",
6395 superClass: [
6396 "Task"
6397 ],
6398 properties: [
6399 {
6400 name: "implementation",
6401 isAttr: true,
6402 type: "String"
6403 },
6404 {
6405 name: "operationRef",
6406 type: "Operation",
6407 isAttr: true,
6408 isReference: true
6409 }
6410 ]
6411 },
6412 {
6413 name: "SubProcess",
6414 superClass: [
6415 "Activity",
6416 "FlowElementsContainer",
6417 "InteractionNode"
6418 ],
6419 properties: [
6420 {
6421 name: "triggeredByEvent",
6422 "default": false,
6423 isAttr: true,
6424 type: "Boolean"
6425 },
6426 {
6427 name: "artifacts",
6428 type: "Artifact",
6429 isMany: true
6430 }
6431 ]
6432 },
6433 {
6434 name: "LoopCharacteristics",
6435 isAbstract: true,
6436 superClass: [
6437 "BaseElement"
6438 ]
6439 },
6440 {
6441 name: "MultiInstanceLoopCharacteristics",
6442 superClass: [
6443 "LoopCharacteristics"
6444 ],
6445 properties: [
6446 {
6447 name: "isSequential",
6448 "default": false,
6449 isAttr: true,
6450 type: "Boolean"
6451 },
6452 {
6453 name: "behavior",
6454 type: "MultiInstanceBehavior",
6455 "default": "All",
6456 isAttr: true
6457 },
6458 {
6459 name: "loopCardinality",
6460 type: "Expression",
6461 xml: {
6462 serialize: "xsi:type"
6463 }
6464 },
6465 {
6466 name: "loopDataInputRef",
6467 type: "ItemAwareElement",
6468 isReference: true
6469 },
6470 {
6471 name: "loopDataOutputRef",
6472 type: "ItemAwareElement",
6473 isReference: true
6474 },
6475 {
6476 name: "inputDataItem",
6477 type: "DataInput",
6478 xml: {
6479 serialize: "property"
6480 }
6481 },
6482 {
6483 name: "outputDataItem",
6484 type: "DataOutput",
6485 xml: {
6486 serialize: "property"
6487 }
6488 },
6489 {
6490 name: "complexBehaviorDefinition",
6491 type: "ComplexBehaviorDefinition",
6492 isMany: true
6493 },
6494 {
6495 name: "completionCondition",
6496 type: "Expression",
6497 xml: {
6498 serialize: "xsi:type"
6499 }
6500 },
6501 {
6502 name: "oneBehaviorEventRef",
6503 type: "EventDefinition",
6504 isAttr: true,
6505 isReference: true
6506 },
6507 {
6508 name: "noneBehaviorEventRef",
6509 type: "EventDefinition",
6510 isAttr: true,
6511 isReference: true
6512 }
6513 ]
6514 },
6515 {
6516 name: "StandardLoopCharacteristics",
6517 superClass: [
6518 "LoopCharacteristics"
6519 ],
6520 properties: [
6521 {
6522 name: "testBefore",
6523 "default": false,
6524 isAttr: true,
6525 type: "Boolean"
6526 },
6527 {
6528 name: "loopCondition",
6529 type: "Expression",
6530 xml: {
6531 serialize: "xsi:type"
6532 }
6533 },
6534 {
6535 name: "loopMaximum",
6536 type: "Integer",
6537 isAttr: true
6538 }
6539 ]
6540 },
6541 {
6542 name: "CallActivity",
6543 superClass: [
6544 "Activity",
6545 "InteractionNode"
6546 ],
6547 properties: [
6548 {
6549 name: "calledElement",
6550 type: "String",
6551 isAttr: true
6552 }
6553 ]
6554 },
6555 {
6556 name: "Task",
6557 superClass: [
6558 "Activity",
6559 "InteractionNode"
6560 ]
6561 },
6562 {
6563 name: "SendTask",
6564 superClass: [
6565 "Task"
6566 ],
6567 properties: [
6568 {
6569 name: "implementation",
6570 isAttr: true,
6571 type: "String"
6572 },
6573 {
6574 name: "operationRef",
6575 type: "Operation",
6576 isAttr: true,
6577 isReference: true
6578 },
6579 {
6580 name: "messageRef",
6581 type: "Message",
6582 isAttr: true,
6583 isReference: true
6584 }
6585 ]
6586 },
6587 {
6588 name: "ReceiveTask",
6589 superClass: [
6590 "Task"
6591 ],
6592 properties: [
6593 {
6594 name: "implementation",
6595 isAttr: true,
6596 type: "String"
6597 },
6598 {
6599 name: "instantiate",
6600 "default": false,
6601 isAttr: true,
6602 type: "Boolean"
6603 },
6604 {
6605 name: "operationRef",
6606 type: "Operation",
6607 isAttr: true,
6608 isReference: true
6609 },
6610 {
6611 name: "messageRef",
6612 type: "Message",
6613 isAttr: true,
6614 isReference: true
6615 }
6616 ]
6617 },
6618 {
6619 name: "ScriptTask",
6620 superClass: [
6621 "Task"
6622 ],
6623 properties: [
6624 {
6625 name: "scriptFormat",
6626 isAttr: true,
6627 type: "String"
6628 },
6629 {
6630 name: "script",
6631 type: "String"
6632 }
6633 ]
6634 },
6635 {
6636 name: "BusinessRuleTask",
6637 superClass: [
6638 "Task"
6639 ],
6640 properties: [
6641 {
6642 name: "implementation",
6643 isAttr: true,
6644 type: "String"
6645 }
6646 ]
6647 },
6648 {
6649 name: "AdHocSubProcess",
6650 superClass: [
6651 "SubProcess"
6652 ],
6653 properties: [
6654 {
6655 name: "completionCondition",
6656 type: "Expression",
6657 xml: {
6658 serialize: "xsi:type"
6659 }
6660 },
6661 {
6662 name: "ordering",
6663 type: "AdHocOrdering",
6664 isAttr: true
6665 },
6666 {
6667 name: "cancelRemainingInstances",
6668 "default": true,
6669 isAttr: true,
6670 type: "Boolean"
6671 }
6672 ]
6673 },
6674 {
6675 name: "Transaction",
6676 superClass: [
6677 "SubProcess"
6678 ],
6679 properties: [
6680 {
6681 name: "protocol",
6682 isAttr: true,
6683 type: "String"
6684 },
6685 {
6686 name: "method",
6687 isAttr: true,
6688 type: "String"
6689 }
6690 ]
6691 },
6692 {
6693 name: "GlobalScriptTask",
6694 superClass: [
6695 "GlobalTask"
6696 ],
6697 properties: [
6698 {
6699 name: "scriptLanguage",
6700 isAttr: true,
6701 type: "String"
6702 },
6703 {
6704 name: "script",
6705 isAttr: true,
6706 type: "String"
6707 }
6708 ]
6709 },
6710 {
6711 name: "GlobalBusinessRuleTask",
6712 superClass: [
6713 "GlobalTask"
6714 ],
6715 properties: [
6716 {
6717 name: "implementation",
6718 isAttr: true,
6719 type: "String"
6720 }
6721 ]
6722 },
6723 {
6724 name: "ComplexBehaviorDefinition",
6725 superClass: [
6726 "BaseElement"
6727 ],
6728 properties: [
6729 {
6730 name: "condition",
6731 type: "FormalExpression"
6732 },
6733 {
6734 name: "event",
6735 type: "ImplicitThrowEvent"
6736 }
6737 ]
6738 },
6739 {
6740 name: "ResourceRole",
6741 superClass: [
6742 "BaseElement"
6743 ],
6744 properties: [
6745 {
6746 name: "resourceRef",
6747 type: "Resource",
6748 isReference: true
6749 },
6750 {
6751 name: "resourceParameterBindings",
6752 type: "ResourceParameterBinding",
6753 isMany: true
6754 },
6755 {
6756 name: "resourceAssignmentExpression",
6757 type: "ResourceAssignmentExpression"
6758 },
6759 {
6760 name: "name",
6761 isAttr: true,
6762 type: "String"
6763 }
6764 ]
6765 },
6766 {
6767 name: "ResourceParameterBinding",
6768 properties: [
6769 {
6770 name: "expression",
6771 type: "Expression",
6772 xml: {
6773 serialize: "xsi:type"
6774 }
6775 },
6776 {
6777 name: "parameterRef",
6778 type: "ResourceParameter",
6779 isAttr: true,
6780 isReference: true
6781 }
6782 ],
6783 superClass: [
6784 "BaseElement"
6785 ]
6786 },
6787 {
6788 name: "ResourceAssignmentExpression",
6789 properties: [
6790 {
6791 name: "expression",
6792 type: "Expression",
6793 xml: {
6794 serialize: "xsi:type"
6795 }
6796 }
6797 ],
6798 superClass: [
6799 "BaseElement"
6800 ]
6801 },
6802 {
6803 name: "Import",
6804 properties: [
6805 {
6806 name: "importType",
6807 isAttr: true,
6808 type: "String"
6809 },
6810 {
6811 name: "location",
6812 isAttr: true,
6813 type: "String"
6814 },
6815 {
6816 name: "namespace",
6817 isAttr: true,
6818 type: "String"
6819 }
6820 ]
6821 },
6822 {
6823 name: "Definitions",
6824 superClass: [
6825 "BaseElement"
6826 ],
6827 properties: [
6828 {
6829 name: "name",
6830 isAttr: true,
6831 type: "String"
6832 },
6833 {
6834 name: "targetNamespace",
6835 isAttr: true,
6836 type: "String"
6837 },
6838 {
6839 name: "expressionLanguage",
6840 "default": "http://www.w3.org/1999/XPath",
6841 isAttr: true,
6842 type: "String"
6843 },
6844 {
6845 name: "typeLanguage",
6846 "default": "http://www.w3.org/2001/XMLSchema",
6847 isAttr: true,
6848 type: "String"
6849 },
6850 {
6851 name: "imports",
6852 type: "Import",
6853 isMany: true
6854 },
6855 {
6856 name: "extensions",
6857 type: "Extension",
6858 isMany: true
6859 },
6860 {
6861 name: "rootElements",
6862 type: "RootElement",
6863 isMany: true
6864 },
6865 {
6866 name: "diagrams",
6867 isMany: true,
6868 type: "bpmndi:BPMNDiagram"
6869 },
6870 {
6871 name: "exporter",
6872 isAttr: true,
6873 type: "String"
6874 },
6875 {
6876 name: "relationships",
6877 type: "Relationship",
6878 isMany: true
6879 },
6880 {
6881 name: "exporterVersion",
6882 isAttr: true,
6883 type: "String"
6884 }
6885 ]
6886 }
6887 ];
6888 var enumerations$3 = [
6889 {
6890 name: "ProcessType",
6891 literalValues: [
6892 {
6893 name: "None"
6894 },
6895 {
6896 name: "Public"
6897 },
6898 {
6899 name: "Private"
6900 }
6901 ]
6902 },
6903 {
6904 name: "GatewayDirection",
6905 literalValues: [
6906 {
6907 name: "Unspecified"
6908 },
6909 {
6910 name: "Converging"
6911 },
6912 {
6913 name: "Diverging"
6914 },
6915 {
6916 name: "Mixed"
6917 }
6918 ]
6919 },
6920 {
6921 name: "EventBasedGatewayType",
6922 literalValues: [
6923 {
6924 name: "Parallel"
6925 },
6926 {
6927 name: "Exclusive"
6928 }
6929 ]
6930 },
6931 {
6932 name: "RelationshipDirection",
6933 literalValues: [
6934 {
6935 name: "None"
6936 },
6937 {
6938 name: "Forward"
6939 },
6940 {
6941 name: "Backward"
6942 },
6943 {
6944 name: "Both"
6945 }
6946 ]
6947 },
6948 {
6949 name: "ItemKind",
6950 literalValues: [
6951 {
6952 name: "Physical"
6953 },
6954 {
6955 name: "Information"
6956 }
6957 ]
6958 },
6959 {
6960 name: "ChoreographyLoopType",
6961 literalValues: [
6962 {
6963 name: "None"
6964 },
6965 {
6966 name: "Standard"
6967 },
6968 {
6969 name: "MultiInstanceSequential"
6970 },
6971 {
6972 name: "MultiInstanceParallel"
6973 }
6974 ]
6975 },
6976 {
6977 name: "AssociationDirection",
6978 literalValues: [
6979 {
6980 name: "None"
6981 },
6982 {
6983 name: "One"
6984 },
6985 {
6986 name: "Both"
6987 }
6988 ]
6989 },
6990 {
6991 name: "MultiInstanceBehavior",
6992 literalValues: [
6993 {
6994 name: "None"
6995 },
6996 {
6997 name: "One"
6998 },
6999 {
7000 name: "All"
7001 },
7002 {
7003 name: "Complex"
7004 }
7005 ]
7006 },
7007 {
7008 name: "AdHocOrdering",
7009 literalValues: [
7010 {
7011 name: "Parallel"
7012 },
7013 {
7014 name: "Sequential"
7015 }
7016 ]
7017 }
7018 ];
7019 var xml$1 = {
7020 tagAlias: "lowerCase",
7021 typePrefix: "t"
7022 };
7023 var BpmnPackage = {
7024 name: name$5,
7025 uri: uri$5,
7026 prefix: prefix$5,
7027 associations: associations$5,
7028 types: types$5,
7029 enumerations: enumerations$3,
7030 xml: xml$1
7031 };
7032
7033 var name$4 = "BPMNDI";
7034 var uri$4 = "http://www.omg.org/spec/BPMN/20100524/DI";
7035 var prefix$4 = "bpmndi";
7036 var types$4 = [
7037 {
7038 name: "BPMNDiagram",
7039 properties: [
7040 {
7041 name: "plane",
7042 type: "BPMNPlane",
7043 redefines: "di:Diagram#rootElement"
7044 },
7045 {
7046 name: "labelStyle",
7047 type: "BPMNLabelStyle",
7048 isMany: true
7049 }
7050 ],
7051 superClass: [
7052 "di:Diagram"
7053 ]
7054 },
7055 {
7056 name: "BPMNPlane",
7057 properties: [
7058 {
7059 name: "bpmnElement",
7060 isAttr: true,
7061 isReference: true,
7062 type: "bpmn:BaseElement",
7063 redefines: "di:DiagramElement#modelElement"
7064 }
7065 ],
7066 superClass: [
7067 "di:Plane"
7068 ]
7069 },
7070 {
7071 name: "BPMNShape",
7072 properties: [
7073 {
7074 name: "bpmnElement",
7075 isAttr: true,
7076 isReference: true,
7077 type: "bpmn:BaseElement",
7078 redefines: "di:DiagramElement#modelElement"
7079 },
7080 {
7081 name: "isHorizontal",
7082 isAttr: true,
7083 type: "Boolean"
7084 },
7085 {
7086 name: "isExpanded",
7087 isAttr: true,
7088 type: "Boolean"
7089 },
7090 {
7091 name: "isMarkerVisible",
7092 isAttr: true,
7093 type: "Boolean"
7094 },
7095 {
7096 name: "label",
7097 type: "BPMNLabel"
7098 },
7099 {
7100 name: "isMessageVisible",
7101 isAttr: true,
7102 type: "Boolean"
7103 },
7104 {
7105 name: "participantBandKind",
7106 type: "ParticipantBandKind",
7107 isAttr: true
7108 },
7109 {
7110 name: "choreographyActivityShape",
7111 type: "BPMNShape",
7112 isAttr: true,
7113 isReference: true
7114 }
7115 ],
7116 superClass: [
7117 "di:LabeledShape"
7118 ]
7119 },
7120 {
7121 name: "BPMNEdge",
7122 properties: [
7123 {
7124 name: "label",
7125 type: "BPMNLabel"
7126 },
7127 {
7128 name: "bpmnElement",
7129 isAttr: true,
7130 isReference: true,
7131 type: "bpmn:BaseElement",
7132 redefines: "di:DiagramElement#modelElement"
7133 },
7134 {
7135 name: "sourceElement",
7136 isAttr: true,
7137 isReference: true,
7138 type: "di:DiagramElement",
7139 redefines: "di:Edge#source"
7140 },
7141 {
7142 name: "targetElement",
7143 isAttr: true,
7144 isReference: true,
7145 type: "di:DiagramElement",
7146 redefines: "di:Edge#target"
7147 },
7148 {
7149 name: "messageVisibleKind",
7150 type: "MessageVisibleKind",
7151 isAttr: true,
7152 "default": "initiating"
7153 }
7154 ],
7155 superClass: [
7156 "di:LabeledEdge"
7157 ]
7158 },
7159 {
7160 name: "BPMNLabel",
7161 properties: [
7162 {
7163 name: "labelStyle",
7164 type: "BPMNLabelStyle",
7165 isAttr: true,
7166 isReference: true,
7167 redefines: "di:DiagramElement#style"
7168 }
7169 ],
7170 superClass: [
7171 "di:Label"
7172 ]
7173 },
7174 {
7175 name: "BPMNLabelStyle",
7176 properties: [
7177 {
7178 name: "font",
7179 type: "dc:Font"
7180 }
7181 ],
7182 superClass: [
7183 "di:Style"
7184 ]
7185 }
7186 ];
7187 var enumerations$2 = [
7188 {
7189 name: "ParticipantBandKind",
7190 literalValues: [
7191 {
7192 name: "top_initiating"
7193 },
7194 {
7195 name: "middle_initiating"
7196 },
7197 {
7198 name: "bottom_initiating"
7199 },
7200 {
7201 name: "top_non_initiating"
7202 },
7203 {
7204 name: "middle_non_initiating"
7205 },
7206 {
7207 name: "bottom_non_initiating"
7208 }
7209 ]
7210 },
7211 {
7212 name: "MessageVisibleKind",
7213 literalValues: [
7214 {
7215 name: "initiating"
7216 },
7217 {
7218 name: "non_initiating"
7219 }
7220 ]
7221 }
7222 ];
7223 var associations$4 = [
7224 ];
7225 var BpmnDiPackage = {
7226 name: name$4,
7227 uri: uri$4,
7228 prefix: prefix$4,
7229 types: types$4,
7230 enumerations: enumerations$2,
7231 associations: associations$4
7232 };
7233
7234 var name$3 = "DC";
7235 var uri$3 = "http://www.omg.org/spec/DD/20100524/DC";
7236 var prefix$3 = "dc";
7237 var types$3 = [
7238 {
7239 name: "Boolean"
7240 },
7241 {
7242 name: "Integer"
7243 },
7244 {
7245 name: "Real"
7246 },
7247 {
7248 name: "String"
7249 },
7250 {
7251 name: "Font",
7252 properties: [
7253 {
7254 name: "name",
7255 type: "String",
7256 isAttr: true
7257 },
7258 {
7259 name: "size",
7260 type: "Real",
7261 isAttr: true
7262 },
7263 {
7264 name: "isBold",
7265 type: "Boolean",
7266 isAttr: true
7267 },
7268 {
7269 name: "isItalic",
7270 type: "Boolean",
7271 isAttr: true
7272 },
7273 {
7274 name: "isUnderline",
7275 type: "Boolean",
7276 isAttr: true
7277 },
7278 {
7279 name: "isStrikeThrough",
7280 type: "Boolean",
7281 isAttr: true
7282 }
7283 ]
7284 },
7285 {
7286 name: "Point",
7287 properties: [
7288 {
7289 name: "x",
7290 type: "Real",
7291 "default": "0",
7292 isAttr: true
7293 },
7294 {
7295 name: "y",
7296 type: "Real",
7297 "default": "0",
7298 isAttr: true
7299 }
7300 ]
7301 },
7302 {
7303 name: "Bounds",
7304 properties: [
7305 {
7306 name: "x",
7307 type: "Real",
7308 "default": "0",
7309 isAttr: true
7310 },
7311 {
7312 name: "y",
7313 type: "Real",
7314 "default": "0",
7315 isAttr: true
7316 },
7317 {
7318 name: "width",
7319 type: "Real",
7320 isAttr: true
7321 },
7322 {
7323 name: "height",
7324 type: "Real",
7325 isAttr: true
7326 }
7327 ]
7328 }
7329 ];
7330 var associations$3 = [
7331 ];
7332 var DcPackage = {
7333 name: name$3,
7334 uri: uri$3,
7335 prefix: prefix$3,
7336 types: types$3,
7337 associations: associations$3
7338 };
7339
7340 var name$2 = "DI";
7341 var uri$2 = "http://www.omg.org/spec/DD/20100524/DI";
7342 var prefix$2 = "di";
7343 var types$2 = [
7344 {
7345 name: "DiagramElement",
7346 isAbstract: true,
7347 properties: [
7348 {
7349 name: "id",
7350 isAttr: true,
7351 isId: true,
7352 type: "String"
7353 },
7354 {
7355 name: "extension",
7356 type: "Extension"
7357 },
7358 {
7359 name: "owningDiagram",
7360 type: "Diagram",
7361 isReadOnly: true,
7362 isVirtual: true,
7363 isReference: true
7364 },
7365 {
7366 name: "owningElement",
7367 type: "DiagramElement",
7368 isReadOnly: true,
7369 isVirtual: true,
7370 isReference: true
7371 },
7372 {
7373 name: "modelElement",
7374 isReadOnly: true,
7375 isVirtual: true,
7376 isReference: true,
7377 type: "Element"
7378 },
7379 {
7380 name: "style",
7381 type: "Style",
7382 isReadOnly: true,
7383 isVirtual: true,
7384 isReference: true
7385 },
7386 {
7387 name: "ownedElement",
7388 type: "DiagramElement",
7389 isReadOnly: true,
7390 isMany: true,
7391 isVirtual: true
7392 }
7393 ]
7394 },
7395 {
7396 name: "Node",
7397 isAbstract: true,
7398 superClass: [
7399 "DiagramElement"
7400 ]
7401 },
7402 {
7403 name: "Edge",
7404 isAbstract: true,
7405 superClass: [
7406 "DiagramElement"
7407 ],
7408 properties: [
7409 {
7410 name: "source",
7411 type: "DiagramElement",
7412 isReadOnly: true,
7413 isVirtual: true,
7414 isReference: true
7415 },
7416 {
7417 name: "target",
7418 type: "DiagramElement",
7419 isReadOnly: true,
7420 isVirtual: true,
7421 isReference: true
7422 },
7423 {
7424 name: "waypoint",
7425 isUnique: false,
7426 isMany: true,
7427 type: "dc:Point",
7428 xml: {
7429 serialize: "xsi:type"
7430 }
7431 }
7432 ]
7433 },
7434 {
7435 name: "Diagram",
7436 isAbstract: true,
7437 properties: [
7438 {
7439 name: "id",
7440 isAttr: true,
7441 isId: true,
7442 type: "String"
7443 },
7444 {
7445 name: "rootElement",
7446 type: "DiagramElement",
7447 isReadOnly: true,
7448 isVirtual: true
7449 },
7450 {
7451 name: "name",
7452 isAttr: true,
7453 type: "String"
7454 },
7455 {
7456 name: "documentation",
7457 isAttr: true,
7458 type: "String"
7459 },
7460 {
7461 name: "resolution",
7462 isAttr: true,
7463 type: "Real"
7464 },
7465 {
7466 name: "ownedStyle",
7467 type: "Style",
7468 isReadOnly: true,
7469 isMany: true,
7470 isVirtual: true
7471 }
7472 ]
7473 },
7474 {
7475 name: "Shape",
7476 isAbstract: true,
7477 superClass: [
7478 "Node"
7479 ],
7480 properties: [
7481 {
7482 name: "bounds",
7483 type: "dc:Bounds"
7484 }
7485 ]
7486 },
7487 {
7488 name: "Plane",
7489 isAbstract: true,
7490 superClass: [
7491 "Node"
7492 ],
7493 properties: [
7494 {
7495 name: "planeElement",
7496 type: "DiagramElement",
7497 subsettedProperty: "DiagramElement-ownedElement",
7498 isMany: true
7499 }
7500 ]
7501 },
7502 {
7503 name: "LabeledEdge",
7504 isAbstract: true,
7505 superClass: [
7506 "Edge"
7507 ],
7508 properties: [
7509 {
7510 name: "ownedLabel",
7511 type: "Label",
7512 isReadOnly: true,
7513 subsettedProperty: "DiagramElement-ownedElement",
7514 isMany: true,
7515 isVirtual: true
7516 }
7517 ]
7518 },
7519 {
7520 name: "LabeledShape",
7521 isAbstract: true,
7522 superClass: [
7523 "Shape"
7524 ],
7525 properties: [
7526 {
7527 name: "ownedLabel",
7528 type: "Label",
7529 isReadOnly: true,
7530 subsettedProperty: "DiagramElement-ownedElement",
7531 isMany: true,
7532 isVirtual: true
7533 }
7534 ]
7535 },
7536 {
7537 name: "Label",
7538 isAbstract: true,
7539 superClass: [
7540 "Node"
7541 ],
7542 properties: [
7543 {
7544 name: "bounds",
7545 type: "dc:Bounds"
7546 }
7547 ]
7548 },
7549 {
7550 name: "Style",
7551 isAbstract: true,
7552 properties: [
7553 {
7554 name: "id",
7555 isAttr: true,
7556 isId: true,
7557 type: "String"
7558 }
7559 ]
7560 },
7561 {
7562 name: "Extension",
7563 properties: [
7564 {
7565 name: "values",
7566 isMany: true,
7567 type: "Element"
7568 }
7569 ]
7570 }
7571 ];
7572 var associations$2 = [
7573 ];
7574 var xml = {
7575 tagAlias: "lowerCase"
7576 };
7577 var DiPackage = {
7578 name: name$2,
7579 uri: uri$2,
7580 prefix: prefix$2,
7581 types: types$2,
7582 associations: associations$2,
7583 xml: xml
7584 };
7585
7586 var name$1 = "bpmn.io colors for BPMN";
7587 var uri$1 = "http://bpmn.io/schema/bpmn/biocolor/1.0";
7588 var prefix$1 = "bioc";
7589 var types$1 = [
7590 {
7591 name: "ColoredShape",
7592 "extends": [
7593 "bpmndi:BPMNShape"
7594 ],
7595 properties: [
7596 {
7597 name: "stroke",
7598 isAttr: true,
7599 type: "String"
7600 },
7601 {
7602 name: "fill",
7603 isAttr: true,
7604 type: "String"
7605 }
7606 ]
7607 },
7608 {
7609 name: "ColoredEdge",
7610 "extends": [
7611 "bpmndi:BPMNEdge"
7612 ],
7613 properties: [
7614 {
7615 name: "stroke",
7616 isAttr: true,
7617 type: "String"
7618 },
7619 {
7620 name: "fill",
7621 isAttr: true,
7622 type: "String"
7623 }
7624 ]
7625 }
7626 ];
7627 var enumerations$1 = [
7628 ];
7629 var associations$1 = [
7630 ];
7631 var BiocPackage = {
7632 name: name$1,
7633 uri: uri$1,
7634 prefix: prefix$1,
7635 types: types$1,
7636 enumerations: enumerations$1,
7637 associations: associations$1
7638 };
7639
7640 var name = "BPMN in Color";
7641 var uri = "http://www.omg.org/spec/BPMN/non-normative/color/1.0";
7642 var prefix = "color";
7643 var types = [
7644 {
7645 name: "ColoredLabel",
7646 "extends": [
7647 "bpmndi:BPMNLabel"
7648 ],
7649 properties: [
7650 {
7651 name: "color",
7652 isAttr: true,
7653 type: "String"
7654 }
7655 ]
7656 },
7657 {
7658 name: "ColoredShape",
7659 "extends": [
7660 "bpmndi:BPMNShape"
7661 ],
7662 properties: [
7663 {
7664 name: "background-color",
7665 isAttr: true,
7666 type: "String"
7667 },
7668 {
7669 name: "border-color",
7670 isAttr: true,
7671 type: "String"
7672 }
7673 ]
7674 },
7675 {
7676 name: "ColoredEdge",
7677 "extends": [
7678 "bpmndi:BPMNEdge"
7679 ],
7680 properties: [
7681 {
7682 name: "border-color",
7683 isAttr: true,
7684 type: "String"
7685 }
7686 ]
7687 }
7688 ];
7689 var enumerations = [
7690 ];
7691 var associations = [
7692 ];
7693 var BpmnInColorPackage = {
7694 name: name,
7695 uri: uri,
7696 prefix: prefix,
7697 types: types,
7698 enumerations: enumerations,
7699 associations: associations
7700 };
7701
7702 var packages = {
7703 bpmn: BpmnPackage,
7704 bpmndi: BpmnDiPackage,
7705 dc: DcPackage,
7706 di: DiPackage,
7707 bioc: BiocPackage,
7708 color: BpmnInColorPackage
7709 };
7710
7711 function simple(additionalPackages, options) {
7712 var pks = assign({}, packages, additionalPackages);
7713
7714 return new BpmnModdle(pks, options);
7715 }
7716
7717 return simple;
7718
7719}));