2007-06-12 18:51:39 +00:00
|
|
|
(*****************************************************************************
|
2016-10-23 23:35:11 +00:00
|
|
|
* su4sml --- an SML repository for managing (Secure)UML/OCL models
|
2007-07-04 06:41:30 +00:00
|
|
|
* http://projects.brucker.ch/su4sml/
|
2007-06-12 18:51:39 +00:00
|
|
|
*
|
2007-07-04 06:41:30 +00:00
|
|
|
* model_import.sml ---
|
|
|
|
* This file is part of su4sml.
|
2007-06-12 18:51:39 +00:00
|
|
|
*
|
2007-07-04 06:41:30 +00:00
|
|
|
* Copyright (c) 2005-2007, ETH Zurich, Switzerland
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials provided
|
|
|
|
* with the distribution.
|
|
|
|
*
|
|
|
|
* * Neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
******************************************************************************)
|
|
|
|
(* $Id$ *)
|
2007-06-12 18:51:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
signature MODEL_IMPORT =
|
|
|
|
sig
|
2007-09-26 07:55:59 +00:00
|
|
|
val parseUML : string -> Rep_Core.transform_model
|
2007-06-12 18:51:39 +00:00
|
|
|
val parseOCL : string -> Context.context list
|
2008-04-03 12:26:02 +00:00
|
|
|
val parseModel : string -> Rep_Core.Classifier list
|
2007-09-26 07:55:59 +00:00
|
|
|
val import : string -> string -> string list -> Rep_Core.transform_model
|
2008-03-30 11:36:01 +00:00
|
|
|
val removePackages : string list -> Rep_Core.transform_model
|
|
|
|
-> Rep_Core.transform_model
|
|
|
|
val removeOclLibrary : Rep_Core.Classifier list -> Rep_Core.Classifier list
|
2007-06-12 18:51:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
structure ModelImport : MODEL_IMPORT =
|
|
|
|
struct
|
|
|
|
(* basic library *)
|
|
|
|
open List
|
|
|
|
open Posix.Error
|
2008-03-17 13:53:09 +00:00
|
|
|
|
|
|
|
(* su4sml *)
|
|
|
|
open Rep_Core
|
2007-06-12 18:51:39 +00:00
|
|
|
|
|
|
|
(* OclParser *)
|
|
|
|
open Context
|
|
|
|
open TypeChecker
|
|
|
|
open Update_Model
|
|
|
|
|
2007-09-26 07:55:59 +00:00
|
|
|
(* Rep_Transform *)
|
|
|
|
(* FIXME: library consolidation? *)
|
|
|
|
open Rep_Transform
|
|
|
|
|
2007-06-12 18:51:39 +00:00
|
|
|
|
|
|
|
(* Error logging *)
|
|
|
|
val high = 5
|
|
|
|
val medium = 20
|
|
|
|
val low = 100
|
|
|
|
|
|
|
|
fun readFileUnNormalized f =
|
2007-09-26 07:55:59 +00:00
|
|
|
(RepParser.transformXMI_ext o XmiParser.readFile) f
|
2007-06-12 18:51:39 +00:00
|
|
|
|
|
|
|
fun importArgoUMLUnNormalized file =
|
|
|
|
let
|
|
|
|
fun basename f = ((hd o rev) o (String.fields (fn x => x = #"/"))) f
|
|
|
|
|
|
|
|
val tmpFile = OS.FileSys.tmpName ()
|
|
|
|
val base = if String.isSuffix ".zargo" file
|
|
|
|
then String.substring(file,0, (String.size file) -6)
|
|
|
|
else file
|
2009-01-04 18:04:16 +00:00
|
|
|
val _ = Logger.debug1 ("*** Syscall: "^Config.unzip^" -p -ca "^base^".zargo "^(basename base)^".xmi > "^tmpFile)
|
|
|
|
val _ = OS.Process.system (Config.unzip^" -p -ca "^base^".zargo "^(basename base)^".xmi > "^tmpFile)
|
2007-06-12 18:51:39 +00:00
|
|
|
val model = readFileUnNormalized tmpFile
|
2009-01-04 18:04:16 +00:00
|
|
|
handle e => (OS.FileSys.remove tmpFile; raise e)
|
2007-06-12 18:51:39 +00:00
|
|
|
val _ = OS.FileSys.remove tmpFile
|
|
|
|
|
2008-02-01 10:44:04 +00:00
|
|
|
|
2007-06-12 18:51:39 +00:00
|
|
|
in
|
|
|
|
model
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun parseUML umlFile =
|
|
|
|
let
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info "### Parsing UML Model ###\n"
|
2007-06-12 18:51:39 +00:00
|
|
|
val umlModel = if String.isSuffix ".zargo" umlFile
|
|
|
|
then importArgoUMLUnNormalized umlFile
|
|
|
|
else readFileUnNormalized umlFile
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info ("### Finished Parsing UML Model ("
|
2007-09-26 07:55:59 +00:00
|
|
|
^(Int.toString(length (#1 umlModel)))
|
2007-06-12 18:51:39 +00:00
|
|
|
^" Classifiers found)###\n\n")
|
|
|
|
in
|
|
|
|
umlModel
|
|
|
|
end
|
|
|
|
|
|
|
|
fun parseOCL oclFile =
|
|
|
|
let
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info "### Parsing OCL File ###\n"
|
2008-04-03 12:26:02 +00:00
|
|
|
val context_classes = case oclFile of
|
|
|
|
"" => ([],[])
|
2007-06-12 18:51:39 +00:00
|
|
|
| filename => OclParser.parse_contextlist oclFile;
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info ("### Finished Parsing OCL File ("
|
2008-04-03 12:26:02 +00:00
|
|
|
^(Int.toString(length (#1 context_classes)))
|
2007-06-12 18:51:39 +00:00
|
|
|
^" Constraints Found) ###\n\n")
|
|
|
|
in
|
2008-04-03 12:26:02 +00:00
|
|
|
(#1 context_classes)
|
|
|
|
end
|
|
|
|
|
|
|
|
fun parseModel oclFile =
|
|
|
|
let
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info "### Parsing OCL File ###\n"
|
2008-04-03 12:26:02 +00:00
|
|
|
val context_classes = case oclFile of
|
|
|
|
"" => ([],[])
|
|
|
|
| filename => OclParser.parse_contextlist oclFile;
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info ("### Finished Parsing OCL File ("
|
2008-04-03 12:26:02 +00:00
|
|
|
^(Int.toString(length (#2 context_classes)))
|
|
|
|
^" Constraints Found) ###\n\n")
|
|
|
|
in
|
|
|
|
(#2 context_classes)
|
2007-06-12 18:51:39 +00:00
|
|
|
end
|
2008-03-30 11:36:01 +00:00
|
|
|
|
|
|
|
fun removePackages packageList (cl,al) =
|
|
|
|
let
|
|
|
|
fun filter_package_assoc model p = filter
|
|
|
|
(fn a => not ((rev o tl o rev) (Rep_Core.name_of_association a) = p)) model
|
|
|
|
fun filter_package model p = filter (fn cl => not (Rep_Core.package_of cl = p)) model
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info "### Excluding Packages ###\n"
|
2008-03-30 11:36:01 +00:00
|
|
|
fun stringToPath s = (String.tokens (fn s => (s = (#":"))) s)
|
|
|
|
val cl =foldr (fn (p,m) => filter_package m (stringToPath p)) cl packageList
|
|
|
|
val al =foldr (fn (p,m) => filter_package_assoc m (stringToPath p)) al packageList
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info ("### Finished excluding Packages ("
|
2008-03-30 11:36:01 +00:00
|
|
|
^(Int.toString(length cl))
|
|
|
|
^ " Classifiers found ###\n\n")
|
|
|
|
(* TODO: Implement check for dangeling references/Types and Ocl Expressions *)
|
|
|
|
in
|
|
|
|
(cl,al)
|
|
|
|
end
|
|
|
|
|
2008-01-27 15:36:57 +00:00
|
|
|
|
2008-03-30 11:36:01 +00:00
|
|
|
fun removeOclLibrary (model) =
|
2007-06-12 18:51:39 +00:00
|
|
|
let
|
|
|
|
fun filter_template model =
|
|
|
|
let
|
|
|
|
fun is_template (Rep_Core.Template _) = true
|
|
|
|
| is_template _ = false
|
|
|
|
in
|
|
|
|
filter (not o is_template) model
|
|
|
|
end
|
|
|
|
fun filter_oclLib model = filter (not o OclLibrary.is_oclLib) model
|
|
|
|
in
|
2008-03-30 11:36:01 +00:00
|
|
|
((filter_oclLib o filter_template) model)
|
2007-06-12 18:51:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
fun import xmifile oclfile excludePackages =
|
|
|
|
let
|
|
|
|
val xmi = parseUML xmifile
|
2009-01-03 21:18:36 +00:00
|
|
|
(* val _ = init_offset() *)
|
2007-06-12 18:51:39 +00:00
|
|
|
val ocl = parseOCL oclfile
|
2008-03-30 11:36:01 +00:00
|
|
|
val (xmi_cls, xmi_assocs) = xmi
|
2009-01-03 21:18:36 +00:00
|
|
|
(* val _ = init_offset() *)
|
2007-06-12 18:51:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
val model = case ocl of
|
2008-03-30 11:36:01 +00:00
|
|
|
[] => (xmi_cls,xmi_assocs)
|
2007-06-12 18:51:39 +00:00
|
|
|
| ocl => let
|
2009-01-03 21:18:36 +00:00
|
|
|
(* val _ = init_offset() *)
|
2008-03-26 17:14:30 +00:00
|
|
|
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info "### Preprocess Context List ###\n"
|
2007-09-26 07:55:59 +00:00
|
|
|
val fixed_ocl = Preprocessor.preprocess_context_list ocl ((OclLibrary.oclLib)@xmi_cls)
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info "### Finished Preprocess Context List ###\n\n"
|
|
|
|
(* val _ = init_offset() *)
|
2007-06-12 18:51:39 +00:00
|
|
|
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info "### Type Checking ###\n"
|
2007-09-26 07:55:59 +00:00
|
|
|
val typed_cl = TypeChecker.check_context_list fixed_ocl (((OclLibrary.oclLib)@xmi_cls),xmi_assocs);
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info "### Finished Type Checking ###\n\n"
|
|
|
|
(* val _ = init_offset() *)
|
2007-06-12 18:51:39 +00:00
|
|
|
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info "### Updating Classifier List ###\n"
|
2007-09-26 07:55:59 +00:00
|
|
|
val model = Update_Model.gen_updated_classifier_list typed_cl ((OclLibrary.oclLib)@xmi_cls);
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info ("### Finished Updating Classifier List "
|
2007-06-12 18:51:39 +00:00
|
|
|
^(Int.toString(length model))
|
|
|
|
^ " Classifiers found (11 from 'oclLib') ###\n")
|
2009-01-03 21:18:36 +00:00
|
|
|
(* val _ = init_offset() *)
|
2007-06-12 18:51:39 +00:00
|
|
|
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info "### Fixing Types ###\n"
|
2007-06-12 18:51:39 +00:00
|
|
|
val model = removeOclLibrary model
|
2008-03-30 11:36:01 +00:00
|
|
|
val model = removePackages excludePackages (model,xmi_assocs)
|
2008-03-11 00:19:37 +00:00
|
|
|
(*
|
2007-06-12 18:51:39 +00:00
|
|
|
val model = FixTyping.transform_ocl_spec FixTyping.transformForHolOcl model
|
2008-03-11 00:19:37 +00:00
|
|
|
*)
|
2009-01-03 21:18:36 +00:00
|
|
|
val _ = Logger.info "### Finished Fixing Types ###\n\n"
|
2007-06-12 18:51:39 +00:00
|
|
|
in
|
|
|
|
model
|
|
|
|
end
|
|
|
|
|
|
|
|
in
|
2007-09-26 07:55:59 +00:00
|
|
|
(* FIXME: propagate associations into the ocl_parser *)
|
2008-03-30 11:36:01 +00:00
|
|
|
model
|
2007-06-12 18:51:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|