void CodeClassFieldDeclarationBlock::syncToParent () { // for role-based accessors, we DON'T write ourselves out when // the name of the role is not defined. if (!(getParentClassField()->parentIsAttribute())) { UMLRole * parent = getParentObject()->asUMLRole(); if (parent == 0) return; if (parent->name().isEmpty()) { getComment()->setWriteOutText(false); setWriteOutText(false); } else { getComment()->setWriteOutText(true); setWriteOutText(true); } } // only update IF we are NOT AutoGenerated if (contentType() != AutoGenerated) return; updateContent(); }
// need to get the ID of the parent object // this is kind of broken for UMLRoles. QString CodeParameter::getID () { UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject); if(role) { // cant use Role "ID" as that is used to distinquish if its // role "A" or "B" UMLAssociation *assoc = role->parentAssociation(); return ID2STR(assoc->id()); } else return ID2STR(m_parentObject->id()); }
/** * Returns the ID of the UMLObject assigned to the given role. * Shorthand for getObject(role)->getID(). * @return ID of the UMLObject in the given role. */ Uml::IDType UMLAssociation::getObjectId(Uml::Role_Type role) const { UMLRole *roleObj = m_pRole[role]; UMLObject *o = roleObj->object(); if (o == NULL) { QString auxID = roleObj->secondaryId(); if (auxID.isEmpty()) { uError() << "role " << role << ": getObject returns NULL"; return Uml::id_None; } else { uDebug() << "role " << role << ": using secondary ID " << auxID; return STR2ID(auxID); } } return o->id(); }
QString CPPCodeClassField::getFieldName() { if (parentIsAttribute()) { UMLAttribute * at = (UMLAttribute*) getParentObject(); return cleanName(at->getName()); } else { UMLRole * role = (UMLRole*) getParentObject(); QString roleName = role->getName(); if(fieldIsSingleValue()) { return roleName.replace(0, 1, roleName.left(1).lower()); } else { return roleName.lower() + "Vector"; } } }
QString RubyCodeClassField::getFieldName() { if (parentIsAttribute()) { UMLAttribute * at = (UMLAttribute*) getParentObject(); return cleanName(at->name()); } else { UMLRole * role = (UMLRole*) getParentObject(); QString roleName = role->name(); if(fieldIsSingleValue()) { return roleName.replace(0, 1, roleName.left(1).toLower()); } else { return roleName.toLower() + QLatin1String("Array"); } } }
/** * set attributes of the node that represents this class * in the XMI document. */ void OwnedHierarchicalCodeBlock::setAttributesOnNode(QDomDocument & doc, QDomElement & elem) { // set super-class attributes HierarchicalCodeBlock::setAttributesOnNode(doc, elem); OwnedCodeBlock::setAttributesOnNode(doc, elem); // set local class attributes elem.setAttribute("parent_id",ID2STR(getParentObject()->id())); // setting ID's takes special treatment // as UMLRoles arent properly stored in the XMI right now. // (change would break the XMI format..save for big version change ) UMLRole * role = dynamic_cast<UMLRole*>(getParentObject()); if(role) { // see comment on role_id at OwnedCodeBlock::setAttributesOnNode() elem.setAttribute("role_id", (role->role() == Uml::A)); } /* else elem.setAttribute("role_id","-1"); */ }
/** * Set attributes of the node that represents this class * in the XMI document. */ void CodeParameter::setAttributesOnNode ( QDomDocument & doc, QDomElement & blockElement) { // set local attributes blockElement.setAttribute("parent_id",getID()); // setting ID's takes special treatment // as UMLRoles arent properly stored in the XMI right now. // (change would break the XMI format..save for big version change ) UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject); if(role) blockElement.setAttribute("role_id", role->role()); else blockElement.setAttribute("role_id","-1"); blockElement.setAttribute("initialValue",getInitialValue()); // a comment which we will store in its own separate child node block QDomElement commElement = doc.createElement( "header" ); getComment()->saveToXMI(doc, commElement); // comment blockElement.appendChild( commElement); }
void RubyCodeClassFieldDeclarationBlock::updateContent( ) { CodeClassField * cf = getParentClassField(); ClassifierCodeDocument * doc = cf->getParentDocument(); RubyCodeClassField * rcf = dynamic_cast<RubyCodeClassField*>(cf); RubyClassifierCodeDocument* rdoc = dynamic_cast<RubyClassifierCodeDocument*>(doc); CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy(); CodeGenerationPolicy::ScopePolicy scopePolicy = p->getAssociationFieldScope(); // Set the comment QString notes = getParentObject()->getDoc(); getComment()->setText(notes); // Set the body QString staticValue = getParentObject()->getStatic() ? "static " : ""; QString scopeStr = rdoc->scopeToRubyDecl(getParentObject()->getVisibility()); // IF this is from an association, then scope taken as appropriate to policy if(!rcf->parentIsAttribute()) { switch (scopePolicy) { case CodeGenerationPolicy::Public: case CodeGenerationPolicy::Private: case CodeGenerationPolicy::Protected: scopeStr = rdoc->scopeToRubyDecl((Uml::Visibility::Value) scopePolicy); break; default: case CodeGenerationPolicy::FromParent: // do nothing here... will leave as from parent object break; } } QString typeName = rcf->getTypeName(); QString fieldName = rcf->getFieldName(); QString initialV = rcf->getInitialValue(); if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue()) typeName = "Array"; QString body = staticValue+scopeStr+' '+typeName+' '+fieldName; if (!initialV.isEmpty()) body.append(" = " + initialV); else if (!cf->parentIsAttribute()) { UMLRole * role = dynamic_cast<UMLRole*>(cf->getParentObject()); if (role->getObject()->getBaseType() == Uml::ot_Interface) { // do nothing.. can't instanciate an interface } else { // FIX?: IF a constructor method exists in the classifiercodedoc // of the parent Object, then we can use that instead (if its empty). if(cf->fieldIsSingleValue()) { if(!typeName.isEmpty()) body.append(" = " + typeName + ".new()"); } else body.append(" = []"); } } setText(body); }
/** * Create an Umbrello object from a PetalNode of the Logical View. * * @return True for success. * Given a PetalNode for which the mapping to Umbrello is not yet * implemented umbrellify() is a no-op but also returns true. */ bool umbrellify(PetalNode *node, UMLPackage *parentPkg = NULL) { if (node == NULL) { uError() << "umbrellify: node is NULL"; return false; } QStringList args = node->initialArgs(); QString objType = args[0]; QString name = clean(args[1]); Uml::IDType id = quid(node); if (objType == "Class_Category") { UMLObject *o = Import_Utils::createUMLObject(UMLObject::ot_Package, name, parentPkg); o->setID(id); PetalNode *logical_models = node->findAttribute("logical_models").node; if (logical_models) { UMLPackage *localParent = static_cast<UMLPackage*>(o); PetalNode::NameValueList atts = logical_models->attributes(); for (int i = 0; i < atts.count(); ++i) { umbrellify(atts[i].second.node, localParent); } } else if (!handleControlledUnit(node, name, id, parentPkg)) { uDebug() << "umbrellify: handling of " << objType << " " << name << " is not yet implemented"; } } else if (objType == "Class") { UMLObject *o = Import_Utils::createUMLObject(UMLObject::ot_Class, name, parentPkg); o->setID(id); UMLClassifier *c = static_cast<UMLClassifier*>(o); // set stereotype QString stereotype = clean(node->findAttribute("stereotype").string); if (!stereotype.isEmpty()) { if (stereotype.toLower() == "interface") c->setBaseType(UMLObject::ot_Interface); else c->setStereotype(stereotype); } // insert attributes AttributesReader attReader(c); attReader.read(node, c->name()); // insert operations OperationsReader opReader(c); opReader.read(node, c->name()); // insert generalizations SuperclassesReader superReader(c); superReader.read(node, c->name()); // insert realizations RealizationsReader realReader(c); realReader.read(node, c->name()); } else if (objType == "Association") { PetalNode *roles = node->findAttribute("roles").node; if (node == NULL) { uError() << "umbrellify: cannot find roles of Association"; return false; } UMLAssociation *assoc = new UMLAssociation(Uml::AssociationType::UniAssociation); PetalNode::NameValueList roleList = roles->attributes(); for (uint i = 0; i <= 1; ++i) { PetalNode *roleNode = roleList[i].second.node; if (roleNode == NULL) { uError() << "umbrellify: roleNode of Association is NULL"; return false; } if (roleNode->name() != "Role") { uDebug() << "umbrellify(" << name << "): expecting Role, found \"" << roleNode->name(); continue; } // index 0 corresponds to Umbrello roleB // index 1 corresponds to Umbrello roleA UMLRole *role = assoc->getUMLRole((Uml::Role_Type) !i); QStringList initialArgs = roleNode->initialArgs(); if (initialArgs.count() > 1) { QString roleName = clean(initialArgs[1]); if (! roleName.startsWith(QLatin1String("$UNNAMED"))) role->setName(roleName); } role->setID(quid(roleNode)); QString quidref = quidu(roleNode); QString type = clean(roleNode->findAttribute("supplier").string); if (!quidref.isEmpty()) { role->setSecondaryId(quidref); } if (!type.isEmpty()) { role->setSecondaryFallback(type); } QString label = clean(roleNode->findAttribute("label").string); if (!label.isEmpty()) { role->setName(label); } QString client_cardinality = clean(roleNode->findAttribute("client_cardinality").string); if (!client_cardinality.isEmpty()) { role->setMultiplicity(client_cardinality); } QString is_navigable = clean(roleNode->findAttribute("is_navigable").string); if (is_navigable == "FALSE") { assoc->setAssociationType(Uml::AssociationType::Association); } QString is_aggregate = clean(roleNode->findAttribute("is_aggregate").string); if (is_aggregate == "TRUE") { assoc->setAssociationType(Uml::AssociationType::Aggregation); } QString containment = clean(roleNode->findAttribute("Containment").string); if (containment == "By Value") { assoc->setAssociationType(Uml::AssociationType::Composition); } QString doc = roleNode->findAttribute("documentation").string; if (! doc.isEmpty()) role->setDoc(doc); } UMLApp::app()->document()->addAssociation(assoc); } else { uDebug() << "umbrellify: object type " << objType << " is not yet implemented"; } return true; }
/** * This will be called by syncToParent whenever the parent object is "modified". */ void DCodeClassFieldDeclarationBlock::updateContent() { CodeClassField * cf = getParentClassField(); DCodeClassField * jcf = dynamic_cast<DCodeClassField*>(cf); if (!jcf) { uError() << "jcf: invalid dynamic cast"; return; } CodeGenerationPolicy * commonpolicy = UMLApp::app()->commonPolicy(); Uml::Visibility::Enum scopePolicy = commonpolicy->getAssociationFieldScope(); // Set the comment QString notes = getParentObject()->doc(); getComment()->setText(notes); // Set the body QString staticValue = getParentObject()->isStatic() ? QLatin1String("static ") : QString(); QString scopeStr = Uml::Visibility::toString(getParentObject()->visibility()); // IF this is from an association, then scope taken as appropriate to policy if (!jcf->parentIsAttribute()) { switch (scopePolicy) { case Uml::Visibility::Public: case Uml::Visibility::Private: case Uml::Visibility::Protected: scopeStr = Uml::Visibility::toString(scopePolicy); break; default: case Uml::Visibility::FromParent: // do nothing here... will leave as from parent object break; } } QString typeName = jcf->getTypeName(); QString fieldName = jcf->getFieldName(); QString initialV = jcf->getInitialValue(); if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue()) typeName = QLatin1String("List"); QString body = staticValue + scopeStr + QLatin1Char(' ') + typeName + QLatin1Char(' ') + fieldName; if (!initialV.isEmpty()) body.append(QLatin1String(" = ") + initialV); else if (!cf->parentIsAttribute()) { UMLRole * role = dynamic_cast<UMLRole*>(cf->getParentObject()); // Check for dynamic casting failure! if (role == NULL) { uError() << "role: invalid dynamic cast"; return; } if (role->object()->baseType() == UMLObject::ot_Interface) { // do nothing.. can't instantiate an interface } else { // FIX?: IF a constructor method exists in the classifiercodedoc // of the parent Object, then we can use that instead (if its empty). if(cf->fieldIsSingleValue()) { if(!typeName.isEmpty()) body.append(QLatin1String(" = new ") + typeName + QLatin1String(" ()")); } else body.append(QLatin1String(" = new Vector ()")); } } setText(body + QLatin1Char(';')); }