[Uml-devel] KDE/kdesdk/umbrello/umbrello
Oliver Kellogg
okellogg at users.sourceforge.net
Tue Dec 11 21:30:19 UTC 2007
SVN commit 747387 by okellogg:
Implement saving/loading of UMLOperation <sourcecode> in the <XMI.extensions> <codegeneration>
CCMAIL:andi.fischer at hispeed.ch
M +59 -20 codegenerator.cpp
M +0 -18 operation.cpp
--- trunk/KDE/kdesdk/umbrello/umbrello/codegenerator.cpp #747386:747387
@@ -177,11 +177,7 @@
void CodeGenerator::loadFromXMI (QDomElement & qElement )
{
- // don't do anything for simple (compatibility) code generators
- if(dynamic_cast<SimpleCodeGenerator*>(this))
- return;
-
- //now look for our particular child element
+ // look for our particular child element
QDomNode node = qElement.firstChild();
QDomElement element = node.toElement();
QString langType = Model_Utils::progLangToString( getLanguage() );
@@ -193,12 +189,35 @@
// codedocuments
QDomNode codeDocNode = qElement.firstChild();
QDomElement codeDocElement = codeDocNode.toElement();
- while( !codeDocElement.isNull() ) {
-
+ while (!codeDocElement.isNull())
+ {
QString docTag = codeDocElement.tagName();
- if( docTag == "codedocument" ||
- docTag == "classifiercodedocument"
- ) {
+ if (docTag == "sourcecode")
+ {
+ QString idStr = codeDocElement.attribute("id", "-1");
+ QString value = codeDocElement.attribute("value", "");
+ Uml::IDType id = STR2ID(idStr);
+ UMLObject *obj = m_document->findObjectById(id);
+ if (obj)
+ {
+ Uml::Object_Type t = obj->getBaseType();
+ if (t == Uml::ot_Operation)
+ {
+ UMLOperation *op = static_cast<UMLOperation*>(obj);
+ op->setSourceCode(value);
+ }
+ else
+ uError() << "CodeGenerator::loadFromXMI: sourcecode id "
+ << idStr << " has unexpected type " << t << endl;
+ }
+ else
+ {
+ uError() << "CodeGenerator::loadFromXMI: unknown sourcecode id "
+ << idStr << endl;
+ }
+ }
+ else if (docTag == "codedocument" || docTag == "classifiercodedocument")
+ {
QString id = codeDocElement.attribute( "id", "-1" );
CodeDocument * codeDoc = findCodeDocumentByID(id);
if(codeDoc)
@@ -220,12 +239,33 @@
QDomElement docElement = doc.createElement( "codegenerator" );
docElement.setAttribute("language",langType);
- CodeDocumentList * docList = getCodeDocumentList();
- CodeDocumentList::iterator it = docList->begin();
- CodeDocumentList::iterator end = docList->end();
- for ( ; it != end; ++it )
- (*it)->saveToXMI(doc, docElement);
-
+ if (dynamic_cast<SimpleCodeGenerator*>(this))
+ {
+ UMLClassifierList concepts = m_document->getClassesAndInterfaces();
+ foreach (UMLClassifier *c, concepts)
+ {
+ UMLOperationList operations = c->getOpList();
+ foreach (UMLOperation *op, operations)
+ {
+ // save the source code
+ QString code = op->getSourceCode();
+ if (code.isEmpty())
+ continue;
+ QDomElement codeElement = doc.createElement("sourcecode");
+ codeElement.setAttribute("id", ID2STR(op->getID()));
+ codeElement.setAttribute("value", code);
+ docElement.appendChild( codeElement );
+ }
+ }
+ }
+ else
+ {
+ CodeDocumentList * docList = getCodeDocumentList();
+ CodeDocumentList::iterator it = docList->begin();
+ CodeDocumentList::iterator end = docList->end();
+ for ( ; it != end; ++it )
+ (*it)->saveToXMI(doc, docElement);
+ }
root.appendChild( docElement );
}
@@ -248,7 +288,7 @@
{
// Walk through the document converting classifiers into
// classifier code documents as needed (e.g only if doesn't exist)
- UMLClassifierList concepts = UMLApp::app()->getDocument()->getClassesAndInterfaces();
+ UMLClassifierList concepts = m_document->getClassesAndInterfaces();
foreach (UMLClassifier *c , concepts)
{
// Doesn't exist? Then build one.
@@ -679,10 +719,9 @@
void CodeGenerator::connect_newcodegen_slots()
{
- UMLDoc *doc = UMLApp::app()->getDocument();
- connect(doc, SIGNAL(sigObjectCreated(UMLObject*)),
+ connect(m_document, SIGNAL(sigObjectCreated(UMLObject*)),
this, SLOT(checkAddUMLObject(UMLObject*)));
- connect(doc, SIGNAL(sigObjectRemoved(UMLObject*)),
+ connect(m_document, SIGNAL(sigObjectRemoved(UMLObject*)),
this, SLOT(checkRemoveUMLObject(UMLObject*)));
CodeGenerationPolicy *commonPolicy = UMLApp::app()->getCommonPolicy();
connect(commonPolicy, SIGNAL(modifiedCodeContent()),
--- trunk/KDE/kdesdk/umbrello/umbrello/operation.cpp #747386:747387
@@ -351,21 +351,6 @@
if (featureElement.hasChildNodes()) {
operationElement.appendChild( featureElement );
}
- // save the source code
- if (! m_Code.isEmpty()) {
- /* //:TODO:
- QDomElement codeElement = qDoc.createElement("UML:SourceCode");
- codeElement.setAttribute("value", m_Code);
- operationElement.appendChild( codeElement );
- */
- CodeGenerator* codegen = UMLApp::app()->getGenerator();
- if (codegen) {
- CodeDocument* codedoc = new CodeDocument();
- CodeBlock* block = new CodeBlock(codedoc, m_Code);
- codedoc->insertTextBlock(block, NULL);
- codegen->addCodeDocument(codedoc);
- }
- }
qElement.appendChild( operationElement );
}
@@ -456,9 +441,6 @@
pAtt->setParmKind(Uml::pd_In);
m_List.append( pAtt );
}
- } else if (Uml::tagEq(tag, "SourceCode")) { //:TODO:
- m_Code = attElement.attribute("value", "");
- // uDebug() << "SourceCode found:\n" << m_Code;
}
node = node.nextSibling();
if (node.isComment())
More information about the umbrello-devel
mailing list