// UML Model Transformation Tool (UMT)
// Copyright (C) 2003, 2004, 2005 SINTEF
// Authors: jon.oldevik at sintef.no | roy.gronmo at sintef.no | tor.neple at sintef.no | fredrik.vraalsen at sintef.no
// Webpage: http://umt.sourceforge.net
// Deloped in the projects: ACEGIS (EU project - IST-2002-37724),
// CAFE (EUREKA/ITEA - ip00004), FAMILIES (ITEA project ip02009)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 2.1
// of the License, or (at your option) any later version.
//
// This program 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser 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
package org.sintef.umt.transgen;
/**
* @author Tor Neple, tne@sintef.no
* copyright (c) 2002, SINTEF
*/
import org.sintef.umt.propertyeditor.PropertyGroup;
import org.sintef.umt.propertyeditor.PropertyManager;
import org.sintef.umt.transgen.XmiSchema;
import org.w3c.dom.Document;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.util.*;
public class XmiSchemaManager {
/**
* Gets all of the names of the classes and datatypes defined in the model stored in the
* complexTypes parameter.
*/
private Vector getNamesOfClassesAndDataTypes(NodeList complexTypes){
Vector retval = new Vector();
Element buffer = null;
for (int i = 0 ; i < complexTypes.getLength(); i ++){
buffer = (Element)complexTypes.item(i);
retval.add(new String(buffer.getAttribute("name")));
}
return retval;
}
public XmiSchema addTypesFromModel(Document model, XmiSchema schema){
Element modelRoot = null;
NodeList classNodes = null;
NodeList typeNodes = null;
modelRoot = model.getDocumentElement();
classNodes = model.getElementsByTagName("class");
typeNodes = model.getElementsByTagName("datatype");
Vector allTheTypes = getNamesOfClassesAndDataTypes(classNodes);
allTheTypes.addAll(getNamesOfClassesAndDataTypes(typeNodes));
Iterator it = allTheTypes.iterator();
while (it.hasNext()){
schema.addValidType((String)it.next());
}
return schema;
}
public XmiSchema addTypesFromModel(String HutnModelFile, XmiSchema schema){
Document model = null;
Element modelRoot = null;
NodeList classNodes = null;
NodeList typeNodes = null;
// Open the modelfile. The modelfile is to be in XMI-light format.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
model = builder.parse( HutnModelFile);
}
catch(Exception e){
System.out.println("DOMXmiSchema::DOMXmiSchema() --> " + e);
}
modelRoot = model.getDocumentElement();
classNodes = model.getElementsByTagName("class");
typeNodes = model.getElementsByTagName("datatype");
Vector allTheTypes = getNamesOfClassesAndDataTypes(classNodes);
allTheTypes.addAll(getNamesOfClassesAndDataTypes(typeNodes));
Iterator it = allTheTypes.iterator();
while (it.hasNext()){
schema.addValidType((String)it.next());
}
return schema;
}
public XmiSchema augumentSchemaFromProfile(PropertyGroup profile, XmiSchema theSchema){
// Find the xsd:simpleType node with the name attribute equalling enumPackageStereoTypeType
// Get hold of all of the items for the <<package>> stereotype
// Map packageMap = profile.getAllPropertiesForStereotypedItem(profile.getName(),"package");
Map packageMap = profile.getProperties();
Iterator it = null;
it = packageMap.keySet().iterator();
String key = null;
String val[];
while (it.hasNext()){
key = (String)it.next();
val = (String[])packageMap.get(key);
// System.out.println(key + " " + val[0]);
if (val[0].equalsIgnoreCase("package"))
theSchema.addValidStereotypeForItem("enumPackageStereoTypeType",key);
else if (val[0].equalsIgnoreCase("class"))
theSchema.addValidStereotypeForItem("enumClassStereoTypeType",key);
else if (val[0].equalsIgnoreCase("model"))
theSchema.addValidStereotypeForItem("enumModelStereoTypeType",key);
else if (val[0].equalsIgnoreCase("operation"))
theSchema.addValidStereotypeForItem("enumOperationStereoTypeType",key);
else if (val[0].equalsIgnoreCase("dependency"))
theSchema.addValidStereotypeForItem("enumAssociationStereoTypeType",key);
}
// Then to do basic type set. This is stored in the <PropertyGroup item="types" name="types" stereotype="" type="types">
Map types = profile.getAllPropertiesForItem("types");
// For the time being, the types are stored in the types variable
// The extxmi.xsd schema needs to be changed so there is a smart place to add these types
it = types.keySet().iterator();
while (it.hasNext()){
key = (String)it.next();
val = (String[])packageMap.get(key);
theSchema.addValidType(key);
}
return theSchema;
}
public XmiSchema augumentSchemaFromProfile(String profileFile, String profileName, XmiSchema theSchema){
PropertyManager pm = new PropertyManager(profileFile);
pm.loadProperties();
// Find the xsd:simpleType node with the name attribute equalling enumPackageStereoTypeType
// Get hold of all of the items for the <<package>> stereotype
Map packageMap = pm.getPropertiesForStereotypedItem(profileName,"package");
Iterator it = null;
it = packageMap.keySet().iterator();
String key = null;
String val[];
while (it.hasNext()){
key = (String)it.next();
val = (String[])packageMap.get(key);
// System.out.println(key + " " + val[0]);
if (val[0].equalsIgnoreCase("package"))
theSchema.addValidStereotypeForItem("enumPackageStereoTypeType",key);
else if (val[0].equalsIgnoreCase("class"))
theSchema.addValidStereotypeForItem("enumClassStereoTypeType",key);
else if (val[0].equalsIgnoreCase("model"))
theSchema.addValidStereotypeForItem("enumModelStereoTypeType",key);
else if (val[0].equalsIgnoreCase("operation"))
theSchema.addValidStereotypeForItem("enumOperationStereoTypeType",key);
else if (val[0].equalsIgnoreCase("dependency"))
theSchema.addValidStereotypeForItem("enumAssociationStereoTypeType",key);
}
// Then to do basic type set. This is stored in the <PropertyGroup item="types" name="types" stereotype="" type="types">
PropertyGroup profile = pm.getPropertyGroupForItem (profileName);
Map types = profile.getAllPropertiesForItem("types");
// For the time being, the types are stored in the types variable
// The extxmi.xsd schema needs to be changed so there is a smart place to add these types
it = types.keySet().iterator();
while (it.hasNext()){
key = (String)it.next();
val = (String[])packageMap.get(key);
theSchema.addValidType(key);
}
return theSchema;
}
}