Пример #1
0
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;
}
Пример #2
0
UMLClassifierList ClassifierInfo::findAssocClassifierObjsInRoles (UMLAssociationList * list)
{
    UMLClassifierList classifiers;

    for (UMLAssociation *a = list->first(); a; a = list->next()) {
        // DONT accept a classifier IF the association role is empty, by
        // convention, that means to ignore the classifier on that end of
        // the association.
        // We also ignore classifiers which are the same as the current one
        // (e.g. id matches), we only want the "other" classifiers
        if (a->getObjectId(Uml::A) == classifier_->getID() && !a->getRoleName(Uml::B).isEmpty()) {
            UMLClassifier *c = dynamic_cast<UMLClassifier*>(a->getObject(Uml::B));
            if(c)
                classifiers.append(c);
        } else if (a->getObjectId(Uml::B) == classifier_->getID() && !a->getRoleName(Uml::A).isEmpty()) {
            UMLClassifier *c = dynamic_cast<UMLClassifier*>(a->getObject(Uml::A));
            if(c)
                classifiers.append(c);
        }
    }

    return classifiers;
}
Пример #3
0
// 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;
}