• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

umbrello/umbrello

  • sources
  • kde-4.12
  • kdesdk
  • umbrello
  • umbrello
  • codegenerators
  • java
javaantcodedocument.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * This program is free software; you can redistribute it and/or modify *
3  * it under the terms of the GNU General Public License as published by *
4  * the Free Software Foundation; either version 2 of the License, or *
5  * (at your option) any later version. *
6  * *
7  * copyright (C) 2003 Brian Thomas <thomas@mail630.gsfc.nasa.gov> *
8  * copyright (C) 2004-2013 *
9  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
10  ***************************************************************************/
11 
12 // own header
13 #include "javaantcodedocument.h"
14 
15 // local includes
16 #include "debug_utils.h"
17 #include "javacodegenerator.h"
18 #include "xmlcodecomment.h"
19 #include "xmlelementcodeblock.h"
20 #include "codegenfactory.h"
21 #include "umldoc.h"
22 #include "uml.h"
23 
24 // qt includes
25 #include <QRegExp>
26 
27 JavaANTCodeDocument::JavaANTCodeDocument ()
28 {
29  setFileName("build"); // default name
30  setFileExtension(".xml");
31  setID("ANTDOC"); // default id tag for this type of document
32 }
33 
34 JavaANTCodeDocument::~JavaANTCodeDocument ()
35 {
36 }
37 
38 //**
39 // * create a new CodeBlockWithComments object belonging to this CodeDocument.
40 // * @return CodeBlockWithComments
41 // */
42 /*
43 CodeBlockWithComments * JavaANTCodeDocument::newCodeBlockWithComments ()
44 {
45  return new XMLElementCodeBlock(this,"empty");
46 }
47 */
48 
49 HierarchicalCodeBlock * JavaANTCodeDocument::newHierarchicalCodeBlock ()
50 {
51  return new XMLElementCodeBlock(this,"empty");
52 }
53 
54 // Sigh. NOT optimal. The only reason that we need to have this
55 // is so we can create the XMLNodes, if needed.
56 // would be better if we could create a handler interface that each
57 // codeblock used so all we have to do here is add the handler
58 void JavaANTCodeDocument::loadChildTextBlocksFromNode (QDomElement & root)
59 {
60  QDomNode tnode = root.firstChild();
61  QDomElement telement = tnode.toElement();
62  bool loadCheckForChildrenOK = false;
63  while(!telement.isNull()) {
64  QString nodeName = telement.tagName();
65 
66  if(nodeName == "textblocks") {
67 
68  QDomNode node = telement.firstChild();
69  QDomElement element = node.toElement();
70 
71  // if there is nothing to begin with, then we don't worry about it
72  loadCheckForChildrenOK = element.isNull() ? true : false;
73 
74  while(!element.isNull()) {
75  QString name = element.tagName();
76 
77  if(name == "codecomment") {
78  CodeComment * block = new XMLCodeComment(this);
79  block->loadFromXMI(element);
80  if(!addTextBlock(block))
81  {
82  uError()<<"Unable to add codeComment to :"<<this;
83  delete block;
84  } else
85  loadCheckForChildrenOK= true;
86  } else
87  if(name == "codeaccessormethod" ||
88  name == "ccfdeclarationcodeblock"
89  ) {
90  QString acctag = element.attribute("tag","");
91  // search for our method in the
92  TextBlock * tb = findCodeClassFieldTextBlockByTag(acctag);
93  if(!tb || !addTextBlock(tb))
94  {
95  uError()<<"Unable to add codeclassfield child method to:"<<this;
96  // DON'T delete
97  } else
98  loadCheckForChildrenOK= true;
99 
100  } else
101  if(name == "codeblock") {
102  CodeBlock * block = newCodeBlock();
103  block->loadFromXMI(element);
104  if(!addTextBlock(block))
105  {
106  uError()<<"Unable to add codeBlock to :"<<this;
107  delete block;
108  } else
109  loadCheckForChildrenOK= true;
110  } else
111  if(name == "codeblockwithcomments") {
112  CodeBlockWithComments * block = newCodeBlockWithComments();
113  block->loadFromXMI(element);
114  if(!addTextBlock(block))
115  {
116  uError()<<"Unable to add codeBlockwithcomments to:"<<this;
117  delete block;
118  } else
119  loadCheckForChildrenOK= true;
120  } else
121  if(name == "header") {
122  // do nothing.. this is treated elsewhere
123  } else
124  if(name == "hierarchicalcodeblock") {
125  HierarchicalCodeBlock * block = newHierarchicalCodeBlock();
126  block->loadFromXMI(element);
127  if(!addTextBlock(block))
128  {
129  uError()<<"Unable to add hierarchicalcodeBlock to:"<<this;
130  delete block;
131  } else
132  loadCheckForChildrenOK= true;
133  } else
134  if(name == "codeoperation") {
135  // find the code operation by id
136  QString id = element.attribute("parent_id","-1");
137  UMLObject * obj = UMLApp::app()->document()->findObjectById(Uml::ID::fromString(id));
138  UMLOperation * op = dynamic_cast<UMLOperation*>(obj);
139  if(op) {
140  CodeOperation * block = 0;
141  uError() << "TODO: implement CodeGenFactory::newCodeOperation() for JavaANTCodeDocument";
142  break; // remove when above is implemented
143  block->loadFromXMI(element);
144  if(addTextBlock(block))
145  loadCheckForChildrenOK= true;
146  else
147  {
148  uError()<<"Unable to add codeoperation to:"<<this;
149  block->deleteLater();
150  }
151  } else
152  uError()<<"Unable to find operation create codeoperation for:"<<this;
153  } else
154  if(name == "xmlelementblock") {
155  QString xmltag = element.attribute("nodeName","UNKNOWN");
156  XMLElementCodeBlock * block = new XMLElementCodeBlock(this, xmltag);
157  block->loadFromXMI(element);
158  if(!addTextBlock(block))
159  {
160  uError()<<"Unable to add XMLelement to Java ANT document:"<<this;
161  delete block;
162  } else
163  loadCheckForChildrenOK= true;
164  }
165  /*
166  // only needed for extreme debugging conditions (E.g. making new codeclassdocument loader)
167  else
168  uDebug()<<" LoadFromXMI: Got strange tag in text block stack:"<<name<<", ignorning";
169  */
170 
171  node = element.nextSibling();
172  element = node.toElement();
173  }
174  break;
175  }
176 
177  tnode = telement.nextSibling();
178  telement = tnode.toElement();
179  }
180 
181  if(!loadCheckForChildrenOK)
182  {
183  CodeDocument * test = dynamic_cast<CodeDocument*>(this);
184  if(test)
185  {
186  uWarning()<<" loadChildBlocks : unable to initialize any child blocks in doc: "<<test->getFileName()<<" "<<this;
187  } else {
188  HierarchicalCodeBlock * hb = dynamic_cast<HierarchicalCodeBlock*>(this);
189  if(hb)
190  uWarning()<<" loadChildBlocks : unable to initialize any child blocks in Hblock: "<<hb->getTag()<<" "<<this;
191  else
192  uDebug()<<" loadChildBlocks : unable to initialize any child blocks in UNKNOWN OBJ:"<<this;
193  }
194  }
195 
196 }
197 
201 void JavaANTCodeDocument::setAttributesFromNode (QDomElement & root)
202 {
203  // superclass save
204  CodeDocument::setAttributesFromNode(root);
205 
206  // now set local attributes
207  // setPackage(root.attribute("package",""));
208 }
209 
213 void JavaANTCodeDocument::loadFromXMI (QDomElement & root)
214 {
215  setAttributesFromNode(root);
216 }
217 
221 void JavaANTCodeDocument::setAttributesOnNode (QDomDocument & doc, QDomElement & docElement)
222 {
223  // superclass call
224  CodeDocument::setAttributesOnNode(doc, docElement);
225 
226  // now set local attributes/fields
227  //FIX
228 }
229 
233 void JavaANTCodeDocument::saveToXMI (QDomDocument & doc, QDomElement & root)
234 {
235  QDomElement docElement = doc.createElement("codedocument");
236 
237  setAttributesOnNode(doc, docElement);
238 
239  root.appendChild(docElement);
240 }
241 
242 // we add in our code blocks that describe how to generate
243 // the project here...
244 void JavaANTCodeDocument::updateContent()
245 {
246  // FIX : fill in more content based on classes
247  // which exist
248  CodeBlockWithComments * xmlDecl = getCodeBlockWithComments("xmlDecl","", 0);
249  xmlDecl->setText("<?xml version=\"1.0\"?>");
250  addTextBlock(xmlDecl);
251 
252  XMLElementCodeBlock * rootNode = new XMLElementCodeBlock(this, "project", "Java ANT build document");
253  rootNode->setTag("projectDecl");
254  addTextBlock(rootNode);
255 
256  // <project name="XDF" default="help" basedir=".">
257  //HierarchicalCodeBlock * projDecl = xmlDecl->getHierarchicalCodeBlock("projectDecl", "Java ANT build document", 1);
258 
259  // set some global properties for the build
260  /*
261  <!-- set global properties for this build -->
262  <!-- paths -->
263  <property name="docApi.dir" value="docs/api"/>
264  <property name="path" value="gov/nasa/gsfc/adc/xdf"/>
265  <property name="src" value="src/${path}/"/>
266  <property name="top" value="."/>
267  <property name="build" value="${top}/gov"/>
268  <property name="buildDir" value="${path}"/>
269  <!-- compiler directives -->
270  <property name="build.compiler" value="modern"/>
271  <property name="useDeprecation" value="no"/>
272  <property name="jarname" value="${project}.jar"/>
273  */
274 }
275 
276 // We overwritten by Java language implementation to get lowercase path
277 QString JavaANTCodeDocument::getPath ()
278 {
279  QString path = getPackage();
280 
281  // Replace all white spaces with blanks
282  path.simplified();
283 
284  // Replace all blanks with underscore
285  path.replace(QRegExp(" "), "_");
286 
287  path.replace(QRegExp("\\."),"/");
288  path.replace(QRegExp("::"), "/");
289 
290  path = path.toLower();
291 
292  return path;
293 }
294 
295 
296 #include "javaantcodedocument.moc"
CodeBlock::loadFromXMI
virtual void loadFromXMI(QDomElement &root)
Load params from the appropriate XMI element node.
Definition: codeblock.cpp:91
JavaANTCodeDocument::loadChildTextBlocksFromNode
virtual void loadChildTextBlocksFromNode(QDomElement &root)
Need to overwrite this for java since we need to pick up the xml declaration blocks.
Definition: javaantcodedocument.cpp:58
XMLCodeComment
class XMLCodeDocumentation A XML (code) comment.
Definition: xmlcodecomment.h:25
CodeDocument::newCodeBlockWithComments
virtual CodeBlockWithComments * newCodeBlockWithComments()
Create a new CodeBlockWithComments object belonging to this CodeDocument.
Definition: codedocument.cpp:465
CodeDocument::newCodeBlock
virtual CodeBlock * newCodeBlock()
Create a new CodeBlock object belonging to this CodeDocument.
Definition: codedocument.cpp:456
CodeBlock
A "chunk" of code within the code document.
Definition: codeblock.h:20
CodeComment::loadFromXMI
virtual void loadFromXMI(QDomElement &root)
Load params from the appropriate XMI element node.
Definition: codecomment.cpp:42
TextBlock::setText
void setText(const QString &text)
Set the value of m_text The actual text of this code block.
Definition: textblock.cpp:80
TextBlock::getTag
QString getTag() const
Get the tag of this text block.
Definition: textblock.cpp:110
JavaANTCodeDocument::~JavaANTCodeDocument
virtual ~JavaANTCodeDocument()
Empty Destructor.
Definition: javaantcodedocument.cpp:34
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
JavaANTCodeDocument::setAttributesFromNode
virtual void setAttributesFromNode(QDomElement &element)
Set the class attributes of this object from the passed element node.
Definition: javaantcodedocument.cpp:201
uWarning
#define uWarning()
Definition: debug_utils.h:97
JavaANTCodeDocument::JavaANTCodeDocument
JavaANTCodeDocument()
Constructor.
Definition: javaantcodedocument.cpp:27
UMLApp::document
UMLDoc * document() const
Returns a pointer to the current document connected to the KMainWindow instance.
Definition: uml.cpp:872
JavaANTCodeDocument::getPath
QString getPath()
Get the value of the path to this code document.
Definition: javaantcodedocument.cpp:277
CodeGenObjectWithTextBlocks::getCodeBlockWithComments
virtual CodeBlockWithComments * getCodeBlockWithComments(const QString &tag, const QString &comment, int indentLevel)
Will get a codeblockwithcomments from the document with given tag.
Definition: codegenobjectwithtextblocks.cpp:217
CodeGenObjectWithTextBlocks::addTextBlock
virtual bool addTextBlock(TextBlock *add_object)
Add a TextBlock object to the m_textblockVector List.
Definition: codegenobjectwithtextblocks.cpp:57
debug_utils.h
UMLObject
This class is the non-graphical version of UMLWidget.
Definition: umlobject.h:41
XMLElementCodeBlock::loadFromXMI
virtual void loadFromXMI(QDomElement &root)
Load params from the appropriate XMI element node.
Definition: xmlelementcodeblock.cpp:46
JavaANTCodeDocument::loadFromXMI
virtual void loadFromXMI(QDomElement &root)
Load params from the appropriate XMI element node.
Definition: javaantcodedocument.cpp:213
CodeBlockWithComments
class CodeBlockWithComments A very common type of text block in any type of code. ...
Definition: codeblockwithcomments.h:24
XMLElementCodeBlock
Definition: xmlelementcodeblock.h:23
codegenfactory.h
HierarchicalCodeBlock::loadFromXMI
virtual void loadFromXMI(QDomElement &root)
load params from the appropriate XMI element node.
Definition: hierarchicalcodeblock.cpp:269
CodeOperation
Definition: codeoperation.h:23
javaantcodedocument.h
CodeOperation::loadFromXMI
virtual void loadFromXMI(QDomElement &root)
Load params from the appropriate XMI element node.
Definition: codeoperation.cpp:83
JavaANTCodeDocument::saveToXMI
virtual void saveToXMI(QDomDocument &doc, QDomElement &root)
Save the XMI representation of this object.
Definition: javaantcodedocument.cpp:233
CodeDocument::setAttributesOnNode
virtual void setAttributesOnNode(QDomDocument &doc, QDomElement &blockElement)
Set attributes of the node that represents this class in the XMI document.
Definition: codedocument.cpp:356
CodeDocument
A document containing the code for one file.
Definition: codedocument.h:32
xmlcodecomment.h
CodeDocument::setAttributesFromNode
virtual void setAttributesFromNode(QDomElement &element)
Set the class attributes of this object from the passed element node.
Definition: codedocument.cpp:386
uDebug
#define uDebug()
Definition: debug_utils.h:95
JavaANTCodeDocument::newHierarchicalCodeBlock
virtual HierarchicalCodeBlock * newHierarchicalCodeBlock()
Create a new HierarchicalCodeBlock object belonging to this CodeDocument.
Definition: javaantcodedocument.cpp:49
CodeDocument::setFileName
void setFileName(const QString &new_var)
Set the complete value (name plus any extension) of m_filename.
Definition: codedocument.cpp:53
JavaANTCodeDocument::setAttributesOnNode
virtual void setAttributesOnNode(QDomDocument &doc, QDomElement &blockElement)
Set attributes of the node that represents this class in the XMI document.
Definition: javaantcodedocument.cpp:221
UMLDoc::findObjectById
UMLObject * findObjectById(Uml::ID::Type id)
Used to find a reference to a UMLObject by its ID.
Definition: umldoc.cpp:766
HierarchicalCodeBlock
Definition: hierarchicalcodeblock.h:22
javacodegenerator.h
umldoc.h
TextBlock
The fundemental unit of text within an output file containing code.
Definition: textblock.h:24
UMLOperation
This class represents an operation in the UML model.
Definition: operation.h:24
JavaANTCodeDocument::updateContent
void updateContent()
Update the content of this code document.
Definition: javaantcodedocument.cpp:244
xmlelementcodeblock.h
CodeDocument::findCodeClassFieldTextBlockByTag
virtual TextBlock * findCodeClassFieldTextBlockByTag(const QString &tag)
Have to implement this for CodeObjectWithTextBlocks.
Definition: codedocument.cpp:516
uError
#define uError()
Definition: debug_utils.h:96
Uml::ID::fromString
ID::Type fromString(const QString &id)
Definition: basictypes.cpp:1053
CodeComment
Text which will be comments.
Definition: codecomment.h:23
CodeDocument::getFileName
QString getFileName() const
Get the value of m_filename.
Definition: codedocument.cpp:63
CodeDocument::setFileExtension
void setFileExtension(const QString &new_var)
Set the value of m_fileExtension.
Definition: codedocument.cpp:72
CodeDocument::getPackage
QString getPackage() const
Get the value of the package of this code document.
Definition: codedocument.cpp:122
CodeDocument::setID
void setID(const QString &new_id)
Set the value of m_ID.
Definition: codedocument.cpp:133
CodeBlockWithComments::loadFromXMI
virtual void loadFromXMI(QDomElement &root)
Load params from the appropriate XMI element node.
Definition: codeblockwithcomments.cpp:96
uml.h
TextBlock::setTag
void setTag(const QString &value)
Set the tag of this text block.
Definition: textblock.cpp:121
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:05:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

umbrello/umbrello

Skip menu "umbrello/umbrello"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal