diff --git a/repository/BaselineOfOPUMLXMI/BaselineOfOPUMLXMI.class.st b/repository/BaselineOfOPUMLXMI/BaselineOfOPUMLXMI.class.st deleted file mode 100644 index b0d415b..0000000 --- a/repository/BaselineOfOPUMLXMI/BaselineOfOPUMLXMI.class.st +++ /dev/null @@ -1,22 +0,0 @@ -" -Baseline for https://github.com/OpenPonk/uml-xmi -" -Class { - #name : 'BaselineOfOPUMLXMI', - #superclass : 'BaselineOf', - #category : 'BaselineOfOPUMLXMI', - #package : 'BaselineOfOPUMLXMI' -} - -{ #category : 'baselines' } -BaselineOfOPUMLXMI >> baseline: spec [ - - spec - for: #common - do: [ spec baseline: 'OPXMI' with: [ spec repository: 'github://openponk/xmi' ]. - spec - baseline: 'UMLMetamodel' - with: [ spec repository: 'github://openponk/uml-metamodel' ]. - spec package: 'OP-UML-XMI' with: [ spec requires: #('OPXMI' 'UMLMetamodel') ]. - spec group: 'default' with: #('OP-UML-XMI') ] -] diff --git a/repository/BaselineOfOPUMLXMI/package.st b/repository/BaselineOfOPUMLXMI/package.st deleted file mode 100644 index 5a2e85f..0000000 --- a/repository/BaselineOfOPUMLXMI/package.st +++ /dev/null @@ -1 +0,0 @@ -Package { #name : 'BaselineOfOPUMLXMI' } diff --git a/repository/BaselineOfOpenPonkUMLXMI/BaselineOfOpenPonkUMLXMI.class.st b/repository/BaselineOfOpenPonkUMLXMI/BaselineOfOpenPonkUMLXMI.class.st new file mode 100644 index 0000000..00ce190 --- /dev/null +++ b/repository/BaselineOfOpenPonkUMLXMI/BaselineOfOpenPonkUMLXMI.class.st @@ -0,0 +1,22 @@ +" +Baseline for https://github.com/OpenPonk/uml-xmi +" +Class { + #name : 'BaselineOfOpenPonkUMLXMI', + #superclass : 'BaselineOf', + #category : 'BaselineOfOpenPonkUMLXMI', + #package : 'BaselineOfOpenPonkUMLXMI' +} + +{ #category : 'baselines' } +BaselineOfOpenPonkUMLXMI >> baseline: spec [ + + spec + for: #common + do: [ spec baseline: 'OpenPonkXMI' with: [ spec repository: 'github://openponk/xmi' ]. + spec + baseline: 'OpenPonkUMLMetamodel' + with: [ spec repository: 'github://openponk/uml-metamodel' ]. + spec package: 'OpenPonk-UML-XMI' with: [ spec requires: #('OpenPonkXMI' 'OpenPonkUMLMetamodel') ]. + spec group: 'default' with: #('OpenPonk-UML-XMI') ] +] diff --git a/repository/BaselineOfOpenPonkUMLXMI/package.st b/repository/BaselineOfOpenPonkUMLXMI/package.st new file mode 100644 index 0000000..9debeee --- /dev/null +++ b/repository/BaselineOfOpenPonkUMLXMI/package.st @@ -0,0 +1 @@ +Package { #name : 'BaselineOfOpenPonkUMLXMI' } diff --git a/repository/OP-UML-XMI/package.st b/repository/OP-UML-XMI/package.st deleted file mode 100644 index f2c33fe..0000000 --- a/repository/OP-UML-XMI/package.st +++ /dev/null @@ -1 +0,0 @@ -Package { #name : 'OP-UML-XMI' } diff --git a/repository/OP-UML-XMI/OPUMLXMIMetaReader.class.st b/repository/OpenPonk-UML-XMI/OPUMLXMIMetaReader.class.st similarity index 95% rename from repository/OP-UML-XMI/OPUMLXMIMetaReader.class.st rename to repository/OpenPonk-UML-XMI/OPUMLXMIMetaReader.class.st index 372279c..c51b8fa 100644 --- a/repository/OP-UML-XMI/OPUMLXMIMetaReader.class.st +++ b/repository/OpenPonk-UML-XMI/OPUMLXMIMetaReader.class.st @@ -1,69 +1,69 @@ -Class { - #name : 'OPUMLXMIMetaReader', - #superclass : 'OPUMLXMIReader', - #category : 'OP-UML-XMI-Reader', - #package : 'OP-UML-XMI', - #tag : 'Reader' -} - -{ #category : 'instance creation' } -OPUMLXMIMetaReader >> createNewInstanceFor: anItem property: aProperty [ - - | name | - name := (#( Package Model Profile ) includes: anItem xmiName) - ifTrue: [ anItem xmiName ] - ifFalse: [ - anItem xmiType - ifNil: [ self error: 'Unknown element type.' ] - ifNotNil: [ :type | (type splitOn: ':') last ] ]. - ^ (Smalltalk at: (self classPrefix , name) asSymbol) new -] - -{ #category : 'reading' } -OPUMLXMIMetaReader >> readItem: anItem property: aProperty [ - | instance groups | - anItem isValueItem - ifTrue: [ ^ self valueFor: anItem value ]. - anItem isReferenceItem - ifTrue: [ ^ anItem referencedElements - collect: [ :each | self readItem: each property: nil ] ]. - instanceCache at: (self uniqueIdOf: anItem) ifPresent: [ :match | ^ match ]. - instance := self instanceFor: anItem property: nil. - groups := self groupedChildrenIn: anItem. - groups - keysAndValuesDo: [ :key :values | - | selector arguments pluralSelector sg pl isMultivalued | - selector := (key , ':') asSymbol. - pluralSelector := ((self asPlural: key) , ':') asSymbol. - sg := (instance class selectors includes: selector) - or: [ instance class superclass name = (self classPrefix , 'Element') - and: [ instance class superclass selectors includes: selector ] ]. - pl := (instance class selectors includes: pluralSelector) - or: [ instance class superclass name = (self classPrefix , 'Element') - and: [ instance class superclass selectors includes: pluralSelector ] ]. - isMultivalued := sg not & pl. - isMultivalued - ifTrue: [ selector := pluralSelector ]. - self assert: [ sg | pl ]. - arguments := values collect: [ :each | self readItem: each property: nil ]. - (arguments anyOne isArray or: [ arguments anyOne isKindOf: OrderedCollection ]) - ifTrue: [ arguments := arguments gather: #yourself ]. - isMultivalued - ifTrue: [ instance perform: selector with: arguments ] - ifFalse: [ self assert: [ values size = 1 ]. - self flag: 'Because unresolved references...'. - arguments size > 0 - ifTrue: [ instance perform: selector with: arguments first ] ] ]. - ^ instance -] - -{ #category : 'reading' } -OPUMLXMIMetaReader >> valueFor: anObject [ - anObject = 'true' - ifTrue: [ ^ true ]. - anObject = 'false' - ifTrue: [ ^ false ]. - (NumberParser isNumber: anObject) - ifTrue: [ ^ Number readFromString: anObject ]. - ^ anObject -] +Class { + #name : 'OPUMLXMIMetaReader', + #superclass : 'OPUMLXMIReader', + #category : 'OpenPonk-UML-XMI-Reader', + #package : 'OpenPonk-UML-XMI', + #tag : 'Reader' +} + +{ #category : 'instance creation' } +OPUMLXMIMetaReader >> createNewInstanceFor: anItem property: aProperty [ + + | name | + name := (#( Package Model Profile ) includes: anItem xmiName) + ifTrue: [ anItem xmiName ] + ifFalse: [ + anItem xmiType + ifNil: [ self error: 'Unknown element type.' ] + ifNotNil: [ :type | (type splitOn: ':') last ] ]. + ^ (Smalltalk at: (self classPrefix , name) asSymbol) new +] + +{ #category : 'reading' } +OPUMLXMIMetaReader >> readItem: anItem property: aProperty [ + | instance groups | + anItem isValueItem + ifTrue: [ ^ self valueFor: anItem value ]. + anItem isReferenceItem + ifTrue: [ ^ anItem referencedElements + collect: [ :each | self readItem: each property: nil ] ]. + instanceCache at: (self uniqueIdOf: anItem) ifPresent: [ :match | ^ match ]. + instance := self instanceFor: anItem property: nil. + groups := self groupedChildrenIn: anItem. + groups + keysAndValuesDo: [ :key :values | + | selector arguments pluralSelector sg pl isMultivalued | + selector := (key , ':') asSymbol. + pluralSelector := ((self asPlural: key) , ':') asSymbol. + sg := (instance class selectors includes: selector) + or: [ instance class superclass name = (self classPrefix , 'Element') + and: [ instance class superclass selectors includes: selector ] ]. + pl := (instance class selectors includes: pluralSelector) + or: [ instance class superclass name = (self classPrefix , 'Element') + and: [ instance class superclass selectors includes: pluralSelector ] ]. + isMultivalued := sg not & pl. + isMultivalued + ifTrue: [ selector := pluralSelector ]. + self assert: [ sg | pl ]. + arguments := values collect: [ :each | self readItem: each property: nil ]. + (arguments anyOne isArray or: [ arguments anyOne isKindOf: OrderedCollection ]) + ifTrue: [ arguments := arguments gather: #yourself ]. + isMultivalued + ifTrue: [ instance perform: selector with: arguments ] + ifFalse: [ self assert: [ values size = 1 ]. + self flag: 'Because unresolved references...'. + arguments size > 0 + ifTrue: [ instance perform: selector with: arguments first ] ] ]. + ^ instance +] + +{ #category : 'reading' } +OPUMLXMIMetaReader >> valueFor: anObject [ + anObject = 'true' + ifTrue: [ ^ true ]. + anObject = 'false' + ifTrue: [ ^ false ]. + (NumberParser isNumber: anObject) + ifTrue: [ ^ Number readFromString: anObject ]. + ^ anObject +] diff --git a/repository/OP-UML-XMI/OPUMLXMIPathmap.class.st b/repository/OpenPonk-UML-XMI/OPUMLXMIPathmap.class.st similarity index 88% rename from repository/OP-UML-XMI/OPUMLXMIPathmap.class.st rename to repository/OpenPonk-UML-XMI/OPUMLXMIPathmap.class.st index 62e079b..a5350bc 100644 --- a/repository/OP-UML-XMI/OPUMLXMIPathmap.class.st +++ b/repository/OpenPonk-UML-XMI/OPUMLXMIPathmap.class.st @@ -1,39 +1,39 @@ -Class { - #name : 'OPUMLXMIPathmap', - #superclass : 'Object', - #instVars : [ - 'mapping' - ], - #category : 'OP-UML-XMI-Utility', - #package : 'OP-UML-XMI', - #tag : 'Utility' -} - -{ #category : 'accessing' } -OPUMLXMIPathmap class >> default [ - ^ self new - add: 'http://www.omg.org/spec/UML/20131001/PrimitiveTypes.xmi'; - add: 'http://www.omg.org/spec/UML/20131001/UML.xmi'; - yourself -] - -{ #category : 'adding' } -OPUMLXMIPathmap >> add: aPath [ - self add: aPath retrieveUsing: [ OPUMLXMISpecsStorage current at: aPath ] -] - -{ #category : 'adding' } -OPUMLXMIPathmap >> add: aPath retrieveUsing: aBlock [ - mapping at: aPath put: aBlock value -] - -{ #category : 'initialization' } -OPUMLXMIPathmap >> initialize [ - super initialize. - mapping := OrderedDictionary new -] - -{ #category : 'accessing' } -OPUMLXMIPathmap >> mapping [ - ^ mapping -] +Class { + #name : 'OPUMLXMIPathmap', + #superclass : 'Object', + #instVars : [ + 'mapping' + ], + #category : 'OpenPonk-UML-XMI-Utility', + #package : 'OpenPonk-UML-XMI', + #tag : 'Utility' +} + +{ #category : 'accessing' } +OPUMLXMIPathmap class >> default [ + ^ self new + add: 'http://www.omg.org/spec/UML/20131001/PrimitiveTypes.xmi'; + add: 'http://www.omg.org/spec/UML/20131001/UML.xmi'; + yourself +] + +{ #category : 'adding' } +OPUMLXMIPathmap >> add: aPath [ + self add: aPath retrieveUsing: [ OPUMLXMISpecsStorage current at: aPath ] +] + +{ #category : 'adding' } +OPUMLXMIPathmap >> add: aPath retrieveUsing: aBlock [ + mapping at: aPath put: aBlock value +] + +{ #category : 'initialization' } +OPUMLXMIPathmap >> initialize [ + super initialize. + mapping := OrderedDictionary new +] + +{ #category : 'accessing' } +OPUMLXMIPathmap >> mapping [ + ^ mapping +] diff --git a/repository/OP-UML-XMI/OPUMLXMIReader.class.st b/repository/OpenPonk-UML-XMI/OPUMLXMIReader.class.st similarity index 96% rename from repository/OP-UML-XMI/OPUMLXMIReader.class.st rename to repository/OpenPonk-UML-XMI/OPUMLXMIReader.class.st index 465f39a..4314ac3 100644 --- a/repository/OP-UML-XMI/OPUMLXMIReader.class.st +++ b/repository/OpenPonk-UML-XMI/OPUMLXMIReader.class.st @@ -1,271 +1,271 @@ -Class { - #name : 'OPUMLXMIReader', - #superclass : 'Object', - #instVars : [ - 'classPrefix', - 'instanceCache' - ], - #category : 'OP-UML-XMI-Reader', - #package : 'OP-UML-XMI', - #tag : 'Reader' -} - -{ #category : 'instance creation' } -OPUMLXMIReader class >> read: anXmlStream [ - ^ self read: anXmlStream pathmap: OPUMLXMIPathmap default -] - -{ #category : 'instance creation' } -OPUMLXMIReader class >> read: anXmlStream pathmap: aPathmap [ - | xmi pathmap xmiResult processedXmi | - pathmap := aPathmap mapping copy. - pathmap at: 'result' put: anXmlStream contents. - xmiResult := OPXMIReader readFromMapping: pathmap. - xmi := xmiResult at: 'result'. - processedXmi := self new readXmi: xmi. - ^ processedXmi first -] - -{ #category : 'instance creation' } -OPUMLXMIReader class >> readFrom: aStream [ - ^ (self new readXmi: (OPXMIReader readFrom: aStream)) first -] - -{ #category : 'as yet unclassified' } -OPUMLXMIReader >> applyStereotype: anStereotypeXMI outOf: possibleStereotypes to: anElement [ - | stereotype groups | - stereotype := (possibleStereotypes at: anStereotypeXMI xmiName) - implementationClass new. - anElement applyStereotype: stereotype. - "anStereotypeXMI containedItems reject: [ :each | each name beginsWith: 'base_' ] thenDo: [:each | stereotype perform: (each xmiName , ':') asSymbol with: each value ]." - groups := self groupedChildrenIn: anStereotypeXMI. - (groups - associationsSelect: [ :each | (each key beginsWith: 'base_') not ]) - keysAndValuesDo: - [ :key :values | self readPropertyNamed: key values: values instance: stereotype ] -] - -{ #category : 'reading' } -OPUMLXMIReader >> applyStereotypesAmongst: elements to: models [ - | possibleStereotypes | - possibleStereotypes := ((models - flatCollect: [ :each | - (each profileApplications collect: #appliedProfile) - flatCollect: [ :eachProfile | eachProfile ownedStereotype ] ]) - collect: [ :each | each name -> each ]) asDictionary. - elements - select: [ :each | - (possibleStereotypes includesKey: each xmiName) - and: [ each containedItems - anySatisfy: [ :any | any xmiName beginsWith: 'base_' ] ] ] - thenDo: [ :each | - self - applyStereotype: each - outOf: possibleStereotypes - to: - (instanceCache - at: - (each containedItems - detect: [ :any | any xmiName beginsWith: 'base_' ]) - referencedElement xmiId) ] -] - -{ #category : 'converting' } -OPUMLXMIReader >> asPlural: aString [ - (aString endsWith: 's') - ifTrue: [ ^ aString , 'es' ]. - (aString endsWith: 'y') - ifTrue: [ ^ (aString withoutSuffix: 'y') , 'ies' ]. - ^ aString , 's' -] - -{ #category : 'accessing' } -OPUMLXMIReader >> classPrefix [ - ^ classPrefix -] - -{ #category : 'accessing' } -OPUMLXMIReader >> classPrefix: anObject [ - classPrefix := anObject -] - -{ #category : 'instance creation' } -OPUMLXMIReader >> createNewInstanceFor: anItem property: aProperty [ - - | name | - name := aProperty - ifNil: [ "Root elements only" - self assert: [ - #( Package Model Profile ) includes: anItem xmiName ]. - anItem xmiName ] - ifNotNil: [ - anItem xmiType - ifNil: [ aProperty type name ] - ifNotNil: [ :type | (type splitOn: ':') last ] ]. - ^ (Smalltalk at: (self classPrefix , name) asSymbol) new - uuid: ([ UUID fromString: anItem xmiId ] - on: Error - do: [ anItem xmiId ]); - yourself -] - -{ #category : 'accessing' } -OPUMLXMIReader >> defaultClassPrefix [ - ^ 'OPUML' -] - -{ #category : 'reading' } -OPUMLXMIReader >> groupedChildrenIn: anObjectElement [ - ^ ((anObjectElement containedItems - reject: [ :each | #('xmi:' 'xmlns:') anySatisfy: [ :prefix | each xmiName beginsWith: prefix ] ]) - reject: [ :each | #('Extension' 'default' 'uri') includes: each xmiName ]) groupedBy: #xmiName -] - -{ #category : 'initialization' } -OPUMLXMIReader >> initialize [ - super initialize. - instanceCache := Dictionary new. - classPrefix := self defaultClassPrefix -] - -{ #category : 'instance creation' } -OPUMLXMIReader >> instanceFor: anObjectElement property: aProperty [ - ^ instanceCache - at: (self uniqueIdOf: anObjectElement) - ifAbsentPut: [ self createNewInstanceFor: anObjectElement property: aProperty ] -] - -{ #category : 'reading' } -OPUMLXMIReader >> readItem: anItem property: aProperty [ - | instance groups | - anItem isValueItem - ifTrue: [ ^ self valueFor: anItem value property: aProperty ]. - - anItem isReferenceItem - ifTrue: [ aProperty name = 'appliedProfile' - ifTrue: [ ^ self readProfileItem: anItem property: aProperty ]. - - (anItem href isNotNil - and: [ anItem href beginsWith: 'http://www.omg.org/spec/UML/' ]) - ifTrue: [ ^ self readMetamodelItem: anItem property: aProperty ]. - (anItem href isNotNil - and: [ anItem href beginsWith: 'http://schema.omg.org/spec/MOF/' ]) - ifTrue: [ ^ self readMofItem: anItem property: aProperty ]. - ^ anItem referencedElements - collect: [ :each | self readItem: each property: aProperty ] ]. - instanceCache - at: (self uniqueIdOf: anItem) - ifPresent: [ :match | ^ match ]. - instance := self instanceFor: anItem property: aProperty. - groups := self groupedChildrenIn: anItem. - groups - keysAndValuesDo: - [ :key :values | self readPropertyNamed: key values: values instance: instance ]. - ^ instance -] - -{ #category : 'reading' } -OPUMLXMIReader >> readMetamodelItem: anItem property: aProperty [ - | parts | - parts := anItem href splitOn: '#'. - (parts first endsWith: 'PrimitiveTypes.xmi') - ifTrue: [ ^ OPUMLXMISpecsStorage primitiveTypeNamed: parts second ]. - (parts first endsWith: 'UML.xmi') - ifTrue: [ ^ OPUMLXMISpecsStorage metaClassNamed: parts second ]. - self error: 'Unknown type at ' , anItem href -] - -{ #category : 'reading' } -OPUMLXMIReader >> readMofItem: anItem property: aProperty [ - | parts | - parts := anItem href splitOn: '#'. - ^ OPUMLXMISpecsStorage primitiveTypeNamed: parts second -] - -{ #category : 'reading' } -OPUMLXMIReader >> readProfileItem: anItem property: aProperty [ - | parts factory | - parts := anItem href splitOn: '#'. - self class environment - at: #OPUmlCustomProfile - ifPresent: [ :cls | - factory := cls allSubclasses - detect: [ :each | each profile URI = parts first ] - ifNone: [ self error: 'No profile with URI ' , parts first , ' found' ] ] - ifAbsent: [ ]. - ^ factory profile -] - -{ #category : 'reading' } -OPUMLXMIReader >> readPropertyNamed: aKey values: values instance: anInstance [ - | property pluralSelector isMultivalued sg arguments pl selector | - property := (anInstance umlMetaClass allAttributes select: [ :each | each name = aKey ]) - last. - selector := (aKey , ':') asSymbol. - pluralSelector := ((self asPlural: aKey) , ':') asSymbol. - sg := (anInstance class selectors includes: selector) - or: [ anInstance class superclass name = (self classPrefix , 'Element') - and: [ anInstance class superclass selectors includes: selector ] ]. - pl := (anInstance class selectors includes: pluralSelector) - or: [ anInstance class superclass name = (self classPrefix , 'Element') - and: [ anInstance class superclass selectors includes: pluralSelector ] ]. - isMultivalued := sg not & pl. - isMultivalued - ifTrue: [ selector := pluralSelector ]. - self assert: [ sg | pl ]. - arguments := values collect: [ :each | self readItem: each property: property ]. - (arguments anyOne isArray or: [ arguments anyOne isKindOf: OrderedCollection ]) - ifTrue: [ arguments := arguments gather: #yourself ]. - ^ isMultivalued - ifTrue: [ anInstance perform: selector with: arguments ] - ifFalse: [ self assert: [ values size = 1 ]. - self flag: 'Because unresolved references...'. - arguments size > 0 - ifTrue: [ anInstance perform: selector with: arguments first ] ] -] - -{ #category : 'reading' } -OPUMLXMIReader >> readXmi: anXmi [ - | elements models | - (anXmi isObjectElement - and: [ #(Model Package Profile) includes: anXmi xmiName ]) - ifTrue: [ ^ self readItem: anXmi property: nil ]. - elements := anXmi containedItems - select: [ :each | each isObjectElement ]. - models := elements - select: [ :each | #(Model Package Profile) includes: each xmiName ] - thenCollect: [ :each | self readItem: each property: nil ]. - self applyStereotypesAmongst: elements to: models. - ^ models -] - -{ #category : 'reading' } -OPUMLXMIReader >> uniqueIdOf: anObject [ - anObject xmiName = 'packageImport' - ifTrue: [ ^ anObject xmiId , '-' - , (anObject containedItems detect: [ :each | each xmiName = #importedPackage ]) referencedElement xmiId ]. - ^ anObject xmiId -] - -{ #category : 'reading' } -OPUMLXMIReader >> valueFor: anObject property: aProperty [ - (#('Integer') includes: aProperty type name) - ifTrue: [ ^ Number readFromString: anObject ]. - aProperty type name = 'UnlimitedNatural' - ifTrue: [ anObject = '*' - ifTrue: [ ^ anObject ]. - ^ Number readFromString: anObject ]. - aProperty type name = 'String' - ifTrue: [ ^ anObject asString ]. - aProperty type name = 'Boolean' - ifTrue: [ self - assert: [ #('true' 'false') includes: anObject ] - description: 'Unexpected type'. - ^ anObject = 'true' ]. - (aProperty type oclIsKindOf: #Enumeration) - ifTrue: [ ^ anObject asSymbol ]. - self error: 'Guessed type.'. - (NumberParser isNumber: anObject) - ifTrue: [ ^ Number readFromString: anObject ]. - ^ anObject -] +Class { + #name : 'OPUMLXMIReader', + #superclass : 'Object', + #instVars : [ + 'classPrefix', + 'instanceCache' + ], + #category : 'OpenPonk-UML-XMI-Reader', + #package : 'OpenPonk-UML-XMI', + #tag : 'Reader' +} + +{ #category : 'instance creation' } +OPUMLXMIReader class >> read: anXmlStream [ + ^ self read: anXmlStream pathmap: OPUMLXMIPathmap default +] + +{ #category : 'instance creation' } +OPUMLXMIReader class >> read: anXmlStream pathmap: aPathmap [ + | xmi pathmap xmiResult processedXmi | + pathmap := aPathmap mapping copy. + pathmap at: 'result' put: anXmlStream contents. + xmiResult := OPXMIReader readFromMapping: pathmap. + xmi := xmiResult at: 'result'. + processedXmi := self new readXmi: xmi. + ^ processedXmi first +] + +{ #category : 'instance creation' } +OPUMLXMIReader class >> readFrom: aStream [ + ^ (self new readXmi: (OPXMIReader readFrom: aStream)) first +] + +{ #category : 'as yet unclassified' } +OPUMLXMIReader >> applyStereotype: anStereotypeXMI outOf: possibleStereotypes to: anElement [ + | stereotype groups | + stereotype := (possibleStereotypes at: anStereotypeXMI xmiName) + implementationClass new. + anElement applyStereotype: stereotype. + "anStereotypeXMI containedItems reject: [ :each | each name beginsWith: 'base_' ] thenDo: [:each | stereotype perform: (each xmiName , ':') asSymbol with: each value ]." + groups := self groupedChildrenIn: anStereotypeXMI. + (groups + associationsSelect: [ :each | (each key beginsWith: 'base_') not ]) + keysAndValuesDo: + [ :key :values | self readPropertyNamed: key values: values instance: stereotype ] +] + +{ #category : 'reading' } +OPUMLXMIReader >> applyStereotypesAmongst: elements to: models [ + | possibleStereotypes | + possibleStereotypes := ((models + flatCollect: [ :each | + (each profileApplications collect: #appliedProfile) + flatCollect: [ :eachProfile | eachProfile ownedStereotype ] ]) + collect: [ :each | each name -> each ]) asDictionary. + elements + select: [ :each | + (possibleStereotypes includesKey: each xmiName) + and: [ each containedItems + anySatisfy: [ :any | any xmiName beginsWith: 'base_' ] ] ] + thenDo: [ :each | + self + applyStereotype: each + outOf: possibleStereotypes + to: + (instanceCache + at: + (each containedItems + detect: [ :any | any xmiName beginsWith: 'base_' ]) + referencedElement xmiId) ] +] + +{ #category : 'converting' } +OPUMLXMIReader >> asPlural: aString [ + (aString endsWith: 's') + ifTrue: [ ^ aString , 'es' ]. + (aString endsWith: 'y') + ifTrue: [ ^ (aString withoutSuffix: 'y') , 'ies' ]. + ^ aString , 's' +] + +{ #category : 'accessing' } +OPUMLXMIReader >> classPrefix [ + ^ classPrefix +] + +{ #category : 'accessing' } +OPUMLXMIReader >> classPrefix: anObject [ + classPrefix := anObject +] + +{ #category : 'instance creation' } +OPUMLXMIReader >> createNewInstanceFor: anItem property: aProperty [ + + | name | + name := aProperty + ifNil: [ "Root elements only" + self assert: [ + #( Package Model Profile ) includes: anItem xmiName ]. + anItem xmiName ] + ifNotNil: [ + anItem xmiType + ifNil: [ aProperty type name ] + ifNotNil: [ :type | (type splitOn: ':') last ] ]. + ^ (Smalltalk at: (self classPrefix , name) asSymbol) new + uuid: ([ UUID fromString: anItem xmiId ] + on: Error + do: [ anItem xmiId ]); + yourself +] + +{ #category : 'accessing' } +OPUMLXMIReader >> defaultClassPrefix [ + ^ 'OPUML' +] + +{ #category : 'reading' } +OPUMLXMIReader >> groupedChildrenIn: anObjectElement [ + ^ ((anObjectElement containedItems + reject: [ :each | #('xmi:' 'xmlns:') anySatisfy: [ :prefix | each xmiName beginsWith: prefix ] ]) + reject: [ :each | #('Extension' 'default' 'uri') includes: each xmiName ]) groupedBy: #xmiName +] + +{ #category : 'initialization' } +OPUMLXMIReader >> initialize [ + super initialize. + instanceCache := Dictionary new. + classPrefix := self defaultClassPrefix +] + +{ #category : 'instance creation' } +OPUMLXMIReader >> instanceFor: anObjectElement property: aProperty [ + ^ instanceCache + at: (self uniqueIdOf: anObjectElement) + ifAbsentPut: [ self createNewInstanceFor: anObjectElement property: aProperty ] +] + +{ #category : 'reading' } +OPUMLXMIReader >> readItem: anItem property: aProperty [ + | instance groups | + anItem isValueItem + ifTrue: [ ^ self valueFor: anItem value property: aProperty ]. + + anItem isReferenceItem + ifTrue: [ aProperty name = 'appliedProfile' + ifTrue: [ ^ self readProfileItem: anItem property: aProperty ]. + + (anItem href isNotNil + and: [ anItem href beginsWith: 'http://www.omg.org/spec/UML/' ]) + ifTrue: [ ^ self readMetamodelItem: anItem property: aProperty ]. + (anItem href isNotNil + and: [ anItem href beginsWith: 'http://schema.omg.org/spec/MOF/' ]) + ifTrue: [ ^ self readMofItem: anItem property: aProperty ]. + ^ anItem referencedElements + collect: [ :each | self readItem: each property: aProperty ] ]. + instanceCache + at: (self uniqueIdOf: anItem) + ifPresent: [ :match | ^ match ]. + instance := self instanceFor: anItem property: aProperty. + groups := self groupedChildrenIn: anItem. + groups + keysAndValuesDo: + [ :key :values | self readPropertyNamed: key values: values instance: instance ]. + ^ instance +] + +{ #category : 'reading' } +OPUMLXMIReader >> readMetamodelItem: anItem property: aProperty [ + | parts | + parts := anItem href splitOn: '#'. + (parts first endsWith: 'PrimitiveTypes.xmi') + ifTrue: [ ^ OPUMLXMISpecsStorage primitiveTypeNamed: parts second ]. + (parts first endsWith: 'UML.xmi') + ifTrue: [ ^ OPUMLXMISpecsStorage metaClassNamed: parts second ]. + self error: 'Unknown type at ' , anItem href +] + +{ #category : 'reading' } +OPUMLXMIReader >> readMofItem: anItem property: aProperty [ + | parts | + parts := anItem href splitOn: '#'. + ^ OPUMLXMISpecsStorage primitiveTypeNamed: parts second +] + +{ #category : 'reading' } +OPUMLXMIReader >> readProfileItem: anItem property: aProperty [ + | parts factory | + parts := anItem href splitOn: '#'. + self class environment + at: #OPUmlCustomProfile + ifPresent: [ :cls | + factory := cls allSubclasses + detect: [ :each | each profile URI = parts first ] + ifNone: [ self error: 'No profile with URI ' , parts first , ' found' ] ] + ifAbsent: [ ]. + ^ factory profile +] + +{ #category : 'reading' } +OPUMLXMIReader >> readPropertyNamed: aKey values: values instance: anInstance [ + | property pluralSelector isMultivalued sg arguments pl selector | + property := (anInstance umlMetaClass allAttributes select: [ :each | each name = aKey ]) + last. + selector := (aKey , ':') asSymbol. + pluralSelector := ((self asPlural: aKey) , ':') asSymbol. + sg := (anInstance class selectors includes: selector) + or: [ anInstance class superclass name = (self classPrefix , 'Element') + and: [ anInstance class superclass selectors includes: selector ] ]. + pl := (anInstance class selectors includes: pluralSelector) + or: [ anInstance class superclass name = (self classPrefix , 'Element') + and: [ anInstance class superclass selectors includes: pluralSelector ] ]. + isMultivalued := sg not & pl. + isMultivalued + ifTrue: [ selector := pluralSelector ]. + self assert: [ sg | pl ]. + arguments := values collect: [ :each | self readItem: each property: property ]. + (arguments anyOne isArray or: [ arguments anyOne isKindOf: OrderedCollection ]) + ifTrue: [ arguments := arguments gather: #yourself ]. + ^ isMultivalued + ifTrue: [ anInstance perform: selector with: arguments ] + ifFalse: [ self assert: [ values size = 1 ]. + self flag: 'Because unresolved references...'. + arguments size > 0 + ifTrue: [ anInstance perform: selector with: arguments first ] ] +] + +{ #category : 'reading' } +OPUMLXMIReader >> readXmi: anXmi [ + | elements models | + (anXmi isObjectElement + and: [ #(Model Package Profile) includes: anXmi xmiName ]) + ifTrue: [ ^ self readItem: anXmi property: nil ]. + elements := anXmi containedItems + select: [ :each | each isObjectElement ]. + models := elements + select: [ :each | #(Model Package Profile) includes: each xmiName ] + thenCollect: [ :each | self readItem: each property: nil ]. + self applyStereotypesAmongst: elements to: models. + ^ models +] + +{ #category : 'reading' } +OPUMLXMIReader >> uniqueIdOf: anObject [ + anObject xmiName = 'packageImport' + ifTrue: [ ^ anObject xmiId , '-' + , (anObject containedItems detect: [ :each | each xmiName = #importedPackage ]) referencedElement xmiId ]. + ^ anObject xmiId +] + +{ #category : 'reading' } +OPUMLXMIReader >> valueFor: anObject property: aProperty [ + (#('Integer') includes: aProperty type name) + ifTrue: [ ^ Number readFromString: anObject ]. + aProperty type name = 'UnlimitedNatural' + ifTrue: [ anObject = '*' + ifTrue: [ ^ anObject ]. + ^ Number readFromString: anObject ]. + aProperty type name = 'String' + ifTrue: [ ^ anObject asString ]. + aProperty type name = 'Boolean' + ifTrue: [ self + assert: [ #('true' 'false') includes: anObject ] + description: 'Unexpected type'. + ^ anObject = 'true' ]. + (aProperty type oclIsKindOf: #Enumeration) + ifTrue: [ ^ anObject asSymbol ]. + self error: 'Guessed type.'. + (NumberParser isNumber: anObject) + ifTrue: [ ^ Number readFromString: anObject ]. + ^ anObject +] diff --git a/repository/OP-UML-XMI/OPUMLXMIReaderTest.class.st b/repository/OpenPonk-UML-XMI/OPUMLXMIReaderTest.class.st similarity index 97% rename from repository/OP-UML-XMI/OPUMLXMIReaderTest.class.st rename to repository/OpenPonk-UML-XMI/OPUMLXMIReaderTest.class.st index 16d1c14..15a072c 100644 --- a/repository/OP-UML-XMI/OPUMLXMIReaderTest.class.st +++ b/repository/OpenPonk-UML-XMI/OPUMLXMIReaderTest.class.st @@ -1,520 +1,520 @@ -Class { - #name : 'OPUMLXMIReaderTest', - #superclass : 'TestCase', - #instVars : [ - 'reader', - 'packagedElementProperty' - ], - #category : 'OP-UML-XMI-Tests', - #package : 'OP-UML-XMI', - #tag : 'Tests' -} - -{ #category : 'instance creation' } -OPUMLXMIReaderTest >> association [ - | assoc ownedAttr ownedEnd | - ownedAttr := OPXMIObjectElement new. - ownedEnd := OPXMIObjectElement new. - assoc := OPXMIObjectElement new. - assoc - xmiName: 'packagedElement'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Association'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'A_annotatedElement_comment'. - OPXMIValueAttribute xmiName: 'name' value: 'A_annotatedElement_comment'. - OPXMIReferenceAttribute - xmiName: 'memberEnd' - referencedElements: - {ownedAttr. - ownedEnd}. - ownedEnd}. - ownedAttr - xmiName: 'ownedAttribute'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Property'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment-annotatedElement'. - OPXMIValueAttribute xmiName: 'name' value: 'annotatedElement'. - OPXMIReferenceAttribute xmiName: 'association' referencedElements: {assoc}}. - ownedEnd - xmiName: 'ownedEnd'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Property'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'A_annotatedElement_comment-comment'. - OPXMIValueAttribute xmiName: 'name' value: 'comment'. - OPXMIReferenceAttribute xmiName: 'association' referencedElements: {assoc}}. - ^ assoc -] - -{ #category : 'instance creation' } -OPUMLXMIReaderTest >> attributeWithHrefType [ - ^ OPXMIReader - readFrom: - ' - -' -] - -{ #category : 'instance creation' } -OPUMLXMIReaderTest >> attributeWithPrimitiveType [ - ^ OPXMIReader - readFrom: - ' - -' -] - -{ #category : 'instance creation' } -OPUMLXMIReaderTest >> defaultValueElement [ - ^ OPXMIObjectElement new - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:LiteralInteger'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'lowerValue'} -] - -{ #category : 'instance creation' } -OPUMLXMIReaderTest >> elementWithGeneralization [ - "Comment -> Element" - - ^ OPXMIObjectElement new - xmiName: 'packagedElement'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Class'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment'. - OPXMIValueAttribute xmiName: 'name' value: 'Comment'. - OPXMIObjectElement new - xmiName: 'generalization'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Generalization'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment-_generalization.0'. - OPXMIReferenceAttribute new - xmiName: 'general'; - referencedElements: - {OPXMIObjectElement new - xmiName: 'packagedElement'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Class'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'Element'. - OPXMIValueAttribute xmiName: 'name' value: 'Element'}}}} -] - -{ #category : 'instance creation' } -OPUMLXMIReaderTest >> generalizationElement [ - "-> Element" - - ^ OPXMIObjectElement new - xmiName: 'generalization'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Generalization'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment-_generalization.0'. - OPXMIReferenceAttribute new - xmiName: 'general'; - referencedElements: - {OPXMIObjectElement new - xmiName: 'packagedElement'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Class'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'Element'. - OPXMIValueAttribute xmiName: 'name' value: 'Element'}}} -] - -{ #category : 'accessing' } -OPUMLXMIReaderTest >> metaClassNamed: aName [ - ^ OPUMLXMISpecsStorage metaClassNamed: aName -] - -{ #category : 'instance creation' } -OPUMLXMIReaderTest >> multipleNestedAttributes [ - ^ OPXMIObjectElement new - xmiName: 'packagedElement'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Class'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment'. - OPXMIValueAttribute xmiName: 'name' value: 'Comment'. - OPXMIObjectElement new - xmiName: 'ownedAttribute'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Property'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment-annotatedElement'. - OPXMIValueElement xmiName: 'name' value: 'annotatedElement'}. - OPXMIObjectElement new - xmiName: 'ownedAttribute'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Property'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment-body'. - OPXMIValueElement xmiName: 'name' value: 'body'}} -] - -{ #category : 'instance creation' } -OPUMLXMIReaderTest >> nestedComplexElement [ - ^ OPXMIObjectElement new - xmiName: 'Attribute'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Property'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'PROPID'. - OPXMIObjectElement new - xmiName: 'upperValue'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:LiteralUnlimitedNatural'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'PROPID_upperValue'. - OPXMIValueElement xmiName: 'value' value: '*'}} -] - -{ #category : 'instance creation' } -OPUMLXMIReaderTest >> packageImportPackage [ - | activities classification | - classification := OPXMIObjectElement new - xmiName: 'packagedElement'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Package'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'Classification'. - OPXMIValueAttribute xmiName: 'name' value: 'Classification'}. - activities := OPXMIObjectElement new - xmiName: 'packagedElement'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Package'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'Activities'. - OPXMIValueAttribute xmiName: 'name' value: 'Activities'. - OPXMIObjectElement new - xmiName: 'packageImport'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:PackageImport'. - OPXMIValueAttribute xmiName: 'xmi:id' value: '_packageImport.1'. - OPXMIReferenceAttribute xmiName: 'importedPackage' referencedElements: {classification}}}. - ^ OPXMIObjectElement new - xmiName: 'uml:Package'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Package'. - OPXMIValueAttribute xmiName: 'xmi:id' value: '_0'. - OPXMIValueAttribute xmiName: 'name' value: 'UML'. - OPXMIObjectElement new - xmiName: 'packageImport'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:PackageImport'. - OPXMIValueAttribute xmiName: 'xmi:id' value: '_packageImport.1'. - OPXMIReferenceAttribute xmiName: 'importedPackage' referencedElements: {activities}}. - OPXMIObjectElement new - xmiName: 'packageImport'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:PackageImport'. - OPXMIValueAttribute xmiName: 'xmi:id' value: '_packageImport.2'. - OPXMIReferenceAttribute xmiName: 'importedPackage' referencedElements: {classification}}} -] - -{ #category : 'accessing' } -OPUMLXMIReaderTest >> primitiveTypeNamed: aName [ - ^ OPUMLXMISpecsStorage primitiveTypeNamed: aName -] - -{ #category : 'running' } -OPUMLXMIReaderTest >> property: aPropertyName in: aContainerClass [ - ^ (OPUMLXMISpecsStorage metaClassFor: aContainerClass) ownedAttributes - detect: [ :each | each name = aPropertyName ] -] - -{ #category : 'running' } -OPUMLXMIReaderTest >> setUp [ - reader := OPUMLXMIReader new. - packagedElementProperty := (OPUMLXMISpecsStorage metaClassFor: OPUMLPackage new) - ownedAttributes detect: [ :each | each name = 'packagedElement' ] -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testAmbiguousPackageImport [ - "xmi:id of elements are not valid and should be ignored (they are not unique). Test that we can load correctly despite that" - - | masterPkg activitiesPkg classificationPkg | - masterPkg := reader readItem: self packageImportPackage property: packagedElementProperty. - self assert: masterPkg name equals: 'UML'. - self assert: masterPkg packageImports size equals: 2. - activitiesPkg := masterPkg packageImports first importedPackage. - classificationPkg := masterPkg packageImports second importedPackage. - self assert: classificationPkg name equals: 'Classification'. - self assert: classificationPkg packageImports asArray equals: #(). - self assert: activitiesPkg name equals: 'Activities'. - self - assert: activitiesPkg packageImports first importedPackage - equals: classificationPkg -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testAssociation [ - | result | - result := reader readItem: self association property: packagedElementProperty. - self assert: result umlClassName equals: #Association. - self assert: result memberEnds size equals: 2. - self - assert: (result memberEnds collect: #name) asArray sorted - equals: #('annotatedElement' 'comment') sorted. - self assert: (result ownedEnds collect: #name) asArray equals: #('comment'). - self assert: (result memberEnds includes: result ownedEnds first) -] - -{ #category : 'tests - reading - value' } -OPUMLXMIReaderTest >> testBooleanStringValue [ - | result stringProperty | - stringProperty := (OPUMLXMISpecsStorage metaClassFor: OPUMLProperty new) allAttributes - detect: [ :each | each name = 'name' ]. - result := reader valueFor: 'true' property: stringProperty. - self assert: result equals: 'true' -] - -{ #category : 'tests - reading - value' } -OPUMLXMIReaderTest >> testBooleanValue [ - | result booleanProperty | - booleanProperty := (OPUMLXMISpecsStorage metaClassFor: OPUMLProperty new) ownedAttributes - detect: [ :each | each name = 'isDerived' ]. - result := reader valueFor: 'true' property: booleanProperty. - self assert: result equals: true -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testCreateNewInstanceProperty [ - | item property | - item := OPXMIObjectElement new - xmiName: 'profileApplication'; - containedItems: {}. - property := (OPUMLXMISpecsStorage metaClassFor: OPUMLPackage new) ownedAttributes - detect: [ :each | each name = 'profileApplication' ]. - self - assert: (reader createNewInstanceFor: item property: property) umlClassName - equals: #ProfileApplication -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testCreateNewInstanceXmiId [ - | item | - item := OPXMIObjectElement new - xmiName: 'packagedElement'; - containedItems: {OPXMIValueElement xmiName: 'xmi:id' value: 'CustomId'}. - self - assert: (reader createNewInstanceFor: item property: packagedElementProperty) uuid - equals: 'CustomId' -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testCreateNewInstanceXmiName [ - | item | - item := OPXMIObjectElement new - xmiName: 'Package'; - containedItems: {}. - self - assert: (reader createNewInstanceFor: item property: nil) umlClassName - equals: #Package -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testCreateNewInstanceXmiType [ - | item | - item := OPXMIObjectElement new - xmiName: 'packagedElement'; - containedItems: {OPXMIValueElement xmiName: 'xmi:type' value: 'uml:Class'}. - self - assert: (reader createNewInstanceFor: item property: packagedElementProperty) umlClassName - equals: #Class -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testGeneralizationElement [ - | result | - result := reader - readItem: self generalizationElement - property: (self property: #generalization in: OPUMLClassifier new). - self assert: result umlClassName equals: 'Generalization'. - self assert: result general name equals: 'Element' -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testGroupedChildren [ - | result | - result := reader groupedChildrenIn: self multipleNestedAttributes. - self assert: result keys sorted equals: #(name ownedAttribute). - self assert: (result at: #name) size equals: 1. - self assert: (result at: #ownedAttribute) size equals: 2 -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testInstance [ - | element result1 result2 | - element := OPXMIObjectElement new - xmiName: 'Package'; - containedItems: {OPXMIValueElement xmiName: 'xmi:id' value: 'CLS'}. - result1 := reader instanceFor: element property: nil. - self assert: result1 umlClassName equals: #Package. - result2 := reader instanceFor: element property: nil. - self assert: result1 == result2 description: 'We expect the same object.' -] - -{ #category : 'tests - reading - value' } -OPUMLXMIReaderTest >> testIntegerStringValue [ - | result stringProperty | - stringProperty := (OPUMLXMISpecsStorage metaClassFor: OPUMLProperty new) allAttributes - detect: [ :each | each name = 'name' ]. - result := reader valueFor: '123' property: stringProperty. - self assert: result equals: '123' -] - -{ #category : 'tests - reading - value' } -OPUMLXMIReaderTest >> testIntegerValue [ - | result integerProperty | - integerProperty := (OPUMLXMISpecsStorage metaClassFor: OPUMLProperty new) allAttributes - detect: [ :each | each name = 'lower' ]. - result := reader valueFor: '123' property: integerProperty. - self assert: result equals: 123 -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testMultipleNestedAttributes [ - | result | - result := reader readItem: self multipleNestedAttributes property: packagedElementProperty. - self assert: result umlClassName equals: #Class. - self assert: result ownedAttributes size equals: 2. - self assert: result ownedAttributes first name equals: 'annotatedElement'. - self assert: result ownedAttributes second name equals: 'body' -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testNestedComplexElement [ - | result | - result := reader - readItem: self nestedComplexElement - property: (self property: 'ownedAttribute' in: OPUMLClass new). - self assert: result umlClassName equals: #Property. - self assert: result upperValue value equals: '*'. - " self assert: result lowerValue value equals: 0." - self assert: result lowerValue value equals: nil -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testReadBoolean [ - | result | - result := reader - readItem: (OPXMIValueAttribute xmiName: 'isDerived' value: 'true') - property: (self property: #isDerived in: OPUMLProperty new). - self assert: result equals: true -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testReadImportedType [ - | result property | - property := (self metaClassNamed: #Class) allAttributes - detect: [ :each | each name = 'ownedAttribute' ]. - result := reader readItem: self attributeWithHrefType property: property. - self assert: result type equals: (self metaClassNamed: #Association) -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testReadPrimitiveType [ - | result property | - property := (self metaClassNamed: #Class) allAttributes - detect: [ :each | each name = 'ownedAttribute' ]. - result := reader readItem: self attributeWithPrimitiveType property: property. - self assert: result type equals: (self primitiveTypeNamed: #Boolean) -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testReadSimpleObject [ - | element result | - element := OPXMIObjectElement new - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment'. - OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Comment'. - OPXMIValueElement xmiName: 'body' value: 'CONTENT'}. - result := reader readItem: element property: packagedElementProperty. - self assert: result umlClassName equals: #Comment. - self assert: result body equals: 'CONTENT' -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testReadTrivialXmi [ - | result | - result := reader readXmi: self trivialXmi. - self assert: result size equals: 1. - self assert: result first umlClassName equals: #Package -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testReadTrivialishXmi [ - | result | - result := reader readXmi: self trivialishXmi. - self assert: result size equals: 1. - self assert: result first umlClassName equals: #Package. - self assert: result first packagedElements size equals: 1. - self assert: result first packagedElements first name equals: 'Activities' -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testReferenceElement [ - | result gen | - result := reader - readItem: self elementWithGeneralization - property: packagedElementProperty. - self assert: result name equals: 'Comment'. - gen := result generalizations first. - self assert: gen umlClassName equals: #Generalization. - self assert: gen general name equals: 'Element' -] - -{ #category : 'tests' } -OPUMLXMIReaderTest >> testUniqueId [ - | regular packageImport | - regular := OPXMIObjectElement new - containedItems: {OPXMIValueAttribute xmiName: 'xmi:id' value: 'AAA'}. - packageImport := OPXMIObjectElement new - xmiName: 'packageImport'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:PackageImport'. - OPXMIValueAttribute xmiName: 'xmi:id' value: '_packageImport.1'. - OPXMIReferenceAttribute xmiName: 'importedPackage' referencedElements: {regular}}. - self assert: (reader uniqueIdOf: regular) equals: 'AAA'. - self assert: (reader uniqueIdOf: packageImport) equals: '_packageImport.1-AAA' -] - -{ #category : 'instance creation' } -OPUMLXMIReaderTest >> trivialXmi [ - ^ OPXMIObjectElement new - xmiName: 'XMI'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmlns:xmi' value: 'http://www.omg.org/spec/XMI/20131001'. - OPXMIValueAttribute xmiName: 'xmlns:uml' value: 'http://www.omg.org/spec/UML/20131001'. - OPXMIValueAttribute - xmiName: 'xmlns:moftext' - value: 'http://www.omg.org/spec/MOF/20131001'. - OPXMIObjectElement new - xmiName: 'Package'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:id' value: '_0'. - OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Package'}. - OPXMIObjectElement new - xmiName: 'Tag'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:id' value: '_1'. - OPXMIValueAttribute xmiName: 'xmi:type' value: 'mofext:Tag'}} -] - -{ #category : 'instance creation' } -OPUMLXMIReaderTest >> trivialishXmi [ - ^ OPXMIObjectElement new - xmiName: 'XMI'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmlns:xmi' value: 'http://www.omg.org/spec/XMI/20131001'. - OPXMIValueAttribute xmiName: 'xmlns:uml' value: 'http://www.omg.org/spec/UML/20131001'. - OPXMIValueAttribute - xmiName: 'xmlns:moftext' - value: 'http://www.omg.org/spec/MOF/20131001'. - OPXMIObjectElement new - xmiName: 'Package'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:id' value: '_0'. - OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Package'. - OPXMIObjectElement new - xmiName: 'packagedElement'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Package'. - OPXMIValueAttribute xmiName: 'xmi:id' value: 'Activities'. - OPXMIValueAttribute xmiName: 'name' value: 'Activities'}}. - OPXMIObjectElement new - xmiName: 'Tag'; - containedItems: - {OPXMIValueAttribute xmiName: 'xmi:id' value: '_1'. - OPXMIValueAttribute xmiName: 'xmi:type' value: 'mofext:Tag'}} -] +Class { + #name : 'OPUMLXMIReaderTest', + #superclass : 'TestCase', + #instVars : [ + 'reader', + 'packagedElementProperty' + ], + #category : 'OpenPonk-UML-XMI-Tests', + #package : 'OpenPonk-UML-XMI', + #tag : 'Tests' +} + +{ #category : 'instance creation' } +OPUMLXMIReaderTest >> association [ + | assoc ownedAttr ownedEnd | + ownedAttr := OPXMIObjectElement new. + ownedEnd := OPXMIObjectElement new. + assoc := OPXMIObjectElement new. + assoc + xmiName: 'packagedElement'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Association'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'A_annotatedElement_comment'. + OPXMIValueAttribute xmiName: 'name' value: 'A_annotatedElement_comment'. + OPXMIReferenceAttribute + xmiName: 'memberEnd' + referencedElements: + {ownedAttr. + ownedEnd}. + ownedEnd}. + ownedAttr + xmiName: 'ownedAttribute'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Property'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment-annotatedElement'. + OPXMIValueAttribute xmiName: 'name' value: 'annotatedElement'. + OPXMIReferenceAttribute xmiName: 'association' referencedElements: {assoc}}. + ownedEnd + xmiName: 'ownedEnd'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Property'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'A_annotatedElement_comment-comment'. + OPXMIValueAttribute xmiName: 'name' value: 'comment'. + OPXMIReferenceAttribute xmiName: 'association' referencedElements: {assoc}}. + ^ assoc +] + +{ #category : 'instance creation' } +OPUMLXMIReaderTest >> attributeWithHrefType [ + ^ OPXMIReader + readFrom: + ' + +' +] + +{ #category : 'instance creation' } +OPUMLXMIReaderTest >> attributeWithPrimitiveType [ + ^ OPXMIReader + readFrom: + ' + +' +] + +{ #category : 'instance creation' } +OPUMLXMIReaderTest >> defaultValueElement [ + ^ OPXMIObjectElement new + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:LiteralInteger'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'lowerValue'} +] + +{ #category : 'instance creation' } +OPUMLXMIReaderTest >> elementWithGeneralization [ + "Comment -> Element" + + ^ OPXMIObjectElement new + xmiName: 'packagedElement'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Class'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment'. + OPXMIValueAttribute xmiName: 'name' value: 'Comment'. + OPXMIObjectElement new + xmiName: 'generalization'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Generalization'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment-_generalization.0'. + OPXMIReferenceAttribute new + xmiName: 'general'; + referencedElements: + {OPXMIObjectElement new + xmiName: 'packagedElement'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Class'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'Element'. + OPXMIValueAttribute xmiName: 'name' value: 'Element'}}}} +] + +{ #category : 'instance creation' } +OPUMLXMIReaderTest >> generalizationElement [ + "-> Element" + + ^ OPXMIObjectElement new + xmiName: 'generalization'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Generalization'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment-_generalization.0'. + OPXMIReferenceAttribute new + xmiName: 'general'; + referencedElements: + {OPXMIObjectElement new + xmiName: 'packagedElement'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Class'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'Element'. + OPXMIValueAttribute xmiName: 'name' value: 'Element'}}} +] + +{ #category : 'accessing' } +OPUMLXMIReaderTest >> metaClassNamed: aName [ + ^ OPUMLXMISpecsStorage metaClassNamed: aName +] + +{ #category : 'instance creation' } +OPUMLXMIReaderTest >> multipleNestedAttributes [ + ^ OPXMIObjectElement new + xmiName: 'packagedElement'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Class'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment'. + OPXMIValueAttribute xmiName: 'name' value: 'Comment'. + OPXMIObjectElement new + xmiName: 'ownedAttribute'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Property'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment-annotatedElement'. + OPXMIValueElement xmiName: 'name' value: 'annotatedElement'}. + OPXMIObjectElement new + xmiName: 'ownedAttribute'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Property'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment-body'. + OPXMIValueElement xmiName: 'name' value: 'body'}} +] + +{ #category : 'instance creation' } +OPUMLXMIReaderTest >> nestedComplexElement [ + ^ OPXMIObjectElement new + xmiName: 'Attribute'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Property'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'PROPID'. + OPXMIObjectElement new + xmiName: 'upperValue'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:LiteralUnlimitedNatural'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'PROPID_upperValue'. + OPXMIValueElement xmiName: 'value' value: '*'}} +] + +{ #category : 'instance creation' } +OPUMLXMIReaderTest >> packageImportPackage [ + | activities classification | + classification := OPXMIObjectElement new + xmiName: 'packagedElement'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Package'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'Classification'. + OPXMIValueAttribute xmiName: 'name' value: 'Classification'}. + activities := OPXMIObjectElement new + xmiName: 'packagedElement'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Package'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'Activities'. + OPXMIValueAttribute xmiName: 'name' value: 'Activities'. + OPXMIObjectElement new + xmiName: 'packageImport'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:PackageImport'. + OPXMIValueAttribute xmiName: 'xmi:id' value: '_packageImport.1'. + OPXMIReferenceAttribute xmiName: 'importedPackage' referencedElements: {classification}}}. + ^ OPXMIObjectElement new + xmiName: 'uml:Package'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Package'. + OPXMIValueAttribute xmiName: 'xmi:id' value: '_0'. + OPXMIValueAttribute xmiName: 'name' value: 'UML'. + OPXMIObjectElement new + xmiName: 'packageImport'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:PackageImport'. + OPXMIValueAttribute xmiName: 'xmi:id' value: '_packageImport.1'. + OPXMIReferenceAttribute xmiName: 'importedPackage' referencedElements: {activities}}. + OPXMIObjectElement new + xmiName: 'packageImport'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:PackageImport'. + OPXMIValueAttribute xmiName: 'xmi:id' value: '_packageImport.2'. + OPXMIReferenceAttribute xmiName: 'importedPackage' referencedElements: {classification}}} +] + +{ #category : 'accessing' } +OPUMLXMIReaderTest >> primitiveTypeNamed: aName [ + ^ OPUMLXMISpecsStorage primitiveTypeNamed: aName +] + +{ #category : 'running' } +OPUMLXMIReaderTest >> property: aPropertyName in: aContainerClass [ + ^ (OPUMLXMISpecsStorage metaClassFor: aContainerClass) ownedAttributes + detect: [ :each | each name = aPropertyName ] +] + +{ #category : 'running' } +OPUMLXMIReaderTest >> setUp [ + reader := OPUMLXMIReader new. + packagedElementProperty := (OPUMLXMISpecsStorage metaClassFor: OPUMLPackage new) + ownedAttributes detect: [ :each | each name = 'packagedElement' ] +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testAmbiguousPackageImport [ + "xmi:id of elements are not valid and should be ignored (they are not unique). Test that we can load correctly despite that" + + | masterPkg activitiesPkg classificationPkg | + masterPkg := reader readItem: self packageImportPackage property: packagedElementProperty. + self assert: masterPkg name equals: 'UML'. + self assert: masterPkg packageImports size equals: 2. + activitiesPkg := masterPkg packageImports first importedPackage. + classificationPkg := masterPkg packageImports second importedPackage. + self assert: classificationPkg name equals: 'Classification'. + self assert: classificationPkg packageImports asArray equals: #(). + self assert: activitiesPkg name equals: 'Activities'. + self + assert: activitiesPkg packageImports first importedPackage + equals: classificationPkg +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testAssociation [ + | result | + result := reader readItem: self association property: packagedElementProperty. + self assert: result umlClassName equals: #Association. + self assert: result memberEnds size equals: 2. + self + assert: (result memberEnds collect: #name) asArray sorted + equals: #('annotatedElement' 'comment') sorted. + self assert: (result ownedEnds collect: #name) asArray equals: #('comment'). + self assert: (result memberEnds includes: result ownedEnds first) +] + +{ #category : 'tests - reading - value' } +OPUMLXMIReaderTest >> testBooleanStringValue [ + | result stringProperty | + stringProperty := (OPUMLXMISpecsStorage metaClassFor: OPUMLProperty new) allAttributes + detect: [ :each | each name = 'name' ]. + result := reader valueFor: 'true' property: stringProperty. + self assert: result equals: 'true' +] + +{ #category : 'tests - reading - value' } +OPUMLXMIReaderTest >> testBooleanValue [ + | result booleanProperty | + booleanProperty := (OPUMLXMISpecsStorage metaClassFor: OPUMLProperty new) ownedAttributes + detect: [ :each | each name = 'isDerived' ]. + result := reader valueFor: 'true' property: booleanProperty. + self assert: result equals: true +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testCreateNewInstanceProperty [ + | item property | + item := OPXMIObjectElement new + xmiName: 'profileApplication'; + containedItems: {}. + property := (OPUMLXMISpecsStorage metaClassFor: OPUMLPackage new) ownedAttributes + detect: [ :each | each name = 'profileApplication' ]. + self + assert: (reader createNewInstanceFor: item property: property) umlClassName + equals: #ProfileApplication +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testCreateNewInstanceXmiId [ + | item | + item := OPXMIObjectElement new + xmiName: 'packagedElement'; + containedItems: {OPXMIValueElement xmiName: 'xmi:id' value: 'CustomId'}. + self + assert: (reader createNewInstanceFor: item property: packagedElementProperty) uuid + equals: 'CustomId' +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testCreateNewInstanceXmiName [ + | item | + item := OPXMIObjectElement new + xmiName: 'Package'; + containedItems: {}. + self + assert: (reader createNewInstanceFor: item property: nil) umlClassName + equals: #Package +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testCreateNewInstanceXmiType [ + | item | + item := OPXMIObjectElement new + xmiName: 'packagedElement'; + containedItems: {OPXMIValueElement xmiName: 'xmi:type' value: 'uml:Class'}. + self + assert: (reader createNewInstanceFor: item property: packagedElementProperty) umlClassName + equals: #Class +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testGeneralizationElement [ + | result | + result := reader + readItem: self generalizationElement + property: (self property: #generalization in: OPUMLClassifier new). + self assert: result umlClassName equals: 'Generalization'. + self assert: result general name equals: 'Element' +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testGroupedChildren [ + | result | + result := reader groupedChildrenIn: self multipleNestedAttributes. + self assert: result keys sorted equals: #(name ownedAttribute). + self assert: (result at: #name) size equals: 1. + self assert: (result at: #ownedAttribute) size equals: 2 +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testInstance [ + | element result1 result2 | + element := OPXMIObjectElement new + xmiName: 'Package'; + containedItems: {OPXMIValueElement xmiName: 'xmi:id' value: 'CLS'}. + result1 := reader instanceFor: element property: nil. + self assert: result1 umlClassName equals: #Package. + result2 := reader instanceFor: element property: nil. + self assert: result1 == result2 description: 'We expect the same object.' +] + +{ #category : 'tests - reading - value' } +OPUMLXMIReaderTest >> testIntegerStringValue [ + | result stringProperty | + stringProperty := (OPUMLXMISpecsStorage metaClassFor: OPUMLProperty new) allAttributes + detect: [ :each | each name = 'name' ]. + result := reader valueFor: '123' property: stringProperty. + self assert: result equals: '123' +] + +{ #category : 'tests - reading - value' } +OPUMLXMIReaderTest >> testIntegerValue [ + | result integerProperty | + integerProperty := (OPUMLXMISpecsStorage metaClassFor: OPUMLProperty new) allAttributes + detect: [ :each | each name = 'lower' ]. + result := reader valueFor: '123' property: integerProperty. + self assert: result equals: 123 +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testMultipleNestedAttributes [ + | result | + result := reader readItem: self multipleNestedAttributes property: packagedElementProperty. + self assert: result umlClassName equals: #Class. + self assert: result ownedAttributes size equals: 2. + self assert: result ownedAttributes first name equals: 'annotatedElement'. + self assert: result ownedAttributes second name equals: 'body' +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testNestedComplexElement [ + | result | + result := reader + readItem: self nestedComplexElement + property: (self property: 'ownedAttribute' in: OPUMLClass new). + self assert: result umlClassName equals: #Property. + self assert: result upperValue value equals: '*'. + " self assert: result lowerValue value equals: 0." + self assert: result lowerValue value equals: nil +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testReadBoolean [ + | result | + result := reader + readItem: (OPXMIValueAttribute xmiName: 'isDerived' value: 'true') + property: (self property: #isDerived in: OPUMLProperty new). + self assert: result equals: true +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testReadImportedType [ + | result property | + property := (self metaClassNamed: #Class) allAttributes + detect: [ :each | each name = 'ownedAttribute' ]. + result := reader readItem: self attributeWithHrefType property: property. + self assert: result type equals: (self metaClassNamed: #Association) +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testReadPrimitiveType [ + | result property | + property := (self metaClassNamed: #Class) allAttributes + detect: [ :each | each name = 'ownedAttribute' ]. + result := reader readItem: self attributeWithPrimitiveType property: property. + self assert: result type equals: (self primitiveTypeNamed: #Boolean) +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testReadSimpleObject [ + | element result | + element := OPXMIObjectElement new + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:id' value: 'Comment'. + OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Comment'. + OPXMIValueElement xmiName: 'body' value: 'CONTENT'}. + result := reader readItem: element property: packagedElementProperty. + self assert: result umlClassName equals: #Comment. + self assert: result body equals: 'CONTENT' +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testReadTrivialXmi [ + | result | + result := reader readXmi: self trivialXmi. + self assert: result size equals: 1. + self assert: result first umlClassName equals: #Package +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testReadTrivialishXmi [ + | result | + result := reader readXmi: self trivialishXmi. + self assert: result size equals: 1. + self assert: result first umlClassName equals: #Package. + self assert: result first packagedElements size equals: 1. + self assert: result first packagedElements first name equals: 'Activities' +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testReferenceElement [ + | result gen | + result := reader + readItem: self elementWithGeneralization + property: packagedElementProperty. + self assert: result name equals: 'Comment'. + gen := result generalizations first. + self assert: gen umlClassName equals: #Generalization. + self assert: gen general name equals: 'Element' +] + +{ #category : 'tests' } +OPUMLXMIReaderTest >> testUniqueId [ + | regular packageImport | + regular := OPXMIObjectElement new + containedItems: {OPXMIValueAttribute xmiName: 'xmi:id' value: 'AAA'}. + packageImport := OPXMIObjectElement new + xmiName: 'packageImport'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:PackageImport'. + OPXMIValueAttribute xmiName: 'xmi:id' value: '_packageImport.1'. + OPXMIReferenceAttribute xmiName: 'importedPackage' referencedElements: {regular}}. + self assert: (reader uniqueIdOf: regular) equals: 'AAA'. + self assert: (reader uniqueIdOf: packageImport) equals: '_packageImport.1-AAA' +] + +{ #category : 'instance creation' } +OPUMLXMIReaderTest >> trivialXmi [ + ^ OPXMIObjectElement new + xmiName: 'XMI'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmlns:xmi' value: 'http://www.omg.org/spec/XMI/20131001'. + OPXMIValueAttribute xmiName: 'xmlns:uml' value: 'http://www.omg.org/spec/UML/20131001'. + OPXMIValueAttribute + xmiName: 'xmlns:moftext' + value: 'http://www.omg.org/spec/MOF/20131001'. + OPXMIObjectElement new + xmiName: 'Package'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:id' value: '_0'. + OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Package'}. + OPXMIObjectElement new + xmiName: 'Tag'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:id' value: '_1'. + OPXMIValueAttribute xmiName: 'xmi:type' value: 'mofext:Tag'}} +] + +{ #category : 'instance creation' } +OPUMLXMIReaderTest >> trivialishXmi [ + ^ OPXMIObjectElement new + xmiName: 'XMI'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmlns:xmi' value: 'http://www.omg.org/spec/XMI/20131001'. + OPXMIValueAttribute xmiName: 'xmlns:uml' value: 'http://www.omg.org/spec/UML/20131001'. + OPXMIValueAttribute + xmiName: 'xmlns:moftext' + value: 'http://www.omg.org/spec/MOF/20131001'. + OPXMIObjectElement new + xmiName: 'Package'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:id' value: '_0'. + OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Package'. + OPXMIObjectElement new + xmiName: 'packagedElement'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:type' value: 'uml:Package'. + OPXMIValueAttribute xmiName: 'xmi:id' value: 'Activities'. + OPXMIValueAttribute xmiName: 'name' value: 'Activities'}}. + OPXMIObjectElement new + xmiName: 'Tag'; + containedItems: + {OPXMIValueAttribute xmiName: 'xmi:id' value: '_1'. + OPXMIValueAttribute xmiName: 'xmi:type' value: 'mofext:Tag'}} +] diff --git a/repository/OP-UML-XMI/OPUMLXMISpecsStorage.class.st b/repository/OpenPonk-UML-XMI/OPUMLXMISpecsStorage.class.st similarity index 94% rename from repository/OP-UML-XMI/OPUMLXMISpecsStorage.class.st rename to repository/OpenPonk-UML-XMI/OPUMLXMISpecsStorage.class.st index b5b6195..57e0d03 100644 --- a/repository/OP-UML-XMI/OPUMLXMISpecsStorage.class.st +++ b/repository/OpenPonk-UML-XMI/OPUMLXMISpecsStorage.class.st @@ -1,173 +1,173 @@ -Class { - #name : 'OPUMLXMISpecsStorage', - #superclass : 'Object', - #instVars : [ - 'storage' - ], - #classVars : [ - 'Current', - 'MetaClassMap', - 'PrimitivesMap', - 'PrimitivesMetaModel', - 'UmlMetaModel' - ], - #category : 'OP-UML-XMI-Utility', - #package : 'OP-UML-XMI', - #tag : 'Utility' -} - -{ #category : 'accessing' } -OPUMLXMISpecsStorage class >> current [ - " - Current := nil - " - ^ Current ifNil: [ Current := self new ] -] - -{ #category : 'accessing' } -OPUMLXMISpecsStorage class >> loadMetamodel [ - " - UmlMetaModel := nil. - PrimitivesMetaModel := nil. - " - - - | pathmap result packages xmiDom models | - pathmap := OPUMLXMIPathmap new. - pathmap add: 'http://www.omg.org/spec/UML/20131001/PrimitiveTypes.xmi'. - pathmap add: 'http://www.omg.org/spec/UML/20131001/UML.xmi'. - result := OPXMIReader readFromMapping: pathmap mapping. - packages := result values - flatCollect: [ :xmi | - xmi containedItems - select: [ :each | each isObjectElement and: [ each xmiName = 'Package' ] ] ]. - (packages first containedItems - detect: [ :each | each isValueAttribute and: [ each xmiName = 'xmi:id' ] ]) value: '_1'. - xmiDom := OPXMIObjectElement new containedItems: packages. - models := OPUMLXMIMetaReader new readXmi: xmiDom. - PrimitivesMetaModel := models first. - UmlMetaModel := models second. - ^ {PrimitivesMetaModel. - UmlMetaModel} -] - -{ #category : 'accessing' } -OPUMLXMISpecsStorage class >> metaClassFor: anElement [ - ^ self metaClassNamed: anElement umlClassName -] - -{ #category : 'accessing' } -OPUMLXMISpecsStorage class >> metaClassMap [ - " - MetaClassMap := nil - " - - ^ MetaClassMap - ifNil: [ MetaClassMap := ((self umlMetamodel packagedElements flatCollect: #packagedElements) - select: [ :each | each umlClassName = #Class ] - thenCollect: [ :each | each name -> each ]) asDictionary ] -] - -{ #category : 'accessing' } -OPUMLXMISpecsStorage class >> metaClassNamed: aClassName [ - ^ self metaClassMap at: aClassName -] - -{ #category : 'accessing' } -OPUMLXMISpecsStorage class >> primitiveTypeNamed: aPrimitiveName [ - ^ self primitivesMap at: aPrimitiveName -] - -{ #category : 'accessing' } -OPUMLXMISpecsStorage class >> primitivesMap [ - " - PrimitivesMap := nil - " - - ^ PrimitivesMap - ifNil: [ PrimitivesMap := (self primitivesMetamodel packagedElements - collect: [ :each | each name -> each ]) asDictionary ] -] - -{ #category : 'accessing' } -OPUMLXMISpecsStorage class >> primitivesMetamodel [ - " - PrimitivesMetaModel := nil. - " - - - PrimitivesMetaModel ifNil: [ self loadMetamodel ]. - ^ PrimitivesMetaModel -] - -{ #category : 'actions' } -OPUMLXMISpecsStorage class >> reset [ - -