2005-08-17 15:45:10 +00:00
|
|
|
|
(*****************************************************************************
|
2005-08-18 05:55:15 +00:00
|
|
|
|
* su4sml - a SecureUML repository for SML
|
2005-08-17 15:45:10 +00:00
|
|
|
|
*
|
|
|
|
|
* xmi_parser.sml - an xmi-parser for the import interface for su4sml
|
|
|
|
|
* Copyright (C) 2005 Achim D. Brucker <brucker@inf.ethz.ch>
|
|
|
|
|
* J<EFBFBD>rgen Doser <doserj@inf.ethz.ch>
|
|
|
|
|
*
|
|
|
|
|
* This file is part of su4sml.
|
|
|
|
|
*
|
|
|
|
|
* su4sml is free software; you can redistribute it and/or modify it under
|
|
|
|
|
* the terms of the GNU General Public License as published by the Free
|
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* su4sml is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
|
* details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
******************************************************************************)
|
|
|
|
|
|
2005-08-19 16:04:10 +00:00
|
|
|
|
structure ParseXMI :
|
|
|
|
|
sig
|
2005-08-20 18:42:39 +00:00
|
|
|
|
val readFile: string -> XMI_UML.XmiContent
|
2005-08-23 08:03:09 +00:00
|
|
|
|
(* generic exception if something is wrong *)
|
|
|
|
|
exception IllFormed of string
|
2005-08-19 16:04:10 +00:00
|
|
|
|
end =
|
2005-08-17 15:45:10 +00:00
|
|
|
|
struct
|
2005-08-18 16:18:28 +00:00
|
|
|
|
|
2005-08-23 08:03:09 +00:00
|
|
|
|
exception NotYetImplemented
|
2005-08-18 16:18:28 +00:00
|
|
|
|
(* generic exception if something is wrong *)
|
2005-08-23 08:03:09 +00:00
|
|
|
|
exception IllFormed of string
|
2005-08-18 16:18:28 +00:00
|
|
|
|
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-18 16:18:28 +00:00
|
|
|
|
|
2005-08-20 18:42:39 +00:00
|
|
|
|
fun getStringAtt string atts = valOf (XmlTree.attvalue_of string atts)
|
2005-08-18 16:18:28 +00:00
|
|
|
|
handle Option => raise IllFormed ("in getAttValue: did not find attribute "^string)
|
|
|
|
|
|
|
|
|
|
fun getBoolAtt string atts =
|
2005-08-19 16:04:10 +00:00
|
|
|
|
let val att = getStringAtt string atts
|
2005-08-18 16:18:28 +00:00
|
|
|
|
in
|
|
|
|
|
(valOf o Bool.fromString) att
|
|
|
|
|
handle Option => raise IllFormed ("in getBoolAtt: found attribute "^string^
|
|
|
|
|
" with unexpected value "^att)
|
|
|
|
|
end
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
|
|
|
|
|
2005-08-19 11:39:04 +00:00
|
|
|
|
fun getIntAtt string atts =
|
2005-08-19 16:04:10 +00:00
|
|
|
|
let val att = getStringAtt string atts
|
2005-08-18 16:18:28 +00:00
|
|
|
|
in
|
|
|
|
|
(valOf o Int.fromString) att
|
2005-08-19 11:39:04 +00:00
|
|
|
|
handle Option => raise IllFormed ("in getIntAtt: found attribute "^string^
|
2005-08-18 16:18:28 +00:00
|
|
|
|
" with unexpected value "^att)
|
|
|
|
|
end
|
|
|
|
|
|
2005-08-19 16:04:10 +00:00
|
|
|
|
fun getXmiId a = getStringAtt "xmi.id" a
|
|
|
|
|
fun getName a = getStringAtt "name" a
|
|
|
|
|
fun getXmiIdref a = getStringAtt "xmi.idref" a
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-18 16:18:28 +00:00
|
|
|
|
fun getVisibility atts =
|
2005-08-20 18:42:39 +00:00
|
|
|
|
let val att = XmlTree.attvalue_of "visibility" atts
|
2005-08-18 16:18:28 +00:00
|
|
|
|
in
|
2005-08-19 11:39:04 +00:00
|
|
|
|
case att of SOME "public" => XMI_UML.public
|
|
|
|
|
| SOME "private" => XMI_UML.private
|
|
|
|
|
| SOME "protected" => XMI_UML.protected
|
|
|
|
|
| SOME "package" => XMI_UML.package
|
|
|
|
|
| NONE => XMI_UML.public
|
2005-08-18 16:18:28 +00:00
|
|
|
|
| SOME string => raise IllFormed ("in getVisibility: found unexpected attribute value "^string)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun getOrdering atts =
|
2005-08-19 16:04:10 +00:00
|
|
|
|
let val att = getStringAtt "ordering" atts
|
2005-08-18 16:18:28 +00:00
|
|
|
|
in
|
|
|
|
|
case att of "unordered" => XMI_UML.Unordered
|
|
|
|
|
| "ordered" => XMI_UML.Ordered
|
|
|
|
|
| _ => raise IllFormed ("in getOrdering: found unexpected attribute value "^att)
|
|
|
|
|
end
|
|
|
|
|
|
2005-08-23 15:03:15 +00:00
|
|
|
|
fun getOrderingMaybe atts =
|
|
|
|
|
let val att = XmlTree.attvalue_of "ordering" atts
|
|
|
|
|
in
|
|
|
|
|
case att of SOME "unordered" => XMI_UML.Unordered
|
|
|
|
|
| SOME "ordered" => XMI_UML.Ordered
|
|
|
|
|
| _ => XMI_UML.Unordered
|
|
|
|
|
end
|
|
|
|
|
|
2005-08-18 16:18:28 +00:00
|
|
|
|
fun getAggregation atts =
|
2005-08-19 16:04:10 +00:00
|
|
|
|
let val att = getStringAtt "aggregation" atts in
|
2005-08-18 16:18:28 +00:00
|
|
|
|
case att of "none" => XMI_UML.NoAggregation
|
|
|
|
|
| "aggregate" => XMI_UML.Aggregate
|
|
|
|
|
| "composite" => XMI_UML.Composite
|
|
|
|
|
| _ => raise IllFormed ("in getAggregation: found unexpected attribute value "^att)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun getChangeability atts =
|
2005-08-19 16:04:10 +00:00
|
|
|
|
let val att = getStringAtt "changeability" atts in
|
2005-08-18 16:18:28 +00:00
|
|
|
|
case att of "changeable" => XMI_UML.Changeable
|
|
|
|
|
| "frozen" => XMI_UML.Frozen
|
|
|
|
|
| "addonly" => XMI_UML.AddOnly
|
|
|
|
|
| _ => raise IllFormed ("in getChangeability: found unexpected attribute value "^att)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun getKind atts =
|
2005-08-19 16:04:10 +00:00
|
|
|
|
let val att = getStringAtt "kind" atts in
|
2005-08-18 16:18:28 +00:00
|
|
|
|
case att of "in" => XMI_UML.In
|
|
|
|
|
| "out" => XMI_UML.Out
|
|
|
|
|
| "inout" => XMI_UML.Inout
|
|
|
|
|
| "return" => XMI_UML.Return
|
|
|
|
|
| _ => raise IllFormed ("in getKind: found unexpected attribute value "^att)
|
|
|
|
|
end
|
|
|
|
|
|
2005-08-19 13:58:50 +00:00
|
|
|
|
fun getRange atts = (getIntAtt "lower" atts, getIntAtt "upper" atts)
|
2005-08-18 16:18:28 +00:00
|
|
|
|
|
2005-08-23 15:03:15 +00:00
|
|
|
|
fun mkMultiplicity tree = map (getRange o XmlTree.attributes_of)
|
|
|
|
|
(((XmlTree.filter "UML:MultiplicityRange") o
|
|
|
|
|
(XmlTree.skip "UML:Multiplicity.range") o hd o
|
|
|
|
|
(XmlTree.skip "UML:Multiplicity")) tree)
|
2005-08-18 16:18:28 +00:00
|
|
|
|
|
2005-08-20 18:42:39 +00:00
|
|
|
|
fun mkAssociationEnd tree =
|
|
|
|
|
let fun f atts trees =
|
|
|
|
|
{ xmiid = getXmiId atts,
|
|
|
|
|
name = getName atts,
|
|
|
|
|
isNavigable = getBoolAtt "isNavigable" atts,
|
|
|
|
|
ordering = getOrdering atts,
|
|
|
|
|
aggregation = getAggregation atts,
|
2005-08-23 15:03:15 +00:00
|
|
|
|
multiplicity = (mkMultiplicity o hd o (XmlTree.follow "UML:AssociationEnd.multiplicity"))
|
|
|
|
|
trees,
|
2005-08-20 18:42:39 +00:00
|
|
|
|
changeability = getChangeability atts,
|
|
|
|
|
visibility = getVisibility atts,
|
|
|
|
|
participant_id = (getXmiIdref o XmlTree.attributes_of o hd o
|
|
|
|
|
(XmlTree.follow "UML:AssociationEnd.participant")) trees }
|
|
|
|
|
in
|
|
|
|
|
XmlTree.apply_on "UML:AssociationEnd" f tree
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkAssociationEnd: "^msg)
|
2005-08-20 18:42:39 +00:00
|
|
|
|
end
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-23 11:37:41 +00:00
|
|
|
|
fun mkAssociationClass tree =
|
|
|
|
|
let fun f atts trees = { xmiid = getXmiId atts,
|
|
|
|
|
name = XmlTree.attvalue_of "name" atts,
|
|
|
|
|
connection = (map mkAssociationEnd
|
|
|
|
|
(XmlTree.follow "UML:Association.connection"
|
|
|
|
|
trees)) }
|
|
|
|
|
in
|
|
|
|
|
XmlTree.apply_on "UML:AssociationClass" f tree
|
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkAssociation: "^msg)
|
|
|
|
|
end
|
|
|
|
|
|
2005-08-20 18:42:39 +00:00
|
|
|
|
fun mkAssociation tree =
|
|
|
|
|
let fun f atts trees = { xmiid = getXmiId atts,
|
2005-08-20 18:55:18 +00:00
|
|
|
|
name = XmlTree.attvalue_of "name" atts,
|
2005-08-20 18:42:39 +00:00
|
|
|
|
connection = (map mkAssociationEnd
|
|
|
|
|
(XmlTree.skip "UML:Association.connection"
|
|
|
|
|
(hd trees))) }
|
|
|
|
|
in
|
|
|
|
|
XmlTree.apply_on "UML:Association" f tree
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkAssociation: "^msg)
|
2005-08-20 18:42:39 +00:00
|
|
|
|
end
|
2005-08-22 15:04:08 +00:00
|
|
|
|
|
|
|
|
|
fun mkVariableDec tree =
|
|
|
|
|
let fun f atts trees =
|
|
|
|
|
{ xmiid = getXmiId atts,
|
|
|
|
|
name = getName atts,
|
|
|
|
|
declaration_type = (getXmiIdref o XmlTree.attributes_of o hd o
|
|
|
|
|
(XmlTree.follow "OCL.Expressions.VariableDeclaration.type")) trees
|
|
|
|
|
}
|
|
|
|
|
in XmlTree.apply_on "UML15OCL.Expressions.VariableDeclaration" f tree
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkVariableDec: "^msg)
|
2005-08-22 15:04:08 +00:00
|
|
|
|
end
|
|
|
|
|
|
2005-08-20 18:42:39 +00:00
|
|
|
|
|
2005-08-17 15:45:10 +00:00
|
|
|
|
(* find the xmi.idref attribute of an element pinted to by name *)
|
2005-08-20 18:42:39 +00:00
|
|
|
|
fun findXmiIdRef name trees = (getXmiIdref o XmlTree.attributes_of o hd)
|
|
|
|
|
(XmlTree.follow name trees)
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
|
|
|
|
(* find the type of an OCl sub-expression *)
|
|
|
|
|
fun findExpressionType trees = findXmiIdRef "OCL.Expressions.OclExpression.type"
|
|
|
|
|
trees
|
2005-08-26 11:50:39 +00:00
|
|
|
|
handle _ => "DummyT"
|
|
|
|
|
(* hack: return a reference to a dummy*)
|
|
|
|
|
(* type if the real type is not found *)
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-20 18:42:39 +00:00
|
|
|
|
fun mkOCLExpression tree =
|
|
|
|
|
let val elem = XmlTree.tagname_of tree
|
|
|
|
|
val atts = XmlTree.attributes_of tree
|
|
|
|
|
val trees = XmlTree.children_of tree
|
2005-08-17 15:45:10 +00:00
|
|
|
|
in
|
|
|
|
|
if elem = "UML15OCL.Expressions.BooleanLiteralExp" then
|
2005-08-19 16:04:10 +00:00
|
|
|
|
XMI_UML.LiteralExp { symbol = getStringAtt "booleanSymbol" atts,
|
2005-08-26 11:56:18 +00:00
|
|
|
|
expression_type = findExpressionType trees }
|
2005-08-17 15:45:10 +00:00
|
|
|
|
else if elem = "UML15OCL.Expressions.IntegerLiteralExp" then
|
2005-08-19 16:04:10 +00:00
|
|
|
|
XMI_UML.LiteralExp { symbol = getStringAtt "integerSymbol" atts,
|
2005-08-26 11:56:18 +00:00
|
|
|
|
expression_type = findExpressionType trees }
|
|
|
|
|
else if elem = "UML15OCL.Expressions.StringLiteralExp" then
|
|
|
|
|
XMI_UML.LiteralExp { symbol = getStringAtt "stringSymbol" atts,
|
|
|
|
|
expression_type = findExpressionType trees }
|
|
|
|
|
else if elem = "UML15OCL.Expressions.RealLiteralExp" then
|
|
|
|
|
XMI_UML.LiteralExp { symbol = getStringAtt "realSymbol" atts,
|
|
|
|
|
expression_type = findExpressionType trees }
|
2005-08-17 15:45:10 +00:00
|
|
|
|
else if elem = "UML15OCL.Expressions.OperationCallExp" then
|
2005-08-20 18:42:39 +00:00
|
|
|
|
let val op_src = hd (XmlTree.follow
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"OCL.Expressions.PropertyCallExp.source"
|
|
|
|
|
trees)
|
|
|
|
|
val op_ref =
|
|
|
|
|
findXmiIdRef
|
|
|
|
|
"OCL.Expressions.OperationCallExp.referredOperation" trees
|
2005-08-20 18:42:39 +00:00
|
|
|
|
val op_args = XmlTree.follow_all
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"OCL.Expressions.OperationCallExp.arguments"
|
|
|
|
|
trees
|
|
|
|
|
in XMI_UML.OperationCallExp
|
2005-08-20 18:42:39 +00:00
|
|
|
|
{ source = mkOCLExpression op_src,
|
|
|
|
|
arguments = map (mkOCLExpression o hd) op_args,
|
2005-08-17 15:45:10 +00:00
|
|
|
|
referredOperation = op_ref,
|
|
|
|
|
expression_type = findExpressionType trees }
|
|
|
|
|
end
|
|
|
|
|
else if elem = "UML15OCL.Expressions.AttributeCallExp" then
|
|
|
|
|
let val att_ref =
|
|
|
|
|
findXmiIdRef
|
|
|
|
|
"OCL.Expressions.AttributeCallExp.referredAttribute" trees
|
2005-08-20 18:42:39 +00:00
|
|
|
|
val att_src = (hd o XmlTree.follow
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"OCL.Expressions.PropertyCallExp.source")
|
|
|
|
|
trees
|
|
|
|
|
in XMI_UML.AttributeCallExp
|
2005-08-20 18:42:39 +00:00
|
|
|
|
{ source = mkOCLExpression att_src,
|
2005-08-17 15:45:10 +00:00
|
|
|
|
referredAttribute = att_ref,
|
|
|
|
|
expression_type = findExpressionType trees }
|
2005-08-20 18:42:39 +00:00
|
|
|
|
end
|
2005-08-17 15:45:10 +00:00
|
|
|
|
else if elem = "UML15OCL.Expressions.AssociationEndCallExp" then
|
2005-08-20 18:42:39 +00:00
|
|
|
|
let val assoc_src = (hd o XmlTree.follow
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"OCL.Expressions.PropertyCallExp.source")
|
|
|
|
|
trees
|
|
|
|
|
val assoc_ref =
|
|
|
|
|
findXmiIdRef
|
|
|
|
|
"OCL.Expressions.AssociationEndCallExp.referredAssociationEnd"
|
|
|
|
|
trees
|
|
|
|
|
in XMI_UML.AssociationEndCallExp
|
2005-08-20 18:42:39 +00:00
|
|
|
|
{ source = mkOCLExpression assoc_src,
|
2005-08-17 15:45:10 +00:00
|
|
|
|
referredAssociationEnd = assoc_ref,
|
|
|
|
|
expression_type = findExpressionType trees }
|
|
|
|
|
end
|
2005-08-23 09:13:15 +00:00
|
|
|
|
else if elem = "UML15OCL.Expressions.AssociationClassCallExp" then
|
2005-08-17 15:45:10 +00:00
|
|
|
|
raise NotYetImplemented
|
|
|
|
|
else if elem = "UML15OCL.Expressions.VariableExp" then
|
|
|
|
|
let val var_ref = findXmiIdRef
|
|
|
|
|
"OCL.Expressions.VariableExp.referredVariable"
|
|
|
|
|
trees
|
|
|
|
|
in XMI_UML.VariableExp { referredVariable = var_ref,
|
|
|
|
|
expression_type = findExpressionType trees }
|
|
|
|
|
end
|
|
|
|
|
else if elem = "UML15OCL.Expressions.IfExp" then
|
2005-08-20 18:42:39 +00:00
|
|
|
|
let val cond = (hd o XmlTree.follow
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"OCL.Expressions.IfExp.condition") trees
|
2005-08-20 18:42:39 +00:00
|
|
|
|
val then_exp = (hd o XmlTree.follow
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"OCL.Expressions.IfExp.thenExpression")
|
|
|
|
|
trees
|
2005-08-20 18:42:39 +00:00
|
|
|
|
val else_exp = (hd o XmlTree.follow
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"OCL.Expressions.IfExp.elseExpression")
|
|
|
|
|
trees
|
2005-08-20 18:42:39 +00:00
|
|
|
|
in XMI_UML.IfExp { condition = mkOCLExpression cond,
|
|
|
|
|
thenExpression = mkOCLExpression then_exp,
|
|
|
|
|
elseExpression = mkOCLExpression else_exp,
|
2005-08-17 15:45:10 +00:00
|
|
|
|
expression_type = findExpressionType trees }
|
|
|
|
|
end
|
|
|
|
|
else if elem = "UML15OCL.Expressions.LetExp" then
|
2005-08-20 18:42:39 +00:00
|
|
|
|
let val var_decl = (hd o XmlTree.follow
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"OCL.Expressions.LetExp.variable") trees
|
2005-08-20 18:42:39 +00:00
|
|
|
|
val var_xmiid = getXmiId (XmlTree.attributes_of var_decl)
|
|
|
|
|
val var_name = getName (XmlTree.attributes_of var_decl)
|
2005-08-17 15:45:10 +00:00
|
|
|
|
val var_type_ref = findXmiIdRef
|
|
|
|
|
"OCL.Expressions.VariableDeclaration.type"
|
2005-08-20 18:42:39 +00:00
|
|
|
|
(XmlTree.children_of var_decl)
|
|
|
|
|
val in_exp = (hd o XmlTree.follow "OCL.Expressions.LetExp.in") trees
|
2005-08-17 15:45:10 +00:00
|
|
|
|
val init_exp =
|
2005-08-20 18:42:39 +00:00
|
|
|
|
(hd o XmlTree.follow
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"OCL.Expressions.VariableDeclaration.initExpression")
|
2005-08-20 18:42:39 +00:00
|
|
|
|
(XmlTree.children_of var_decl)
|
2005-08-17 15:45:10 +00:00
|
|
|
|
in XMI_UML.LetExp
|
|
|
|
|
{ variable = { xmiid = var_xmiid,
|
|
|
|
|
name = var_name,
|
|
|
|
|
declaration_type = var_type_ref },
|
2005-08-20 18:42:39 +00:00
|
|
|
|
initExpression = mkOCLExpression init_exp ,
|
|
|
|
|
inExpression = mkOCLExpression in_exp,
|
2005-08-17 15:45:10 +00:00
|
|
|
|
expression_type = findExpressionType trees }
|
|
|
|
|
end
|
|
|
|
|
else if elem = "UML15OCL.Expressions.IterateExp" then
|
|
|
|
|
raise NotYetImplemented
|
|
|
|
|
else if elem = "UML15OCL.Expressions.IteratorExp" then
|
2005-08-22 15:04:08 +00:00
|
|
|
|
let val iterator_src = (hd o XmlTree.follow
|
|
|
|
|
"OCL.Expressions.PropertyCallExp.source")
|
|
|
|
|
trees
|
|
|
|
|
val iterator_body = (hd o XmlTree.follow
|
|
|
|
|
"OCL.Expressions.LoopExp.body")
|
|
|
|
|
trees
|
|
|
|
|
val iterators = XmlTree.follow "OCL.Expressions.LoopExp.iterators"
|
|
|
|
|
trees
|
|
|
|
|
in
|
|
|
|
|
XMI_UML.IteratorExp { name = getName atts,
|
|
|
|
|
iterators = map mkVariableDec iterators,
|
|
|
|
|
body = mkOCLExpression iterator_body,
|
|
|
|
|
source = mkOCLExpression iterator_src,
|
|
|
|
|
expression_type = findExpressionType trees }
|
|
|
|
|
end
|
2005-08-20 18:42:39 +00:00
|
|
|
|
else raise IllFormed ("in mkOCLExpression: found unexpected element "^elem)
|
2005-08-17 15:45:10 +00:00
|
|
|
|
end
|
|
|
|
|
|
2005-08-23 11:37:41 +00:00
|
|
|
|
fun getAssociations t = (map mkAssociation (XmlTree.filter "UML:Association" t))@
|
|
|
|
|
(map mkAssociationClass (XmlTree.filter "UML:AssociationClass" t))
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-20 18:42:39 +00:00
|
|
|
|
fun filterConstraints trees = XmlTree.filter "UML:Constraint" trees
|
|
|
|
|
fun filterStereotypes trees = XmlTree.filter "UML:Stereotype" trees
|
|
|
|
|
fun filterVariableDecs trees = XmlTree.filter "UML15OCL.Expressions.VariableDeclaration" trees
|
|
|
|
|
fun filterPackages trees = append (XmlTree.filter "UML:Package" trees)
|
|
|
|
|
(XmlTree.filter "UML:Model" trees)
|
2005-08-17 15:45:10 +00:00
|
|
|
|
(* FIX: other classifiers *)
|
|
|
|
|
fun filterClassifiers trees =
|
2005-08-20 18:42:39 +00:00
|
|
|
|
filter (fn x => let val elem = XmlTree.tagname_of x in
|
2005-08-17 15:45:10 +00:00
|
|
|
|
elem = "UML:Class" orelse
|
|
|
|
|
elem = "UML:Primitive" orelse
|
|
|
|
|
elem = "UML:DataType" orelse
|
|
|
|
|
elem = "UML:Interface" orelse
|
|
|
|
|
elem = "UML:Enumeration" orelse
|
|
|
|
|
elem = "UML15OCL.Types.SequenceType" orelse
|
|
|
|
|
elem = "UML15OCL.Types.BagType" orelse
|
|
|
|
|
elem = "UML15OCL.Types.SetType" orelse
|
|
|
|
|
elem = "UML15OCL.Types.CollectionType" orelse
|
2005-08-23 11:37:41 +00:00
|
|
|
|
elem = "UML15OCL.Types.VoidType" orelse
|
|
|
|
|
elem = "UML:AssociationClass"
|
2005-08-17 15:45:10 +00:00
|
|
|
|
end) trees
|
|
|
|
|
|
2005-08-20 18:42:39 +00:00
|
|
|
|
fun mkConstraint tree =
|
|
|
|
|
let fun f atts trees =
|
|
|
|
|
let val expr = (hd o (XmlTree.follow
|
|
|
|
|
"OCL.Expressions.ExpressionInOcl.bodyExpression") o
|
|
|
|
|
(XmlTree.follow "UML15OCL.Expressions.ExpressionInOcl") o
|
|
|
|
|
(XmlTree.follow "UML:Constraint.body"))
|
|
|
|
|
trees
|
|
|
|
|
val st_type = hd (XmlTree.follow "UML:ModelElement.stereotype" trees)
|
|
|
|
|
val st_type_ref = getXmiIdref (XmlTree.attributes_of st_type)
|
|
|
|
|
in { xmiid = getXmiId atts,
|
|
|
|
|
name = case XmlTree.attvalue_of "name" atts of SOME s => SOME s | _ => NONE,
|
|
|
|
|
constraint_type = st_type_ref,
|
|
|
|
|
body = mkOCLExpression expr }
|
|
|
|
|
end
|
|
|
|
|
in XmlTree.apply_on "UML:Constraint" f tree
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkConstraint: "^msg)
|
2005-08-20 18:42:39 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun mkParameter tree =
|
|
|
|
|
let fun f atts trees = { xmiid = getXmiId atts,
|
|
|
|
|
name = getName atts,
|
|
|
|
|
kind = getKind atts,
|
|
|
|
|
type_id = (getXmiIdref o
|
|
|
|
|
XmlTree.attributes_of o hd o
|
|
|
|
|
(XmlTree.follow "UML:Parameter.type"))
|
|
|
|
|
trees }
|
|
|
|
|
in XmlTree.apply_on "UML:Parameter" f tree
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkParameter: "^msg)
|
2005-08-20 18:42:39 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun mkOperation tree =
|
|
|
|
|
let fun f atts trees =
|
|
|
|
|
{ xmiid = getXmiId atts,
|
|
|
|
|
name = getName atts,
|
|
|
|
|
visibility = getVisibility atts,
|
|
|
|
|
isQuery = getBoolAtt "isQuery" atts,
|
|
|
|
|
parameter = (map mkParameter
|
|
|
|
|
(XmlTree.follow "UML:BehavioralFeature.parameter"
|
|
|
|
|
trees)),
|
|
|
|
|
constraints = if XmlTree.exists "UML:ModelElement.constraint" trees
|
|
|
|
|
then map (getXmiIdref o XmlTree.attributes_of)
|
|
|
|
|
(XmlTree.follow "UML:ModelElement.constraint"
|
|
|
|
|
trees)
|
|
|
|
|
else nil}
|
|
|
|
|
in XmlTree.apply_on "UML:Operation" f tree
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkOperation: "^msg)
|
2005-08-20 18:42:39 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun mkAttribute tree =
|
|
|
|
|
let fun f atts trees =
|
|
|
|
|
{ xmiid = getXmiId atts,
|
|
|
|
|
name = getName atts,
|
|
|
|
|
visibility = getVisibility atts,
|
|
|
|
|
changeability = getChangeability atts,
|
2005-08-23 15:03:15 +00:00
|
|
|
|
ordering = getOrderingMaybe atts,
|
2005-08-20 18:42:39 +00:00
|
|
|
|
type_id = (getXmiIdref o XmlTree.attributes_of o hd o
|
2005-08-23 15:03:15 +00:00
|
|
|
|
(XmlTree.follow "UML:StructuralFeature.type")) trees,
|
|
|
|
|
multiplicity = (mkMultiplicity o hd o (XmlTree.follow "UML:StructuralFeature.multiplicity"))
|
|
|
|
|
trees}
|
2005-08-20 18:42:39 +00:00
|
|
|
|
in XmlTree.apply_on "UML:Attribute" f tree
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkAttribute: "^msg)
|
2005-08-20 18:42:39 +00:00
|
|
|
|
end
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-19 11:39:04 +00:00
|
|
|
|
fun mkClass atts trees
|
2005-08-17 15:45:10 +00:00
|
|
|
|
= XMI_UML.Class { xmiid = getXmiId atts,
|
|
|
|
|
name = getName atts,
|
|
|
|
|
isActive = getBoolAtt "isActive" atts,
|
|
|
|
|
visibility = getVisibility atts,
|
|
|
|
|
isLeaf = getBoolAtt "isLeaf" atts,
|
2005-08-20 18:42:39 +00:00
|
|
|
|
generalizations = (map (getXmiIdref o XmlTree.attributes_of o hd)
|
|
|
|
|
(XmlTree.follow_all
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"UML:GeneralizableElement.generalization"
|
|
|
|
|
trees)),
|
2005-08-20 18:42:39 +00:00
|
|
|
|
attributes = if XmlTree.exists "UML:Classifier.feature" trees
|
|
|
|
|
then map mkAttribute
|
|
|
|
|
((XmlTree.filter "UML:Attribute")
|
|
|
|
|
(XmlTree.follow "UML:Classifier.feature"
|
2005-08-17 15:45:10 +00:00
|
|
|
|
trees))
|
|
|
|
|
else nil,
|
2005-08-20 18:42:39 +00:00
|
|
|
|
operations = if XmlTree.exists "UML:Classifier.feature" trees
|
|
|
|
|
then map mkOperation
|
|
|
|
|
((XmlTree.filter "UML:Operation")
|
|
|
|
|
(XmlTree.follow "UML:Classifier.feature"
|
2005-08-17 15:45:10 +00:00
|
|
|
|
trees))
|
|
|
|
|
else nil,
|
2005-08-20 18:42:39 +00:00
|
|
|
|
invariant = if XmlTree.exists "UML:ModelElement.constraint" trees
|
|
|
|
|
then map (getXmiIdref o XmlTree.attributes_of)
|
|
|
|
|
(XmlTree.follow "UML:ModelElement.constraint"
|
2005-08-17 15:45:10 +00:00
|
|
|
|
trees)
|
|
|
|
|
else nil}
|
|
|
|
|
|
2005-08-19 11:39:04 +00:00
|
|
|
|
fun mkPrimitive atts trees
|
2005-08-17 15:45:10 +00:00
|
|
|
|
= XMI_UML.Primitive { xmiid = getXmiId atts,
|
|
|
|
|
name = getName atts,
|
2005-08-20 18:42:39 +00:00
|
|
|
|
operations = if XmlTree.exists "UML:Classifier.feature" trees
|
|
|
|
|
then map mkOperation
|
|
|
|
|
((XmlTree.filter "UML:Operation")
|
|
|
|
|
(XmlTree.follow "UML:Classifier.feature"
|
2005-08-17 15:45:10 +00:00
|
|
|
|
trees))
|
|
|
|
|
else nil,
|
2005-08-20 18:42:39 +00:00
|
|
|
|
generalizations = (map (getXmiIdref o XmlTree.attributes_of o hd)
|
|
|
|
|
(XmlTree.follow_all
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"UML:GeneralizableElement.generalization"
|
|
|
|
|
trees)),
|
2005-08-20 18:42:39 +00:00
|
|
|
|
invariant = if XmlTree.exists "UML:ModelElement.constraint" trees
|
|
|
|
|
then map (getXmiIdref o XmlTree.attributes_of)
|
|
|
|
|
(XmlTree.follow "UML:ModelElement.constraint"
|
2005-08-17 15:45:10 +00:00
|
|
|
|
trees)
|
|
|
|
|
else nil
|
|
|
|
|
}
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkPrimitive: "^msg)
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-19 11:39:04 +00:00
|
|
|
|
fun mkEnumeration atts trees
|
2005-08-17 15:45:10 +00:00
|
|
|
|
= XMI_UML.Enumeration { xmiid = getXmiId atts,
|
2005-08-20 18:42:39 +00:00
|
|
|
|
name = getName atts,
|
|
|
|
|
operations = if XmlTree.exists "UML:Classifier.feature" trees
|
|
|
|
|
then map mkOperation
|
|
|
|
|
((XmlTree.filter "UML:Operation")
|
|
|
|
|
(XmlTree.follow "UML:Classifier.feature"
|
|
|
|
|
trees))
|
|
|
|
|
else nil,
|
|
|
|
|
generalizations = (map (getXmiIdref o XmlTree.attributes_of o hd)
|
|
|
|
|
(XmlTree.follow_all
|
|
|
|
|
"UML:GeneralizableElement.generalization"
|
|
|
|
|
trees)),
|
|
|
|
|
literals = nil, (* FIX *)
|
|
|
|
|
invariant = if XmlTree.exists "UML:ModelElement.constraint" trees
|
|
|
|
|
then map (getXmiIdref o XmlTree.attributes_of)
|
|
|
|
|
(XmlTree.follow "UML:ModelElement.constraint"
|
|
|
|
|
trees)
|
|
|
|
|
else nil
|
|
|
|
|
}
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkEnumeration: "^msg)
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-19 11:39:04 +00:00
|
|
|
|
fun mkVoid atts trees = XMI_UML.Void { xmiid = getXmiId atts,
|
2005-08-20 18:42:39 +00:00
|
|
|
|
name = getName atts }
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkVoid: "^msg)
|
2005-08-18 16:18:28 +00:00
|
|
|
|
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
|
|
|
|
fun mkGenericCollection atts trees =
|
|
|
|
|
{ xmiid = getXmiId atts,
|
|
|
|
|
name = getName atts,
|
2005-08-20 18:42:39 +00:00
|
|
|
|
operations = if XmlTree.exists "UML:Classifier.feature" trees
|
|
|
|
|
then map mkOperation
|
|
|
|
|
((XmlTree.filter "UML:Operation")
|
|
|
|
|
(XmlTree.follow "UML:Classifier.feature"
|
2005-08-17 15:45:10 +00:00
|
|
|
|
trees))
|
|
|
|
|
else nil,
|
2005-08-20 18:42:39 +00:00
|
|
|
|
generalizations = (map (getXmiIdref o XmlTree.attributes_of o hd)
|
|
|
|
|
(XmlTree.follow_all
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"UML:GeneralizableElement.generalization"
|
|
|
|
|
trees)),
|
2005-08-20 18:42:39 +00:00
|
|
|
|
elementtype = ((getXmiIdref o XmlTree.attributes_of o hd)
|
|
|
|
|
(XmlTree.follow
|
2005-08-17 15:45:10 +00:00
|
|
|
|
"OCL.Types.CollectionType.elementType"
|
|
|
|
|
trees))
|
|
|
|
|
}
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkGenericCollection: "^msg)
|
2005-08-18 16:18:28 +00:00
|
|
|
|
|
2005-08-20 18:42:39 +00:00
|
|
|
|
|
2005-08-19 11:39:04 +00:00
|
|
|
|
fun mkCollection atts trees = XMI_UML.Collection (mkGenericCollection atts trees)
|
|
|
|
|
fun mkSequence atts trees = XMI_UML.Sequence (mkGenericCollection atts trees)
|
|
|
|
|
fun mkSet atts trees = XMI_UML.Set (mkGenericCollection atts trees)
|
|
|
|
|
fun mkBag atts trees = XMI_UML.Bag (mkGenericCollection atts trees)
|
|
|
|
|
fun mkOrderedSet atts trees = XMI_UML.OrderedSet (mkGenericCollection atts trees)
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-20 18:42:39 +00:00
|
|
|
|
fun mkClassifier tree =
|
|
|
|
|
let val elem = XmlTree.tagname_of tree
|
|
|
|
|
val atts = XmlTree.attributes_of tree
|
|
|
|
|
val trees = XmlTree.children_of tree
|
2005-08-17 15:45:10 +00:00
|
|
|
|
in
|
2005-08-23 11:37:41 +00:00
|
|
|
|
if elem = "UML:Class" orelse
|
|
|
|
|
elem = "UML:AssociationClass" then mkClass atts trees
|
|
|
|
|
else if elem = "UML:Interface" orelse (* FIX: use a custom mkInterface *)
|
|
|
|
|
elem = "UML:DataType" orelse
|
|
|
|
|
elem = "UML:Primitive" then mkPrimitive atts trees
|
2005-08-19 11:39:04 +00:00
|
|
|
|
else if elem = "UML:Enumeration" then mkEnumeration atts trees
|
|
|
|
|
else if elem = "UML15OCL.Types.VoidType" then mkVoid atts trees
|
2005-08-17 15:45:10 +00:00
|
|
|
|
else if elem = "UML15OCL.Types.CollectionType" then
|
2005-08-19 11:39:04 +00:00
|
|
|
|
mkCollection atts trees
|
|
|
|
|
else if elem = "UML15OCL.Types.SequenceType" then mkSequence atts trees
|
|
|
|
|
else if elem = "UML15OCL.Types.SetType" then mkSet atts trees
|
|
|
|
|
else if elem = "UML15OCL.Types.BagType" then mkBag atts trees
|
2005-08-17 15:45:10 +00:00
|
|
|
|
else if elem = "UML15OCL.Types.OrderedSetType" then
|
2005-08-19 11:39:04 +00:00
|
|
|
|
mkOrderedSet atts trees
|
2005-08-20 18:42:39 +00:00
|
|
|
|
else raise IllFormed ("in mkClassifier: found unexpected element "^elem)
|
2005-08-17 15:45:10 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-08-20 18:42:39 +00:00
|
|
|
|
fun mkGeneralization tree =
|
|
|
|
|
let fun f atts trees =
|
|
|
|
|
{ xmiid = getXmiId atts,
|
|
|
|
|
child_id = (getXmiIdref o XmlTree.attributes_of o hd o
|
|
|
|
|
(XmlTree.follow "UML:Generalization.child")) trees,
|
|
|
|
|
parent_id = (getXmiIdref o XmlTree.attributes_of o hd o
|
|
|
|
|
(XmlTree.follow "UML:Generalization.parent")) trees }
|
|
|
|
|
in XmlTree.apply_on "UML:Generalization" f tree
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkGeneralization: "^msg)
|
2005-08-20 18:42:39 +00:00
|
|
|
|
end
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-20 18:42:39 +00:00
|
|
|
|
fun mkPackage tree =
|
|
|
|
|
(if XmlTree.tagname_of tree = "UML:Model" orelse
|
|
|
|
|
XmlTree.tagname_of tree = "UML:Package" then
|
|
|
|
|
let val trees = XmlTree.skip "UML:Namespace.ownedElement"
|
|
|
|
|
((hd o XmlTree.children_of) tree)
|
|
|
|
|
val atts = XmlTree.attributes_of tree in
|
|
|
|
|
XMI_UML.Package { xmiid = getXmiId atts,
|
|
|
|
|
name = getName atts,
|
|
|
|
|
visibility = getVisibility atts,
|
|
|
|
|
packages = (map mkPackage
|
|
|
|
|
(filterPackages trees)),
|
|
|
|
|
classifiers = (map mkClassifier
|
|
|
|
|
(filterClassifiers trees)),
|
|
|
|
|
associations = getAssociations trees,
|
|
|
|
|
generalizations = (map mkGeneralization
|
|
|
|
|
(XmlTree.filter "UML:Generalization"
|
|
|
|
|
trees)),
|
|
|
|
|
constraints = map mkConstraint
|
|
|
|
|
(filterConstraints trees) }
|
2005-08-18 16:18:28 +00:00
|
|
|
|
end
|
2005-08-20 18:42:39 +00:00
|
|
|
|
else raise IllFormed "did not find a UML:Model or UML: Package")
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkPackage: "^msg)
|
2005-08-20 18:42:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun mkStereotype tree =
|
|
|
|
|
let fun f atts trees = { xmiid = getXmiId atts,
|
|
|
|
|
name = getName atts,
|
|
|
|
|
baseClass = NONE, (*FIX*)
|
|
|
|
|
stereotypeConstraint = NONE (*FIX*)
|
|
|
|
|
}
|
|
|
|
|
in XmlTree.apply_on "UML:Stereotype" f tree
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkStereotype: "^msg)
|
2005-08-20 18:42:39 +00:00
|
|
|
|
end
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-20 18:42:39 +00:00
|
|
|
|
fun mkXmiContent tree =
|
|
|
|
|
let fun f atts trees =
|
|
|
|
|
{ packages = (map mkPackage (filterPackages trees)),
|
|
|
|
|
constraints = (map mkConstraint (filterConstraints trees)),
|
|
|
|
|
classifiers = (map mkClassifier (filterClassifiers trees)),
|
|
|
|
|
stereotypes = (map mkStereotype (filterStereotypes trees)),
|
2005-08-20 20:50:18 +00:00
|
|
|
|
variable_declarations = (map mkVariableDec (filterVariableDecs trees)) }
|
|
|
|
|
in XmlTree.apply_on "XMI.content" f tree
|
2005-08-23 09:13:15 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => raise IllFormed ("in mkXmiContent: "^msg)
|
2005-08-20 18:42:39 +00:00
|
|
|
|
end
|
|
|
|
|
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-20 20:50:18 +00:00
|
|
|
|
val emptyXmiContent = { packages = nil,
|
|
|
|
|
constraints = nil,
|
|
|
|
|
classifiers = nil,
|
|
|
|
|
stereotypes = nil,
|
|
|
|
|
variable_declarations = nil }
|
|
|
|
|
|
|
|
|
|
fun findXmiContent tree = valOf (XmlTree.dfs "XMI.content" tree)
|
|
|
|
|
handle Option => raise IllFormed "in findXmiContent: did not find XMI.content"
|
2005-08-17 15:45:10 +00:00
|
|
|
|
|
2005-08-20 20:50:18 +00:00
|
|
|
|
fun readFile f = (mkXmiContent o findXmiContent o ParseXmlTree.readFile) f
|
2005-08-23 08:03:09 +00:00
|
|
|
|
handle XmlTree.IllFormed msg => (print ("Warning: "^msg^"\n"); emptyXmiContent)
|
2005-08-23 09:13:15 +00:00
|
|
|
|
| IllFormed msg => (print ("Warning: "^msg^"\n"); emptyXmiContent)
|
2005-08-17 15:45:10 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|