umbrello API Documentation

javaantcodedocument.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) 2004-2007                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 /*  This code generated by:
00013  *      Author : thomas
00014  *      Date   : Tue Jun 24 2003
00015  */
00016 
00017 // own header
00018 #include "javaantcodedocument.h"
00019 
00020 // qt/kde includes
00021 #include <qregexp.h>
00022 #include <kdebug.h>
00023 
00024 // local includes
00025 #include "javacodegenerator.h"
00026 #include "xmlcodecomment.h"
00027 #include "xmlelementcodeblock.h"
00028 #include "codegenfactory.h"
00029 #include "../umldoc.h"
00030 #include "../uml.h"
00031 
00032 
00033 // Constructors/Destructors
00034 //
00035 
00036 JavaANTCodeDocument::JavaANTCodeDocument ( )
00037 {
00038     setFileName("build"); // default name
00039     setFileExtension(".xml");
00040     setID("ANTDOC"); // default id tag for this type of document
00041 }
00042 
00043 JavaANTCodeDocument::~JavaANTCodeDocument ( ) { }
00044 
00045 //
00046 // Methods
00047 //
00048 
00049 // Other methods
00050 //
00051 
00056 /*
00057 CodeBlockWithComments * JavaANTCodeDocument::newCodeBlockWithComments ( ) {
00058         return new XMLElementCodeBlock(this,"empty");
00059 }
00060 */
00061 
00062 HierarchicalCodeBlock * JavaANTCodeDocument::newHierarchicalCodeBlock ( ) {
00063     return new XMLElementCodeBlock(this,"empty");
00064 }
00065 
00066 // Sigh. NOT optimal. The only reason that we need to have this
00067 // is so we can create the XMLNodes, if needed.
00068 // would be better if we could create a handler interface that each
00069 // codeblock used so all we have to do here is add the handler
00070 void JavaANTCodeDocument::loadChildTextBlocksFromNode ( QDomElement & root)
00071 {
00072 
00073     QDomNode tnode = root.firstChild();
00074     QDomElement telement = tnode.toElement();
00075     bool loadCheckForChildrenOK = false;
00076     while( !telement.isNull() ) {
00077         QString nodeName = telement.tagName();
00078 
00079         if( nodeName == "textblocks" ) {
00080 
00081             QDomNode node = telement.firstChild();
00082             QDomElement element = node.toElement();
00083 
00084             // if there is nothing to begin with, then we don't worry about it
00085             loadCheckForChildrenOK = element.isNull() ? true : false;
00086 
00087             while( !element.isNull() ) {
00088                 QString name = element.tagName();
00089 
00090                 if( name == "codecomment" ) {
00091                     CodeComment * block = new XMLCodeComment(this);
00092                     block->loadFromXMI(element);
00093                     if(!addTextBlock(block))
00094                     {
00095                         kError()<<"Unable to add codeComment to :"<<this<<endl;
00096                         block->deleteLater();
00097                     } else
00098                         loadCheckForChildrenOK= true;
00099                 } else
00100                     if( name == "codeaccessormethod" ||
00101                             name == "ccfdeclarationcodeblock"
00102                       ) {
00103                         QString acctag = element.attribute("tag","");
00104                         // search for our method in the
00105                         TextBlock * tb = findCodeClassFieldTextBlockByTag(acctag);
00106                         if(!tb || !addTextBlock(tb))
00107                         {
00108                             kError()<<"Unable to add codeclassfield child method to:"<<this<<endl;
00109                             // DON'T delete
00110                         } else
00111                             loadCheckForChildrenOK= true;
00112 
00113                     } else
00114                         if( name == "codeblock" ) {
00115                             CodeBlock * block = newCodeBlock();
00116                             block->loadFromXMI(element);
00117                             if(!addTextBlock(block))
00118                             {
00119                                 kError()<<"Unable to add codeBlock to :"<<this<<endl;
00120                                 block->deleteLater();
00121                             } else
00122                                 loadCheckForChildrenOK= true;
00123                         } else
00124                             if( name == "codeblockwithcomments" ) {
00125                                 CodeBlockWithComments * block = newCodeBlockWithComments();
00126                                 block->loadFromXMI(element);
00127                                 if(!addTextBlock(block))
00128                                 {
00129                                     kError()<<"Unable to add codeBlockwithcomments to:"<<this<<endl;
00130                                     block->deleteLater();
00131                                 } else
00132                                     loadCheckForChildrenOK= true;
00133                             } else
00134                                 if( name == "header" ) {
00135                                     // do nothing.. this is treated elsewhere
00136                                 } else
00137                                     if( name == "hierarchicalcodeblock" ) {
00138                                         HierarchicalCodeBlock * block = newHierarchicalCodeBlock();
00139                                         block->loadFromXMI(element);
00140                                         if(!addTextBlock(block))
00141                                         {
00142                                             kError()<<"Unable to add hierarchicalcodeBlock to:"<<this<<endl;
00143                                             block->deleteLater();
00144                                         } else
00145                                             loadCheckForChildrenOK= true;
00146                                     } else
00147                                         if( name == "codeoperation" ) {
00148                                             // find the code operation by id
00149                                             QString id = element.attribute("parent_id","-1");
00150                                             UMLObject * obj = UMLApp::app()->getDocument()->findObjectById(STR2ID(id));
00151                                             UMLOperation * op = dynamic_cast<UMLOperation*>(obj);
00152                                             if(op) {
00153                                                 CodeOperation * block = 0;
00154                                                 kError() << "TODO: implement CodeGenFactory::newCodeOperation() for JavaANTCodeDocument" << endl;
00155                                                 break;  // remove when above is implemented
00156                                                 block->loadFromXMI(element);
00157                                                 if(addTextBlock(block))
00158                                                     loadCheckForChildrenOK= true;
00159                                                 else
00160                                                 {
00161                                                     kError()<<"Unable to add codeoperation to:"<<this<<endl;
00162                                                     block->deleteLater();
00163                                                 }
00164                                             } else
00165                                                 kError()<<"Unable to find operation create codeoperation for:"<<this<<endl;
00166                                         } else
00167                                             if( name == "xmlelementblock" ) {
00168                                                 QString xmltag = element.attribute("nodeName","UNKNOWN");
00169                                                 XMLElementCodeBlock * block = new XMLElementCodeBlock(this,xmltag);
00170                                                 block->loadFromXMI(element);
00171                                                 if(!addTextBlock(block))
00172                                                 {
00173                                                     kError()<<"Unable to add XMLelement to Java ANT document:"<<this<<endl;
00174                                                     block->deleteLater();
00175                                                 } else
00176                                                     loadCheckForChildrenOK= true;
00177                                             }
00178                 /*
00179                                                 // only needed for extreme debugging conditions (E.g. making new codeclassdocument loader)
00180                                                 else
00181                                                         kDebug()<<" LoadFromXMI: Got strange tag in text block stack:"<<name<<", ignorning"<<endl;
00182                 */
00183 
00184                 node = element.nextSibling();
00185                 element = node.toElement();
00186             }
00187             break;
00188         }
00189 
00190         tnode = telement.nextSibling();
00191         telement = tnode.toElement();
00192     }
00193 
00194     if(!loadCheckForChildrenOK)
00195     {
00196         CodeDocument * test = dynamic_cast<CodeDocument*>(this);
00197         if(test)
00198         {
00199             kWarning()<<" loadChildBlocks : unable to initialize any child blocks in doc: "<<test->getFileName()<<" "<<this<<endl;
00200         } else {
00201             HierarchicalCodeBlock * hb = dynamic_cast<HierarchicalCodeBlock*>(this);
00202             if(hb)
00203                 kWarning()<<" loadChildBlocks : unable to initialize any child blocks in Hblock: "<<hb->getTag()<<" "<<this<<endl;
00204             else
00205                 kDebug()<<" loadChildBlocks : unable to initialize any child blocks in UNKNOWN OBJ:"<<this<<endl;
00206         }
00207     }
00208 
00209 }
00210 
00214 void JavaANTCodeDocument::setAttributesFromNode ( QDomElement & root)
00215 {
00216 
00217     // superclass save
00218     CodeDocument::setAttributesFromNode(root);
00219 
00220     // now set local attributes
00221     // setPackage(root.attribute("package",""));
00222 
00223 }
00224 
00228 void JavaANTCodeDocument::loadFromXMI ( QDomElement & root ) {
00229     setAttributesFromNode(root);
00230 }
00231 
00235 void JavaANTCodeDocument::setAttributesOnNode ( QDomDocument & doc, QDomElement & docElement)
00236 {
00237 
00238     // superclass call
00239     CodeDocument::setAttributesOnNode(doc,docElement);
00240 
00241     // now set local attributes/fields
00242     //FIX
00243 }
00244 
00248 void JavaANTCodeDocument::saveToXMI ( QDomDocument & doc, QDomElement & root ) {
00249     QDomElement docElement = doc.createElement( "codedocument" );
00250 
00251     setAttributesOnNode(doc, docElement);
00252 
00253     root.appendChild( docElement );
00254 }
00255 
00256 // we add in our code blocks that describe how to generate
00257 // the project here...
00258 void JavaANTCodeDocument::updateContent( ) {
00259     // FIX : fill in more content based on classes
00260     // which exist
00261     CodeBlockWithComments * xmlDecl = getCodeBlockWithComments("xmlDecl","",0);
00262     xmlDecl->setText("<?xml version=\"1.0\"?>");
00263     addTextBlock(xmlDecl);
00264 
00265     XMLElementCodeBlock * rootNode = new XMLElementCodeBlock(this, "project", "Java ANT build document");
00266     rootNode->setTag("projectDecl");
00267     addTextBlock(rootNode);
00268 
00269     // <project name="XDF" default="help" basedir=".">
00270     //HierarchicalCodeBlock * projDecl = xmlDecl->getHierarchicalCodeBlock("projectDecl", "Java ANT build document", 1);
00271 
00272     // set some global properties for the build
00273     /*
00274       <!-- set global properties for this build -->
00275       <!-- paths -->
00276       <property name="docApi.dir"  value="docs/api"/>
00277       <property name="path" value="gov/nasa/gsfc/adc/xdf"/>
00278       <property name="src" value="src/${path}/"/>
00279       <property name="top" value="."/>
00280       <property name="build" value="${top}/gov"/>
00281       <property name="buildDir" value="${path}"/>
00282       <!-- compiler directives -->
00283       <property name="build.compiler" value="modern"/>
00284       <property name="useDeprecation" value="no"/>
00285       <property name="jarname" value="${project}.jar"/>
00286     */
00287 
00288 }
00289 
00290 // We overwritten by Java language implementation to get lowercase path
00291 QString JavaANTCodeDocument::getPath ( )
00292 {
00293 
00294     QString path = getPackage();
00295 
00296     // Replace all white spaces with blanks
00297     path.simplifyWhiteSpace();
00298 
00299     // Replace all blanks with underscore
00300     path.replace(QRegExp(" "), "_");
00301 
00302     path.replace(QRegExp("\\."),"/");
00303     path.replace(QRegExp("::"), "/");
00304 
00305     path.lower();
00306 
00307     return path;
00308 
00309 }
00310 
00311 
00312 #include "javaantcodedocument.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:57 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003