umbrello API Documentation

javacodeclassfield.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   : Mon Jun 30 2003
00015  */
00016 
00017 // own header
00018 #include "javacodeclassfield.h"
00019 
00020 // qt/kde includes
00021 #include <qregexp.h>
00022 #include <kdebug.h>
00023 
00024 // local includes
00025 #include "javacodecomment.h"
00026 #include "javacodegenerator.h"
00027 
00028 #include "../attribute.h"
00029 #include "../umlobject.h"
00030 #include "../umlrole.h"
00031 #include "../uml.h"
00032 
00033 // #include "javacodeaccessormethod.h"
00034 #include "javaclassifiercodedocument.h"
00035 
00036 // Constructors/Destructors
00037 //
00038 
00039 JavaCodeClassField::JavaCodeClassField (ClassifierCodeDocument * parentDoc, UMLRole * role)
00040         : CodeClassField(parentDoc, role)
00041 {
00042 
00043 }
00044 
00045 JavaCodeClassField::JavaCodeClassField (ClassifierCodeDocument * parentDoc, UMLAttribute * attrib)
00046         : CodeClassField(parentDoc, attrib)
00047 {
00048 
00049 }
00050 
00051 JavaCodeClassField::~JavaCodeClassField ( ) { }
00052 
00053 //
00054 // Methods
00055 //
00056 
00057 // Other methods
00058 //
00059 
00060 QString JavaCodeClassField::getFieldName() {
00061     if (parentIsAttribute())
00062     {
00063         UMLAttribute * at = (UMLAttribute*) getParentObject();
00064         return cleanName(at->getName());
00065     }
00066     else
00067     {
00068         UMLRole * role = (UMLRole*) getParentObject();
00069         QString roleName = role->getName();
00070         if(fieldIsSingleValue()) {
00071             return roleName.replace(0, 1, roleName.left(1).lower());
00072         } else {
00073             return roleName.lower() + "Vector";
00074         }
00075     }
00076 }
00077 
00078 
00079 QString JavaCodeClassField::getInitialValue() {
00080 
00081     if (parentIsAttribute())
00082     {
00083         UMLAttribute * at = dynamic_cast<UMLAttribute*>( getParentObject() );
00084         if (at) {
00085             return fixInitialStringDeclValue(at->getInitialValue(), getTypeName());
00086         } else {
00087             kError() << "JavaodeClassField::getInitialValue: parent object is not a UMLAttribute"
00088             << endl;
00089             return "";
00090         }
00091         return fixInitialStringDeclValue(at->getInitialValue(), getTypeName());
00092     }
00093     else
00094     {
00095         if(fieldIsSingleValue()) {
00096             // FIX : IF the multiplicity is "1" then we should init a new object here, if its 0 or 1,
00097             //       then we can just return 'empty' string (minor problem).
00098             return QString("");
00099         } else {
00100             return " new "+JavaCodeGenerator::getListFieldClassName()+"( )";
00101         }
00102     }
00103 
00104 }
00105 
00106 QString JavaCodeClassField::getTypeName ( )
00107 {
00108     return JavaCodeGenerator::fixTypeName(CodeClassField::getTypeName());
00109 }
00110 
00111 #include "javacodeclassfield.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