diff --git a/repository/BaselineOfOPXMI/BaselineOfOPXMI.class.st b/repository/BaselineOfOPXMI/BaselineOfOPXMI.class.st deleted file mode 100644 index 2110250..0000000 --- a/repository/BaselineOfOPXMI/BaselineOfOPXMI.class.st +++ /dev/null @@ -1,32 +0,0 @@ -" -Baseline for https://github.com/OpenPonk/xmi -" -Class { - #name : 'BaselineOfOPXMI', - #superclass : 'BaselineOf', - #category : 'BaselineOfOPXMI', - #package : 'BaselineOfOPXMI' -} - -{ #category : 'baselines' } -BaselineOfOPXMI >> baseline: spec [ - - - spec for: #common do: [ - spec - baseline: 'XMLDOMVisitor' - with: [ - spec repository: 'github://OpenPonk/xml-dom-visitor' ]. - spec baseline: 'XMLWriter' with: [ - spec - loads: #( 'Core' ); - repository: - 'github://pharo-contributions/XML-XMLWriter:v3.1.x' ]. - spec - package: 'OP-XMI' - with: [ spec requires: #( 'XMLDOMVisitor' 'XMLWriter' ) ]. - spec - package: 'OP-XMI-GTExtensions' - with: [ spec requires: #( 'OP-XMI' ) ]. - spec group: 'default' with: #( 'OP-XMI' 'OP-XMI-GTExtensions' ) ] -] diff --git a/repository/BaselineOfOPXMI/package.st b/repository/BaselineOfOPXMI/package.st deleted file mode 100644 index 01d810b..0000000 --- a/repository/BaselineOfOPXMI/package.st +++ /dev/null @@ -1 +0,0 @@ -Package { #name : 'BaselineOfOPXMI' } diff --git a/repository/BaselineOfOpenPonkXMI/BaselineOfOpenPonkXMI.class.st b/repository/BaselineOfOpenPonkXMI/BaselineOfOpenPonkXMI.class.st new file mode 100644 index 0000000..7b10154 --- /dev/null +++ b/repository/BaselineOfOpenPonkXMI/BaselineOfOpenPonkXMI.class.st @@ -0,0 +1,32 @@ +" +Baseline for https://github.com/OpenPonk/xmi +" +Class { + #name : 'BaselineOfOpenPonkXMI', + #superclass : 'BaselineOf', + #category : 'BaselineOfOpenPonkXMI', + #package : 'BaselineOfOpenPonkXMI' +} + +{ #category : 'baselines' } +BaselineOfOpenPonkXMI >> baseline: spec [ + + + spec for: #common do: [ + spec + baseline: 'OpenPonkXMLDOMVisitor' + with: [ + spec repository: 'github://OpenPonk/xml-dom-visitor' ]. + spec baseline: 'XMLWriter' with: [ + spec + loads: #( 'Core' ); + repository: + 'github://pharo-contributions/XML-XMLWriter:v3.1.x' ]. + spec + package: 'OpenPonk-XMI' + with: [ spec requires: #( 'OpenPonkXMLDOMVisitor' 'XMLWriter' ) ]. + spec + package: 'OpenPonk-XMI-Inspection' + with: [ spec requires: #( 'OpenPonk-XMI' ) ]. + spec group: 'default' with: #( 'OpenPonk-XMI' 'OpenPonk-XMI-Inspection' ) ] +] diff --git a/repository/BaselineOfOpenPonkXMI/package.st b/repository/BaselineOfOpenPonkXMI/package.st new file mode 100644 index 0000000..6f6dedc --- /dev/null +++ b/repository/BaselineOfOpenPonkXMI/package.st @@ -0,0 +1 @@ +Package { #name : 'BaselineOfOpenPonkXMI' } diff --git a/repository/OP-XMI-GTExtensions/package.st b/repository/OP-XMI-GTExtensions/package.st deleted file mode 100644 index 5006cb6..0000000 --- a/repository/OP-XMI-GTExtensions/package.st +++ /dev/null @@ -1 +0,0 @@ -Package { #name : 'OP-XMI-GTExtensions' } diff --git a/repository/OP-XMI/package.st b/repository/OP-XMI/package.st deleted file mode 100644 index e2582aa..0000000 --- a/repository/OP-XMI/package.st +++ /dev/null @@ -1 +0,0 @@ -Package { #name : 'OP-XMI' } diff --git a/repository/OP-XMI-GTExtensions/OPXMIElement.extension.st b/repository/OpenPonk-XMI-Inspection/OPXMIElement.extension.st similarity index 70% rename from repository/OP-XMI-GTExtensions/OPXMIElement.extension.st rename to repository/OpenPonk-XMI-Inspection/OPXMIElement.extension.st index 279c441..2a1cc2d 100644 --- a/repository/OP-XMI-GTExtensions/OPXMIElement.extension.st +++ b/repository/OpenPonk-XMI-Inspection/OPXMIElement.extension.st @@ -1,6 +1,6 @@ -Extension { #name : 'OPXMIElement' } - -{ #category : '*OP-XMI-GTExtensions' } -OPXMIElement >> writeXMLOn: aWriter [ - aWriter tag: self xmiName -] +Extension { #name : 'OPXMIElement' } + +{ #category : '*OpenPonk-XMI-Inspection' } +OPXMIElement >> writeXMLOn: aWriter [ + aWriter tag: self xmiName +] diff --git a/repository/OP-XMI-GTExtensions/OPXMIInfoItems.extension.st b/repository/OpenPonk-XMI-Inspection/OPXMIInfoItems.extension.st similarity index 69% rename from repository/OP-XMI-GTExtensions/OPXMIInfoItems.extension.st rename to repository/OpenPonk-XMI-Inspection/OPXMIInfoItems.extension.st index 3c46f7c..a0f6a11 100644 --- a/repository/OP-XMI-GTExtensions/OPXMIInfoItems.extension.st +++ b/repository/OpenPonk-XMI-Inspection/OPXMIInfoItems.extension.st @@ -1,15 +1,15 @@ -Extension { #name : 'OPXMIInfoItems' } - -{ #category : '*OP-XMI-GTExtensions' } -OPXMIInfoItems >> treeViewLabelText [ - ^ self asHighlightedTextWrittenWith: [ :writer | self writeTreeViewLabelXMLOn: writer ] -] - -{ #category : '*OP-XMI-GTExtensions' } -OPXMIInfoItems >> writeTreeViewLabelXMLOn: aWriter [ - self writeXMLOn: aWriter -] - -{ #category : '*OP-XMI-GTExtensions' } -OPXMIInfoItems >> writeXMLOn: aWriter [ -] +Extension { #name : 'OPXMIInfoItems' } + +{ #category : '*OpenPonk-XMI-Inspection' } +OPXMIInfoItems >> treeViewLabelText [ + ^ self asHighlightedTextWrittenWith: [ :writer | self writeTreeViewLabelXMLOn: writer ] +] + +{ #category : '*OpenPonk-XMI-Inspection' } +OPXMIInfoItems >> writeTreeViewLabelXMLOn: aWriter [ + self writeXMLOn: aWriter +] + +{ #category : '*OpenPonk-XMI-Inspection' } +OPXMIInfoItems >> writeXMLOn: aWriter [ +] diff --git a/repository/OP-XMI-GTExtensions/OPXMIObjectElement.extension.st b/repository/OpenPonk-XMI-Inspection/OPXMIObjectElement.extension.st similarity index 86% rename from repository/OP-XMI-GTExtensions/OPXMIObjectElement.extension.st rename to repository/OpenPonk-XMI-Inspection/OPXMIObjectElement.extension.st index 94f1864..2cb6aaf 100644 --- a/repository/OP-XMI-GTExtensions/OPXMIObjectElement.extension.st +++ b/repository/OpenPonk-XMI-Inspection/OPXMIObjectElement.extension.st @@ -1,27 +1,27 @@ -Extension { #name : 'OPXMIObjectElement' } - -{ #category : '*OP-XMI-GTExtensions' } -OPXMIObjectElement >> inspectionProperties [ - - "" - ^ SpTreePresenter new - roots: { self }; - children: [ :each | - each isObjectElement - ifTrue: [ each containedItems ] - ifFalse: [ - each isReferenceItem - ifTrue: [ each referencedElements ] - ifFalse: [ #( ) ] ] ]; - display: [ :each | each treeViewLabelText ]; - yourself -] - -{ #category : '*OP-XMI-GTExtensions' } -OPXMIObjectElement >> writeXMLOn: aWriter [ - aWriter - tag: self xmiName - attributes: - ({#xmi:id -> self xmiId. - #xmi:type -> self xmiType} select: [:pair | pair value isNotNil]) -] +Extension { #name : 'OPXMIObjectElement' } + +{ #category : '*OpenPonk-XMI-Inspection' } +OPXMIObjectElement >> inspectionProperties [ + + "" + ^ SpTreePresenter new + roots: { self }; + children: [ :each | + each isObjectElement + ifTrue: [ each containedItems ] + ifFalse: [ + each isReferenceItem + ifTrue: [ each referencedElements ] + ifFalse: [ #( ) ] ] ]; + display: [ :each | each treeViewLabelText ]; + yourself +] + +{ #category : '*OpenPonk-XMI-Inspection' } +OPXMIObjectElement >> writeXMLOn: aWriter [ + aWriter + tag: self xmiName + attributes: + ({#xmi:id -> self xmiId. + #xmi:type -> self xmiType} select: [:pair | pair value isNotNil]) +] diff --git a/repository/OP-XMI-GTExtensions/OPXMIReferenceAttribute.extension.st b/repository/OpenPonk-XMI-Inspection/OPXMIReferenceAttribute.extension.st similarity index 81% rename from repository/OP-XMI-GTExtensions/OPXMIReferenceAttribute.extension.st rename to repository/OpenPonk-XMI-Inspection/OPXMIReferenceAttribute.extension.st index 8ecd78e..078b4ad 100644 --- a/repository/OP-XMI-GTExtensions/OPXMIReferenceAttribute.extension.st +++ b/repository/OpenPonk-XMI-Inspection/OPXMIReferenceAttribute.extension.st @@ -1,8 +1,8 @@ -Extension { #name : 'OPXMIReferenceAttribute' } - -{ #category : '*OP-XMI-GTExtensions' } -OPXMIReferenceAttribute >> writeXMLOn: aWriter [ - aWriter - tag: self xmiName - with: [ self referencedElements do: [ :each | each writeXMLOn: aWriter ] ] -] +Extension { #name : 'OPXMIReferenceAttribute' } + +{ #category : '*OpenPonk-XMI-Inspection' } +OPXMIReferenceAttribute >> writeXMLOn: aWriter [ + aWriter + tag: self xmiName + with: [ self referencedElements do: [ :each | each writeXMLOn: aWriter ] ] +] diff --git a/repository/OP-XMI-GTExtensions/OPXMIReferenceElement.extension.st b/repository/OpenPonk-XMI-Inspection/OPXMIReferenceElement.extension.st similarity index 81% rename from repository/OP-XMI-GTExtensions/OPXMIReferenceElement.extension.st rename to repository/OpenPonk-XMI-Inspection/OPXMIReferenceElement.extension.st index 602f24b..4f9642d 100644 --- a/repository/OP-XMI-GTExtensions/OPXMIReferenceElement.extension.st +++ b/repository/OpenPonk-XMI-Inspection/OPXMIReferenceElement.extension.st @@ -1,8 +1,8 @@ -Extension { #name : 'OPXMIReferenceElement' } - -{ #category : '*OP-XMI-GTExtensions' } -OPXMIReferenceElement >> writeXMLOn: aWriter [ - href - ifNil: [ aWriter tag: self xmiName ] - ifNotNil: [ aWriter tag: self xmiName attributes: {#href -> href} ] -] +Extension { #name : 'OPXMIReferenceElement' } + +{ #category : '*OpenPonk-XMI-Inspection' } +OPXMIReferenceElement >> writeXMLOn: aWriter [ + href + ifNil: [ aWriter tag: self xmiName ] + ifNotNil: [ aWriter tag: self xmiName attributes: {#href -> href} ] +] diff --git a/repository/OP-XMI-GTExtensions/OPXMIValueAttribute.extension.st b/repository/OpenPonk-XMI-Inspection/OPXMIValueAttribute.extension.st similarity index 75% rename from repository/OP-XMI-GTExtensions/OPXMIValueAttribute.extension.st rename to repository/OpenPonk-XMI-Inspection/OPXMIValueAttribute.extension.st index 189feed..30b7d1b 100644 --- a/repository/OP-XMI-GTExtensions/OPXMIValueAttribute.extension.st +++ b/repository/OpenPonk-XMI-Inspection/OPXMIValueAttribute.extension.st @@ -1,6 +1,6 @@ -Extension { #name : 'OPXMIValueAttribute' } - -{ #category : '*OP-XMI-GTExtensions' } -OPXMIValueAttribute >> writeXMLOn: aWriter [ - aWriter tag: self xmiName with: self value -] +Extension { #name : 'OPXMIValueAttribute' } + +{ #category : '*OpenPonk-XMI-Inspection' } +OPXMIValueAttribute >> writeXMLOn: aWriter [ + aWriter tag: self xmiName with: self value +] diff --git a/repository/OP-XMI-GTExtensions/OPXMIValueElement.extension.st b/repository/OpenPonk-XMI-Inspection/OPXMIValueElement.extension.st similarity index 74% rename from repository/OP-XMI-GTExtensions/OPXMIValueElement.extension.st rename to repository/OpenPonk-XMI-Inspection/OPXMIValueElement.extension.st index cd41c23..6ed1dac 100644 --- a/repository/OP-XMI-GTExtensions/OPXMIValueElement.extension.st +++ b/repository/OpenPonk-XMI-Inspection/OPXMIValueElement.extension.st @@ -1,6 +1,6 @@ -Extension { #name : 'OPXMIValueElement' } - -{ #category : '*OP-XMI-GTExtensions' } -OPXMIValueElement >> writeXMLOn: aWriter [ - aWriter tag: self xmiName with: self value -] +Extension { #name : 'OPXMIValueElement' } + +{ #category : '*OpenPonk-XMI-Inspection' } +OPXMIValueElement >> writeXMLOn: aWriter [ + aWriter tag: self xmiName with: self value +] diff --git a/repository/OpenPonk-XMI-Inspection/package.st b/repository/OpenPonk-XMI-Inspection/package.st new file mode 100644 index 0000000..507a305 --- /dev/null +++ b/repository/OpenPonk-XMI-Inspection/package.st @@ -0,0 +1 @@ +Package { #name : 'OpenPonk-XMI-Inspection' } diff --git a/repository/OP-XMI/OPXMIAttribute.class.st b/repository/OpenPonk-XMI/OPXMIAttribute.class.st similarity index 84% rename from repository/OP-XMI/OPXMIAttribute.class.st rename to repository/OpenPonk-XMI/OPXMIAttribute.class.st index 2cdf1a2..ed8d467 100644 --- a/repository/OP-XMI/OPXMIAttribute.class.st +++ b/repository/OpenPonk-XMI/OPXMIAttribute.class.st @@ -1,30 +1,30 @@ -Class { - #name : 'OPXMIAttribute', - #superclass : 'OPXMIInfoItems', - #instVars : [ - 'xmiName' - ], - #category : 'OP-XMI-DOM', - #package : 'OP-XMI', - #tag : 'DOM' -} - -{ #category : 'testing' } -OPXMIAttribute class >> isAbstract [ - ^ self = OPXMIAttribute -] - -{ #category : 'testing' } -OPXMIAttribute >> isAttribute [ - ^ true -] - -{ #category : 'accessing' } -OPXMIAttribute >> xmiName [ - ^ xmiName -] - -{ #category : 'accessing' } -OPXMIAttribute >> xmiName: aString [ - xmiName := aString -] +Class { + #name : 'OPXMIAttribute', + #superclass : 'OPXMIInfoItems', + #instVars : [ + 'xmiName' + ], + #category : 'OpenPonk-XMI-DOM', + #package : 'OpenPonk-XMI', + #tag : 'DOM' +} + +{ #category : 'testing' } +OPXMIAttribute class >> isAbstract [ + ^ self = OPXMIAttribute +] + +{ #category : 'testing' } +OPXMIAttribute >> isAttribute [ + ^ true +] + +{ #category : 'accessing' } +OPXMIAttribute >> xmiName [ + ^ xmiName +] + +{ #category : 'accessing' } +OPXMIAttribute >> xmiName: aString [ + xmiName := aString +] diff --git a/repository/OP-XMI/OPXMIElement.class.st b/repository/OpenPonk-XMI/OPXMIElement.class.st similarity index 84% rename from repository/OP-XMI/OPXMIElement.class.st rename to repository/OpenPonk-XMI/OPXMIElement.class.st index 353e09e..c40a650 100644 --- a/repository/OP-XMI/OPXMIElement.class.st +++ b/repository/OpenPonk-XMI/OPXMIElement.class.st @@ -1,30 +1,30 @@ -Class { - #name : 'OPXMIElement', - #superclass : 'OPXMIInfoItems', - #instVars : [ - 'xmiName' - ], - #category : 'OP-XMI-DOM', - #package : 'OP-XMI', - #tag : 'DOM' -} - -{ #category : 'testing' } -OPXMIElement class >> isAbstract [ - ^ self = OPXMIElement -] - -{ #category : 'testing' } -OPXMIElement >> isElement [ - ^ true -] - -{ #category : 'accessing' } -OPXMIElement >> xmiName [ - ^ xmiName -] - -{ #category : 'accessing' } -OPXMIElement >> xmiName: aString [ - xmiName := aString -] +Class { + #name : 'OPXMIElement', + #superclass : 'OPXMIInfoItems', + #instVars : [ + 'xmiName' + ], + #category : 'OpenPonk-XMI-DOM', + #package : 'OpenPonk-XMI', + #tag : 'DOM' +} + +{ #category : 'testing' } +OPXMIElement class >> isAbstract [ + ^ self = OPXMIElement +] + +{ #category : 'testing' } +OPXMIElement >> isElement [ + ^ true +] + +{ #category : 'accessing' } +OPXMIElement >> xmiName [ + ^ xmiName +] + +{ #category : 'accessing' } +OPXMIElement >> xmiName: aString [ + xmiName := aString +] diff --git a/repository/OP-XMI/OPXMIInfoItems.class.st b/repository/OpenPonk-XMI/OPXMIInfoItems.class.st similarity index 89% rename from repository/OP-XMI/OPXMIInfoItems.class.st rename to repository/OpenPonk-XMI/OPXMIInfoItems.class.st index 3d53be5..bdc3d16 100644 --- a/repository/OP-XMI/OPXMIInfoItems.class.st +++ b/repository/OpenPonk-XMI/OPXMIInfoItems.class.st @@ -1,57 +1,57 @@ -Class { - #name : 'OPXMIInfoItems', - #superclass : 'Object', - #category : 'OP-XMI-DOM', - #package : 'OP-XMI', - #tag : 'DOM' -} - -{ #category : 'testing' } -OPXMIInfoItems class >> isAbstract [ - ^ self = OPXMIInfoItems -] - -{ #category : 'testing' } -OPXMIInfoItems >> isAttribute [ - ^ false -] - -{ #category : 'testing' } -OPXMIInfoItems >> isElement [ - ^ false -] - -{ #category : 'testing' } -OPXMIInfoItems >> isObjectElement [ - ^ false -] - -{ #category : 'testing' } -OPXMIInfoItems >> isReferenceAttribute [ - ^ false -] - -{ #category : 'testing' } -OPXMIInfoItems >> isReferenceElement [ - ^ false -] - -{ #category : 'testing' } -OPXMIInfoItems >> isReferenceItem [ - ^ self isReferenceAttribute | self isReferenceElement -] - -{ #category : 'testing' } -OPXMIInfoItems >> isValueAttribute [ - ^ false -] - -{ #category : 'testing' } -OPXMIInfoItems >> isValueElement [ - ^ false -] - -{ #category : 'testing' } -OPXMIInfoItems >> isValueItem [ - ^ self isValueAttribute | self isValueElement -] +Class { + #name : 'OPXMIInfoItems', + #superclass : 'Object', + #category : 'OpenPonk-XMI-DOM', + #package : 'OpenPonk-XMI', + #tag : 'DOM' +} + +{ #category : 'testing' } +OPXMIInfoItems class >> isAbstract [ + ^ self = OPXMIInfoItems +] + +{ #category : 'testing' } +OPXMIInfoItems >> isAttribute [ + ^ false +] + +{ #category : 'testing' } +OPXMIInfoItems >> isElement [ + ^ false +] + +{ #category : 'testing' } +OPXMIInfoItems >> isObjectElement [ + ^ false +] + +{ #category : 'testing' } +OPXMIInfoItems >> isReferenceAttribute [ + ^ false +] + +{ #category : 'testing' } +OPXMIInfoItems >> isReferenceElement [ + ^ false +] + +{ #category : 'testing' } +OPXMIInfoItems >> isReferenceItem [ + ^ self isReferenceAttribute | self isReferenceElement +] + +{ #category : 'testing' } +OPXMIInfoItems >> isValueAttribute [ + ^ false +] + +{ #category : 'testing' } +OPXMIInfoItems >> isValueElement [ + ^ false +] + +{ #category : 'testing' } +OPXMIInfoItems >> isValueItem [ + ^ self isValueAttribute | self isValueElement +] diff --git a/repository/OP-XMI/OPXMIObjectElement.class.st b/repository/OpenPonk-XMI/OPXMIObjectElement.class.st similarity index 93% rename from repository/OP-XMI/OPXMIObjectElement.class.st rename to repository/OpenPonk-XMI/OPXMIObjectElement.class.st index b9c889f..6b06fee 100644 --- a/repository/OP-XMI/OPXMIObjectElement.class.st +++ b/repository/OpenPonk-XMI/OPXMIObjectElement.class.st @@ -1,107 +1,107 @@ -" -XMIObjectElement is an XML element that can contain other information items (XML elements and attributes). -" -Class { - #name : 'OPXMIObjectElement', - #superclass : 'OPXMIElement', - #instVars : [ - 'containedItems' - ], - #category : 'OP-XMI-DOM', - #package : 'OP-XMI', - #tag : 'DOM' -} - -{ #category : 'visiting' } -OPXMIObjectElement >> accept: aVisitor [ - aVisitor visitObjectElement: self -] - -{ #category : 'accessing' } -OPXMIObjectElement >> containedItem [ - ^ containedItems ifEmpty: [ ^ nil ] ifNotEmpty: #first -] - -{ #category : 'accessing' } -OPXMIObjectElement >> containedItems [ - ^ containedItems -] - -{ #category : 'accessing' } -OPXMIObjectElement >> containedItems: aCollection [ - containedItems := aCollection -] - -{ #category : 'accessing' } -OPXMIObjectElement >> elementNamed: aName [ - "return the first element with the given name" - - ^ self containedItems - detect: [ :each | each xmiName = aName ] - ifFound: #yourself - ifNone: [ nil ] -] - -{ #category : 'searching' } -OPXMIObjectElement >> findElementWithXmiId: aXmiId [ - self xmiId = aXmiId - ifTrue: [ ^ self ]. - self containedItems - select: #isObjectElement - thenDo: [ :each | (each findElementWithXmiId: aXmiId) ifNotNil: [ :match | ^ match ] ]. - ^ nil -] - -{ #category : 'initialization' } -OPXMIObjectElement >> initialize [ - super initialize. - containedItems := OrderedCollection new -] - -{ #category : 'testing' } -OPXMIObjectElement >> isObjectElement [ - ^ true -] - -{ #category : 'accessing - shortcuts' } -OPXMIObjectElement >> nameValue [ - "Retrieve the value of child element. Throw up if none is present." - - ^ (self containedItems detect: [ :each | each xmiName = #name ]) value -] - -{ #category : 'printing' } -OPXMIObjectElement >> printOn: aStream [ - aStream - << 'XMIObjectElement('; - << xmiName. - self xmiId - ifNotNil: [ :id | - aStream - << ' xmi:id="'; - << id; - << '"' ]. - self xmiType - ifNotNil: [ :type | - aStream - << ' xmi:type="'; - << type; - << '"' ]. - aStream << ')' -] - -{ #category : 'accessing - shortcuts' } -OPXMIObjectElement >> xmiId [ - ^ self containedItems - detect: [ :each | each xmiName = #xmi:id ] - ifFound: [ :each | each value ] - ifNone: [ nil ] -] - -{ #category : 'accessing - shortcuts' } -OPXMIObjectElement >> xmiType [ - ^ self containedItems - detect: [ :each | each xmiName = #xmi:type ] - ifFound: [ :each | each value ] - ifNone: [ nil ] -] +" +XMIObjectElement is an XML element that can contain other information items (XML elements and attributes). +" +Class { + #name : 'OPXMIObjectElement', + #superclass : 'OPXMIElement', + #instVars : [ + 'containedItems' + ], + #category : 'OpenPonk-XMI-DOM', + #package : 'OpenPonk-XMI', + #tag : 'DOM' +} + +{ #category : 'visiting' } +OPXMIObjectElement >> accept: aVisitor [ + aVisitor visitObjectElement: self +] + +{ #category : 'accessing' } +OPXMIObjectElement >> containedItem [ + ^ containedItems ifEmpty: [ ^ nil ] ifNotEmpty: #first +] + +{ #category : 'accessing' } +OPXMIObjectElement >> containedItems [ + ^ containedItems +] + +{ #category : 'accessing' } +OPXMIObjectElement >> containedItems: aCollection [ + containedItems := aCollection +] + +{ #category : 'accessing' } +OPXMIObjectElement >> elementNamed: aName [ + "return the first element with the given name" + + ^ self containedItems + detect: [ :each | each xmiName = aName ] + ifFound: #yourself + ifNone: [ nil ] +] + +{ #category : 'searching' } +OPXMIObjectElement >> findElementWithXmiId: aXmiId [ + self xmiId = aXmiId + ifTrue: [ ^ self ]. + self containedItems + select: #isObjectElement + thenDo: [ :each | (each findElementWithXmiId: aXmiId) ifNotNil: [ :match | ^ match ] ]. + ^ nil +] + +{ #category : 'initialization' } +OPXMIObjectElement >> initialize [ + super initialize. + containedItems := OrderedCollection new +] + +{ #category : 'testing' } +OPXMIObjectElement >> isObjectElement [ + ^ true +] + +{ #category : 'accessing - shortcuts' } +OPXMIObjectElement >> nameValue [ + "Retrieve the value of child element. Throw up if none is present." + + ^ (self containedItems detect: [ :each | each xmiName = #name ]) value +] + +{ #category : 'printing' } +OPXMIObjectElement >> printOn: aStream [ + aStream + << 'XMIObjectElement('; + << xmiName. + self xmiId + ifNotNil: [ :id | + aStream + << ' xmi:id="'; + << id; + << '"' ]. + self xmiType + ifNotNil: [ :type | + aStream + << ' xmi:type="'; + << type; + << '"' ]. + aStream << ')' +] + +{ #category : 'accessing - shortcuts' } +OPXMIObjectElement >> xmiId [ + ^ self containedItems + detect: [ :each | each xmiName = #xmi:id ] + ifFound: [ :each | each value ] + ifNone: [ nil ] +] + +{ #category : 'accessing - shortcuts' } +OPXMIObjectElement >> xmiType [ + ^ self containedItems + detect: [ :each | each xmiName = #xmi:type ] + ifFound: [ :each | each value ] + ifNone: [ nil ] +] diff --git a/repository/OP-XMI/OPXMIObjectElementTest.class.st b/repository/OpenPonk-XMI/OPXMIObjectElementTest.class.st similarity index 94% rename from repository/OP-XMI/OPXMIObjectElementTest.class.st rename to repository/OpenPonk-XMI/OPXMIObjectElementTest.class.st index 0caeda4..9c04d02 100644 --- a/repository/OP-XMI/OPXMIObjectElementTest.class.st +++ b/repository/OpenPonk-XMI/OPXMIObjectElementTest.class.st @@ -1,120 +1,120 @@ -Class { - #name : 'OPXMIObjectElementTest', - #superclass : 'TestCase', - #category : 'OP-XMI-Tests', - #package : 'OP-XMI', - #tag : 'Tests' -} - -{ #category : 'instance creation' } -OPXMIObjectElementTest >> nestedObjects [ - ^ OPXMIObjectElement new - xmiName: 'aaa'; - containedItems: - {OPXMIValueAttribute new - xmiName: 'xmi:id'; - value: 'AAA'. - OPXMIObjectElement new - xmiName: 'bbb'; - containedItems: - {OPXMIValueAttribute new - xmiName: 'xmi:id'; - value: 'BBB'}. - OPXMIObjectElement new - xmiName: 'ccc'; - containedItems: - {OPXMIValueAttribute new - xmiName: 'xmi:id'; - value: 'CCC'. - OPXMIObjectElement new - xmiName: 'ddd'; - containedItems: - {OPXMIValueAttribute new - xmiName: 'xmi:id'; - value: 'DDD'}}} -] - -{ #category : 'tests' } -OPXMIObjectElementTest >> testElementNamed [ - | el | - (el := OPXMIObjectElement new) - xmiName: 'container'; - containedItems: {OPXMIObjectElement new xmiName: 'element'}. - self assert: (el elementNamed: 'element') xmiName equals: 'element'. - self assert: (el elementNamed: 'none') equals: nil -] - -{ #category : 'tests' } -OPXMIObjectElementTest >> testFindElementWithXmiId1 [ - | root result | - root := self nestedObjects. - result := root findElementWithXmiId: 'AAA'. - self assert: result equals: root -] - -{ #category : 'tests' } -OPXMIObjectElementTest >> testFindElementWithXmiId2 [ - | root result | - root := self nestedObjects. - result := root findElementWithXmiId: 'BBB'. - self assert: result xmiName equals: 'bbb' -] - -{ #category : 'tests' } -OPXMIObjectElementTest >> testFindElementWithXmiId3 [ - | root result | - root := self nestedObjects. - result := root findElementWithXmiId: 'CCC'. - self assert: result xmiName equals: 'ccc' -] - -{ #category : 'tests' } -OPXMIObjectElementTest >> testFindElementWithXmiId4 [ - | root result | - root := self nestedObjects. - result := root findElementWithXmiId: 'DDD'. - self assert: result xmiName equals: 'ddd' -] - -{ #category : 'tests' } -OPXMIObjectElementTest >> testFindElementWithXmiId5 [ - | root result | - root := self nestedObjects. - result := root findElementWithXmiId: 'EEE'. - self assert: result equals: nil -] - -{ #category : 'tests' } -OPXMIObjectElementTest >> testId [ - | element | - element := OPXMIObjectElement new. - self assert: element xmiId equals: nil. - element - containedItems: - {OPXMIValueAttribute new - xmiName: #xmi:id; - value: 'ID'}. - self assert: element xmiId equals: 'ID' -] - -{ #category : 'tests' } -OPXMIObjectElementTest >> testNameValue [ - | element | - element := OPXMIObjectElement new - containedItems: {OPXMIValueElement xmiName: 'name' value: 'hello'}. - self assert: element nameValue equals: 'hello'. - self should: [ OPXMIObjectElement new nameValue ] raise: NotFound -] - -{ #category : 'tests' } -OPXMIObjectElementTest >> testType [ - | element | - element := OPXMIObjectElement new. - self assert: element xmiType equals: nil. - element - containedItems: - {OPXMIValueAttribute new - xmiName: #xmi:type; - value: 'TYPE'}. - self assert: element xmiType equals: 'TYPE' -] +Class { + #name : 'OPXMIObjectElementTest', + #superclass : 'TestCase', + #category : 'OpenPonk-XMI-Tests', + #package : 'OpenPonk-XMI', + #tag : 'Tests' +} + +{ #category : 'instance creation' } +OPXMIObjectElementTest >> nestedObjects [ + ^ OPXMIObjectElement new + xmiName: 'aaa'; + containedItems: + {OPXMIValueAttribute new + xmiName: 'xmi:id'; + value: 'AAA'. + OPXMIObjectElement new + xmiName: 'bbb'; + containedItems: + {OPXMIValueAttribute new + xmiName: 'xmi:id'; + value: 'BBB'}. + OPXMIObjectElement new + xmiName: 'ccc'; + containedItems: + {OPXMIValueAttribute new + xmiName: 'xmi:id'; + value: 'CCC'. + OPXMIObjectElement new + xmiName: 'ddd'; + containedItems: + {OPXMIValueAttribute new + xmiName: 'xmi:id'; + value: 'DDD'}}} +] + +{ #category : 'tests' } +OPXMIObjectElementTest >> testElementNamed [ + | el | + (el := OPXMIObjectElement new) + xmiName: 'container'; + containedItems: {OPXMIObjectElement new xmiName: 'element'}. + self assert: (el elementNamed: 'element') xmiName equals: 'element'. + self assert: (el elementNamed: 'none') equals: nil +] + +{ #category : 'tests' } +OPXMIObjectElementTest >> testFindElementWithXmiId1 [ + | root result | + root := self nestedObjects. + result := root findElementWithXmiId: 'AAA'. + self assert: result equals: root +] + +{ #category : 'tests' } +OPXMIObjectElementTest >> testFindElementWithXmiId2 [ + | root result | + root := self nestedObjects. + result := root findElementWithXmiId: 'BBB'. + self assert: result xmiName equals: 'bbb' +] + +{ #category : 'tests' } +OPXMIObjectElementTest >> testFindElementWithXmiId3 [ + | root result | + root := self nestedObjects. + result := root findElementWithXmiId: 'CCC'. + self assert: result xmiName equals: 'ccc' +] + +{ #category : 'tests' } +OPXMIObjectElementTest >> testFindElementWithXmiId4 [ + | root result | + root := self nestedObjects. + result := root findElementWithXmiId: 'DDD'. + self assert: result xmiName equals: 'ddd' +] + +{ #category : 'tests' } +OPXMIObjectElementTest >> testFindElementWithXmiId5 [ + | root result | + root := self nestedObjects. + result := root findElementWithXmiId: 'EEE'. + self assert: result equals: nil +] + +{ #category : 'tests' } +OPXMIObjectElementTest >> testId [ + | element | + element := OPXMIObjectElement new. + self assert: element xmiId equals: nil. + element + containedItems: + {OPXMIValueAttribute new + xmiName: #xmi:id; + value: 'ID'}. + self assert: element xmiId equals: 'ID' +] + +{ #category : 'tests' } +OPXMIObjectElementTest >> testNameValue [ + | element | + element := OPXMIObjectElement new + containedItems: {OPXMIValueElement xmiName: 'name' value: 'hello'}. + self assert: element nameValue equals: 'hello'. + self should: [ OPXMIObjectElement new nameValue ] raise: NotFound +] + +{ #category : 'tests' } +OPXMIObjectElementTest >> testType [ + | element | + element := OPXMIObjectElement new. + self assert: element xmiType equals: nil. + element + containedItems: + {OPXMIValueAttribute new + xmiName: #xmi:type; + value: 'TYPE'}. + self assert: element xmiType equals: 'TYPE' +] diff --git a/repository/OP-XMI/OPXMIReader.class.st b/repository/OpenPonk-XMI/OPXMIReader.class.st similarity index 94% rename from repository/OP-XMI/OPXMIReader.class.st rename to repository/OpenPonk-XMI/OPXMIReader.class.st index 9846952..c3fd4bd 100644 --- a/repository/OP-XMI/OPXMIReader.class.st +++ b/repository/OpenPonk-XMI/OPXMIReader.class.st @@ -1,73 +1,73 @@ -Class { - #name : 'OPXMIReader', - #superclass : 'Object', - #instVars : [ - 'document' - ], - #category : 'OP-XMI-Reader', - #package : 'OP-XMI', - #tag : 'Reader' -} - -{ #category : 'instance creation' } -OPXMIReader class >> read: aStream mapping: aMapping [ - aMapping at: 'result' put: aStream contents. - ^ (self readFromMapping: aMapping) at: 'result' -] - -{ #category : 'instance creation' } -OPXMIReader class >> readFrom: aStream [ - ^ self new readFrom: aStream -] - -{ #category : 'instance creation' } -OPXMIReader class >> readFromMapping: aMapping [ - "aMapping is a Dictionary of HREF URI -> XMI contents" - - ^ self new readFromMapping: aMapping -] - -{ #category : 'instance creation' } -OPXMIReader >> readFrom: aStream [ - | dom root | - dom := XMLDOMParser parse: aStream usingNamespaces: false. - root := OPXMIReaderVisitor new visitDocument: dom. - ^ root -] - -{ #category : 'instance creation' } -OPXMIReader >> readFromMapping: aMapping [ - | graphs | - graphs := OrderedDictionary new. - aMapping keysAndValuesDo: [ :key :value | graphs at: key put: (self readFrom: value) ]. - graphs valuesDo: [ :root | self resolveHrefsIn: root with: graphs ]. - ^ graphs -] - -{ #category : 'instance creation' } -OPXMIReader >> resolveHrefIn: aReferenceItem with: aMapping [ - | parts ref | - aReferenceItem href ifNil: [ ^ self ]. - parts := aReferenceItem href splitOn: '#'. - self flag: 'hack to circumvent package imports which are not properly resolved yet'. - aMapping - at: parts first - ifPresent: [ :root | ref := root findElementWithXmiId: parts second ]. - (ref isNil - and: - [ aReferenceItem isReferenceElement and: [ aReferenceItem xmiType = 'uml:PrimitiveType' ] ]) - ifTrue: [ aMapping values - detect: [ :root | (root findElementWithXmiId: parts second) isNotNil ] - ifFound: [ :root | ref := root findElementWithXmiId: parts second ] ]. - " ref ifNil: [ self error: 'Unable to resolve a reference.' ]." - ref ifNotNil: [ aReferenceItem referencedElements: {ref} ] -] - -{ #category : 'instance creation' } -OPXMIReader >> resolveHrefsIn: anElement with: aMapping [ - anElement isReferenceElement - ifTrue: [ ^ self resolveHrefIn: anElement with: aMapping ]. - anElement isObjectElement - ifFalse: [ ^ self ]. - anElement containedItems do: [ :each | self resolveHrefsIn: each with: aMapping ] -] +Class { + #name : 'OPXMIReader', + #superclass : 'Object', + #instVars : [ + 'document' + ], + #category : 'OpenPonk-XMI-Reader', + #package : 'OpenPonk-XMI', + #tag : 'Reader' +} + +{ #category : 'instance creation' } +OPXMIReader class >> read: aStream mapping: aMapping [ + aMapping at: 'result' put: aStream contents. + ^ (self readFromMapping: aMapping) at: 'result' +] + +{ #category : 'instance creation' } +OPXMIReader class >> readFrom: aStream [ + ^ self new readFrom: aStream +] + +{ #category : 'instance creation' } +OPXMIReader class >> readFromMapping: aMapping [ + "aMapping is a Dictionary of HREF URI -> XMI contents" + + ^ self new readFromMapping: aMapping +] + +{ #category : 'instance creation' } +OPXMIReader >> readFrom: aStream [ + | dom root | + dom := XMLDOMParser parse: aStream usingNamespaces: false. + root := OPXMIReaderVisitor new visitDocument: dom. + ^ root +] + +{ #category : 'instance creation' } +OPXMIReader >> readFromMapping: aMapping [ + | graphs | + graphs := OrderedDictionary new. + aMapping keysAndValuesDo: [ :key :value | graphs at: key put: (self readFrom: value) ]. + graphs valuesDo: [ :root | self resolveHrefsIn: root with: graphs ]. + ^ graphs +] + +{ #category : 'instance creation' } +OPXMIReader >> resolveHrefIn: aReferenceItem with: aMapping [ + | parts ref | + aReferenceItem href ifNil: [ ^ self ]. + parts := aReferenceItem href splitOn: '#'. + self flag: 'hack to circumvent package imports which are not properly resolved yet'. + aMapping + at: parts first + ifPresent: [ :root | ref := root findElementWithXmiId: parts second ]. + (ref isNil + and: + [ aReferenceItem isReferenceElement and: [ aReferenceItem xmiType = 'uml:PrimitiveType' ] ]) + ifTrue: [ aMapping values + detect: [ :root | (root findElementWithXmiId: parts second) isNotNil ] + ifFound: [ :root | ref := root findElementWithXmiId: parts second ] ]. + " ref ifNil: [ self error: 'Unable to resolve a reference.' ]." + ref ifNotNil: [ aReferenceItem referencedElements: {ref} ] +] + +{ #category : 'instance creation' } +OPXMIReader >> resolveHrefsIn: anElement with: aMapping [ + anElement isReferenceElement + ifTrue: [ ^ self resolveHrefIn: anElement with: aMapping ]. + anElement isObjectElement + ifFalse: [ ^ self ]. + anElement containedItems do: [ :each | self resolveHrefsIn: each with: aMapping ] +] diff --git a/repository/OP-XMI/OPXMIReaderTest.class.st b/repository/OpenPonk-XMI/OPXMIReaderTest.class.st similarity index 94% rename from repository/OP-XMI/OPXMIReaderTest.class.st rename to repository/OpenPonk-XMI/OPXMIReaderTest.class.st index 2780c3f..a83e3c1 100644 --- a/repository/OP-XMI/OPXMIReaderTest.class.st +++ b/repository/OpenPonk-XMI/OPXMIReaderTest.class.st @@ -1,95 +1,95 @@ -Class { - #name : 'OPXMIReaderTest', - #superclass : 'TestCase', - #category : 'OP-XMI-Tests', - #package : 'OP-XMI', - #tag : 'Tests' -} - -{ #category : 'instance creation' } -OPXMIReaderTest >> fileAAContents [ - ^ ' - - - -' -] - -{ #category : 'instance creation' } -OPXMIReaderTest >> fileBBContents [ - ^ ' - - - -' -] - -{ #category : 'instance creation' } -OPXMIReaderTest >> fileCCContents [ - ^ ' - -' -] - -{ #category : 'tests' } -OPXMIReaderTest >> testReadFromMapping [ - | mapping result aaItem bbItem ccItem | - "ordered to have both forward (B->C) and backward (B<-A) lookup" - mapping := OrderedDictionary - with: 'BB.xmi' -> self fileBBContents - with: 'AA.xmi' -> self fileAAContents - with: 'CC.xmi' -> self fileCCContents. - result := OPXMIReader readFromMapping: mapping. - aaItem := (result at: 'AA.xmi') containedItems first. - bbItem := (result at: 'BB.xmi') containedItems first. - ccItem := (result at: 'CC.xmi') containedItems first. - self assert: aaItem containedItems second referencedElement equals: bbItem. - self assert: bbItem containedItems second referencedElement equals: ccItem -] - -{ #category : 'tests' } -OPXMIReaderTest >> testReadFromTypedMapping [ - | mapping result uml type | - mapping := OrderedDictionary - with: 'UML.xmi' -> self umlTypedElementContents - with: 'PrimitiveTypes.xmi' -> self umlTypesContents. - result := OPXMIReader readFromMapping: mapping. - uml := (result at: 'UML.xmi') containedItems first. - type := (result at: 'PrimitiveTypes.xmi') containedItems first. - self assert: uml containedItems first referencedElement equals: type -] - -{ #category : 'tests' } -OPXMIReaderTest >> testResolveHref [ - | reference map someFileXmi | - reference := OPXMIReferenceElement new - xmiName: 'reference'; - href: 'someFile.xmi#AAA'. - someFileXmi := OPXMIObjectElement new - xmiName: 'container'; - containedItems: - {OPXMIObjectElement new - xmiName: 'item'; - containedItems: - {OPXMIValueAttribute new - xmiName: 'xmi:id'; - value: 'AAA'}}. - map := Dictionary with: 'someFile.xmi' -> someFileXmi. - OPXMIReader new resolveHrefIn: reference with: map. - self assert: reference referencedElements size equals: 1. - self assert: reference referencedElement equals: someFileXmi containedItem -] - -{ #category : 'instance creation' } -OPXMIReaderTest >> umlTypedElementContents [ - ^ ' - -' -] - -{ #category : 'instance creation' } -OPXMIReaderTest >> umlTypesContents [ - ^ ' - -' -] +Class { + #name : 'OPXMIReaderTest', + #superclass : 'TestCase', + #category : 'OpenPonk-XMI-Tests', + #package : 'OpenPonk-XMI', + #tag : 'Tests' +} + +{ #category : 'instance creation' } +OPXMIReaderTest >> fileAAContents [ + ^ ' + + + +' +] + +{ #category : 'instance creation' } +OPXMIReaderTest >> fileBBContents [ + ^ ' + + + +' +] + +{ #category : 'instance creation' } +OPXMIReaderTest >> fileCCContents [ + ^ ' + +' +] + +{ #category : 'tests' } +OPXMIReaderTest >> testReadFromMapping [ + | mapping result aaItem bbItem ccItem | + "ordered to have both forward (B->C) and backward (B<-A) lookup" + mapping := OrderedDictionary + with: 'BB.xmi' -> self fileBBContents + with: 'AA.xmi' -> self fileAAContents + with: 'CC.xmi' -> self fileCCContents. + result := OPXMIReader readFromMapping: mapping. + aaItem := (result at: 'AA.xmi') containedItems first. + bbItem := (result at: 'BB.xmi') containedItems first. + ccItem := (result at: 'CC.xmi') containedItems first. + self assert: aaItem containedItems second referencedElement equals: bbItem. + self assert: bbItem containedItems second referencedElement equals: ccItem +] + +{ #category : 'tests' } +OPXMIReaderTest >> testReadFromTypedMapping [ + | mapping result uml type | + mapping := OrderedDictionary + with: 'UML.xmi' -> self umlTypedElementContents + with: 'PrimitiveTypes.xmi' -> self umlTypesContents. + result := OPXMIReader readFromMapping: mapping. + uml := (result at: 'UML.xmi') containedItems first. + type := (result at: 'PrimitiveTypes.xmi') containedItems first. + self assert: uml containedItems first referencedElement equals: type +] + +{ #category : 'tests' } +OPXMIReaderTest >> testResolveHref [ + | reference map someFileXmi | + reference := OPXMIReferenceElement new + xmiName: 'reference'; + href: 'someFile.xmi#AAA'. + someFileXmi := OPXMIObjectElement new + xmiName: 'container'; + containedItems: + {OPXMIObjectElement new + xmiName: 'item'; + containedItems: + {OPXMIValueAttribute new + xmiName: 'xmi:id'; + value: 'AAA'}}. + map := Dictionary with: 'someFile.xmi' -> someFileXmi. + OPXMIReader new resolveHrefIn: reference with: map. + self assert: reference referencedElements size equals: 1. + self assert: reference referencedElement equals: someFileXmi containedItem +] + +{ #category : 'instance creation' } +OPXMIReaderTest >> umlTypedElementContents [ + ^ ' + +' +] + +{ #category : 'instance creation' } +OPXMIReaderTest >> umlTypesContents [ + ^ ' + +' +] diff --git a/repository/OP-XMI/OPXMIReaderVisitor.class.st b/repository/OpenPonk-XMI/OPXMIReaderVisitor.class.st similarity index 95% rename from repository/OP-XMI/OPXMIReaderVisitor.class.st rename to repository/OpenPonk-XMI/OPXMIReaderVisitor.class.st index e587cf1..05f8945 100644 --- a/repository/OP-XMI/OPXMIReaderVisitor.class.st +++ b/repository/OpenPonk-XMI/OPXMIReaderVisitor.class.st @@ -1,152 +1,152 @@ -Class { - #name : 'OPXMIReaderVisitor', - #superclass : 'XMLDOMVisitor', - #instVars : [ - 'document', - 'root', - 'mapping', - 'unresolved', - 'refIdMapping' - ], - #category : 'OP-XMI-Reader', - #package : 'OP-XMI', - #tag : 'Reader' -} - -{ #category : 'factory' } -OPXMIReaderVisitor >> attributeFor: aXMLAttribute [ - (self isReferenceAttribute: aXMLAttribute) - ifTrue: [ ^ self referenceAttributeFor: aXMLAttribute ]. - ^ self valueAttributeFor: aXMLAttribute -] - -{ #category : 'accessing' } -OPXMIReaderVisitor >> elementAt: aXMLElement [ - ^ mapping at: aXMLElement -] - -{ #category : 'factory' } -OPXMIReaderVisitor >> elementFor: aXMLElement [ - (self isValueElement: aXMLElement) - ifTrue: [ ^ self valueElementFor: aXMLElement ]. - (self isReferenceElement: aXMLElement) - ifTrue: [ ^ self referenceElementFor: aXMLElement ]. - ^ self objectElementFor: aXMLElement -] - -{ #category : 'initialization' } -OPXMIReaderVisitor >> initialize [ - super initialize. - mapping := Dictionary new. - refIdMapping := Dictionary new. - unresolved := OrderedCollection new -] - -{ #category : 'factory' } -OPXMIReaderVisitor >> isReferenceAttribute: aXMLAttribute [ - (aXMLAttribute parent isNotNil - and: [ aXMLAttribute value = (self elementAt: aXMLAttribute parent) xmiId ]) - ifTrue: [ ^ false ]. - aXMLAttribute prefix = 'xmi' - ifTrue: [ ^ false ]. - ^ (aXMLAttribute value splitOn: ' ') - allSatisfy: [ :each | refIdMapping includesKey: each ] -] - -{ #category : 'testing' } -OPXMIReaderVisitor >> isReferenceElement: aXMLElement [ - | names | - aXMLElement hasAttributes not | aXMLElement hasElements - ifTrue: [ ^ false ]. - names := aXMLElement attributeNodes collect: #name. - ^ names allSatisfy: [ :each | #('xmi:idref' 'href' 'xmi:type') includes: each ] -] - -{ #category : 'testing' } -OPXMIReaderVisitor >> isValueElement: aXMLElement [ - aXMLElement hasAttributes - ifTrue: [ ^ false ]. - aXMLElement nodes size = 0 - ifTrue: [ ^ true ]. - ^ aXMLElement nodes size = 1 and: [ aXMLElement nodes first isStringNode ] -] - -{ #category : 'factory' } -OPXMIReaderVisitor >> objectElementFor: aXMLElement [ - | element | - element := OPXMIObjectElement new - xmiName: aXMLElement localName; - yourself. - element - containedItems: - (aXMLElement attributeNodes collect: [ :attr | self valueAttributeFor: attr ]) - asOrderedCollection. - unresolved - add: [ element - containedItems: - (aXMLElement attributeNodes collect: [ :attr | self attributeFor: attr ]) - asOrderedCollection, (element containedItems select: #isElement) ]. - ^ element -] - -{ #category : 'factory' } -OPXMIReaderVisitor >> referenceAttributeFor: aXMLAttribute [ - ^ OPXMIReferenceAttribute new - xmiName: aXMLAttribute name; - referencedElements: ((aXMLAttribute value splitOn: ' ') collect: [ :each | refIdMapping at: each ]); - yourself -] - -{ #category : 'factory' } -OPXMIReaderVisitor >> referenceElementFor: aXMLElement [ - | el attribute | - (el := OPXMIReferenceElement new) xmiName: aXMLElement localName. - attribute := aXMLElement attributeNodes - detect: [ :each | each name = 'href' | (each name = 'xmi:idref') ]. - attribute name = 'href' - ifTrue: [ el href: attribute value ] - ifFalse: [ unresolved add: [ el referencedElements: {refIdMapping at: attribute value} ] ]. - aXMLElement attributeNodes - detect: [ :each | each name = 'xmi:type' ] - ifFound: [ :typeAttrib | el xmiType: typeAttrib value ]. - ^ el -] - -{ #category : 'actions' } -OPXMIReaderVisitor >> resolveAll [ - unresolved do: #value -] - -{ #category : 'factory' } -OPXMIReaderVisitor >> valueAttributeFor: aXMLAttribute [ - ^ OPXMIValueAttribute new - xmiName: aXMLAttribute name; - value: aXMLAttribute value; - yourself -] - -{ #category : 'factory' } -OPXMIReaderVisitor >> valueElementFor: aXMLElement [ - ^ OPXMIValueElement new - xmiName: aXMLElement localName; - value: (aXMLElement stringNodes ifEmpty: [ '' ] ifNotEmpty: [ :nodes | nodes first string ]); - yourself -] - -{ #category : 'visiting' } -OPXMIReaderVisitor >> visitDocument: aDocument [ - self visit: aDocument root. - self resolveAll. - ^ self elementAt: aDocument root -] - -{ #category : 'visiting' } -OPXMIReaderVisitor >> visitElement: aXMLElement [ - | element | - element := self elementFor: aXMLElement. - mapping at: aXMLElement put: element. - mapping at: aXMLElement parent ifPresent: [ :parent | parent containedItems add: element ]. - element isObjectElement - ifTrue: [ refIdMapping at: element xmiId put: element ]. - super visitElement: aXMLElement -] +Class { + #name : 'OPXMIReaderVisitor', + #superclass : 'XMLDOMVisitor', + #instVars : [ + 'document', + 'root', + 'mapping', + 'unresolved', + 'refIdMapping' + ], + #category : 'OpenPonk-XMI-Reader', + #package : 'OpenPonk-XMI', + #tag : 'Reader' +} + +{ #category : 'factory' } +OPXMIReaderVisitor >> attributeFor: aXMLAttribute [ + (self isReferenceAttribute: aXMLAttribute) + ifTrue: [ ^ self referenceAttributeFor: aXMLAttribute ]. + ^ self valueAttributeFor: aXMLAttribute +] + +{ #category : 'accessing' } +OPXMIReaderVisitor >> elementAt: aXMLElement [ + ^ mapping at: aXMLElement +] + +{ #category : 'factory' } +OPXMIReaderVisitor >> elementFor: aXMLElement [ + (self isValueElement: aXMLElement) + ifTrue: [ ^ self valueElementFor: aXMLElement ]. + (self isReferenceElement: aXMLElement) + ifTrue: [ ^ self referenceElementFor: aXMLElement ]. + ^ self objectElementFor: aXMLElement +] + +{ #category : 'initialization' } +OPXMIReaderVisitor >> initialize [ + super initialize. + mapping := Dictionary new. + refIdMapping := Dictionary new. + unresolved := OrderedCollection new +] + +{ #category : 'factory' } +OPXMIReaderVisitor >> isReferenceAttribute: aXMLAttribute [ + (aXMLAttribute parent isNotNil + and: [ aXMLAttribute value = (self elementAt: aXMLAttribute parent) xmiId ]) + ifTrue: [ ^ false ]. + aXMLAttribute prefix = 'xmi' + ifTrue: [ ^ false ]. + ^ (aXMLAttribute value splitOn: ' ') + allSatisfy: [ :each | refIdMapping includesKey: each ] +] + +{ #category : 'testing' } +OPXMIReaderVisitor >> isReferenceElement: aXMLElement [ + | names | + aXMLElement hasAttributes not | aXMLElement hasElements + ifTrue: [ ^ false ]. + names := aXMLElement attributeNodes collect: #name. + ^ names allSatisfy: [ :each | #('xmi:idref' 'href' 'xmi:type') includes: each ] +] + +{ #category : 'testing' } +OPXMIReaderVisitor >> isValueElement: aXMLElement [ + aXMLElement hasAttributes + ifTrue: [ ^ false ]. + aXMLElement nodes size = 0 + ifTrue: [ ^ true ]. + ^ aXMLElement nodes size = 1 and: [ aXMLElement nodes first isStringNode ] +] + +{ #category : 'factory' } +OPXMIReaderVisitor >> objectElementFor: aXMLElement [ + | element | + element := OPXMIObjectElement new + xmiName: aXMLElement localName; + yourself. + element + containedItems: + (aXMLElement attributeNodes collect: [ :attr | self valueAttributeFor: attr ]) + asOrderedCollection. + unresolved + add: [ element + containedItems: + (aXMLElement attributeNodes collect: [ :attr | self attributeFor: attr ]) + asOrderedCollection, (element containedItems select: #isElement) ]. + ^ element +] + +{ #category : 'factory' } +OPXMIReaderVisitor >> referenceAttributeFor: aXMLAttribute [ + ^ OPXMIReferenceAttribute new + xmiName: aXMLAttribute name; + referencedElements: ((aXMLAttribute value splitOn: ' ') collect: [ :each | refIdMapping at: each ]); + yourself +] + +{ #category : 'factory' } +OPXMIReaderVisitor >> referenceElementFor: aXMLElement [ + | el attribute | + (el := OPXMIReferenceElement new) xmiName: aXMLElement localName. + attribute := aXMLElement attributeNodes + detect: [ :each | each name = 'href' | (each name = 'xmi:idref') ]. + attribute name = 'href' + ifTrue: [ el href: attribute value ] + ifFalse: [ unresolved add: [ el referencedElements: {refIdMapping at: attribute value} ] ]. + aXMLElement attributeNodes + detect: [ :each | each name = 'xmi:type' ] + ifFound: [ :typeAttrib | el xmiType: typeAttrib value ]. + ^ el +] + +{ #category : 'actions' } +OPXMIReaderVisitor >> resolveAll [ + unresolved do: #value +] + +{ #category : 'factory' } +OPXMIReaderVisitor >> valueAttributeFor: aXMLAttribute [ + ^ OPXMIValueAttribute new + xmiName: aXMLAttribute name; + value: aXMLAttribute value; + yourself +] + +{ #category : 'factory' } +OPXMIReaderVisitor >> valueElementFor: aXMLElement [ + ^ OPXMIValueElement new + xmiName: aXMLElement localName; + value: (aXMLElement stringNodes ifEmpty: [ '' ] ifNotEmpty: [ :nodes | nodes first string ]); + yourself +] + +{ #category : 'visiting' } +OPXMIReaderVisitor >> visitDocument: aDocument [ + self visit: aDocument root. + self resolveAll. + ^ self elementAt: aDocument root +] + +{ #category : 'visiting' } +OPXMIReaderVisitor >> visitElement: aXMLElement [ + | element | + element := self elementFor: aXMLElement. + mapping at: aXMLElement put: element. + mapping at: aXMLElement parent ifPresent: [ :parent | parent containedItems add: element ]. + element isObjectElement + ifTrue: [ refIdMapping at: element xmiId put: element ]. + super visitElement: aXMLElement +] diff --git a/repository/OP-XMI/OPXMIReaderVisitorExtraRulesTest.class.st b/repository/OpenPonk-XMI/OPXMIReaderVisitorExtraRulesTest.class.st similarity index 93% rename from repository/OP-XMI/OPXMIReaderVisitorExtraRulesTest.class.st rename to repository/OpenPonk-XMI/OPXMIReaderVisitorExtraRulesTest.class.st index f725e22..6c46e6c 100644 --- a/repository/OP-XMI/OPXMIReaderVisitorExtraRulesTest.class.st +++ b/repository/OpenPonk-XMI/OPXMIReaderVisitorExtraRulesTest.class.st @@ -1,65 +1,65 @@ -Class { - #name : 'OPXMIReaderVisitorExtraRulesTest', - #superclass : 'TestCase', - #instVars : [ - 'visitor', - 'result' - ], - #category : 'OP-XMI-Tests', - #package : 'OP-XMI', - #tag : 'Tests' -} - -{ #category : 'instance creation' } -OPXMIReaderVisitorExtraRulesTest >> elementNamed: aName [ - ^ XMLElement named: aName -] - -{ #category : 'instance creation' } -OPXMIReaderVisitorExtraRulesTest >> elementNamed: aName attributes: aCollection [ - ^ (XMLElement named: aName) - usesNamespaces: false; - setAttributes: aCollection; - yourself -] - -{ #category : 'running' } -OPXMIReaderVisitorExtraRulesTest >> setUp [ - super setUp. - visitor := OPXMIReaderVisitor new -] - -{ #category : 'tests' } -OPXMIReaderVisitorExtraRulesTest >> testNoSelfReference [ - " -the name attribute should be ValueAttribute because it refers to itself" - - | element | - element := self - elementNamed: 'packagedElement' - attributes: - {#xmi:type -> 'uml:Package'. - #xmi:id -> 'Classification'. - #name -> 'Classification'}. - visitor visitElement: element. - result := visitor elementAt: element. - self assert: result containedItems last isValueAttribute. - visitor resolveAll. - self assert: result containedItems last isValueAttribute -] - -{ #category : 'tests' } -OPXMIReaderVisitorExtraRulesTest >> testNoSelfReferenceIsReferenceAttributeNot [ - "goes with testNoSelfReference" - - | element | - element := self - elementNamed: 'whatever' - attributes: - {#xmi:id -> 'NAME'. - #name -> 'NAME'}. - self deny: (visitor isReferenceAttribute: (XMLAttribute name: 'name' value: 'NAME')). - visitor visitElement: element. - self assert: (visitor isReferenceAttribute: (XMLAttribute name: 'name' value: 'NAME')). - self deny: (visitor isReferenceAttribute: (element attributeNodeAt: 'name')) -] +Class { + #name : 'OPXMIReaderVisitorExtraRulesTest', + #superclass : 'TestCase', + #instVars : [ + 'visitor', + 'result' + ], + #category : 'OpenPonk-XMI-Tests', + #package : 'OpenPonk-XMI', + #tag : 'Tests' +} + +{ #category : 'instance creation' } +OPXMIReaderVisitorExtraRulesTest >> elementNamed: aName [ + ^ XMLElement named: aName +] + +{ #category : 'instance creation' } +OPXMIReaderVisitorExtraRulesTest >> elementNamed: aName attributes: aCollection [ + ^ (XMLElement named: aName) + usesNamespaces: false; + setAttributes: aCollection; + yourself +] + +{ #category : 'running' } +OPXMIReaderVisitorExtraRulesTest >> setUp [ + super setUp. + visitor := OPXMIReaderVisitor new +] + +{ #category : 'tests' } +OPXMIReaderVisitorExtraRulesTest >> testNoSelfReference [ + " +the name attribute should be ValueAttribute because it refers to itself" + + | element | + element := self + elementNamed: 'packagedElement' + attributes: + {#xmi:type -> 'uml:Package'. + #xmi:id -> 'Classification'. + #name -> 'Classification'}. + visitor visitElement: element. + result := visitor elementAt: element. + self assert: result containedItems last isValueAttribute. + visitor resolveAll. + self assert: result containedItems last isValueAttribute +] + +{ #category : 'tests' } +OPXMIReaderVisitorExtraRulesTest >> testNoSelfReferenceIsReferenceAttributeNot [ + "goes with testNoSelfReference" + + | element | + element := self + elementNamed: 'whatever' + attributes: + {#xmi:id -> 'NAME'. + #name -> 'NAME'}. + self deny: (visitor isReferenceAttribute: (XMLAttribute name: 'name' value: 'NAME')). + visitor visitElement: element. + self assert: (visitor isReferenceAttribute: (XMLAttribute name: 'name' value: 'NAME')). + self deny: (visitor isReferenceAttribute: (element attributeNodeAt: 'name')) +] diff --git a/repository/OP-XMI/OPXMIReaderVisitorTest.class.st b/repository/OpenPonk-XMI/OPXMIReaderVisitorTest.class.st similarity index 96% rename from repository/OP-XMI/OPXMIReaderVisitorTest.class.st rename to repository/OpenPonk-XMI/OPXMIReaderVisitorTest.class.st index a428927..fe773ef 100644 --- a/repository/OP-XMI/OPXMIReaderVisitorTest.class.st +++ b/repository/OpenPonk-XMI/OPXMIReaderVisitorTest.class.st @@ -1,245 +1,245 @@ -Class { - #name : 'OPXMIReaderVisitorTest', - #superclass : 'TestCase', - #instVars : [ - 'visitor', - 'result' - ], - #category : 'OP-XMI-Tests', - #package : 'OP-XMI', - #tag : 'Tests' -} - -{ #category : 'instance creation' } -OPXMIReaderVisitorTest >> elementNamed: aName [ - ^ XMLElement named: aName -] - -{ #category : 'instance creation' } -OPXMIReaderVisitorTest >> elementNamed: aName attributes: aCollection [ - ^ (XMLElement named: aName) - usesNamespaces: false; - setAttributes: aCollection; - yourself -] - -{ #category : 'running' } -OPXMIReaderVisitorTest >> setUp [ - super setUp. - visitor := OPXMIReaderVisitor new -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testIsReferenceAttribute [ - self deny: (visitor isReferenceAttribute: (XMLAttribute name: 'name' value: 'ID')). - visitor visitElement: (self elementNamed: 'whatever' attributes: {#xmi:id -> 'ID'}). - self assert: (visitor isReferenceAttribute: (XMLAttribute name: 'name' value: 'ID')) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testIsReferenceAttributeMulti [ - self - deny: (visitor isReferenceAttribute: (XMLAttribute name: 'name' value: 'ID1 ID2')). - visitor visitElement: (self elementNamed: 'whatever' attributes: {#xmi:id -> 'ID1'}). - visitor visitElement: (self elementNamed: 'whatever' attributes: {#xmi:id -> 'ID2'}). - self - assert: (visitor isReferenceAttribute: (XMLAttribute name: 'name' value: 'ID1 ID2')) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testIsReferenceAttributeNotXmi [ - self deny: (visitor isReferenceAttribute: (XMLAttribute name: 'xmi:idref' value: 'value')). - self deny: (visitor isReferenceAttribute: (XMLAttribute name: 'xmi:id' value: 'value')) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testIsReferenceElementHref [ - self - assert: (visitor isReferenceElement: (self elementNamed: 'el' attributes: {#href -> #content})) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testIsReferenceElementHref2 [ - self - assert: - (visitor - isReferenceElement: - (self - elementNamed: 'el' - attributes: - {#xmi:type -> 'type'. - #href -> #content})) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testIsReferenceElementIdRef [ - self - assert: (visitor isReferenceElement: (self elementNamed: 'el' attributes: {#xmi:idref -> #value})) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testIsReferenceElementNot [ - self - deny: (visitor isReferenceElement: (self elementNamed: 'el' attributes: {#other -> #sth})) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testIsValueElement [ - self - assert: - (visitor - isValueElement: - (XMLElement new - name: 'el'; - addString: 'content'; - yourself)) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testIsValueElementNot [ - self deny: (visitor isValueElement: (XMLElement name: 'el' attributes: {#key -> #value})) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testIsValueElementNot2 [ - self - deny: - (visitor - isValueElement: - ((XMLElement name: 'el') - addNode: (XMLElement name: 'child'); - yourself)) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testObjectElement [ - result := visitor objectElementFor: (self elementNamed: 'el'). - self assert: result isObjectElement. - self assert: result xmiName equals: 'el' -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testObjectElementWithAttributes [ - result := visitor - objectElementFor: (self elementNamed: 'el' attributes: {#name -> #value}). - self assert: result xmiName equals: 'el'. - self assert: result containedItems size equals: 1. - self assert: result containedItems first isValueAttribute. - self assert: result containedItems first xmiName equals: 'name'. - self assert: result containedItems first value equals: 'value' -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testReferenceAttribute [ - | target reference attribute | - target := self elementNamed: 'Target' attributes: {#xmi:id -> #target}. - reference := self elementNamed: 'Reference' attributes: {#object -> #target}. - visitor visitElement: reference. - visitor visitElement: target. - visitor resolveAll. - result := visitor elementAt: reference. - self assert: result containedItems size equals: 1. - attribute := result containedItem. - self assert: attribute isReferenceAttribute. - self assert: attribute referencedElements size equals: 1. - self assert: attribute referencedElement equals: (visitor elementAt: target) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testReferenceAttributeMulti [ - | target1 target2 reference attribute | - target1 := self elementNamed: 'Target' attributes: {#xmi:id -> #target1}. - target2 := self elementNamed: 'Target' attributes: {#xmi:id -> #target2}. - reference := self elementNamed: 'Reference' attributes: {#object -> 'target1 target2'}. - visitor visitElement: reference. - visitor visitElement: target1. - visitor visitElement: target2. - visitor resolveAll. - result := visitor elementAt: reference. - self assert: result containedItems size equals: 1. - attribute := result containedItem. - self assert: attribute isReferenceAttribute. - self assert: attribute referencedElements size equals: 2. - self assert: attribute referencedElements first equals: (visitor elementAt: target1). - self assert: attribute referencedElements second equals: (visitor elementAt: target2) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testReferenceElement [ - | target reference | - target := self elementNamed: 'Target' attributes: {#xmi:id -> #target}. - reference := self elementNamed: 'Reference' attributes: {#xmi:idref -> #target}. - visitor visitElement: target. - visitor visitElement: reference. - visitor resolveAll. - result := visitor elementAt: reference. - self assert: result isReferenceElement. - self assert: result referencedElements size equals: 1. - self assert: result referencedElement equals: (visitor elementAt: target) -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testReferenceElementHrefUnresolved [ - | reference | - reference := self - elementNamed: 'importedPackage' - attributes: {#href -> 'http://www.omg.org/spec/DD/20131001/DI.xmi#_0'}. - visitor visitElement: reference. - visitor resolveAll. - result := visitor elementAt: reference. - self assert: result isReferenceElement. - self assert: result href equals: 'http://www.omg.org/spec/DD/20131001/DI.xmi#_0'. - self assert: result referencedElements size equals: 0 -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testReferenceElementHrefUnresolvedWithType [ - | reference | - reference := self - elementNamed: 'type' - attributes: - {#xmi:type -> 'uml:PrimitiveType'. - #href -> 'PrimitiveTypes.xmi#String'}. - visitor visitElement: reference. - visitor resolveAll. - result := visitor elementAt: reference. - self assert: result isReferenceElement. - self assert: result href equals: 'PrimitiveTypes.xmi#String'. - self assert: result xmiType equals: 'uml:PrimitiveType'. - self assert: result referencedElements size equals: 0 -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testValueAttribute [ - result := visitor valueAttributeFor: (XMLAttribute name: 'name' value: 'value'). - self assert: result isValueAttribute. - self assert: result xmiName equals: 'name'. - self assert: result value equals: 'value' -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testValueElement [ - result := visitor - valueElementFor: - (XMLElement new - name: 'el'; - addString: 'content'; - yourself). - self assert: result isValueElement. - self assert: result xmiName equals: 'el'. - self assert: result value equals: 'content' -] - -{ #category : 'tests' } -OPXMIReaderVisitorTest >> testVisitObjectElementWithChild [ - | node | - node := (self elementNamed: 'parent' attributes: {#xmi:type -> 'type'}) - addNode: (self elementNamed: 'child'); - yourself. - visitor visitElement: node. - result := visitor elementAt: node. - self assert: result xmiName equals: 'parent'. - self assert: result containedItems size equals: 2. - self assert: result containedItems second isElement. - self assert: result containedItems second xmiName equals: 'child' -] +Class { + #name : 'OPXMIReaderVisitorTest', + #superclass : 'TestCase', + #instVars : [ + 'visitor', + 'result' + ], + #category : 'OpenPonk-XMI-Tests', + #package : 'OpenPonk-XMI', + #tag : 'Tests' +} + +{ #category : 'instance creation' } +OPXMIReaderVisitorTest >> elementNamed: aName [ + ^ XMLElement named: aName +] + +{ #category : 'instance creation' } +OPXMIReaderVisitorTest >> elementNamed: aName attributes: aCollection [ + ^ (XMLElement named: aName) + usesNamespaces: false; + setAttributes: aCollection; + yourself +] + +{ #category : 'running' } +OPXMIReaderVisitorTest >> setUp [ + super setUp. + visitor := OPXMIReaderVisitor new +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testIsReferenceAttribute [ + self deny: (visitor isReferenceAttribute: (XMLAttribute name: 'name' value: 'ID')). + visitor visitElement: (self elementNamed: 'whatever' attributes: {#xmi:id -> 'ID'}). + self assert: (visitor isReferenceAttribute: (XMLAttribute name: 'name' value: 'ID')) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testIsReferenceAttributeMulti [ + self + deny: (visitor isReferenceAttribute: (XMLAttribute name: 'name' value: 'ID1 ID2')). + visitor visitElement: (self elementNamed: 'whatever' attributes: {#xmi:id -> 'ID1'}). + visitor visitElement: (self elementNamed: 'whatever' attributes: {#xmi:id -> 'ID2'}). + self + assert: (visitor isReferenceAttribute: (XMLAttribute name: 'name' value: 'ID1 ID2')) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testIsReferenceAttributeNotXmi [ + self deny: (visitor isReferenceAttribute: (XMLAttribute name: 'xmi:idref' value: 'value')). + self deny: (visitor isReferenceAttribute: (XMLAttribute name: 'xmi:id' value: 'value')) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testIsReferenceElementHref [ + self + assert: (visitor isReferenceElement: (self elementNamed: 'el' attributes: {#href -> #content})) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testIsReferenceElementHref2 [ + self + assert: + (visitor + isReferenceElement: + (self + elementNamed: 'el' + attributes: + {#xmi:type -> 'type'. + #href -> #content})) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testIsReferenceElementIdRef [ + self + assert: (visitor isReferenceElement: (self elementNamed: 'el' attributes: {#xmi:idref -> #value})) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testIsReferenceElementNot [ + self + deny: (visitor isReferenceElement: (self elementNamed: 'el' attributes: {#other -> #sth})) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testIsValueElement [ + self + assert: + (visitor + isValueElement: + (XMLElement new + name: 'el'; + addString: 'content'; + yourself)) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testIsValueElementNot [ + self deny: (visitor isValueElement: (XMLElement name: 'el' attributes: {#key -> #value})) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testIsValueElementNot2 [ + self + deny: + (visitor + isValueElement: + ((XMLElement name: 'el') + addNode: (XMLElement name: 'child'); + yourself)) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testObjectElement [ + result := visitor objectElementFor: (self elementNamed: 'el'). + self assert: result isObjectElement. + self assert: result xmiName equals: 'el' +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testObjectElementWithAttributes [ + result := visitor + objectElementFor: (self elementNamed: 'el' attributes: {#name -> #value}). + self assert: result xmiName equals: 'el'. + self assert: result containedItems size equals: 1. + self assert: result containedItems first isValueAttribute. + self assert: result containedItems first xmiName equals: 'name'. + self assert: result containedItems first value equals: 'value' +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testReferenceAttribute [ + | target reference attribute | + target := self elementNamed: 'Target' attributes: {#xmi:id -> #target}. + reference := self elementNamed: 'Reference' attributes: {#object -> #target}. + visitor visitElement: reference. + visitor visitElement: target. + visitor resolveAll. + result := visitor elementAt: reference. + self assert: result containedItems size equals: 1. + attribute := result containedItem. + self assert: attribute isReferenceAttribute. + self assert: attribute referencedElements size equals: 1. + self assert: attribute referencedElement equals: (visitor elementAt: target) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testReferenceAttributeMulti [ + | target1 target2 reference attribute | + target1 := self elementNamed: 'Target' attributes: {#xmi:id -> #target1}. + target2 := self elementNamed: 'Target' attributes: {#xmi:id -> #target2}. + reference := self elementNamed: 'Reference' attributes: {#object -> 'target1 target2'}. + visitor visitElement: reference. + visitor visitElement: target1. + visitor visitElement: target2. + visitor resolveAll. + result := visitor elementAt: reference. + self assert: result containedItems size equals: 1. + attribute := result containedItem. + self assert: attribute isReferenceAttribute. + self assert: attribute referencedElements size equals: 2. + self assert: attribute referencedElements first equals: (visitor elementAt: target1). + self assert: attribute referencedElements second equals: (visitor elementAt: target2) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testReferenceElement [ + | target reference | + target := self elementNamed: 'Target' attributes: {#xmi:id -> #target}. + reference := self elementNamed: 'Reference' attributes: {#xmi:idref -> #target}. + visitor visitElement: target. + visitor visitElement: reference. + visitor resolveAll. + result := visitor elementAt: reference. + self assert: result isReferenceElement. + self assert: result referencedElements size equals: 1. + self assert: result referencedElement equals: (visitor elementAt: target) +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testReferenceElementHrefUnresolved [ + | reference | + reference := self + elementNamed: 'importedPackage' + attributes: {#href -> 'http://www.omg.org/spec/DD/20131001/DI.xmi#_0'}. + visitor visitElement: reference. + visitor resolveAll. + result := visitor elementAt: reference. + self assert: result isReferenceElement. + self assert: result href equals: 'http://www.omg.org/spec/DD/20131001/DI.xmi#_0'. + self assert: result referencedElements size equals: 0 +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testReferenceElementHrefUnresolvedWithType [ + | reference | + reference := self + elementNamed: 'type' + attributes: + {#xmi:type -> 'uml:PrimitiveType'. + #href -> 'PrimitiveTypes.xmi#String'}. + visitor visitElement: reference. + visitor resolveAll. + result := visitor elementAt: reference. + self assert: result isReferenceElement. + self assert: result href equals: 'PrimitiveTypes.xmi#String'. + self assert: result xmiType equals: 'uml:PrimitiveType'. + self assert: result referencedElements size equals: 0 +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testValueAttribute [ + result := visitor valueAttributeFor: (XMLAttribute name: 'name' value: 'value'). + self assert: result isValueAttribute. + self assert: result xmiName equals: 'name'. + self assert: result value equals: 'value' +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testValueElement [ + result := visitor + valueElementFor: + (XMLElement new + name: 'el'; + addString: 'content'; + yourself). + self assert: result isValueElement. + self assert: result xmiName equals: 'el'. + self assert: result value equals: 'content' +] + +{ #category : 'tests' } +OPXMIReaderVisitorTest >> testVisitObjectElementWithChild [ + | node | + node := (self elementNamed: 'parent' attributes: {#xmi:type -> 'type'}) + addNode: (self elementNamed: 'child'); + yourself. + visitor visitElement: node. + result := visitor elementAt: node. + self assert: result xmiName equals: 'parent'. + self assert: result containedItems size equals: 2. + self assert: result containedItems second isElement. + self assert: result containedItems second xmiName equals: 'child' +] diff --git a/repository/OP-XMI/OPXMIReferenceAttribute.class.st b/repository/OpenPonk-XMI/OPXMIReferenceAttribute.class.st similarity index 92% rename from repository/OP-XMI/OPXMIReferenceAttribute.class.st rename to repository/OpenPonk-XMI/OPXMIReferenceAttribute.class.st index 7f65076..741fbce 100644 --- a/repository/OP-XMI/OPXMIReferenceAttribute.class.st +++ b/repository/OpenPonk-XMI/OPXMIReferenceAttribute.class.st @@ -1,71 +1,71 @@ -" -XMIReferenceAttribute is an XML attribute that references an XMIElement by id. -" -Class { - #name : 'OPXMIReferenceAttribute', - #superclass : 'OPXMIAttribute', - #instVars : [ - 'referencedElements', - 'href' - ], - #category : 'OP-XMI-DOM', - #package : 'OP-XMI', - #tag : 'DOM' -} - -{ #category : 'instance creation' } -OPXMIReferenceAttribute class >> xmiName: aName referencedElements: aCollection [ - ^ self new - xmiName: aName; - referencedElements: aCollection; - yourself -] - -{ #category : 'visiting' } -OPXMIReferenceAttribute >> accept: aVisitor [ - aVisitor visitReferenceAttribute: self -] - -{ #category : 'accessing' } -OPXMIReferenceAttribute >> href [ - ^ href -] - -{ #category : 'accessing' } -OPXMIReferenceAttribute >> href: anObject [ - href := anObject -] - -{ #category : 'initialization' } -OPXMIReferenceAttribute >> initialize [ - super initialize. - referencedElements := OrderedCollection new -] - -{ #category : 'testing' } -OPXMIReferenceAttribute >> isReferenceAttribute [ - ^ true -] - -{ #category : 'printing' } -OPXMIReferenceAttribute >> printOn: aStream [ - aStream - << 'XMIReferenceAttribute('; - << xmiName; - << '")' -] - -{ #category : 'accessing' } -OPXMIReferenceAttribute >> referencedElement [ - ^ referencedElements ifEmpty: [ nil ] ifNotEmpty: [ referencedElements first ] -] - -{ #category : 'accessing' } -OPXMIReferenceAttribute >> referencedElements [ - ^ referencedElements -] - -{ #category : 'accessing' } -OPXMIReferenceAttribute >> referencedElements: aCollection [ - referencedElements := aCollection -] +" +XMIReferenceAttribute is an XML attribute that references an XMIElement by id. +" +Class { + #name : 'OPXMIReferenceAttribute', + #superclass : 'OPXMIAttribute', + #instVars : [ + 'referencedElements', + 'href' + ], + #category : 'OpenPonk-XMI-DOM', + #package : 'OpenPonk-XMI', + #tag : 'DOM' +} + +{ #category : 'instance creation' } +OPXMIReferenceAttribute class >> xmiName: aName referencedElements: aCollection [ + ^ self new + xmiName: aName; + referencedElements: aCollection; + yourself +] + +{ #category : 'visiting' } +OPXMIReferenceAttribute >> accept: aVisitor [ + aVisitor visitReferenceAttribute: self +] + +{ #category : 'accessing' } +OPXMIReferenceAttribute >> href [ + ^ href +] + +{ #category : 'accessing' } +OPXMIReferenceAttribute >> href: anObject [ + href := anObject +] + +{ #category : 'initialization' } +OPXMIReferenceAttribute >> initialize [ + super initialize. + referencedElements := OrderedCollection new +] + +{ #category : 'testing' } +OPXMIReferenceAttribute >> isReferenceAttribute [ + ^ true +] + +{ #category : 'printing' } +OPXMIReferenceAttribute >> printOn: aStream [ + aStream + << 'XMIReferenceAttribute('; + << xmiName; + << '")' +] + +{ #category : 'accessing' } +OPXMIReferenceAttribute >> referencedElement [ + ^ referencedElements ifEmpty: [ nil ] ifNotEmpty: [ referencedElements first ] +] + +{ #category : 'accessing' } +OPXMIReferenceAttribute >> referencedElements [ + ^ referencedElements +] + +{ #category : 'accessing' } +OPXMIReferenceAttribute >> referencedElements: aCollection [ + referencedElements := aCollection +] diff --git a/repository/OP-XMI/OPXMIReferenceElement.class.st b/repository/OpenPonk-XMI/OPXMIReferenceElement.class.st similarity index 92% rename from repository/OP-XMI/OPXMIReferenceElement.class.st rename to repository/OpenPonk-XMI/OPXMIReferenceElement.class.st index 78006fa..4d1cfe9 100644 --- a/repository/OP-XMI/OPXMIReferenceElement.class.st +++ b/repository/OpenPonk-XMI/OPXMIReferenceElement.class.st @@ -1,74 +1,74 @@ -" -XMIReferenceElement is an XML element with an idref or href attribute that references another XMIElement, by id, URI, or URI and XPointer. -" -Class { - #name : 'OPXMIReferenceElement', - #superclass : 'OPXMIElement', - #instVars : [ - 'referencedElements', - 'href', - 'xmiType' - ], - #category : 'OP-XMI-DOM', - #package : 'OP-XMI', - #tag : 'DOM' -} - -{ #category : 'instance creation' } -OPXMIReferenceElement class >> xmiName: aName referencedElements: aCollection [ - ^ self new - xmiName: aName; - referencedElements: aCollection; - yourself -] - -{ #category : 'visiting' } -OPXMIReferenceElement >> accept: aVisitor [ - aVisitor visitReferenceElement: self -] - -{ #category : 'accessing' } -OPXMIReferenceElement >> href [ - ^ href -] - -{ #category : 'accessing' } -OPXMIReferenceElement >> href: anObject [ - href := anObject -] - -{ #category : 'initialization' } -OPXMIReferenceElement >> initialize [ - super initialize. - referencedElements := OrderedCollection new -] - -{ #category : 'testing' } -OPXMIReferenceElement >> isReferenceElement [ - ^ true -] - -{ #category : 'accessing' } -OPXMIReferenceElement >> referencedElement [ - ^ referencedElements ifEmpty: [ nil ] ifNotEmpty: [ referencedElements first ] -] - -{ #category : 'accessing' } -OPXMIReferenceElement >> referencedElements [ - ^ referencedElements -] - -{ #category : 'accessing' } -OPXMIReferenceElement >> referencedElements: aCollection [ - referencedElements := aCollection -] - -{ #category : 'accessing' } -OPXMIReferenceElement >> xmiType [ - ^ xmiType -] - -{ #category : 'accessing' } -OPXMIReferenceElement >> xmiType: anObject [ - xmiType := anObject -] +" +XMIReferenceElement is an XML element with an idref or href attribute that references another XMIElement, by id, URI, or URI and XPointer. +" +Class { + #name : 'OPXMIReferenceElement', + #superclass : 'OPXMIElement', + #instVars : [ + 'referencedElements', + 'href', + 'xmiType' + ], + #category : 'OpenPonk-XMI-DOM', + #package : 'OpenPonk-XMI', + #tag : 'DOM' +} + +{ #category : 'instance creation' } +OPXMIReferenceElement class >> xmiName: aName referencedElements: aCollection [ + ^ self new + xmiName: aName; + referencedElements: aCollection; + yourself +] + +{ #category : 'visiting' } +OPXMIReferenceElement >> accept: aVisitor [ + aVisitor visitReferenceElement: self +] + +{ #category : 'accessing' } +OPXMIReferenceElement >> href [ + ^ href +] + +{ #category : 'accessing' } +OPXMIReferenceElement >> href: anObject [ + href := anObject +] + +{ #category : 'initialization' } +OPXMIReferenceElement >> initialize [ + super initialize. + referencedElements := OrderedCollection new +] + +{ #category : 'testing' } +OPXMIReferenceElement >> isReferenceElement [ + ^ true +] + +{ #category : 'accessing' } +OPXMIReferenceElement >> referencedElement [ + ^ referencedElements ifEmpty: [ nil ] ifNotEmpty: [ referencedElements first ] +] + +{ #category : 'accessing' } +OPXMIReferenceElement >> referencedElements [ + ^ referencedElements +] + +{ #category : 'accessing' } +OPXMIReferenceElement >> referencedElements: aCollection [ + referencedElements := aCollection +] + +{ #category : 'accessing' } +OPXMIReferenceElement >> xmiType [ + ^ xmiType +] + +{ #category : 'accessing' } +OPXMIReferenceElement >> xmiType: anObject [ + xmiType := anObject +] diff --git a/repository/OP-XMI/OPXMIReferenceItemTest.class.st b/repository/OpenPonk-XMI/OPXMIReferenceItemTest.class.st similarity index 89% rename from repository/OP-XMI/OPXMIReferenceItemTest.class.st rename to repository/OpenPonk-XMI/OPXMIReferenceItemTest.class.st index cc54245..2d6ce6e 100644 --- a/repository/OP-XMI/OPXMIReferenceItemTest.class.st +++ b/repository/OpenPonk-XMI/OPXMIReferenceItemTest.class.st @@ -1,23 +1,23 @@ -Class { - #name : 'OPXMIReferenceItemTest', - #superclass : 'TestCase', - #category : 'OP-XMI-Tests', - #package : 'OP-XMI', - #tag : 'Tests' -} - -{ #category : 'tests' } -OPXMIReferenceItemTest >> testConstructorAttribute [ - | element | - element := OPXMIReferenceAttribute xmiName: 'NAME' referencedElements: #(1). - self assert: element xmiName equals: 'NAME'. - self assert: element referencedElements equals: #(1) -] - -{ #category : 'tests' } -OPXMIReferenceItemTest >> testConstructorElement [ - | element | - element := OPXMIReferenceElement xmiName: 'NAME' referencedElements: #(1). - self assert: element xmiName equals: 'NAME'. - self assert: element referencedElements equals: #(1) -] +Class { + #name : 'OPXMIReferenceItemTest', + #superclass : 'TestCase', + #category : 'OpenPonk-XMI-Tests', + #package : 'OpenPonk-XMI', + #tag : 'Tests' +} + +{ #category : 'tests' } +OPXMIReferenceItemTest >> testConstructorAttribute [ + | element | + element := OPXMIReferenceAttribute xmiName: 'NAME' referencedElements: #(1). + self assert: element xmiName equals: 'NAME'. + self assert: element referencedElements equals: #(1) +] + +{ #category : 'tests' } +OPXMIReferenceItemTest >> testConstructorElement [ + | element | + element := OPXMIReferenceElement xmiName: 'NAME' referencedElements: #(1). + self assert: element xmiName equals: 'NAME'. + self assert: element referencedElements equals: #(1) +] diff --git a/repository/OP-XMI/OPXMITest.class.st b/repository/OpenPonk-XMI/OPXMITest.class.st similarity index 89% rename from repository/OP-XMI/OPXMITest.class.st rename to repository/OpenPonk-XMI/OPXMITest.class.st index 4c4624c..04b6cd4 100644 --- a/repository/OP-XMI/OPXMITest.class.st +++ b/repository/OpenPonk-XMI/OPXMITest.class.st @@ -1,33 +1,33 @@ -Class { - #name : 'OPXMITest', - #superclass : 'TestCase', - #category : 'OP-XMI-Tests', - #package : 'OP-XMI', - #tag : 'Tests' -} - -{ #category : 'tests' } -OPXMITest >> normalized: aString [ - ^ (aString copyReplaceAll: String cr with: String lf) - copyReplaceAll: String tab - with: ' ' -] - -{ #category : 'tests' } -OPXMITest >> testReadWrite [ - | in root out | - in := ' - - - - - - - Content - - -'. - root := OPXMIReader readFrom: in readStream. - out := OPXMIWriter toString: root. - self assert: (self normalized: in) equals: (self normalized: out) -] +Class { + #name : 'OPXMITest', + #superclass : 'TestCase', + #category : 'OpenPonk-XMI-Tests', + #package : 'OpenPonk-XMI', + #tag : 'Tests' +} + +{ #category : 'tests' } +OPXMITest >> normalized: aString [ + ^ (aString copyReplaceAll: String cr with: String lf) + copyReplaceAll: String tab + with: ' ' +] + +{ #category : 'tests' } +OPXMITest >> testReadWrite [ + | in root out | + in := ' + + + + + + + Content + + +'. + root := OPXMIReader readFrom: in readStream. + out := OPXMIWriter toString: root. + self assert: (self normalized: in) equals: (self normalized: out) +] diff --git a/repository/OP-XMI/OPXMIValueAttribute.class.st b/repository/OpenPonk-XMI/OPXMIValueAttribute.class.st similarity index 91% rename from repository/OP-XMI/OPXMIValueAttribute.class.st rename to repository/OpenPonk-XMI/OPXMIValueAttribute.class.st index 6c88137..f4e6bfd 100644 --- a/repository/OP-XMI/OPXMIValueAttribute.class.st +++ b/repository/OpenPonk-XMI/OPXMIValueAttribute.class.st @@ -1,67 +1,67 @@ -" -XMIValueAttribute is simply an XML attribute with a value. -" -Class { - #name : 'OPXMIValueAttribute', - #superclass : 'OPXMIAttribute', - #instVars : [ - 'value' - ], - #category : 'OP-XMI-DOM', - #package : 'OP-XMI', - #tag : 'DOM' -} - -{ #category : 'instance creation' } -OPXMIValueAttribute class >> xmiName: aName value: aValue [ - ^ self new - xmiName: aName; - value: aValue; - yourself -] - -{ #category : 'comparing' } -OPXMIValueAttribute >> = aValueAttribute [ - self species = aValueAttribute species - ifFalse: [ ^ false ]. - self xmiName = aValueAttribute xmiName - ifFalse: [ ^ false ]. - self value = aValueAttribute value - ifFalse: [ ^ false ]. - ^ true -] - -{ #category : 'visiting' } -OPXMIValueAttribute >> accept: aVisitor [ - aVisitor visitValueAttribute: self -] - -{ #category : 'comparing' } -OPXMIValueAttribute >> hash [ - ^ self species hash bitXor: (self xmiName hash bitXor: self value hash) -] - -{ #category : 'testing' } -OPXMIValueAttribute >> isValueAttribute [ - ^ true -] - -{ #category : 'printing' } -OPXMIValueAttribute >> printOn: aStream [ - aStream - << 'XMIValueAttribute('; - << xmiName; - << '="'; - << value; - << '")' -] - -{ #category : 'accessing' } -OPXMIValueAttribute >> value [ - ^ value -] - -{ #category : 'accessing' } -OPXMIValueAttribute >> value: aString [ - value := aString -] +" +XMIValueAttribute is simply an XML attribute with a value. +" +Class { + #name : 'OPXMIValueAttribute', + #superclass : 'OPXMIAttribute', + #instVars : [ + 'value' + ], + #category : 'OpenPonk-XMI-DOM', + #package : 'OpenPonk-XMI', + #tag : 'DOM' +} + +{ #category : 'instance creation' } +OPXMIValueAttribute class >> xmiName: aName value: aValue [ + ^ self new + xmiName: aName; + value: aValue; + yourself +] + +{ #category : 'comparing' } +OPXMIValueAttribute >> = aValueAttribute [ + self species = aValueAttribute species + ifFalse: [ ^ false ]. + self xmiName = aValueAttribute xmiName + ifFalse: [ ^ false ]. + self value = aValueAttribute value + ifFalse: [ ^ false ]. + ^ true +] + +{ #category : 'visiting' } +OPXMIValueAttribute >> accept: aVisitor [ + aVisitor visitValueAttribute: self +] + +{ #category : 'comparing' } +OPXMIValueAttribute >> hash [ + ^ self species hash bitXor: (self xmiName hash bitXor: self value hash) +] + +{ #category : 'testing' } +OPXMIValueAttribute >> isValueAttribute [ + ^ true +] + +{ #category : 'printing' } +OPXMIValueAttribute >> printOn: aStream [ + aStream + << 'XMIValueAttribute('; + << xmiName; + << '="'; + << value; + << '")' +] + +{ #category : 'accessing' } +OPXMIValueAttribute >> value [ + ^ value +] + +{ #category : 'accessing' } +OPXMIValueAttribute >> value: aString [ + value := aString +] diff --git a/repository/OP-XMI/OPXMIValueElement.class.st b/repository/OpenPonk-XMI/OPXMIValueElement.class.st similarity index 88% rename from repository/OP-XMI/OPXMIValueElement.class.st rename to repository/OpenPonk-XMI/OPXMIValueElement.class.st index 65c09e0..2c9cfeb 100644 --- a/repository/OP-XMI/OPXMIValueElement.class.st +++ b/repository/OpenPonk-XMI/OPXMIValueElement.class.st @@ -1,41 +1,41 @@ -" -XMIValueElement is an XML element that can have a value, but cannot contain other XML elements or attributes. -" -Class { - #name : 'OPXMIValueElement', - #superclass : 'OPXMIElement', - #instVars : [ - 'value' - ], - #category : 'OP-XMI-DOM', - #package : 'OP-XMI', - #tag : 'DOM' -} - -{ #category : 'instance creation' } -OPXMIValueElement class >> xmiName: aName value: aValue [ - ^ self new - xmiName: aName; - value: aValue; - yourself -] - -{ #category : 'visiting' } -OPXMIValueElement >> accept: aVisitor [ - aVisitor visitValueElement: self -] - -{ #category : 'testing' } -OPXMIValueElement >> isValueElement [ - ^ true -] - -{ #category : 'accessing' } -OPXMIValueElement >> value [ - ^ value -] - -{ #category : 'accessing' } -OPXMIValueElement >> value: aString [ - value := aString -] +" +XMIValueElement is an XML element that can have a value, but cannot contain other XML elements or attributes. +" +Class { + #name : 'OPXMIValueElement', + #superclass : 'OPXMIElement', + #instVars : [ + 'value' + ], + #category : 'OpenPonk-XMI-DOM', + #package : 'OpenPonk-XMI', + #tag : 'DOM' +} + +{ #category : 'instance creation' } +OPXMIValueElement class >> xmiName: aName value: aValue [ + ^ self new + xmiName: aName; + value: aValue; + yourself +] + +{ #category : 'visiting' } +OPXMIValueElement >> accept: aVisitor [ + aVisitor visitValueElement: self +] + +{ #category : 'testing' } +OPXMIValueElement >> isValueElement [ + ^ true +] + +{ #category : 'accessing' } +OPXMIValueElement >> value [ + ^ value +] + +{ #category : 'accessing' } +OPXMIValueElement >> value: aString [ + value := aString +] diff --git a/repository/OP-XMI/OPXMIValueItemTest.class.st b/repository/OpenPonk-XMI/OPXMIValueItemTest.class.st similarity index 88% rename from repository/OP-XMI/OPXMIValueItemTest.class.st rename to repository/OpenPonk-XMI/OPXMIValueItemTest.class.st index cfb9a54..c856e52 100644 --- a/repository/OP-XMI/OPXMIValueItemTest.class.st +++ b/repository/OpenPonk-XMI/OPXMIValueItemTest.class.st @@ -1,23 +1,23 @@ -Class { - #name : 'OPXMIValueItemTest', - #superclass : 'TestCase', - #category : 'OP-XMI-Tests', - #package : 'OP-XMI', - #tag : 'Tests' -} - -{ #category : 'tests' } -OPXMIValueItemTest >> testConstructorAttribute [ - | element | - element := OPXMIValueAttribute xmiName: 'NAME' value: 'VALUE'. - self assert: element xmiName equals: 'NAME'. - self assert: element value equals: 'VALUE' -] - -{ #category : 'tests' } -OPXMIValueItemTest >> testConstructorElement [ - |element| - element := OPXMIValueElement xmiName: 'NAME' value: 'VALUE'. - self assert: element xmiName equals: 'NAME'. - self assert: element value equals: 'VALUE' -] +Class { + #name : 'OPXMIValueItemTest', + #superclass : 'TestCase', + #category : 'OpenPonk-XMI-Tests', + #package : 'OpenPonk-XMI', + #tag : 'Tests' +} + +{ #category : 'tests' } +OPXMIValueItemTest >> testConstructorAttribute [ + | element | + element := OPXMIValueAttribute xmiName: 'NAME' value: 'VALUE'. + self assert: element xmiName equals: 'NAME'. + self assert: element value equals: 'VALUE' +] + +{ #category : 'tests' } +OPXMIValueItemTest >> testConstructorElement [ + |element| + element := OPXMIValueElement xmiName: 'NAME' value: 'VALUE'. + self assert: element xmiName equals: 'NAME'. + self assert: element value equals: 'VALUE' +] diff --git a/repository/OP-XMI/OPXMIWriter.class.st b/repository/OpenPonk-XMI/OPXMIWriter.class.st similarity index 82% rename from repository/OP-XMI/OPXMIWriter.class.st rename to repository/OpenPonk-XMI/OPXMIWriter.class.st index 9704d89..91bebde 100644 --- a/repository/OP-XMI/OPXMIWriter.class.st +++ b/repository/OpenPonk-XMI/OPXMIWriter.class.st @@ -1,22 +1,22 @@ -Class { - #name : 'OPXMIWriter', - #superclass : 'Object', - #category : 'OP-XMI-Writer', - #package : 'OP-XMI', - #tag : 'Writer' -} - -{ #category : 'writing' } -OPXMIWriter class >> toString: anXMI [ - - | visitor | - visitor := OPXMIWriterVisitor new. - visitor visit: anXMI. - ^ visitor contents -] - -{ #category : 'writing' } -OPXMIWriter class >> write: anXMI toStream: aStream [ - - aStream << (self toString: anXMI) -] +Class { + #name : 'OPXMIWriter', + #superclass : 'Object', + #category : 'OpenPonk-XMI-Writer', + #package : 'OpenPonk-XMI', + #tag : 'Writer' +} + +{ #category : 'writing' } +OPXMIWriter class >> toString: anXMI [ + + | visitor | + visitor := OPXMIWriterVisitor new. + visitor visit: anXMI. + ^ visitor contents +] + +{ #category : 'writing' } +OPXMIWriter class >> write: anXMI toStream: aStream [ + + aStream << (self toString: anXMI) +] diff --git a/repository/OP-XMI/OPXMIWriterVisitor.class.st b/repository/OpenPonk-XMI/OPXMIWriterVisitor.class.st similarity index 95% rename from repository/OP-XMI/OPXMIWriterVisitor.class.st rename to repository/OpenPonk-XMI/OPXMIWriterVisitor.class.st index 0e826f9..e5a0428 100644 --- a/repository/OP-XMI/OPXMIWriterVisitor.class.st +++ b/repository/OpenPonk-XMI/OPXMIWriterVisitor.class.st @@ -1,100 +1,100 @@ -Class { - #name : 'OPXMIWriterVisitor', - #superclass : 'Object', - #instVars : [ - 'writer' - ], - #category : 'OP-XMI-Writer', - #package : 'OP-XMI', - #tag : 'Writer' -} - -{ #category : 'accessing' } -OPXMIWriterVisitor >> contents [ - ^ writer contents -] - -{ #category : 'initialization' } -OPXMIWriterVisitor >> initialize [ - super initialize. - writer := XMLWriter new. - writer formatter: OPXMLPrettyPrintingWriterFormatter new. - writer lineBreak: ' '. - writer xml encoding: 'UTF-8' -] - -{ #category : 'visiting' } -OPXMIWriterVisitor >> visit: anElement [ - anElement accept: self -] - -{ #category : 'visiting' } -OPXMIWriterVisitor >> visitObjectElement: anObjectElement [ - "2a:XMIObjectElement ::= ( ""<"" 2k:QName 2d:XMIAttributes ""/>"" ) -| ( ""<"" 2k:QName 2d:XMIAttributes "">"" -(2:XMIElement)* -"""" )" - -"NOTE: I am not handling namespaces properly... thus I explicitly change XMI to xmi:XMI" - - writer - tag: - (anObjectElement xmiName = 'XMI' - ifTrue: [ 'xmi:XMI' ] - ifFalse: [ anObjectElement xmiName ]) - with: [ anObjectElement containedItems - select: #isAttribute - thenDo: [ :each | self visit: each ]. - anObjectElement containedItems select: #isElement thenDo: [ :each | self visit: each ] ] -] - -{ #category : 'visiting' } -OPXMIWriterVisitor >> visitReferenceAttribute: aReferenceAttribute [ - "2j:XMIReferenceAttribute ::= //xmiName// ""=’"" ( //refId// )+ ""’" - - writer writeAttributeName: aReferenceAttribute xmiName value: ((aReferenceAttribute referencedElements collect: #xmiId) joinUsing: ' ') -] - -{ #category : 'visiting' } -OPXMIWriterVisitor >> visitReferenceElement: aReferenceElement [ - " -2c:XMIReferenceElement::= ""<"" //xmiName// 2l:LinkAttribs ""/>"" -2l:LinkAttribs ::= ""xmi:idref=’"" //refId// ""’"" | 2m:Link -2m:Link ::= ""href='"" 2n:URIref ""'"" -2n:URIref ::= (2k:QName)? //URI reference// - -Additionally every modeling tool adds xmi:type information, even though the specs do not seem to allow it. -" - - writer - tag: aReferenceElement xmiName - with: [ aReferenceElement xmiType - ifNotNil: [ writer writeAttributeName: #xmi:type value: aReferenceElement xmiType ]. - aReferenceElement href - ifNil: - [ "idref" writer writeAttributeName: #xmi:idref value: aReferenceElement referencedElement xmiId ] - ifNotNil: [ "href" writer writeAttributeName: 'href' value: aReferenceElement href ] ] -] - -{ #category : 'visiting' } -OPXMIWriterVisitor >> visitValueAttribute: aValueAttribute [ - "2i:XMIValueAttribute ::= //xmiName// ""=’"" value ""’""" - - writer writeAttributeName: aValueAttribute xmiName value: aValueAttribute value -] - -{ #category : 'visiting' } -OPXMIWriterVisitor >> visitValueElement: aValueElement [ - "2b:XMIValueElement ::= ( ""<"" //xmiName// "">"" //value// -"""" ) -| ( """" )" - - "xsi:nil shouldBeImplement" - - writer tag: aValueElement xmiName with: aValueElement value -] - -{ #category : 'accessing' } -OPXMIWriterVisitor >> writer [ - ^ writer -] +Class { + #name : 'OPXMIWriterVisitor', + #superclass : 'Object', + #instVars : [ + 'writer' + ], + #category : 'OpenPonk-XMI-Writer', + #package : 'OpenPonk-XMI', + #tag : 'Writer' +} + +{ #category : 'accessing' } +OPXMIWriterVisitor >> contents [ + ^ writer contents +] + +{ #category : 'initialization' } +OPXMIWriterVisitor >> initialize [ + super initialize. + writer := XMLWriter new. + writer formatter: OPXMLPrettyPrintingWriterFormatter new. + writer lineBreak: ' '. + writer xml encoding: 'UTF-8' +] + +{ #category : 'visiting' } +OPXMIWriterVisitor >> visit: anElement [ + anElement accept: self +] + +{ #category : 'visiting' } +OPXMIWriterVisitor >> visitObjectElement: anObjectElement [ + "2a:XMIObjectElement ::= ( ""<"" 2k:QName 2d:XMIAttributes ""/>"" ) +| ( ""<"" 2k:QName 2d:XMIAttributes "">"" +(2:XMIElement)* +"""" )" + +"NOTE: I am not handling namespaces properly... thus I explicitly change XMI to xmi:XMI" + + writer + tag: + (anObjectElement xmiName = 'XMI' + ifTrue: [ 'xmi:XMI' ] + ifFalse: [ anObjectElement xmiName ]) + with: [ anObjectElement containedItems + select: #isAttribute + thenDo: [ :each | self visit: each ]. + anObjectElement containedItems select: #isElement thenDo: [ :each | self visit: each ] ] +] + +{ #category : 'visiting' } +OPXMIWriterVisitor >> visitReferenceAttribute: aReferenceAttribute [ + "2j:XMIReferenceAttribute ::= //xmiName// ""=’"" ( //refId// )+ ""’" + + writer writeAttributeName: aReferenceAttribute xmiName value: ((aReferenceAttribute referencedElements collect: #xmiId) joinUsing: ' ') +] + +{ #category : 'visiting' } +OPXMIWriterVisitor >> visitReferenceElement: aReferenceElement [ + " +2c:XMIReferenceElement::= ""<"" //xmiName// 2l:LinkAttribs ""/>"" +2l:LinkAttribs ::= ""xmi:idref=’"" //refId// ""’"" | 2m:Link +2m:Link ::= ""href='"" 2n:URIref ""'"" +2n:URIref ::= (2k:QName)? //URI reference// + +Additionally every modeling tool adds xmi:type information, even though the specs do not seem to allow it. +" + + writer + tag: aReferenceElement xmiName + with: [ aReferenceElement xmiType + ifNotNil: [ writer writeAttributeName: #xmi:type value: aReferenceElement xmiType ]. + aReferenceElement href + ifNil: + [ "idref" writer writeAttributeName: #xmi:idref value: aReferenceElement referencedElement xmiId ] + ifNotNil: [ "href" writer writeAttributeName: 'href' value: aReferenceElement href ] ] +] + +{ #category : 'visiting' } +OPXMIWriterVisitor >> visitValueAttribute: aValueAttribute [ + "2i:XMIValueAttribute ::= //xmiName// ""=’"" value ""’""" + + writer writeAttributeName: aValueAttribute xmiName value: aValueAttribute value +] + +{ #category : 'visiting' } +OPXMIWriterVisitor >> visitValueElement: aValueElement [ + "2b:XMIValueElement ::= ( ""<"" //xmiName// "">"" //value// +"""" ) +| ( """" )" + + "xsi:nil shouldBeImplement" + + writer tag: aValueElement xmiName with: aValueElement value +] + +{ #category : 'accessing' } +OPXMIWriterVisitor >> writer [ + ^ writer +] diff --git a/repository/OP-XMI/OPXMIWriterVisitorTest.class.st b/repository/OpenPonk-XMI/OPXMIWriterVisitorTest.class.st similarity index 94% rename from repository/OP-XMI/OPXMIWriterVisitorTest.class.st rename to repository/OpenPonk-XMI/OPXMIWriterVisitorTest.class.st index abcd01f..9d4a0a0 100644 --- a/repository/OP-XMI/OPXMIWriterVisitorTest.class.st +++ b/repository/OpenPonk-XMI/OPXMIWriterVisitorTest.class.st @@ -1,123 +1,123 @@ -Class { - #name : 'OPXMIWriterVisitorTest', - #superclass : 'TestCase', - #instVars : [ - 'visitor' - ], - #category : 'OP-XMI-Tests', - #package : 'OP-XMI', - #tag : 'Tests' -} - -{ #category : 'running' } -OPXMIWriterVisitorTest >> setUp [ - super setUp. - visitor := OPXMIWriterVisitor new -] - -{ #category : 'tests' } -OPXMIWriterVisitorTest >> testVisitObjectElement [ - visitor - visitObjectElement: - (OPXMIObjectElement new - xmiName: 'Object'; - containedItems: - {OPXMIValueAttribute new - xmiName: 'xmi:id'; - value: 'ID'. - OPXMIValueElement new - xmiName: 'body'; - value: 'CONTENT'}). - self - assert: visitor contents - equals: - ' - - CONTENT -' -] - -{ #category : 'tests' } -OPXMIWriterVisitorTest >> testVisitReferenceAttribute [ - visitor writer - tag: 'outer' - with: [ visitor - visitReferenceAttribute: - (OPXMIReferenceAttribute new - xmiName: 'key'; - referencedElements: - {OPXMIObjectElement new - xmiName: 'whatever'; - containedItems: - {OPXMIValueAttribute new - xmiName: 'xmi:id'; - value: 'AAA'}}) ]. - self assert: visitor contents lines last equals: '' -] - -{ #category : 'tests' } -OPXMIWriterVisitorTest >> testVisitReferenceElement [ - visitor - visitReferenceElement: - (OPXMIReferenceElement new - xmiName: 'name'; - referencedElements: - {OPXMIObjectElement new - xmiName: 'whatever'; - containedItems: - {OPXMIValueElement new - xmiName: 'xmi:id'; - value: 'AAA'}}). - self assert: visitor contents lines last equals: '' -] - -{ #category : 'tests' } -OPXMIWriterVisitorTest >> testVisitReferenceElementHref [ - visitor - visitReferenceElement: - (OPXMIReferenceElement new - xmiName: 'name'; - href: 'http://UNIVERSE'). - self assert: visitor contents lines last equals: '' -] - -{ #category : 'tests' } -OPXMIWriterVisitorTest >> testVisitReferenceElementHrefType [ - visitor - visitReferenceElement: - (OPXMIReferenceElement new - xmiName: 'name'; - xmiType: 'uml:PrimitiveType'; - href: 'http://UNIVERSE'). - self - assert: visitor contents lines last - equals: '' -] - -{ #category : 'tests' } -OPXMIWriterVisitorTest >> testVisitValueAttribute [ - visitor writer - tag: 'outer' - with: [ visitor - visitValueAttribute: - (OPXMIValueAttribute new - xmiName: 'key'; - value: 'VALUE') ]. - self assert: visitor contents lines last equals: '' -] - -{ #category : 'tests' } -OPXMIWriterVisitorTest >> testVisitValueElement [ - visitor visitValueElement: (OPXMIValueElement new xmiName: 'name'; value: 'VALUE'). - self assert: visitor contents lines last equals: 'VALUE' -] - -{ #category : 'tests' } -OPXMIWriterVisitorTest >> testVisitXmiElement [ - visitor visitObjectElement: (OPXMIObjectElement new xmiName: 'XMI'). - self - assert: visitor contents - equals: - ' -' -] +Class { + #name : 'OPXMIWriterVisitorTest', + #superclass : 'TestCase', + #instVars : [ + 'visitor' + ], + #category : 'OpenPonk-XMI-Tests', + #package : 'OpenPonk-XMI', + #tag : 'Tests' +} + +{ #category : 'running' } +OPXMIWriterVisitorTest >> setUp [ + super setUp. + visitor := OPXMIWriterVisitor new +] + +{ #category : 'tests' } +OPXMIWriterVisitorTest >> testVisitObjectElement [ + visitor + visitObjectElement: + (OPXMIObjectElement new + xmiName: 'Object'; + containedItems: + {OPXMIValueAttribute new + xmiName: 'xmi:id'; + value: 'ID'. + OPXMIValueElement new + xmiName: 'body'; + value: 'CONTENT'}). + self + assert: visitor contents + equals: + ' + + CONTENT +' +] + +{ #category : 'tests' } +OPXMIWriterVisitorTest >> testVisitReferenceAttribute [ + visitor writer + tag: 'outer' + with: [ visitor + visitReferenceAttribute: + (OPXMIReferenceAttribute new + xmiName: 'key'; + referencedElements: + {OPXMIObjectElement new + xmiName: 'whatever'; + containedItems: + {OPXMIValueAttribute new + xmiName: 'xmi:id'; + value: 'AAA'}}) ]. + self assert: visitor contents lines last equals: '' +] + +{ #category : 'tests' } +OPXMIWriterVisitorTest >> testVisitReferenceElement [ + visitor + visitReferenceElement: + (OPXMIReferenceElement new + xmiName: 'name'; + referencedElements: + {OPXMIObjectElement new + xmiName: 'whatever'; + containedItems: + {OPXMIValueElement new + xmiName: 'xmi:id'; + value: 'AAA'}}). + self assert: visitor contents lines last equals: '' +] + +{ #category : 'tests' } +OPXMIWriterVisitorTest >> testVisitReferenceElementHref [ + visitor + visitReferenceElement: + (OPXMIReferenceElement new + xmiName: 'name'; + href: 'http://UNIVERSE'). + self assert: visitor contents lines last equals: '' +] + +{ #category : 'tests' } +OPXMIWriterVisitorTest >> testVisitReferenceElementHrefType [ + visitor + visitReferenceElement: + (OPXMIReferenceElement new + xmiName: 'name'; + xmiType: 'uml:PrimitiveType'; + href: 'http://UNIVERSE'). + self + assert: visitor contents lines last + equals: '' +] + +{ #category : 'tests' } +OPXMIWriterVisitorTest >> testVisitValueAttribute [ + visitor writer + tag: 'outer' + with: [ visitor + visitValueAttribute: + (OPXMIValueAttribute new + xmiName: 'key'; + value: 'VALUE') ]. + self assert: visitor contents lines last equals: '' +] + +{ #category : 'tests' } +OPXMIWriterVisitorTest >> testVisitValueElement [ + visitor visitValueElement: (OPXMIValueElement new xmiName: 'name'; value: 'VALUE'). + self assert: visitor contents lines last equals: 'VALUE' +] + +{ #category : 'tests' } +OPXMIWriterVisitorTest >> testVisitXmiElement [ + visitor visitObjectElement: (OPXMIObjectElement new xmiName: 'XMI'). + self + assert: visitor contents + equals: + ' +' +] diff --git a/repository/OP-XMI/OPXMLPrettyPrintingWriterFormatter.class.st b/repository/OpenPonk-XMI/OPXMLPrettyPrintingWriterFormatter.class.st similarity index 89% rename from repository/OP-XMI/OPXMLPrettyPrintingWriterFormatter.class.st rename to repository/OpenPonk-XMI/OPXMLPrettyPrintingWriterFormatter.class.st index 8434367..6032664 100644 --- a/repository/OP-XMI/OPXMLPrettyPrintingWriterFormatter.class.st +++ b/repository/OpenPonk-XMI/OPXMLPrettyPrintingWriterFormatter.class.st @@ -1,29 +1,29 @@ -Class { - #name : 'OPXMLPrettyPrintingWriterFormatter', - #superclass : 'XMLPrettyPrintingWriterFormatter', - #instVars : [ - 'lineBreak' - ], - #category : 'OP-XMI-Writer', - #package : 'OP-XMI', - #tag : 'Writer' -} - -{ #category : 'writing' } -OPXMLPrettyPrintingWriterFormatter >> lineBreak: aCharacterOrString [ - lineBreak := aCharacterOrString asString -] - -{ #category : 'writing' } -OPXMLPrettyPrintingWriterFormatter >> writeLineBreak [ - self writer atBeginning - ifFalse: [ self writer nextPutAll: lineBreak. - (self currentIndentLevel > 0 and: [ self indentString size > 0 ]) - ifTrue: [ self writeIndent ] ] -] - -{ #category : 'writing' } -OPXMLPrettyPrintingWriterFormatter >> writer: aWriter [ - super writer: aWriter. - lineBreak ifNil: [ lineBreak := aWriter lineBreak ] -] +Class { + #name : 'OPXMLPrettyPrintingWriterFormatter', + #superclass : 'XMLPrettyPrintingWriterFormatter', + #instVars : [ + 'lineBreak' + ], + #category : 'OpenPonk-XMI-Writer', + #package : 'OpenPonk-XMI', + #tag : 'Writer' +} + +{ #category : 'writing' } +OPXMLPrettyPrintingWriterFormatter >> lineBreak: aCharacterOrString [ + lineBreak := aCharacterOrString asString +] + +{ #category : 'writing' } +OPXMLPrettyPrintingWriterFormatter >> writeLineBreak [ + self writer atBeginning + ifFalse: [ self writer nextPutAll: lineBreak. + (self currentIndentLevel > 0 and: [ self indentString size > 0 ]) + ifTrue: [ self writeIndent ] ] +] + +{ #category : 'writing' } +OPXMLPrettyPrintingWriterFormatter >> writer: aWriter [ + super writer: aWriter. + lineBreak ifNil: [ lineBreak := aWriter lineBreak ] +] diff --git a/repository/OpenPonk-XMI/package.st b/repository/OpenPonk-XMI/package.st new file mode 100644 index 0000000..f78df31 --- /dev/null +++ b/repository/OpenPonk-XMI/package.st @@ -0,0 +1 @@ +Package { #name : 'OpenPonk-XMI' }