uml2mof transformer QBE200301220100-BLD200301241017
authormmatula@netbeans.org
Mon, 20 Jan 2003 22:53:26 +0000
changeset 1173441aa750e214
parent 1172 bb832da9daa0
child 1174 9fdd8dbb5b15
uml2mof transformer
mdr/extras/uml2mof/build.xml
mdr/extras/uml2mof/manifest.mf
mdr/extras/uml2mof/src/org/netbeans/lib/jmi/uml2mof/Main.java
mdr/extras/uml2mof/src/org/netbeans/lib/jmi/uml2mof/Transformer.java
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mdr/extras/uml2mof/build.xml	Mon Jan 20 22:53:26 2003 +0000
     1.3 @@ -0,0 +1,140 @@
     1.4 +<?xml version="1.0" encoding="UTF-8"?>
     1.5 +<!--
     1.6 +                Sun Public License Notice
     1.7 +
     1.8 +The contents of this file are subject to the Sun Public License
     1.9 +Version 1.0 (the "License"). You may not use this file except in
    1.10 +compliance with the License. A copy of the License is available at
    1.11 +http://www.sun.com/
    1.12 +
    1.13 +The Original Code is NetBeans. The Initial Developer of the Original
    1.14 +Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
    1.15 +Microsystems, Inc. All Rights Reserved.
    1.16 +-->
    1.17 +
    1.18 +<project name="uml2mof" basedir="." default="jars">
    1.19 +  <!-- =========================================================== -->
    1.20 +  <!-- == Properties ============================================= -->
    1.21 +  <!-- =========================================================== -->
    1.22 +  <property file="ant.properties"/>
    1.23 +  <property name="nbroot" location="../../../"/>
    1.24 +  <property name="nbext" location="${nbroot}/nbbuild"/>
    1.25 +  <property name="build.compiler.debug" value="true"/>
    1.26 +  <property name="build.compiler.deprecation" value="true"/>
    1.27 +  <property name="homepage.base" value="netbeans.org"/>
    1.28 +  <property name="dist.base" value="www.netbeans.org/download/nbms/40/MDR"/>
    1.29 +  <property name="build.dir" location="release"/>
    1.30 +  <property name="build.classes.dir" location="src"/>
    1.31 +
    1.32 +  <!-- all external files and directories -->
    1.33 +  <!--property name="nbantext.jar" location="${nbext}/nbantext.jar"/-->
    1.34 +  <property name="openide-lookup.jar" location="${nbroot}/openide/standalone/openide-lookup.jar"/>
    1.35 +  <property name="standard-jar-excludes.txt" location="${nbroot}/nbbuild/standard-jar-excludes.txt"/>
    1.36 +  <property name="standard-nbm-license.txt" location="${nbroot}/nbbuild/standard-nbm-license.txt"/>
    1.37 +  <property name="xml-apis.jar" location="${nbroot}/core/netbeans/lib/ext/xml-apis-1.0b2.jar"/>
    1.38 +  <property name="xmlparser.jar" location="${nbroot}/core/netbeans/lib/ext/crimson-1.1.3.jar"/>
    1.39 +  <property name="jmi.jar" location="${nbroot}/mdr/netbeans/modules/autoload/jmi.jar"/>
    1.40 +  <property name="mof.jar" location="${nbroot}/mdr/netbeans/modules/autoload/mof.jar"/>
    1.41 +  <property name="mdrapi.jar" location="${nbroot}/mdr/netbeans/modules/autoload/mdrapi.jar"/>
    1.42 +  <property name="jmiutils.jar" location="${nbroot}/mdr/netbeans/modules/autoload/ext/jmiutils.jar"/>
    1.43 +  <property name="nbmdr.jar" location="${nbroot}/mdr/netbeans/modules/ext/nbmdr.jar"/>
    1.44 +  <property name="umlclasses.dir" location="uml"/>
    1.45 +  <property name="umlmetamodel.xml" location="uml/01-02-15.xml"/>
    1.46 +  <property name="umlmetamodel.diff" location="${nbroot}/mdr/xmidiffs/01-02-15_Diff.xml"/>
    1.47 +  
    1.48 +  <!-- =========================================================== -->
    1.49 +  <!-- == Taskdefs =============================================== -->
    1.50 +  <!-- =========================================================== -->
    1.51 +
    1.52 +  <!--taskdef name="makenbm" classname="org.netbeans.nbbuild.MakeNBM" classpath="${nbantext.jar}"/-->
    1.53 +  <!--taskdef name="genlist" classname="org.netbeans.nbbuild.MakeListOfNBM" classpath="${nbantext.jar}"/-->
    1.54 +  <!--taskdef name="locjar" classname="org.netbeans.nbbuild.LocalizedJar" classpath="${nbantext.jar}"/-->
    1.55 +
    1.56 +  <!-- =========================================================== -->
    1.57 +  <!-- == Initialization ========================================= -->
    1.58 +  <!-- =========================================================== -->
    1.59 +
    1.60 +  <target name="init">
    1.61 +    <!--tstamp>
    1.62 +    	<format property="buildnumber" pattern="yyyyMMddHHmm"/>
    1.63 +    </tstamp>
    1.64 +    <property name="buildnumber" value="${DSTAMP}-${TSTAMP}"/>
    1.65 +    <echo message="buildnumber = ${buildnumber}"/-->
    1.66 +    
    1.67 +    <mkdir dir="${build.classes.dir}"/>
    1.68 +
    1.69 +    <!--ant dir="external" target="unscramble"/-->
    1.70 +  </target>
    1.71 +
    1.72 +  <!-- =========================================================== -->
    1.73 +  <!-- == Compilation of all parts =============================== -->
    1.74 +  <!-- =========================================================== -->
    1.75 +
    1.76 +  <target name="compile" depends="init">
    1.77 +    <!-- sources -->
    1.78 +    <javac srcdir="src" destdir="${build.classes.dir}"
    1.79 +           debug="${build.compiler.debug}" 
    1.80 +           deprecation="${build.compiler.deprecation}">
    1.81 +      <classpath>
    1.82 +        <pathelement location="${openide-lookup.jar}"/>
    1.83 +        <pathelement location="${xml-apis.jar}"/>
    1.84 +        <pathelement location="${jmi.jar}"/>
    1.85 +        <pathelement location="${mof.jar}"/>
    1.86 +        <pathelement location="${mdrapi.jar}"/>
    1.87 +        <pathelement location="${umlclasses.dir}"/>
    1.88 +      </classpath>
    1.89 +    </javac>    
    1.90 +  </target>
    1.91 +  
    1.92 +  <!-- =========================================================== -->
    1.93 +  <!-- == Creating all mdr jars ================================== -->
    1.94 +  <!-- =========================================================== -->
    1.95 +
    1.96 +  <target name="jars" depends="compile">
    1.97 +    <mkdir dir="${build.dir}"/>
    1.98 +
    1.99 +    <mkdir dir="${umlclasses.dir}/org/omg/uml/resources"/>
   1.100 +    <copy file="${umlmetamodel.xml}" todir="${umlclasses.dir}/org/omg/uml/resources"/>
   1.101 +    <copy file="${umlmetamodel.diff}" todir="${umlclasses.dir}/org/omg/uml/resources"/>
   1.102 +
   1.103 +    <jar jarfile="${build.dir}/uml-1.4.jar" compress="false">
   1.104 +      <fileset dir="${umlclasses.dir}" excludesfile="${standard-jar-excludes.txt}">
   1.105 +        <include name="org/omg/uml/"/>
   1.106 +      </fileset>
   1.107 +    </jar>
   1.108 +    
   1.109 +    <copy file="${xmlparser.jar}" todir="${build.dir}"/>
   1.110 +    <copy file="${jmi.jar}" todir="${build.dir}"/>
   1.111 +    <copy file="${mof.jar}" todir="${build.dir}"/>
   1.112 +    <copy file="${mdrapi.jar}" todir="${build.dir}"/>
   1.113 +    <copy file="${nbmdr.jar}" todir="${build.dir}"/>
   1.114 +    <copy file="${jmiutils.jar}" todir="${build.dir}"/>
   1.115 +    <copy file="${xml-apis.jar}" todir="${build.dir}"/>
   1.116 +    <copy file="${openide-lookup.jar}" todir="${build.dir}"/>
   1.117 +
   1.118 +    <jar jarfile="${build.dir}/uml2mof.jar" compress="false" manifest="manifest.mf">
   1.119 +      <fileset dir="${build.classes.dir}" excludesfile="${standard-jar-excludes.txt}">
   1.120 +        <include name="org/netbeans/lib/jmi/uml2mof"/>
   1.121 +      </fileset>
   1.122 +      <fileset dir="src" excludesfile="${standard-jar-excludes.txt}">
   1.123 +        <include name="org/netbeans/lib/jmi/uml2mof/"/>
   1.124 +      </fileset>
   1.125 +    </jar>
   1.126 +  </target>
   1.127 +
   1.128 +  <!-- =========================================================== -->
   1.129 +  <!-- == Cleaning compiled stuff ================================ -->
   1.130 +  <!-- =========================================================== -->
   1.131 +
   1.132 +  <target name="clean" description="Removes all build products.">
   1.133 +    <delete>
   1.134 +      <fileset dir="${build.classes.dir}">
   1.135 +        <include name="**/*.class"/>
   1.136 +      </fileset>
   1.137 +    </delete>
   1.138 +    <delete dir="${umlclasses.dir}/org/omg/uml/resouces"/>
   1.139 +    <delete dir="${build.dir}"/>
   1.140 +    <delete file="manifest.mf"/>
   1.141 +  </target>
   1.142 +
   1.143 +</project>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/mdr/extras/uml2mof/manifest.mf	Mon Jan 20 22:53:26 2003 +0000
     2.3 @@ -0,0 +1,3 @@
     2.4 +Manifest-Version: 1.0
     2.5 +Class-Path: uml-1.4.jar crimson-1.1.3.jar jmi.jar mof.jar mdrapi.jar nbmdr.jar jmiutils.jar xml-apis-1.0b2.jar openide-lookup.jar
     2.6 +Main-Class: org.netbeans.lib.jmi.uml2mof.Main
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/mdr/extras/uml2mof/src/org/netbeans/lib/jmi/uml2mof/Main.java	Mon Jan 20 22:53:26 2003 +0000
     3.3 @@ -0,0 +1,102 @@
     3.4 +/*
     3.5 + *                 Sun Public License Notice
     3.6 + *
     3.7 + * The contents of this file are subject to the Sun Public License
     3.8 + * Version 1.0 (the "License"). You may not use this file except in
     3.9 + * compliance with the License. A copy of the License is available at
    3.10 + * http://www.sun.com/
    3.11 + *
    3.12 + * The Original Code is NetBeans. The Initial Developer of the Original
    3.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
    3.14 + * Microsystems, Inc. All Rights Reserved.
    3.15 + */
    3.16 +package org.netbeans.lib.jmi.uml2mof;
    3.17 +
    3.18 +import java.io.File;
    3.19 +import java.io.FileOutputStream;
    3.20 +import java.util.Iterator;
    3.21 +import javax.jmi.model.ModelPackage;
    3.22 +import javax.jmi.model.MofPackage;
    3.23 +import javax.jmi.xmi.XmiReader;
    3.24 +import javax.jmi.xmi.XmiWriter;
    3.25 +import org.netbeans.api.mdr.MDRManager;
    3.26 +import org.netbeans.api.mdr.MDRepository;
    3.27 +import org.omg.uml.UmlPackage;
    3.28 +import org.openide.ErrorManager;
    3.29 +import org.openide.util.Lookup;
    3.30 +
    3.31 +/**
    3.32 + *
    3.33 + * @author  mm109185
    3.34 + */
    3.35 +public class Main {
    3.36 +    private static final String MOF_INSTANCE = "MOFInstance";
    3.37 +    private static final String UML_INSTANCE = "UMLInstance";
    3.38 +    private static final String UML_MM = "UML";
    3.39 +    
    3.40 +    public static MDRepository rep;
    3.41 +    public static UmlPackage uml;
    3.42 +    public static ModelPackage mof;
    3.43 +    public static XmiReader reader;
    3.44 +    
    3.45 +    /** Creates a new instance of Main */
    3.46 +    public Main() {
    3.47 +    }
    3.48 + 
    3.49 +    public static void main(String args[]) {
    3.50 +        try {
    3.51 +            rep = MDRManager.getDefault().getDefaultRepository();
    3.52 +            String uri = new File(args[0]).toURL().toString();
    3.53 +            FileOutputStream out = new FileOutputStream(args[1]);
    3.54 +            reader = (XmiReader) Lookup.getDefault().lookup(XmiReader.class);
    3.55 +            XmiWriter writer = (XmiWriter) Lookup.getDefault().lookup(XmiWriter.class);
    3.56 +            init();
    3.57 +            rep.beginTrans(true);
    3.58 +            try {
    3.59 +                reader.read(uri, uml);
    3.60 +                Transformer.execute(uml, mof);
    3.61 +                writer.write(out, mof, null);
    3.62 +            } finally {
    3.63 +                rep.endTrans(true);
    3.64 +                MDRManager.getDefault().shutdownAll();
    3.65 +                out.close();
    3.66 +            }
    3.67 +        } catch (Exception e) {
    3.68 +            ErrorManager.getDefault().notify(ErrorManager.ERROR, e);
    3.69 +        }
    3.70 +    }
    3.71 +    
    3.72 +    private static void init() throws Exception {
    3.73 +        mof = (ModelPackage) rep.getExtent(MOF_INSTANCE);
    3.74 +        uml = (UmlPackage) rep.getExtent(UML_INSTANCE);
    3.75 +        if (mof == null) {
    3.76 +            mof = (ModelPackage) rep.createExtent(MOF_INSTANCE);
    3.77 +        }
    3.78 +        if (uml == null) {
    3.79 +            uml = (UmlPackage) rep.createExtent(UML_INSTANCE, getUmlPackage());
    3.80 +        }
    3.81 +    }
    3.82 +    
    3.83 +    private static MofPackage getUmlPackage() throws Exception {
    3.84 +        ModelPackage umlMM = (ModelPackage) rep.getExtent(UML_MM);
    3.85 +        if (umlMM == null) {
    3.86 +            umlMM = (ModelPackage) rep.createExtent(UML_MM);
    3.87 +        }
    3.88 +        MofPackage result = getUmlPackage(umlMM);
    3.89 +        if (result == null) {
    3.90 +            reader.read(UmlPackage.class.getResource("resources/01-02-15_Diff.xml").toString(), umlMM);
    3.91 +        }
    3.92 +        result = getUmlPackage(umlMM);
    3.93 +        return result;
    3.94 +    }
    3.95 +    
    3.96 +    private static MofPackage getUmlPackage(ModelPackage umlMM) {
    3.97 +        for (Iterator it = umlMM.getMofPackage().refAllOfClass().iterator(); it.hasNext();) {
    3.98 +            MofPackage pkg = (MofPackage) it.next();
    3.99 +            if (pkg.getContainer() == null && "UML".equals(pkg.getName())) {
   3.100 +                return pkg;
   3.101 +            }
   3.102 +        }
   3.103 +        return null;
   3.104 +    }
   3.105 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/mdr/extras/uml2mof/src/org/netbeans/lib/jmi/uml2mof/Transformer.java	Mon Jan 20 22:53:26 2003 +0000
     4.3 @@ -0,0 +1,664 @@
     4.4 +/*
     4.5 + *                 Sun Public License Notice
     4.6 + *
     4.7 + * The contents of this file are subject to the Sun Public License
     4.8 + * Version 1.0 (the "License"). You may not use this file except in
     4.9 + * compliance with the License. A copy of the License is available at
    4.10 + * http://www.sun.com/
    4.11 + *
    4.12 + * The Original Code is NetBeans. The Initial Developer of the Original
    4.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
    4.14 + * Microsystems, Inc. All Rights Reserved.
    4.15 + */
    4.16 +package org.netbeans.lib.jmi.uml2mof;
    4.17 +
    4.18 +import java.util.ArrayList;
    4.19 +import java.util.Collection;
    4.20 +import java.util.HashMap;
    4.21 +import java.util.HashSet;
    4.22 +import java.util.Iterator;
    4.23 +import java.util.Map;
    4.24 +import java.util.NoSuchElementException;
    4.25 +import java.util.StringTokenizer;
    4.26 +import javax.jmi.model.AliasType;
    4.27 +import javax.jmi.model.Association;
    4.28 +import javax.jmi.model.Classifier;
    4.29 +import javax.jmi.model.CollectionType;
    4.30 +import javax.jmi.model.DirectionKind;
    4.31 +import javax.jmi.model.DirectionKindEnum;
    4.32 +import javax.jmi.model.EnumerationType;
    4.33 +import javax.jmi.model.Import;
    4.34 +import javax.jmi.model.ModelPackage;
    4.35 +import javax.jmi.model.MofClass;
    4.36 +import javax.jmi.model.MofException;
    4.37 +import javax.jmi.model.MofPackage;
    4.38 +import javax.jmi.model.MultiplicityType;
    4.39 +import javax.jmi.model.NameNotFoundException;
    4.40 +import javax.jmi.model.PrimitiveType;
    4.41 +import javax.jmi.model.PrimitiveTypeClass;
    4.42 +import javax.jmi.model.Reference;
    4.43 +import javax.jmi.model.ScopeKindEnum;
    4.44 +import javax.jmi.model.StructuralFeature;
    4.45 +import javax.jmi.model.StructureField;
    4.46 +import javax.jmi.model.StructureType;
    4.47 +import javax.jmi.model.Tag;
    4.48 +import javax.jmi.model.VisibilityKindEnum;
    4.49 +import javax.jmi.reflect.RefObject;
    4.50 +import org.omg.uml.behavioralelements.commonbehavior.UmlException;
    4.51 +import org.omg.uml.modelmanagement.UmlPackage;
    4.52 +import org.omg.uml.foundation.core.AStereotypeExtendedElement;
    4.53 +import org.omg.uml.foundation.core.AssociationEnd;
    4.54 +import org.omg.uml.foundation.core.Attribute;
    4.55 +import org.omg.uml.foundation.core.DataType;
    4.56 +import org.omg.uml.foundation.core.Dependency;
    4.57 +import org.omg.uml.foundation.core.Element;
    4.58 +import org.omg.uml.foundation.core.Enumeration;
    4.59 +import org.omg.uml.foundation.core.EnumerationLiteral;
    4.60 +import org.omg.uml.foundation.core.GeneralizableElement;
    4.61 +import org.omg.uml.foundation.core.Generalization;
    4.62 +import org.omg.uml.foundation.core.ModelElement;
    4.63 +import org.omg.uml.foundation.core.Namespace;
    4.64 +import org.omg.uml.foundation.core.Operation;
    4.65 +import org.omg.uml.foundation.core.Parameter;
    4.66 +import org.omg.uml.foundation.core.Stereotype;
    4.67 +import org.omg.uml.foundation.core.TaggedValue;
    4.68 +import org.omg.uml.foundation.core.UmlAssociation;
    4.69 +import org.omg.uml.foundation.core.UmlClass;
    4.70 +import org.omg.uml.foundation.datatypes.AggregationKind;
    4.71 +import org.omg.uml.foundation.datatypes.AggregationKindEnum;
    4.72 +import org.omg.uml.foundation.datatypes.ChangeableKindEnum;
    4.73 +import org.omg.uml.foundation.datatypes.Multiplicity;
    4.74 +import org.omg.uml.foundation.datatypes.MultiplicityRange;
    4.75 +import org.omg.uml.foundation.datatypes.OrderingKindEnum;
    4.76 +import org.omg.uml.foundation.datatypes.ParameterDirectionKind;
    4.77 +import org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum;
    4.78 +import org.omg.uml.modelmanagement.ElementImport;
    4.79 +import org.openide.ErrorManager;
    4.80 +
    4.81 +/**
    4.82 + *
    4.83 + * @author  mm109185
    4.84 + */
    4.85 +public class Transformer {
    4.86 +    // stereotypes
    4.87 +    private static final String STEREOTYPE_METAMODEL = "metamodel";
    4.88 +    private static final String STEREOTYPE_IMPLICIT = "implicit";
    4.89 +    private static final String STEREOTYPE_REFERENCE = "reference";
    4.90 +
    4.91 +    private static final String STEREOTYPE_ALIAS = "alias";
    4.92 +    private static final String STEREOTYPE_EXCEPTION = "exception";
    4.93 +    private static final String STEREOTYPE_STRUCTURE = "structure";
    4.94 +    private static final String STEREOTYPE_COLLECTION = "collection";
    4.95 +    private static final String STEREOTYPE_IMPORTS = "import";
    4.96 +    private static final String STEREOTYPE_CLUSTERS = "clustering";
    4.97 +    private static final String STEREOTYPE_SPECIALIZES = "subtyping";
    4.98 +    
    4.99 +    // tags
   4.100 +//    private static final String TAG_CLUSTERED_IMPORT = "org.omg.uml2mof.clusteredImport";
   4.101 +    private static final String TAG_IMPLICIT_REFERENCES = "org.omg.uml2mof.hasImplicitReferences";
   4.102 +    private static final String TAG_SINGLETON = "org.omg.uml2mof.isSingleton";
   4.103 +    private static final String TAG_ATTR_DERIVED = "org.omg.uml2mof.isDerived";
   4.104 +    private static final String TAG_UNIQUE = "org.omg.uml2mof.isUnique";
   4.105 +    private static final String TAG_REFERENCED_END = "org.omg.uml2mof.referencedEnd";
   4.106 +    private static final String TAG_MULTIPLICITY = "org.omg.uml2mof.multiplicity";
   4.107 +    private static final String TAG_ORDERED = "org.omg.uml2mof.isOrdered";
   4.108 +
   4.109 +    private static final String TAG_RAISED_EXCEPTIONS = "org.netbeans.uml2mof.raisedExceptions";
   4.110 +    private static final String TAG_ALIAS_FOR = "org.netbeans.uml2mof.aliasFor";
   4.111 +    private static final String TAG_ASSOC_DERIVED = "org.netbeans.uml2mof.isDerived";
   4.112 +    
   4.113 +    // special attributes
   4.114 +    private static final String ATTR_ITEMS = "items";
   4.115 +    
   4.116 +    private static final ErrorManager logger = ErrorManager.getDefault().getInstance("org.netbeans.lib.uml2mof.Logger");
   4.117 +    
   4.118 +    // source extent
   4.119 +    private final org.omg.uml.UmlPackage uml;
   4.120 +    // target extent
   4.121 +    private final ModelPackage mof;
   4.122 +    // cache of all stereotypes used in model
   4.123 +    private final HashMap stereotypes = new HashMap();
   4.124 +    // mapped elements (used for late resolution of supertypes, types and imports) (key=source, value=target)
   4.125 +    private final HashMap elements = new HashMap();
   4.126 +    // imports that should be resolved (key=imported element, value=list of imports)
   4.127 +//    private final HashMap imports = new HashMap();
   4.128 +    // registry of fully qualified names to resolve (key=object referencing elements identified by FQNs, value = list of FQNs)
   4.129 +    private final HashMap fqnsToResolve = new HashMap();
   4.130 +    // implicit references that should be added to the correct containers
   4.131 +    private final HashSet references = new HashSet();
   4.132 +    // PrimitiveTypes package
   4.133 +    private MofPackage primitivesPackage;
   4.134 +    // table of primitive types (key=type name, value=type)
   4.135 +    private HashMap primitives;
   4.136 +    // packages that need to import PrimitiveTypes package
   4.137 +    private final HashSet ptImports = new HashSet();
   4.138 +    
   4.139 +    // indicates, whether the package that is being processed has implicit references
   4.140 +    private boolean implicitReferences;
   4.141 +    // outermost package that is currently being processed
   4.142 +    private MofPackage outermost;
   4.143 +    
   4.144 +    /** Creates a new instance of Transformer */
   4.145 +    private Transformer(org.omg.uml.UmlPackage uml, ModelPackage mof) {
   4.146 +        this.uml = uml;
   4.147 +        this.mof = mof;
   4.148 +        // cache all the stereotypes
   4.149 +        for (Iterator it = uml.getCore().getStereotype().refAllOfClass().iterator(); it.hasNext();) {
   4.150 +            Stereotype temp = (Stereotype) it.next();
   4.151 +            stereotypes.put(temp.getName(), temp);
   4.152 +        }
   4.153 +    }
   4.154 +    
   4.155 +    public static void execute(org.omg.uml.UmlPackage uml, ModelPackage mof) {
   4.156 +        new Transformer(uml, mof).transform(); 
   4.157 +    }
   4.158 +    
   4.159 +    private void transform() {
   4.160 +        // get all outermost elements, and find all outermost models extended by metamodel stereotype
   4.161 +        for (Iterator it = uml.getCore().getNamespace().refAllOfType().iterator(); it.hasNext();) {
   4.162 +            Namespace temp = (Namespace) it.next();
   4.163 +            if (temp.getNamespace() == null) {
   4.164 +                lookForModel(temp);
   4.165 +            }
   4.166 +        }
   4.167 +        resolveTypes();
   4.168 +        resolveFQNs();
   4.169 +        resolveReferences();
   4.170 +        resolveImports();
   4.171 +    }
   4.172 +    
   4.173 +    private void resolveTypes() {
   4.174 +        info("*** Resolving types...");
   4.175 +        for (Iterator it = elements.entrySet().iterator(); it.hasNext();) {
   4.176 +            Map.Entry entry = (Map.Entry) it.next();
   4.177 +            if (entry.getKey() instanceof GeneralizableElement && entry.getValue() instanceof javax.jmi.model.GeneralizableElement) {
   4.178 +                GeneralizableElement ge = (GeneralizableElement) entry.getKey();
   4.179 +                Collection supertypes = ((javax.jmi.model.GeneralizableElement) entry.getValue()).getSupertypes();
   4.180 +                for (Iterator g = ge.getGeneralization().iterator(); g.hasNext();) {
   4.181 +                    Generalization temp = (Generalization) g.next();
   4.182 +                    supertypes.add(elements.get(temp.getParent()));
   4.183 +                }
   4.184 +            }
   4.185 +            if (entry.getKey() instanceof AssociationEnd) {
   4.186 +                ((javax.jmi.model.AssociationEnd) entry.getValue()).setType(mapType(((AssociationEnd) entry.getKey()).getParticipant(), entry.getValue()));
   4.187 +            } else if (entry.getKey() instanceof Attribute) {
   4.188 +                ((javax.jmi.model.TypedElement) entry.getValue()).setType(mapType(((Attribute) entry.getKey()).getType(), entry.getValue()));
   4.189 +            } else if (entry.getKey() instanceof Parameter) {
   4.190 +                ((javax.jmi.model.TypedElement) entry.getValue()).setType(mapType(((Parameter) entry.getKey()).getType(), entry.getValue()));
   4.191 +            }
   4.192 +        }
   4.193 +    }
   4.194 +    
   4.195 +    private void resolveFQNs() {
   4.196 +        info("*** Resolving FQNs");
   4.197 +        for (Iterator it = fqnsToResolve.entrySet().iterator(); it.hasNext();) {
   4.198 +            Map.Entry entry = (Map.Entry) it.next();
   4.199 +            if (entry.getKey() instanceof javax.jmi.model.Operation) {
   4.200 +                mapByFQNs(((javax.jmi.model.Operation) entry.getKey()).getExceptions(),(Collection) entry.getValue());
   4.201 +            } else if (entry.getKey() instanceof AliasType) {
   4.202 +                ((AliasType) entry.getKey()).setType((javax.jmi.model.Classifier) resolveFQN((String) ((Collection) entry.getValue()).iterator().next()));
   4.203 +            } else if (entry.getKey() instanceof Reference) {
   4.204 +                ((Reference) entry.getKey()).setReferencedEnd((javax.jmi.model.AssociationEnd) resolveFQN((String) ((Collection) entry.getValue()).iterator().next()));
   4.205 +            }
   4.206 +        }
   4.207 +    }
   4.208 +    
   4.209 +    private void resolveReferences() {
   4.210 +        info("*** Resolving references");
   4.211 +        for (Iterator it = elements.values().iterator(); it.hasNext();) {
   4.212 +            Object temp = it.next();
   4.213 +            if (temp instanceof Reference) {
   4.214 +                Reference ref = (Reference) temp;
   4.215 +                javax.jmi.model.AssociationEnd end = ref.getReferencedEnd();
   4.216 +                ref.setChangeable(end.isChangeable());
   4.217 +                ref.setMultiplicity(end.getMultiplicity());
   4.218 +                ref.setType(end.getType());
   4.219 +            }
   4.220 +        }
   4.221 +        for (Iterator it = references.iterator(); it.hasNext();) {
   4.222 +            Reference ref = (Reference) it.next();
   4.223 +            ref.setContainer(ref.getExposedEnd().getType());
   4.224 +            ref.setType(ref.getReferencedEnd().getType());
   4.225 +        }
   4.226 +    }
   4.227 +    
   4.228 +    private void resolveImports() {
   4.229 +        info("*** Resolving imports");
   4.230 +        for (Iterator it = ptImports.iterator(); it.hasNext();) {
   4.231 +            MofPackage pkg = (MofPackage) it.next();
   4.232 +            Import i = mof.getImport().createImport("PrimitiveTypes", "", VisibilityKindEnum.PUBLIC_VIS, false);
   4.233 +            i.setContainer(pkg);
   4.234 +            i.setImportedNamespace(primitivesPackage);
   4.235 +        }
   4.236 +        
   4.237 +        for (Iterator it = uml.getCore().getDependency().refAllOfClass().iterator(); it.hasNext();) {
   4.238 +            Dependency dep = (Dependency) it.next();
   4.239 +            Object client = elements.get(dep.getClient().iterator().next());
   4.240 +            Object supplier = elements.get(dep.getSupplier().iterator().next());
   4.241 +            if (client != null && supplier != null && client instanceof MofPackage && supplier instanceof MofPackage) {
   4.242 +                if (isOfType(dep, STEREOTYPE_IMPORTS) || isOfType(dep, STEREOTYPE_CLUSTERS)) {
   4.243 +                    Import i = mof.getImport().createImport(dep.getName(), getAnnotation(dep), VisibilityKindEnum.PUBLIC_VIS, isOfType(dep, STEREOTYPE_CLUSTERS));
   4.244 +                    i.setContainer((MofPackage) client);
   4.245 +                    i.setImportedNamespace((MofPackage) supplier);
   4.246 +                } else if (isOfType(dep, STEREOTYPE_SPECIALIZES)) {
   4.247 +                    ((MofPackage) client).getSupertypes().add((MofPackage) supplier);
   4.248 +                }
   4.249 +            }
   4.250 +        }
   4.251 +    }
   4.252 +    
   4.253 +    private void lookForModel(Namespace ns) {
   4.254 +        if (ns instanceof UmlPackage && isOfType(ns, STEREOTYPE_METAMODEL)) {
   4.255 +            info("*** Outermost package found: " + ns.getName());
   4.256 +            transform((UmlPackage) ns, null);
   4.257 +        } else {
   4.258 +            for (Iterator it = ns.getOwnedElement().iterator(); it.hasNext();) {
   4.259 +                Object temp = it.next();
   4.260 +                if (temp instanceof Namespace) lookForModel((Namespace) temp);
   4.261 +            }
   4.262 +        }
   4.263 +    }
   4.264 +
   4.265 +    ///////////////////////////////////////////////////////////////////////////////
   4.266 +    // Transformation Methods
   4.267 +    ///////////////////////////////////////////////////////////////////////////////
   4.268 +    private void transformPackage(UmlPackage model, MofPackage container) {
   4.269 +        if (elements.containsKey(model)) return;
   4.270 +
   4.271 +        // create corresponding MofPackage
   4.272 +        // [PENDING] visibility is always set to PUBLIC_VIS
   4.273 +        info("transforming package: " + model.getName());
   4.274 +        MofPackage pkg = mof.getMofPackage().createMofPackage(model.getName(), getAnnotation(model), model.isRoot(), model.isLeaf(), model.isAbstract(), VisibilityKindEnum.PUBLIC_VIS);
   4.275 +        pkg.setContainer(container);
   4.276 +        elements.put(model, pkg);
   4.277 +        
   4.278 +        if (container == null) {
   4.279 +            implicitReferences = true;
   4.280 +            outermost = pkg;
   4.281 +            implicitReferences = "true".equals(getTagValue(model, TAG_IMPLICIT_REFERENCES, "true"));
   4.282 +        }
   4.283 +        
   4.284 +        // iterate through tagged values
   4.285 +        mapTags(model, pkg);
   4.286 +        
   4.287 +        // iterate through all imports
   4.288 +//        mapContent(model.getElementImport(), pkg);
   4.289 +        
   4.290 +        // iterate through content
   4.291 +        mapContent(model.getOwnedElement(), pkg);
   4.292 +    }
   4.293 +    
   4.294 +//    private void transform(ElementImport element, MofPackage container) {
   4.295 +//        if (elements.containsKey(element)) return;
   4.296 +//        
   4.297 +//        String name = element.getAlias();
   4.298 +//        Import i = mof.getImport().createImport(element.getAlias(), getAnnotation(element), VisibilityKindEnum.PUBLIC_VIS, clusteredImports.contains(element.getAlias()));
   4.299 +//        i.setContainer(outermost);
   4.300 +//        ModelElement imported = element.getImportedElement();
   4.301 +//        ArrayList list = (ArrayList) imports.get(imported);
   4.302 +//        if (list == null) {
   4.303 +//            list = new ArrayList();
   4.304 +//            imports.put(imported, list);
   4.305 +//        }
   4.306 +//        list.add(i);
   4.307 +//        elements.put(element, i);
   4.308 +//    }
   4.309 +    
   4.310 +    private void transformClass(UmlClass cls, javax.jmi.model.Namespace container) {
   4.311 +        if (elements.containsKey(cls)) return;
   4.312 +        
   4.313 +        javax.jmi.model.Namespace mofElement;
   4.314 +        if (isOfType(cls, STEREOTYPE_STRUCTURE)) {
   4.315 +            mofElement = mof.getStructureType().createStructureType(cls.getName(), getAnnotation(cls), true, true, false, VisibilityKindEnum.PUBLIC_VIS);
   4.316 +        } else if (isOfType(cls, STEREOTYPE_EXCEPTION)) {
   4.317 +            mofElement = mof.getMofException().createMofException(cls.getName(), getAnnotation(cls), ScopeKindEnum.CLASSIFIER_LEVEL, VisibilityKindEnum.PUBLIC_VIS);
   4.318 +        } else if (isOfType(cls, STEREOTYPE_COLLECTION)) {
   4.319 +            mofElement = mof.getCollectionType().createCollectionType(cls.getName(), getAnnotation(cls), true, true, false, VisibilityKindEnum.PUBLIC_VIS, null);
   4.320 +        } else {
   4.321 +            mofElement = mof.getMofClass().createMofClass(cls.getName(), getAnnotation(cls), cls.isRoot(), cls.isLeaf(), cls.isAbstract(), VisibilityKindEnum.PUBLIC_VIS, "true".equals(getTagValue(cls, TAG_SINGLETON, null)));
   4.322 +        }
   4.323 +        elements.put(cls, mofElement);
   4.324 +        mofElement.setContainer(container);
   4.325 +        mapTags(cls, mofElement);
   4.326 +        mapContent(cls.getOwnedElement(), mofElement);
   4.327 +        mapContent(cls.getFeature(), mofElement);
   4.328 +    }
   4.329 +    
   4.330 +//    private void transform(UmlException ex, javax.jmi.model.Namespace container) {
   4.331 +//        if (elements.containsKey(ex)) return;
   4.332 +//        
   4.333 +//        MofException mofEx = mof.getMofException().createMofException(ex.getName(), getAnnotation(ex), ScopeKindEnum.CLASSIFIER_LEVEL, VisibilityKindEnum.PUBLIC_VIS);
   4.334 +//        elements.put(ex, mofEx);
   4.335 +//        mofEx.setContainer(container);
   4.336 +//        mapTags(ex, mofEx);
   4.337 +//        mapContent(ex.getOwnedElement(), mofEx);
   4.338 +//        mapContent(ex.getFeature(), mofEx);
   4.339 +//    }
   4.340 +    
   4.341 +    private void transformEnum(Enumeration enum, javax.jmi.model.Namespace container) {
   4.342 +        if (elements.containsKey(enum)) return;
   4.343 +     
   4.344 +        EnumerationType mofEnum = mof.getEnumerationType().createEnumerationType(enum.getName(), getAnnotation(enum), true, true, false, VisibilityKindEnum.PUBLIC_VIS, null);
   4.345 +        elements.put(enum, mofEnum);
   4.346 +        mofEnum.setContainer(container);
   4.347 +        mapTags(enum, mofEnum);
   4.348 +        
   4.349 +        for (Iterator it = enum.getLiteral().iterator(); it.hasNext();) {
   4.350 +            EnumerationLiteral literal = (EnumerationLiteral) it.next();
   4.351 +            mofEnum.getLabels().add(literal.getName());
   4.352 +        }
   4.353 +    }
   4.354 +    
   4.355 +    private void transformDataType(DataType type, javax.jmi.model.Namespace container) {
   4.356 +        if (elements.containsKey(type)) return;
   4.357 +        
   4.358 +        if (isOfType(type, STEREOTYPE_ALIAS)) {
   4.359 +            AliasType alias = mof.getAliasType().createAliasType(type.getName(), getAnnotation(type), true, true, false, VisibilityKindEnum.PUBLIC_VIS);
   4.360 +            mapTags(type, alias);
   4.361 +            elements.put(type, alias);
   4.362 +            alias.setContainer(container);
   4.363 +            fqnsToResolve.put(alias, getTagValues(type, TAG_ALIAS_FOR));
   4.364 +        }
   4.365 +    }
   4.366 +    
   4.367 +    private void transformAssoc(UmlAssociation assoc, javax.jmi.model.Namespace container) {
   4.368 +        if (elements.containsKey(assoc)) return;
   4.369 +        if (isOfType(assoc, STEREOTYPE_IMPLICIT)) return;
   4.370 +        
   4.371 +        Association mofAssoc = mof.getAssociation().createAssociation(assoc.getName(), getAnnotation(assoc), assoc.isRoot(), assoc.isLeaf(), assoc.isAbstract(), VisibilityKindEnum.PUBLIC_VIS, "true".equals(getTagValue(assoc, TAG_ASSOC_DERIVED, null)));
   4.372 +        elements.put(assoc, mofAssoc);
   4.373 +        mofAssoc.setContainer(container);
   4.374 +        mapTags(assoc, mofAssoc);
   4.375 +        mapContent(assoc.getConnection(), mofAssoc);
   4.376 +    }
   4.377 +    
   4.378 +    private void transformAssocEnd(AssociationEnd assocEnd, javax.jmi.model.Namespace container) {
   4.379 +        if (elements.containsKey(assocEnd)) return;
   4.380 +        
   4.381 +        javax.jmi.model.AssociationEnd mofEnd = mof.getAssociationEnd().createAssociationEnd(assocEnd.getName(), getAnnotation(assocEnd), assocEnd.isNavigable(), getAggregation(assocEnd.getAggregation()), getMultiplicity(assocEnd.getMultiplicity(), OrderingKindEnum.OK_ORDERED.equals(assocEnd.getOrdering()), true), ChangeableKindEnum.CK_CHANGEABLE.equals(assocEnd.getChangeability()));
   4.382 +        elements.put(assocEnd, mofEnd);
   4.383 +        mofEnd.setContainer(container);
   4.384 +        mapTags(assocEnd, mofEnd);
   4.385 +        
   4.386 +        if (implicitReferences) {
   4.387 +            Reference ref = mof.getReference().createReference(mofEnd.getName(), mofEnd.getAnnotation(), ScopeKindEnum.INSTANCE_LEVEL, VisibilityKindEnum.PUBLIC_VIS, mofEnd.getMultiplicity(), mofEnd.isChangeable());
   4.388 +            ref.setReferencedEnd(mofEnd);
   4.389 +            references.add(ref);
   4.390 +        }
   4.391 +    }
   4.392 +    
   4.393 +    private void transformAttr(Attribute attr, MofClass container) {
   4.394 +        if (elements.containsKey(attr)) return;
   4.395 +        
   4.396 +        StructuralFeature mofFeature;
   4.397 +        if (isOfType(attr, STEREOTYPE_REFERENCE)) {
   4.398 +            mofFeature = mof.getReference().createReference(attr.getName(), getAnnotation(attr), ScopeKindEnum.INSTANCE_LEVEL, VisibilityKindEnum.PUBLIC_VIS, null, true);
   4.399 +            fqnsToResolve.put(mofFeature, getTagValues(attr, TAG_REFERENCED_END));
   4.400 +        } else {
   4.401 +            mofFeature = mof.getAttribute().createAttribute(attr.getName(), getAnnotation(attr), getScope(attr.getOwnerScope()), VisibilityKindEnum.PUBLIC_VIS, getMultiplicity(attr.getMultiplicity(), OrderingKindEnum.OK_ORDERED.equals(attr.getOrdering()), "true".equals(getTagValue(attr, TAG_UNIQUE, null))), ChangeableKindEnum.CK_CHANGEABLE.equals(attr.getChangeability()), "true".equals(getTagValue(attr, TAG_ATTR_DERIVED, null)));
   4.402 +        }
   4.403 +        elements.put(attr, mofFeature);
   4.404 +        mofFeature.setContainer(container);
   4.405 +        mapTags(attr, mofFeature);
   4.406 +    }
   4.407 +    
   4.408 +    private void transformOperation(Operation oper, MofClass container) {
   4.409 +        if (elements.containsKey(oper)) return;
   4.410 +        
   4.411 +        javax.jmi.model.Operation mofOper = mof.getOperation().createOperation(oper.getName(), getAnnotation(oper), getScope(oper.getOwnerScope()), VisibilityKindEnum.PUBLIC_VIS, oper.isQuery());
   4.412 +        elements.put(oper, mofOper);
   4.413 +        mofOper.setContainer(container);
   4.414 +        mapTags(oper, mofOper);
   4.415 +        mapContent(oper.getParameter(), mofOper);
   4.416 +        fqnsToResolve.put(mofOper, getTagValues(oper, TAG_RAISED_EXCEPTIONS));
   4.417 +    }
   4.418 +    
   4.419 +    private void transformEParam(Attribute attr, MofException ex) {
   4.420 +        if (elements.containsKey(attr)) return;
   4.421 +        
   4.422 +        javax.jmi.model.Parameter mofParam = mof.getParameter().createParameter(attr.getName(), getAnnotation(attr), DirectionKindEnum.OUT_DIR, getMultiplicity(attr.getMultiplicity(), OrderingKindEnum.OK_ORDERED.equals(attr.getOrdering()), "true".equals(getTagValue(attr, TAG_UNIQUE, null))));
   4.423 +        elements.put(attr, mofParam);
   4.424 +        mofParam.setContainer(ex);
   4.425 +        mapTags(attr, mofParam);
   4.426 +    }
   4.427 +    
   4.428 +    private void transformOParam(Parameter param, javax.jmi.model.Operation mofOper) {
   4.429 +        if (elements.containsKey(param)) return;
   4.430 +        
   4.431 +        javax.jmi.model.Parameter mofParam = mof.getParameter().createParameter(param.getName(), getAnnotation(param), getDirection(param.getKind()), getMultiplicity(getTagValue(param, TAG_MULTIPLICITY, null), "true".equals(getTagValue(param, TAG_ORDERED, null)), "true".equals(getTagValue(param, TAG_UNIQUE, null))));
   4.432 +        elements.put(param, mofParam);
   4.433 +        mofParam.setContainer(mofOper);
   4.434 +        mapTags(param, mofParam);
   4.435 +    }
   4.436 +    
   4.437 +    private void transformStructField(Attribute attr, StructureType struct) {
   4.438 +        if (elements.containsKey(attr)) return;
   4.439 +        
   4.440 +        StructureField mofField = mof.getStructureField().createStructureField(attr.getName(), getAnnotation(attr));
   4.441 +        elements.put(attr, mofField);
   4.442 +        mofField.setContainer(struct);
   4.443 +        mapTags(attr, mofField);
   4.444 +    }
   4.445 +    
   4.446 +    private void transformCollection(Attribute attr, CollectionType coll) {
   4.447 +        if (elements.containsKey(attr) || !ATTR_ITEMS.equals(attr.getName())) return;
   4.448 +        mapTags(attr, coll);
   4.449 +        coll.setMultiplicity(getMultiplicity(attr.getMultiplicity(), OrderingKindEnum.OK_ORDERED.equals(attr.getOrdering()), "true".equals(getTagValue(attr, TAG_UNIQUE, null))));
   4.450 +        elements.put(attr, coll);
   4.451 +    }
   4.452 +    
   4.453 +    private void transform(Object obj, javax.jmi.model.Namespace container) {
   4.454 +        if (obj instanceof UmlPackage) {
   4.455 +            transformPackage((UmlPackage) obj, (MofPackage) container);
   4.456 +        } else if (obj instanceof UmlAssociation) {
   4.457 +            transformAssoc((UmlAssociation) obj, container);
   4.458 +        } else if (obj instanceof AssociationEnd) {
   4.459 +            transformAssocEnd((AssociationEnd) obj, container);
   4.460 +        } else if (obj instanceof Attribute) {
   4.461 +            Attribute attr = (Attribute) obj;
   4.462 +            if (container instanceof MofClass) {
   4.463 +                transformAttr(attr, (MofClass) container);
   4.464 +            } else if (container instanceof CollectionType) {
   4.465 +                transformCollection(attr, (CollectionType) container);
   4.466 +            } else if (container instanceof MofException) {
   4.467 +                transformEParam(attr, (MofException) container);
   4.468 +            } else if (container instanceof StructureType) {
   4.469 +                transformStructField(attr, (StructureType) container);
   4.470 +            } else {
   4.471 +                warning("Ignoring attribute: " + attr.getName() + " from container: " + container.getName());
   4.472 +            }
   4.473 +        } else if (obj instanceof UmlClass) {
   4.474 +            transformClass((UmlClass) obj, container);
   4.475 +        } else if (obj instanceof DataType) {
   4.476 +            transformDataType((DataType) obj, container);
   4.477 +        } else if (obj instanceof Enumeration) {
   4.478 +            transformEnum((Enumeration) obj, container);
   4.479 +        } else if (obj instanceof Parameter) {
   4.480 +            transformOParam((Parameter) obj, (javax.jmi.model.Operation) container);
   4.481 +        } else if (obj instanceof Operation) {
   4.482 +            transformOperation((Operation) obj, (MofClass) container);
   4.483 +        } else {
   4.484 +            // element does not fit any specific transofm methods => ignore it
   4.485 +            warning("Ignoring instance of " + obj.getClass().getName() + "; container instance of " + container.getClass().getName());
   4.486 +        }
   4.487 +    }
   4.488 +    
   4.489 +    //////////////////////////////////////////////////////////////////////////////////
   4.490 +    // Utility Methods
   4.491 +    //////////////////////////////////////////////////////////////////////////////////
   4.492 +    
   4.493 +    private String getAnnotation(Object umlElement) {
   4.494 +        // [PENDING] implement correctly
   4.495 +        return "";
   4.496 +    }
   4.497 +    
   4.498 +    private String getTagValue(ModelElement element, String tagName, String defaultValue) {
   4.499 +        for (Iterator it = element.getTaggedValue().iterator(); it.hasNext();) {
   4.500 +            TaggedValue tag = (TaggedValue) it.next();
   4.501 +            if (tagName.equals(tag.getName())) {
   4.502 +                return (String) tag.getDataValue().iterator().next();
   4.503 +            }
   4.504 +        }
   4.505 +        return defaultValue;
   4.506 +    }
   4.507 +    
   4.508 +    private ArrayList getTagValues(ModelElement element, String tagName) {
   4.509 +        for (Iterator it = element.getTaggedValue().iterator(); it.hasNext();) {
   4.510 +            TaggedValue tag = (TaggedValue) it.next();
   4.511 +            if (tagName.equals(tag.getName())) {
   4.512 +                return new ArrayList(tag.getDataValue());
   4.513 +            }
   4.514 +        }
   4.515 +        return new ArrayList();
   4.516 +    }
   4.517 +    
   4.518 +    private void mapTags(ModelElement umlElement, javax.jmi.model.ModelElement mofElement) {
   4.519 +        // iterate through tagged values
   4.520 +        for (Iterator it = umlElement.getTaggedValue().iterator(); it.hasNext();) {
   4.521 +            TaggedValue tag = (TaggedValue) it.next();
   4.522 +            String tagName = tag.getName();
   4.523 +            if (tagName == null || tagName.startsWith("org.omg.uml2mof.") || tagName.startsWith("org.netbeans.uml2mof.")) continue;
   4.524 +            if (!elements.containsKey(tag)) {
   4.525 +                info("copying tag: " + tagName);
   4.526 +                Tag mofTag = mof.getTag().createTag(tagName, getAnnotation(tag), tagName, new ArrayList(tag.getDataValue()));
   4.527 +                mofTag.setContainer(outermost);
   4.528 +                mofTag.getElements().add(mofElement);
   4.529 +                elements.put(tag, mofTag);
   4.530 +            }
   4.531 +        }
   4.532 +    }
   4.533 +    
   4.534 +    private void mapContent(Collection content, javax.jmi.model.Namespace container) {
   4.535 +        for (Iterator it = content.iterator(); it.hasNext();) {
   4.536 +            transform(it.next(), container);
   4.537 +        }
   4.538 +    }        
   4.539 +    
   4.540 +    private javax.jmi.model.AggregationKind getAggregation(AggregationKind aggr) {
   4.541 +        if (AggregationKindEnum.AK_AGGREGATE.equals(aggr)) {
   4.542 +            return javax.jmi.model.AggregationKindEnum.SHARED;
   4.543 +        } else if (AggregationKindEnum.AK_COMPOSITE.equals(aggr)) {
   4.544 +            return javax.jmi.model.AggregationKindEnum.COMPOSITE;
   4.545 +        } else {
   4.546 +            return javax.jmi.model.AggregationKindEnum.NONE;
   4.547 +        }
   4.548 +    }
   4.549 +    
   4.550 +    private MultiplicityType getMultiplicity(Multiplicity m, boolean isOrdered, boolean isUnique) {
   4.551 +        MultiplicityRange range = (MultiplicityRange) m.getRange().iterator().next();
   4.552 +        return mof.createMultiplicityType(range.getLower(), range.getUpper(), isOrdered, isUnique);
   4.553 +    }
   4.554 +    
   4.555 +    private MultiplicityType getMultiplicity(String m, boolean isOrdered, boolean isUnique) {
   4.556 +        StringTokenizer st = new StringTokenizer(m, ".");
   4.557 +        int lower = 0;
   4.558 +        int upper = -1;
   4.559 +        try {
   4.560 +            lower = Integer.parseInt(st.nextToken());
   4.561 +            upper = Integer.parseInt(st.nextToken());
   4.562 +        } catch (NumberFormatException e) {
   4.563 +            // ignore
   4.564 +        } catch (NoSuchElementException e) {
   4.565 +            // ignore
   4.566 +        }
   4.567 +        return mof.createMultiplicityType(lower, upper, isOrdered, isUnique);
   4.568 +    }
   4.569 +    
   4.570 +    private ScopeKindEnum getScope(org.omg.uml.foundation.datatypes.ScopeKind s) {
   4.571 +        if (org.omg.uml.foundation.datatypes.ScopeKindEnum.SK_CLASSIFIER.equals(s)) {
   4.572 +            return ScopeKindEnum.CLASSIFIER_LEVEL;
   4.573 +        } else {
   4.574 +            return ScopeKindEnum.INSTANCE_LEVEL;
   4.575 +        }
   4.576 +    }
   4.577 +    
   4.578 +    private DirectionKindEnum getDirection(ParameterDirectionKind dk) {
   4.579 +        if (ParameterDirectionKindEnum.PDK_RETURN.equals(dk)) {
   4.580 +            return DirectionKindEnum.RETURN_DIR;
   4.581 +        } else if (ParameterDirectionKindEnum.PDK_INOUT.equals(dk)) {
   4.582 +            return DirectionKindEnum.INOUT_DIR;
   4.583 +        } else if (ParameterDirectionKindEnum.PDK_OUT.equals(dk)) {
   4.584 +            return DirectionKindEnum.OUT_DIR;
   4.585 +        } else {
   4.586 +            return DirectionKindEnum.IN_DIR;
   4.587 +        }
   4.588 +    }
   4.589 +    
   4.590 +    private boolean isOfType(ModelElement element, String stereotype) {
   4.591 +        return element.getStereotype().contains(stereotypes.get(stereotype));
   4.592 +    }
   4.593 +    
   4.594 +    private javax.jmi.model.Classifier mapType(ModelElement element, Object obj) {
   4.595 +        if (element instanceof DataType) {
   4.596 +            initPrimitives();
   4.597 +            ptImports.add(((RefObject) obj).refOutermostComposite());
   4.598 +            return (javax.jmi.model.Classifier) primitives.get(element.getName());
   4.599 +        } else {
   4.600 +            return (javax.jmi.model.Classifier) elements.get(element);
   4.601 +        }
   4.602 +    }
   4.603 +    
   4.604 +    private void initPrimitives() {
   4.605 +        if (primitives == null) {
   4.606 +            primitives = new HashMap();
   4.607 +            primitivesPackage = mof.getMofPackage().createMofPackage("PrimitiveTypes", "", true, true, false, VisibilityKindEnum.PUBLIC_VIS);
   4.608 +            createPrimitive("Integer");
   4.609 +            createPrimitive("Long");
   4.610 +            createPrimitive("Float");
   4.611 +            createPrimitive("Double");
   4.612 +            createPrimitive("Boolean");
   4.613 +            createPrimitive("String");
   4.614 +        }
   4.615 +    }
   4.616 +    
   4.617 +    private void createPrimitive(String name) {
   4.618 +        PrimitiveType pt = mof.getPrimitiveType().createPrimitiveType(name, "", true, true, false, VisibilityKindEnum.PUBLIC_VIS);
   4.619 +        primitives.put(name, pt);
   4.620 +        pt.setContainer(primitivesPackage);
   4.621 +    }
   4.622 +    
   4.623 +    private void mapByFQNs(Collection target, Collection source) {
   4.624 +        for (Iterator it = source.iterator(); it.hasNext();) {
   4.625 +            String fqn = (String) it.next();
   4.626 +            Object result = resolveFQN(fqn);
   4.627 +            if (result == null) {
   4.628 +                warning("Fully qualified name not resolved: " + fqn);
   4.629 +            } else {
   4.630 +                target.add(result);
   4.631 +            }
   4.632 +        }
   4.633 +    }
   4.634 +    
   4.635 +    private javax.jmi.model.ModelElement resolveFQN(String fqn) {
   4.636 +        javax.jmi.model.ModelElement result = null;
   4.637 +        StringTokenizer st = new StringTokenizer(fqn, ".:");
   4.638 +        String name = st.nextToken();
   4.639 +        if ("PrimitiveTypes".equals(name)) initPrimitives();
   4.640 +        for (Iterator c = mof.getMofPackage().refAllOfClass().iterator(); c.hasNext();) {
   4.641 +            result = (javax.jmi.model.ModelElement) c.next();
   4.642 +            if (result.getContainer() == null && name.equals(result.getName())) {
   4.643 +                break;
   4.644 +            } else {
   4.645 +                result = null;
   4.646 +            }
   4.647 +        }
   4.648 +        while (result != null && st.hasMoreTokens()) {
   4.649 +            try {
   4.650 +                result = ((javax.jmi.model.Namespace) result).lookupElement(st.nextToken());
   4.651 +            } catch (NameNotFoundException ex) {
   4.652 +                result = null;
   4.653 +            } catch (ClassCastException ex) {
   4.654 +                result = null;
   4.655 +            }
   4.656 +        }
   4.657 +        return result;
   4.658 +    }
   4.659 +    
   4.660 +    private static void warning(String text) {
   4.661 +        logger.log(ErrorManager.WARNING, text);
   4.662 +    }
   4.663 +    
   4.664 +    private static void info(String text) {
   4.665 +        logger.log(ErrorManager.INFORMATIONAL, text);
   4.666 +    }
   4.667 +}