From de936e6745f3f6df1832de28609a4c5eb78bf76e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Doser?= Date: Wed, 21 Sep 2005 14:17:47 +0000 Subject: [PATCH] some support for Dependencies between Classifiers (e.g., a class realizes an interface) git-svn-id: https://projects.brucker.ch/su4sml/svn/infsec-import/trunk/src/su4sml@3108 3260e6d1-4efc-4170-b0a7-36055960796d --- src/xmi.sml | 3 ++- src/xmi2rep.sml | 3 ++- src/xmi_core.sml | 18 +++++++++++++-- src/xmi_idtable.sml | 12 +++++++++- src/xml2xmi.sml | 56 +++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 82 insertions(+), 10 deletions(-) diff --git a/src/xmi.sml b/src/xmi.sml index 1a82fd9..7c371b5 100644 --- a/src/xmi.sml +++ b/src/xmi.sml @@ -60,7 +60,8 @@ datatype Package = Package of { xmiid : string, associations : Association list, generalizations: Generalization list, constraints : Constraint list, - stereotypes : Stereotype list} + stereotypes : Stereotype list, + dependencies : Dependency list} end diff --git a/src/xmi2rep.sml b/src/xmi2rep.sml index a7d64bd..5c88816 100644 --- a/src/xmi2rep.sml +++ b/src/xmi2rep.sml @@ -151,7 +151,8 @@ val filter_named_aends = List.filter (fn {name=SOME _,...}:XMI.AssociationEnd = fun transform_classifier t (XMI.Class {xmiid,name,isActive,visibility,isLeaf, generalizations,attributes,operations, - invariant,stereotype}) = + invariant,stereotype,clientDependency, + supplierDependency}) = let val parents = map ((find_classifier_type t) o (find_parent t)) generalizations val filtered_parents = filter (fn x => x <> Rep_OclType.OclAny) parents diff --git a/src/xmi_core.sml b/src/xmi_core.sml index 3f76cd9..eaf7d47 100644 --- a/src/xmi_core.sml +++ b/src/xmi_core.sml @@ -172,6 +172,16 @@ structure XMI_Core = struct open XMI_ExtensionMechanisms + +(* UML distinguishes between different kinds of dependencies: *) +(* Abstraction, Binding, Permission, and Usage. WE do not distinguish *) +(* these at the moment *) + +type Dependency = { xmiid: string, + client: string, + supplier: string, + stereotype: string} + (* from UML 1.5 Core: -------------------------------------------------------- * A generalization is a taxonomic relationship between a more general * element and a more specific element. The more specific element is @@ -270,7 +280,9 @@ type Class = { xmiid : string, (* inherited from ModelElement: *) (* xmi.idref to Constraint *) invariant: string list , - stereotype: string list} + stereotype: string list, + clientDependency: string list, + supplierDependency: string list} (* from UML 1.5 Core: -------------------------------------------------------- * A data type is a type whose values have no identity (i.e., they are @@ -318,7 +330,9 @@ type Interface = { xmiid : string, name: string, generalizations: string list, operations : Operation list, - invariant: string list} + invariant: string list, + clientDependency: string list, + supplierDependency: string list} type Collection = { xmiid : string, diff --git a/src/xmi_idtable.sml b/src/xmi_idtable.sml index a6f8973..9350d54 100644 --- a/src/xmi_idtable.sml +++ b/src/xmi_idtable.sml @@ -42,6 +42,7 @@ datatype HashTableEntry = Package of Rep_OclType.Path | AssociationEnd of Rep_OclType.Path | State of XMI.StateVertex | Transition of XMI.Transition + | Dependency of XMI.Dependency fun find_state t xmiid = (case valOf (HashTable.find t xmiid) @@ -55,6 +56,12 @@ fun find_transition t xmiid = | _ => raise Option) handle Option => raise IllFormed ("expected Transition "^xmiid^" in table") +fun find_dependency t xmiid = + (case valOf (HashTable.find t xmiid) + of Dependency x => x + | _ => raise Option) + handle Option => raise IllFormed ("expected Dependency "^xmiid^" in table") + fun find_generalization t xmiid = (case valOf (HashTable.find t xmiid) of Generalization x => x @@ -217,6 +224,8 @@ XMI.mk_ActivityGraph ag::ags)) insert_state table (#top ag) end +fun insert_dependency table dep = + HashTable.insert table (#xmiid dep, Dependency dep) fun insert_classifier table package_prefix class = let val id = XMI.classifier_xmiid_of class @@ -268,6 +277,7 @@ fun insert_package table package_prefix (XMI.Package p) = map (insert_classifier table full_name) (#classifiers p); map (insert_package table full_name) (#packages p); map (insert_activity_graph table) (#activity_graphs p); + map (insert_dependency table) (#dependencies p); HashTable.insert table (#xmiid p,Package full_name) end @@ -295,5 +305,5 @@ fun initial_state_of table (XMI.mk_ActivityGraph ag) = fun successor_states_of table (st:XMI.StateVertex) = map ((find_state table) o XMI.transition_target_of o (find_transition table)) - (XMI.state_outgoing_trans_of st) + (XMI.state_outgoing_trans_of st) end diff --git a/src/xml2xmi.sml b/src/xml2xmi.sml index 4d5530f..7ad371e 100644 --- a/src/xml2xmi.sml +++ b/src/xml2xmi.sml @@ -353,6 +353,8 @@ val filterPackages = fn trees => append (XmlTree.filter "UML:Package" trees val filterStateMachines = XmlTree.filter "UML:StateMachine" val filterActivityGraphs= XmlTree.filter "UML:ActivityGraph" +(* there may be other kinds of dependencies, but we do not parse them atm *) +val filterDependencies = XmlTree.filter "UML:Abstraction" (* FIX: other classifiers *) fun filterClassifiers trees = @@ -370,6 +372,19 @@ fun filterClassifiers trees = elem = "UML:AssociationClass" end) trees +fun mkDependency tree = + let fun f atts trees = + { xmiid = getXmiId atts, + client = ((getXmiIdref o XmlTree.attributes_of o hd) + (XmlTree.follow "UML:Dependency.client" trees)), + supplier = ((getXmiIdref o XmlTree.attributes_of o hd) + (XmlTree.follow "UML:Dependency.supplier" trees)), + stereotype = ((getXmiIdref o XmlTree.attributes_of o hd) + (XmlTree.follow "UML:ModelElement.stereotype" trees))} + in XmlTree.apply_on "UML:Abstraction" f tree + handle XmlTree.IllFormed msg => raise IllFormed ("in mkDependency: "^msg) + end + fun mkConstraint tree = let fun f atts trees = let val expr = (hd o (XmlTree.follow @@ -457,9 +472,16 @@ fun mkClass atts trees invariant = (map (getXmiIdref o XmlTree.attributes_of) (XmlTree.follow "UML:ModelElement.constraint" trees)), - stereotype = map (getXmiIdref o XmlTree.attributes_of) - (XmlTree.follow "UML:ModelElement.stereotype" - trees)} + stereotype = (map (getXmiIdref o XmlTree.attributes_of) + (XmlTree.follow "UML:ModelElement.stereotype" + trees)), + clientDependency = (map (getXmiIdref o XmlTree.attributes_of) + (XmlTree.follow "UML:ModelElement.clientDependency" + trees)), + supplierDependency = (map (getXmiIdref o XmlTree.attributes_of) + (XmlTree.follow "UML:ModelElement.supplierDependency" + trees))} + fun mkPrimitive atts trees = XMI.Primitive { xmiid = getXmiId atts, @@ -477,7 +499,30 @@ fun mkPrimitive atts trees trees)) } handle XmlTree.IllFormed msg => raise IllFormed ("in mkPrimitive: "^msg) - + +fun mkInterface atts trees + = XMI.Interface { xmiid = getXmiId atts, + name = getName atts, + operations = (map mkOperation + ((XmlTree.filter "UML:Operation") + (XmlTree.follow "UML:Classifier.feature" + trees))), + generalizations = (map (getXmiIdref o XmlTree.attributes_of o hd) + (XmlTree.follow_all + "UML:GeneralizableElement.generalization" + trees)), + invariant = (map (getXmiIdref o XmlTree.attributes_of) + (XmlTree.follow "UML:ModelElement.constraint" + trees)), + clientDependency = (map (getXmiIdref o XmlTree.attributes_of) + (XmlTree.follow "UML:ModelElement.clientDependency" + trees)), + supplierDependency = (map (getXmiIdref o XmlTree.attributes_of) + (XmlTree.follow "UML:ModelElement.supplierDependency" + trees)) + } + handle XmlTree.IllFormed msg => raise IllFormed ("in mkPrimitive: "^msg) + fun mkEnumeration atts trees = XMI.Enumeration { xmiid = getXmiId atts, name = getName atts, @@ -845,7 +890,8 @@ fun mkPackage tree = stereotypes = (map mkStereotype (filterStereotypes trees)), state_machines = nil, - activity_graphs = nil + activity_graphs = nil, + dependencies = (map mkDependency (filterDependencies trees)) } end else raise IllFormed "did not find a UML:Model or UML: Package")