umbrello API Documentation

component.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2003-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 // own header
00013 #include "component.h"
00014 // qt/kde includes
00015 #include <kdebug.h>
00016 #include <klocale.h>
00017 // app includes
00018 #include "association.h"
00019 #include "object_factory.h"
00020 #include "model_utils.h"
00021 #include "clipboard/idchangelog.h"
00022 
00023 UMLComponent::UMLComponent(const QString & name, Uml::IDType id)
00024         : UMLPackage(name, id) {
00025     init();
00026 }
00027 
00028 UMLComponent::~UMLComponent() {
00029 }
00030 
00031 void UMLComponent::init() {
00032     m_BaseType = Uml::ot_Component;
00033     m_executable = false;
00034 }
00035 
00036 UMLObject* UMLComponent::clone() const {
00037     UMLComponent *clone = new UMLComponent();
00038     UMLObject::copyInto(clone);
00039     return clone;
00040 }
00041 
00042 void UMLComponent::saveToXMI(QDomDocument& qDoc, QDomElement& qElement) {
00043     QDomElement componentElement = UMLObject::save("UML:Component", qDoc);
00044     componentElement.setAttribute("executable", m_executable);
00045     // Save contained components if any.
00046     if (m_objects.count()) {
00047         QDomElement ownedElement = qDoc.createElement( "UML:Namespace.ownedElement" );
00048         for (UMLObject *obj = m_objects.first(); obj; obj = m_objects.next())
00049             obj->saveToXMI (qDoc, ownedElement);
00050         componentElement.appendChild(ownedElement);
00051     }
00052     qElement.appendChild(componentElement);
00053 }
00054 
00055 bool UMLComponent::load(QDomElement& element) {
00056     QString executable = element.attribute("executable", "0");
00057     m_executable = (bool)executable.toInt();
00058     for (QDomNode node = element.firstChild(); !node.isNull();
00059             node = node.nextSibling()) {
00060         if (node.isComment())
00061             continue;
00062         QDomElement tempElement = node.toElement();
00063         QString type = tempElement.tagName();
00064         if (Model_Utils::isCommonXMIAttribute(type))
00065             continue;
00066         if (Uml::tagEq(type, "Namespace.ownedElement") ||
00067                 Uml::tagEq(type, "Namespace.contents")) {
00068             //CHECK: Umbrello currently assumes that nested elements
00069             // are ownedElements anyway.
00070             // Therefore these tags are not further interpreted.
00071             if (! load(tempElement))
00072                 return false;
00073             continue;
00074         }
00075         UMLObject *pObject = Object_Factory::makeObjectFromXMI(type);
00076         if( !pObject ) {
00077             kWarning() << "UMLComponent::load: "
00078                         << "Unknown type of umlobject to create: "
00079                         << type << endl;
00080             continue;
00081         }
00082         pObject->setUMLPackage(this);
00083         if (pObject->loadFromXMI(tempElement)) {
00084             addObject(pObject);
00085         } else {
00086             delete pObject;
00087         }
00088     }
00089     return true;
00090 }
00091 
00092 void UMLComponent::setExecutable(bool executable) {
00093     m_executable = executable;
00094 }
00095 
00096 bool UMLComponent::getExecutable() {
00097     return m_executable;
00098 }
00099 
00100 #include "component.moc"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:55 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003