Skip to content

Commit

Permalink
Updates for Pharo 12
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed May 7, 2024
1 parent 9e6c744 commit 1f13d3e
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 165 deletions.
28 changes: 16 additions & 12 deletions repository/OP-UML-XMI/OPUMLXMIMetaReader.class.st
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
Class {
#name : #OPUMLXMIMetaReader,
#superclass : #OPUMLXMIReader,
#category : 'OP-UML-XMI-Reader'
#name : 'OPUMLXMIMetaReader',
#superclass : 'OPUMLXMIReader',
#category : 'OP-UML-XMI-Reader',
#package : 'OP-UML-XMI',
#tag : 'Reader'
}

{ #category : #'instance creation' }
{ #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 ] ].
^ (self classPrefix , name) asSymbol asClass new
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 }
{ #category : 'reading' }
OPUMLXMIMetaReader >> readItem: anItem property: aProperty [
| instance groups |
anItem isValueItem
Expand Down Expand Up @@ -53,7 +57,7 @@ OPUMLXMIMetaReader >> readItem: anItem property: aProperty [
^ instance
]

{ #category : #reading }
{ #category : 'reading' }
OPUMLXMIMetaReader >> valueFor: anObject [
anObject = 'true'
ifTrue: [ ^ true ].
Expand Down
18 changes: 10 additions & 8 deletions repository/OP-UML-XMI/OPUMLXMIPathmap.class.st
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
Class {
#name : #OPUMLXMIPathmap,
#superclass : #Object,
#name : 'OPUMLXMIPathmap',
#superclass : 'Object',
#instVars : [
'mapping'
],
#category : 'OP-UML-XMI-Utility'
#category : 'OP-UML-XMI-Utility',
#package : 'OP-UML-XMI',
#tag : 'Utility'
}

{ #category : #accessing }
{ #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 }
{ #category : 'adding' }
OPUMLXMIPathmap >> add: aPath [
self add: aPath retrieveUsing: [ OPUMLXMISpecsStorage current at: aPath ]
]

{ #category : #adding }
{ #category : 'adding' }
OPUMLXMIPathmap >> add: aPath retrieveUsing: aBlock [
mapping at: aPath put: aBlock value
]

{ #category : #initialization }
{ #category : 'initialization' }
OPUMLXMIPathmap >> initialize [
super initialize.
mapping := OrderedDictionary new
]

{ #category : #accessing }
{ #category : 'accessing' }
OPUMLXMIPathmap >> mapping [
^ mapping
]
76 changes: 40 additions & 36 deletions repository/OP-UML-XMI/OPUMLXMIReader.class.st
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
Class {
#name : #OPUMLXMIReader,
#superclass : #Object,
#name : 'OPUMLXMIReader',
#superclass : 'Object',
#instVars : [
'classPrefix',
'instanceCache'
],
#category : #'OP-UML-XMI-Reader'
#category : 'OP-UML-XMI-Reader',
#package : 'OP-UML-XMI',
#tag : 'Reader'
}

{ #category : #'instance creation' }
{ #category : 'instance creation' }
OPUMLXMIReader class >> read: anXmlStream [
^ self read: anXmlStream pathmap: OPUMLXMIPathmap default
]

{ #category : #'instance creation' }
{ #category : 'instance creation' }
OPUMLXMIReader class >> read: anXmlStream pathmap: aPathmap [
| xmi pathmap xmiResult processedXmi |
pathmap := aPathmap mapping copy.
Expand All @@ -24,12 +26,12 @@ OPUMLXMIReader class >> read: anXmlStream pathmap: aPathmap [
^ processedXmi first
]

{ #category : #'instance creation' }
{ #category : 'instance creation' }
OPUMLXMIReader class >> readFrom: aStream [
^ (self new readXmi: (OPXMIReader readFrom: aStream)) first
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
OPUMLXMIReader >> applyStereotype: anStereotypeXMI outOf: possibleStereotypes to: anElement [
| stereotype groups |
stereotype := (possibleStereotypes at: anStereotypeXMI xmiName)
Expand All @@ -43,7 +45,7 @@ OPUMLXMIReader >> applyStereotype: anStereotypeXMI outOf: possibleStereotypes to
[ :key :values | self readPropertyNamed: key values: values instance: stereotype ]
]

{ #category : #reading }
{ #category : 'reading' }
OPUMLXMIReader >> applyStereotypesAmongst: elements to: models [
| possibleStereotypes |
possibleStereotypes := ((models
Expand All @@ -68,7 +70,7 @@ OPUMLXMIReader >> applyStereotypesAmongst: elements to: models [
referencedElement xmiId) ]
]

{ #category : #converting }
{ #category : 'converting' }
OPUMLXMIReader >> asPlural: aString [
(aString endsWith: 's')
ifTrue: [ ^ aString , 'es' ].
Expand All @@ -77,61 +79,63 @@ OPUMLXMIReader >> asPlural: aString [
^ aString , 's'
]

{ #category : #accessing }
{ #category : 'accessing' }
OPUMLXMIReader >> classPrefix [
^ classPrefix
]

{ #category : #accessing }
{ #category : 'accessing' }
OPUMLXMIReader >> classPrefix: anObject [
classPrefix := anObject
]

{ #category : #'instance creation' }
{ #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 ] ].
^ (self classPrefix , name) asSymbol asClass new
uuid:
([ UUID fromString: anItem xmiId ]
on: Error
do: [ anItem xmiId ]);
yourself
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 }
{ #category : 'accessing' }
OPUMLXMIReader >> defaultClassPrefix [
^ 'OPUML'
]

{ #category : #reading }
{ #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 }
{ #category : 'initialization' }
OPUMLXMIReader >> initialize [
super initialize.
instanceCache := Dictionary new.
classPrefix := self defaultClassPrefix
]

{ #category : #'instance creation' }
{ #category : 'instance creation' }
OPUMLXMIReader >> instanceFor: anObjectElement property: aProperty [
^ instanceCache
at: (self uniqueIdOf: anObjectElement)
ifAbsentPut: [ self createNewInstanceFor: anObjectElement property: aProperty ]
]

{ #category : #reading }
{ #category : 'reading' }
OPUMLXMIReader >> readItem: anItem property: aProperty [
| instance groups |
anItem isValueItem
Expand Down Expand Up @@ -160,7 +164,7 @@ OPUMLXMIReader >> readItem: anItem property: aProperty [
^ instance
]

{ #category : #reading }
{ #category : 'reading' }
OPUMLXMIReader >> readMetamodelItem: anItem property: aProperty [
| parts |
parts := anItem href splitOn: '#'.
Expand All @@ -171,14 +175,14 @@ OPUMLXMIReader >> readMetamodelItem: anItem property: aProperty [
self error: 'Unknown type at ' , anItem href
]

{ #category : #reading }
{ #category : 'reading' }
OPUMLXMIReader >> readMofItem: anItem property: aProperty [
| parts |
parts := anItem href splitOn: '#'.
^ OPUMLXMISpecsStorage primitiveTypeNamed: parts second
]

{ #category : #reading }
{ #category : 'reading' }
OPUMLXMIReader >> readProfileItem: anItem property: aProperty [
| parts factory |
parts := anItem href splitOn: '#'.
Expand All @@ -192,7 +196,7 @@ OPUMLXMIReader >> readProfileItem: anItem property: aProperty [
^ factory profile
]

{ #category : #reading }
{ #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 ])
Expand Down Expand Up @@ -220,7 +224,7 @@ OPUMLXMIReader >> readPropertyNamed: aKey values: values instance: anInstance [
ifTrue: [ anInstance perform: selector with: arguments first ] ]
]

{ #category : #reading }
{ #category : 'reading' }
OPUMLXMIReader >> readXmi: anXmi [
| elements models |
(anXmi isObjectElement
Expand All @@ -235,15 +239,15 @@ OPUMLXMIReader >> readXmi: anXmi [
^ models
]

{ #category : #reading }
{ #category : 'reading' }
OPUMLXMIReader >> uniqueIdOf: anObject [
anObject xmiName = 'packageImport'
ifTrue: [ ^ anObject xmiId , '-'
, (anObject containedItems detect: [ :each | each xmiName = #importedPackage ]) referencedElement xmiId ].
^ anObject xmiId
]

{ #category : #reading }
{ #category : 'reading' }
OPUMLXMIReader >> valueFor: anObject property: aProperty [
(#('Integer') includes: aProperty type name)
ifTrue: [ ^ Number readFromString: anObject ].
Expand Down
Loading

0 comments on commit 1f13d3e

Please sign in to comment.