void CSharpWriter::writeAssociatedAttributes(UMLAssociationList &associated, UMLClassifier *c, QTextStream &cs) { UMLAssociation *a; for (a = associated.first(); a ; a = associated.next()) { if (c != a->getObject(Uml::A)) // we need to be at the A side continue; UMLObject *o = a->getObject(Uml::B); if (o == NULL) { kError() << "composition role B object is NULL" << endl; continue; } // Take name and documentaton from Role, take type name from the referenced object QString roleName = cleanName(a->getRoleName(Uml::B)); QString typeName = cleanName(o->getName()); if (roleName.isEmpty()) { roleName = QString("UnnamedRoleB_%1").arg(m_unnamedRoles++); } QString roleDoc = a->getRoleDoc(Uml::B); //FIXME:is this simple condition enough? if (a->getMulti(Uml::B).isEmpty() || a->getMulti(Uml::B) == "1") { // normal attribute writeAttribute(roleDoc, a->getVisibility(Uml::B), false, typeName, roleName, "", ( a->getVisibility(Uml::B) != Uml::Visibility::Private), cs); } else { // array roleDoc += "\n(Array of " + typeName + ')'; writeAttribute(roleDoc, a->getVisibility(Uml::B), false, "ArrayList", roleName, "", ( a->getVisibility(Uml::B) != Uml::Visibility::Private), cs); } } }
UMLObjectList XMLSchemaWriter::findChildObjsInAssociations (UMLClassifier *c, UMLAssociationList associations) { Uml::IDType id = c->getID(); UMLObjectList list; for(UMLAssociation *a = associations.first(); a; a = associations.next()) { if (a->getObjectId(Uml::A) == id && a->getVisibility(Uml::B) != Uml::Visibility::Private && !a->getRoleName(Uml::B).isEmpty() ) list.append(a->getObject(Uml::B)); if (a->getObjectId(Uml::B) == id && a->getVisibility(Uml::A) != Uml::Visibility::Private && !a->getRoleName(Uml::A).isEmpty() ) list.append(a->getObject(Uml::A)); } return list; }
// all that matters here is roleA, the role served by the children of this class // in any composition or aggregation association. In full associations, I have only // considered the case of "self" association, so it shouldn't matter if we use role A or // B to find the child class as long as we don't use BOTH roles. I bet this will fail // badly for someone using a plain association between 2 different classes. THAT should // be done, but isnt yet (this is why I have left role b code in for now). -b.t. bool XMLSchemaWriter::writeAssociationDecls(UMLAssociationList associations, bool noRoleNameOK, bool didFirstOne, Uml::IDType id, QTextStream &XMLschema) { if( !associations.isEmpty() ) { bool printRoleA = false, printRoleB = false; for(UMLAssociation *a = associations.first(); a; a = associations.next()) { // it may seem counter intuitive, but you want to insert the role of the // *other* class into *this* class. if (a->getObjectId(Uml::A) == id && a->getVisibility(Uml::B) != Uml::Visibility::Private) printRoleB = true; if (a->getObjectId(Uml::B) == id && a->getVisibility(Uml::A) != Uml::Visibility::Private) printRoleA = true; // First: we insert documentaion for association IF it has either role // AND some documentation (!) if ((printRoleA || printRoleB) && !(a->getDoc().isEmpty())) writeComment(a->getDoc(), XMLschema); // opening for sequence if(!didFirstOne && (printRoleA || printRoleB)) { didFirstOne = true; XMLschema<<getIndent()<<"<"<<makeSchemaTag("sequence")<<">"<<m_endl; m_indentLevel++; } // print RoleB decl /* // As mentioned in the header comment for this method: this block of code is // commented out for now as it will only be needed if/when plain associations // between different classes are to be treated if (printRoleB) { UMLClassifier *classifierB = dynamic_cast<UMLClassifier*>(a->getObjectB()); if (classifierB) { // ONLY write out IF there is a rolename given // otherwise its not meant to be declared if (!a->getRoleNameB().isEmpty() || noRoleNameOK) writeAssociationRoleDecl(classifierB, a->getMultiB(), XMLschema); } } */ // print RoleA decl if (printRoleA) { UMLClassifier *classifierA = dynamic_cast<UMLClassifier*>(a->getObject(Uml::A)); if (classifierA) { // ONLY write out IF there is a rolename given // otherwise its not meant to be declared if (!a->getRoleName(Uml::A).isEmpty() || noRoleNameOK ) writeAssociationRoleDecl(classifierA, a->getMulti(Uml::A), XMLschema); } } } } return didFirstOne; }