void GenerateNewCSInit(const Uml::Diagram &diagram, ostream &output, string fname) { output << "\t" << "public class Init" << endl; output << "\t" << "{" << endl; output << "\t\t" << "public static bool initialized = false;" << endl; output << "\t\t" << "public static Udm.DataNetwork dn = null;" << endl; output << "\t\t" << "public static Uml.Diagram umldiagram = null;" << endl; output << "\t\t" << "static Init()" << endl; output << "\t\t" << "{"<<endl; output << "\t\t\t" << "if(initialized) return;" << endl; output << "\t\t\t" << "initialized = true;" << endl; output << "\t\t\t" << "if(!Uml.Init.initialized) throw new Udm.udm_exception(\"UML Diagram is not yet initialized!\");" << endl; string hname = diagram.name(); output << "\t\t\t" << "dn = new Static.StaticDataNetwork(Uml.Init.dn.GetRootMeta());" << endl; output << "\t\t\t" << "dn.CreateNew(\"" << hname << ".mem\", \"\",ref Uml.Diagram.meta, Udm.BackEndSemantics.CHANGES_LOST_DEFAULT);"<< endl; output << "\t\t\t" << "umldiagram = Uml.Diagram.Cast(dn.GetRootObject());" << endl; output << "\t\t\t" << "umldiagram.name =\"" << hname << "\";" << endl; set<Uml::Class> classes = diagram.classes(); set<Uml::Class>::iterator c; //classes for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; output << "\t\t\t" << cl.name() << ".meta = Uml.Class.Create(umldiagram);" << endl; } //attributes for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; set<Uml::Attribute> attributes = cl.attributes(); //todo: non-persistent attributes for( set<Uml::Attribute>::iterator i = attributes.begin(); i != attributes.end(); i++) { output << "\t\t\t" << cl.name() << ".meta_" << (*i).name() << " = Uml.Attribute.Create(" << cl.name()<<".meta);" << endl; } } //class attributes for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; string ster; if(((string)cl.stereotype()).length()) ster = string(", \"")+(string)cl.stereotype()+"\""; output << "\t\t\t" << cl.name() << ".meta.name = \"" << cl.name() << "\";" <<endl; output << "\t\t\t" << cl.name() << ".meta.isAbstract = " << (cl.isAbstract() ? "true" : "false") << ";" << endl; if (!ster.empty()) output << "\t\t\t" << cl.name() << ".meta.stereotype = \"" << cl.stereotype() << "\";" <<endl; } //attribute attributes ;-) for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; // Uml::Class tempcl(Uml::classByName(tempdiagram, cl.name())); set<Uml::Attribute> attributes = cl.attributes(); for(set<Uml::Attribute>::iterator att_i = attributes.begin(); att_i != attributes.end(); att_i++) //nonpersistent is false for attributes coming from the real diagram att_i->nonpersistent() = false; for( set<Uml::Attribute>::iterator i = attributes.begin(); i != attributes.end(); i++) { output << "\t\t\t" << cl.name() << ".meta_" << (*i).name() << ".name = \"" << (*i).name() << "\";" << endl; output << "\t\t\t" << cl.name() << ".meta_" << (*i).name() << ".type = \"" << (*i).type() << "\";" << endl; output << "\t\t\t" << cl.name() << ".meta_" << (*i).name() << ".min = " << (*i).min() << ";" << endl; output << "\t\t\t" << cl.name() << ".meta_" << (*i).name() << ".max = " << (*i).max() << ";" << endl; output << "\t\t\t" << cl.name() << ".meta_" << (*i).name() << ".nonpersistent = " << ((*i).nonpersistent() ? "true" : "false") << ";" << endl; } } //associations { const set<Uml::Association> &asss = diagram.associations(); set<Uml::Association>::const_iterator a; for(a = asss.begin(); a != asss.end(); a++ ) { set<Uml::AssociationRole> ar = a->roles(); ASSERT(ar.size() == 2); output << "\t\t\t{" << endl; output << "\t\t\t\tUml.Association ass = Uml.Association.Create(umldiagram);" << endl; Uml::Class aclass = a->assocClass(); if (!((string)a->name()).empty()) output << "\t\t\t\tass.name = \"" << a->name() << "\";" <<endl; if(aclass) { output << "\t\t\t\tass.assocClass = " << aclass.name() << ".meta;" << endl; } set<Uml::AssociationRole> roles = a->roles(); for( set<Uml::AssociationRole>::iterator i = roles.begin(); i != roles.end(); i++) { Uml::AssociationRole zz = Uml::theOther(*i); string aname(MakeRoleName(zz)); Uml::Class cl = i->target(); output << "\t\t\t\t" << cl.name() << ".meta_" << aname << " = Uml.AssociationRole.Create(ass);" <<endl; output << "\t\t\t\t" << cl.name() << ".meta_" << aname << ".name = \"" << aname << "\";" <<endl; output << "\t\t\t\t" << cl.name() << ".meta_" << aname << ".min = " << zz.min() << ";" <<endl; output << "\t\t\t\t" << cl.name() << ".meta_" << aname << ".max = " << zz.max() << ";" <<endl; output << "\t\t\t\t" << cl.name() << ".meta_" << aname << ".isNavigable = " << (zz.isNavigable() ? "true":"false") << ";" <<endl; output << "\t\t\t\t" << cl.name() << ".meta_" << aname << ".isPrimary = " << (zz.isPrimary() ? "true":"false") << ";" <<endl; output << "\t\t\t\t" << cl.name() << ".meta_" << aname << ".target = " << ((Uml::Class)zz.target()).name() << ".meta;" <<endl; Uml::Class aclass = a->assocClass(); if(aclass) { Uml::Class cl2 = zz.target(); output << "\t\t\t\t" << aclass.name() << ".meta_" << aname << "_end_ = " << cl2.name() << ".meta_" << MakeRoleName(*i) << "_rev = " << cl.name() << ".meta_" << aname << ";" << endl; } } output << "\t\t\t}" << endl; } } //compositions { const set<Uml::Composition> &comps = diagram.compositions(); set<Uml::Composition>::const_iterator c; for(c = comps.begin(); c != comps.end(); c++ ) { output << "\t\t\t{" << endl; output << "\t\t\t\tUml.Composition comp = Uml.Composition.Create(umldiagram);" << endl; if (!((string)c->name()).empty()) output << "\t\t\t\tcomp.name =\"" << c->name() << "\";" <<endl; output << "\t\t\t\tcomp.nonpersistent =" << (c->nonpersistent() ? "true" : "false") << ";" << endl; output << "\t\t" << endl; Uml::CompositionParentRole x1 = (*c).parentRole(); Uml::CompositionChildRole x2 = (*c).childRole(); Uml::CompositionParentRole zzp = c->parentRole(); Uml::CompositionChildRole zzc = c->childRole(); string aname(MakeRoleName(zzp)); output << "\t\t\t\t" << ((Uml::Class)zzc.target()).name() << ".meta_" << aname << " = Uml.CompositionParentRole.Create(comp);" << endl; output << "\t\t\t\t" << ((Uml::Class)zzc.target()).name() << ".meta_" << aname << ".name = \"" << aname << "\";" << endl; output << "\t\t\t\t" << ((Uml::Class)zzc.target()).name() << ".meta_" << aname << ".isNavigable = " << (zzp.isNavigable() ? "true;" : "false;") << endl; output << "\t\t\t\t" << ((Uml::Class)zzc.target()).name() << ".meta_" << aname << ".target = " << ((Uml::Class)zzp.target()).name() << ".meta;" << endl; string cname(MakeRoleName(zzc)); output << "\t\t\t\t" << ((Uml::Class)zzp.target()).name() << ".meta_" << cname << " = Uml.CompositionChildRole.Create(comp);" << endl; output << "\t\t\t\t" << ((Uml::Class)zzp.target()).name() << ".meta_" << cname << ".name = \"" << MakeShortRoleName(zzc) << "\";" << endl; output << "\t\t\t\t" << ((Uml::Class)zzp.target()).name() << ".meta_" << cname << ".min = " << zzc.min() << ";"<< endl; output << "\t\t\t\t" << ((Uml::Class)zzp.target()).name() << ".meta_" << cname << ".max = " << zzc.max() << ";"<< endl; output << "\t\t\t\t" << ((Uml::Class)zzp.target()).name() << ".meta_" << cname << ".isNavigable = " << (zzc.isNavigable() ? "true;" : "false;") << endl; output << "\t\t\t\t" << ((Uml::Class)zzp.target()).name() << ".meta_" << cname << ".target = " << ((Uml::Class)zzc.target()).name() << ".meta;" << endl; output << "\t\t\t}" << endl; } } for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; set<Uml::Class> st = cl.subTypes(); if (st.size()) { output << "\t\t\t" <<"Hashtable " << (string)cl.name() << "_meta_subtypes = new Hashtable();" << endl; for( set<Uml::Class>::iterator i = st.begin(); i != st.end(); i++) { output << "\t\t\t" << cl.name() << "_meta_subtypes[" << (*i).name() << ".meta] = " <<(*i).name() << ".meta;" << endl; } output << "\t\t\t" << cl.name() << ".meta.subTypes = " << cl.name() << "_meta_subtypes;" << endl; output << endl; } } output << "\t\t" << "}"<<endl; //end of Init.init(); output << "\t" << "}"<<endl; //end of class Init(); output << "}" << endl; //end of namespace }
void GenerateCSInit(const Uml::Diagram &diagram, ostream &output, string fname) { output << "\t" << "public class Init" << endl; output << "\t" << "{" << endl; output << "\t\t" << "public static bool initialized = false;" << endl; output << "\t\t" << "public static Udm.DataNetwork dn = null;" << endl; output << "\t\t" << "public static Uml.Diagram umldiagram = null;" << endl; output << "\t\t" << "static Init()" << endl; output << "\t\t" << "{"<<endl; output << "\t\t\t" << "if(initialized) return;" << endl; output << "\t\t\t" << "initialized = true;" << endl; output << "\t\t\t" << "if(!Uml.Init.initialized) throw new Udm.udm_exception(\"UML Diagram is not yet initialized!\");" << endl; output << "\t\t\t" << "umldiagram = Uml.UmlExt.CreateDiagram();" << endl; set<Uml::Class> classes = diagram.classes(); set<Uml::Class>::iterator c; //create classes for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; output << "\t\t\t" << cl.name() << ".meta = Uml.UmlExt.CreateClass();" << endl; } //create attributes for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; set<Uml::Attribute> attributes = cl.attributes(); //todo Non-persistent attribute support for C# UDM for( set<Uml::Attribute>::iterator i = attributes.begin(); i != attributes.end(); i++) { output << "\t\t\t" << cl.name() << ".meta_" << (*i).name() << " = Uml.UmlExt.CreateAttribute();" << endl; } } //create association roles for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; set<Uml::AssociationRole> assocs = cl.associationRoles(); for( set<Uml::AssociationRole>::iterator i = assocs.begin(); i != assocs.end(); i++) { string aname(MakeRoleName(Uml::theOther(*i))); output << "\t\t\t" << cl.name() << ".meta_" << aname << " = Uml.UmlExt.CreateAssociationRole();" << endl; } } //create composition parent roles for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; set<Uml::CompositionChildRole> children = cl.childRoles(); for( set<Uml::CompositionChildRole>::iterator i = children.begin(); i != children.end(); i++) { string aname(MakeRoleName(Uml::theOther(*i))); output << "\t\t\t" << cl.name() << ".meta_" << aname << " = Uml.UmlExt.CreateCompositionParentRole();" << endl; } } //create composition child roles for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; set<Uml::CompositionParentRole> children = cl.parentRoles(); for( set<Uml::CompositionParentRole>::iterator i = children.begin(); i != children.end(); i++) { string aname(MakeRoleName(Uml::theOther(*i))); output << "\t\t\t" << cl.name() << ".meta_" << aname << " = Uml.UmlExt.CreateCompositionChildRole();" << endl; } } //end of creations, output << "\t\t\t" << "Udm.Object.SolveMetaDependencies();"<< endl; //init part //diagram output << "\t\t\tUml.UmlExt.InitDiagram(umldiagram, \"" << diagram.name() << "\");" << endl << endl; //classes for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; string ster; if(((string)cl.stereotype()).length()) ster = string(", \"")+(string)cl.stereotype()+"\""; string from; if(((string)cl.from()).length()) from = string(", \"")+(string)cl.from()+"\""; output << "\t\t\tUml.UmlExt.InitClass(" << cl.name() << ".meta, umldiagram, \"" << cl.name() << "\", " << (cl.isAbstract() ? "true" : "false")<< ster << from << ");" << endl; } output << "\t\t" << endl; //atributes for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; // Uml::Class tempcl(Uml::classByName(tempdiagram, cl.name())); set<Uml::Attribute> attributes = cl.attributes(); for( set<Uml::Attribute>::iterator i = attributes.begin(); i != attributes.end(); i++) { output << "\t\t\tUml.UmlExt.InitAttribute(" << cl.name() << ".meta_" << (*i).name() << ", " << cl.name() << ".meta, \"" << (*i).name() << "\", \"" << (*i).type() << "\", " << ((*i).nonpersistent() ? "true" : "false") << ", " << (*i).min() << ", " << (*i).max() << ");" << endl; } } output << "\t\t" << endl; //associations { const set<Uml::Association> &asss = diagram.associations(); set<Uml::Association>::const_iterator a; for(a = asss.begin(); a != asss.end(); a++ ) { set<Uml::AssociationRole> ar = a->roles(); ASSERT(ar.size() == 2); // { output << "\t\t\t{" << endl; // Uml::Association ass = Uml::CreateAssociation(); output << "\t\t\t\tUml.Association ass = Uml.UmlExt.CreateAssociation();" << endl; // Uml::InitAssociation(ass, diagram, "AtoB"); // or : Uml::InitAssociationClass(ass, C::meta); Uml::Class aclass = a->assocClass(); output << "\t\t\t\tUml.UmlExt.InitAssociation(ass , umldiagram, \"" << a->name() << "\");" << endl; if(aclass) { output << "\t\t\tUml.UmlExt.InitAssociationClass(ass, " << aclass.name() << ".meta);" << endl; } // Uml::InitAssociationRole(A::meta_dst, ass, "dst", 0, 1, B::meta); // C:: meta_dst_end_ = B:meta_src_rev = A::meta_dst; set<Uml::AssociationRole> roles = a->roles(); for( set<Uml::AssociationRole>::iterator i = roles.begin(); i != roles.end(); i++) { Uml::AssociationRole zz = Uml::theOther(*i); string aname(MakeRoleName(zz)); Uml::Class cl = i->target(); output << "\t\t\t\tUml.UmlExt.InitAssociationRole(" << cl.name() << ".meta_" << aname << ", ass, \"" << aname << "\", " << (zz.isNavigable() ? "true, " : "false, ") << (zz.isPrimary() ? "true, " : "false, ") << zz.min() << ", " << zz.max() << ", " << ((Uml::Class)zz.target()).name() << ".meta);" << endl; Uml::Class aclass = a->assocClass(); if(aclass) { Uml::Class cl2 = zz.target(); output << "\t\t\t" << aclass.name() << ".meta_" << aname << "_end_ = " << cl2.name() << ".meta_" << MakeRoleName(*i) << "_rev = " << cl.name() << ".meta_" << aname << ";" << endl; } } // } output << "\t\t\t}" << endl; } } //compositions { const set<Uml::Composition> &comps = diagram.compositions(); set<Uml::Composition>::const_iterator c; for(c = comps.begin(); c != comps.end(); c++ ) { // { output << "\t\t\t{" << endl; // Uml::Composition comp = Uml::CreateComposition(); output << "\t\t\t\tUml.Composition comp = Uml.UmlExt.CreateComposition();" << endl; // Uml::InitComposition(comp, diagram, "DtoA"); output << "\t\t\t\tUml.UmlExt.InitComposition(comp , umldiagram, \"" << c->name() << "\");" << endl; output << "\t\t" << endl; Uml::CompositionParentRole x1 = (*c).parentRole(); Uml::CompositionChildRole x2 = (*c).childRole(); // Uml::InitCompositionParentRole(A::meta_parent, comp, "parent", D::meta); Uml::CompositionParentRole zzp = c->parentRole(); Uml::CompositionChildRole zzc = c->childRole(); string aname(MakeRoleName(zzp)); output << "\t\t\t\tUml.UmlExt.InitCompositionParentRole(" << ((Uml::Class)zzc.target()).name() << ".meta_" << aname << ", comp, \""<< aname << "\", " << (zzp.isNavigable() ? "true, " : "false, ") << ((Uml::Class)zzp.target()).name() << ".meta);" << endl; // Uml::InitCompositionChildRole(D::meta_as, comp, "as", true, 0, -1, A::meta); string cname(MakeRoleName(zzc)); output << "\t\t\t\tUml.UmlExt.InitCompositionChildRole(" << ((Uml::Class)zzp.target()).name() << ".meta_" << cname << ", comp, \""<< MakeShortRoleName(zzc) << "\", " << (zzc.isNavigable() ? "true, " : "false, ") << zzc.min() << ", " << zzc.max() << ", " << ((Uml::Class)zzc.target()).name() << ".meta);" << endl; // } output << "\t\t\t}" << endl; } } //inheritence // Uml::AddInheritance(A::meta, C::meta); for(c = classes.begin(); c != classes.end(); c++ ) { Uml::Class cl = *c; set<Uml::Class> st = cl.subTypes(); for( set<Uml::Class>::iterator i = st.begin(); i != st.end(); i++) { output << "\t\t\tUml.UmlExt.AddInheritance(" << cl.name() << ".meta, " << (*i).name() << ".meta);" << endl; } } output << endl; output << "\t\t\t" << "Static.StaticDataNetwork sdn = new Static.StaticDataNetwork(umldiagram);" << endl; output << "\t\t\t" << "sdn.CreateFromRootObj(\"" << diagram.name() <<"\", umldiagram, Udm.BackEndSemantics.CHANGES_LOST_DEFAULT);" << endl; output << "\t\t\t" << "dn = sdn;" << endl; output << "\t\t" << "}"<<endl; //end of Init.init(); output << "\t" << "}"<<endl; //end of class Init(); output << "}" << endl; //end of namespace }