ij-16.png   inspectorJ -- JavaTM Profiler
sf project site browse source checkout source
SourceForge.net Logo



src/inspectorj/toolset/profiletoolset.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   inspectorJ - java profiler                                            *
00003  *   Copyright (C) 2007 by James May
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00027 #include "profiletoolset.h"
00028 
00029 namespace inspectorj {
00030 namespace toolset {
00031 
00032 using inspectorj::client::SessionProfile;
00033 
00034 ProfileToolSet::ProfileToolSet()
00035 {
00036 }
00037 
00038 
00039 ProfileToolSet::~ProfileToolSet()
00040 {
00041 }
00042 
00043 
00047 bool ProfileToolSet::loadProfile(inspectorj::client::SessionProfile& profile, QString fileName) {
00048     return ProfileToolSet::loadProfile(profile, fileName.toLocal8Bit().data());
00049 }
00050 
00057 bool ProfileToolSet::loadProfile(inspectorj::client::SessionProfile& profile, char *fileName)
00058 {
00059     // load a profile from an xml document
00060     TiXmlDocument doc(fileName);
00061     if (doc.LoadFile()) {
00062 
00063         TiXmlHandle hDoc(&doc);
00064         TiXmlElement* elem;
00065         TiXmlHandle hRoot(0); 
00066                
00067         elem = hDoc.FirstChildElement().Element();
00068         // should always have a valid root but handle gracefully if it does
00069         if (!elem) return false;
00070 
00071         hRoot = TiXmlHandle(elem);  
00072               
00073         // make sure we have the profile element
00074         elem = hRoot.FirstChild("profile").Element();
00075         if (!elem) return false;
00076         profile.setName(QString(elem->Attribute("name")));
00077         profile.setFileName(QString(elem->Attribute("file-name")));
00078         hRoot = TiXmlHandle(elem);
00079         
00080         // set the profile's ijConnection
00081         elem = hRoot.FirstChild("connection").Element();
00082         if (elem)
00083         {
00084             inspectorj::client::ijConnection conn;
00085             conn.host = elem->Attribute("host");
00086             conn.port = elem->Attribute("port");
00087             profile.setConnection(conn);
00088         } else { return false; }   
00089          
00090         // set the profile's jreHome
00091         elem = hRoot.FirstChild("jre-home").Element();
00092         if (elem)
00093         {
00094             QString jreHome(elem->GetText());
00095             profile.setJreHome(jreHome);
00096         } else { return false; }  
00097         
00098         // set the profile's javaOptions
00099         elem = hRoot.FirstChild("java-options").Element();
00100         if (elem)
00101         {
00102             QString javaOptions(elem->GetText());
00103             profile.setJavaOptions(javaOptions);
00104         }  else { return false; }       
00105          
00106         // set the profile's applicationArgs
00107         elem = hRoot.FirstChild("application-args").Element();
00108         if (elem)
00109         {
00110             QString appArgs(elem->GetText());
00111             profile.setApplicationArgs(appArgs);
00112         } else { return false; }  
00113                 
00114         // set the profile's applicationEntry
00115         elem = hRoot.FirstChild("application-entry").Element();
00116         if (elem)
00117         {
00118             QString applicationEntry(elem->GetText());
00119             profile.setApplicationEntry(applicationEntry);
00120         } else { return false; }  
00121                  
00122         // set the profile's jarFile attribute
00123         elem = hRoot.FirstChild("jar-file").Element();
00124         if (elem)
00125         {
00126             QString jarFile(elem->GetText());
00127             if (!jarFile.isEmpty() && jarFile == "true") {
00128                 profile.setJarFile(true);
00129             } else {
00130                 profile.setJarFile(false);
00131             }
00132         } else { return false; }  
00133         
00134         // set the profile's tomcatApp attribute
00135         elem = hRoot.FirstChild("tomcat-application").Element();
00136         if (elem)
00137         {
00138             QString tomcatApp(elem->GetText());
00139             if (!tomcatApp.isEmpty() && tomcatApp == "true") {
00140                 profile.setTomcatApp(true);
00141             } else {
00142                 profile.setTomcatApp(false);
00143             }
00144         } else { return false; }         
00145             
00146         // set the profile's externalLaunch attribute
00147         elem = hRoot.FirstChild("external-launch").Element();
00148         if (elem)
00149         {
00150             QString extLaunch(elem->GetText());
00151             if (!extLaunch.isEmpty() && extLaunch == "true") {
00152                 profile.setExternalLaunch(true);
00153             } else {
00154                 profile.setExternalLaunch(false);
00155             }
00156         } else { return false; }   
00157              
00158         // set the profile's classPath list
00159         elem = hRoot.FirstChild("classpath").Element();
00160         if (elem)
00161         {
00162             TiXmlHandle cpRoot(elem);
00163             elem = cpRoot.FirstChild("entry").Element();
00164             QStringList classPaths;
00165             while (elem) {
00166                 QString cpEntry(elem->GetText());
00167                 classPaths << cpEntry;
00168                 elem = elem->NextSiblingElement();
00169             }
00170             profile.setClassPath(classPaths);
00171         } else { return false; }   
00172         
00173         // set the profile's classFilter list
00174         elem = hRoot.FirstChild("classfilter").Element();
00175         if (elem)
00176         {
00177             TiXmlHandle cfRoot(elem);
00178             elem = cfRoot.FirstChild("entry").Element();
00179             QStringList classFilters;
00180             while (elem) {
00181                 QString cfEntry(elem->GetText());
00182                 classFilters << cfEntry;
00183                 elem = elem->NextSiblingElement();
00184             }
00185             profile.setClassFilters(classFilters);
00186         } else { return false; }  
00187                                         
00188         return true;
00189     } else {
00190         return false;
00191     }
00192 }
00193 
00200 bool ProfileToolSet::saveProfile(inspectorj::client::SessionProfile &profile, QString dir)
00201 {
00202     // create document and declaration
00203     QList<void *> ptrs;
00204     TiXmlDocument doc;
00205     TiXmlDeclaration *decl = new TiXmlDeclaration ( "1.0", "", "" );  
00206     doc.LinkEndChild( decl ); 
00207          
00208     // create inspectorj root element
00209     TiXmlElement *root = new TiXmlElement ("inspectorj");
00210     doc.LinkEndChild(root);
00211 
00212     // create comment
00213     TiXmlComment *comment = new TiXmlComment();
00214     comment->SetValue(" Session Profile for inspectorJ " );  
00215     root->LinkEndChild( comment );     
00216     
00217     // create profile element
00218     TiXmlElement *prof = new TiXmlElement ("profile"); 
00219     prof->SetAttribute("name", profile.getName().toLocal8Bit().data());
00220     prof->SetAttribute("file-name", profile.getFileName().toLocal8Bit().data());   
00221     root->LinkEndChild( prof ); 
00222     
00223     // create connection element
00224     TiXmlElement *conn = new TiXmlElement ("connection"); 
00225     conn->SetAttribute("host", profile.getConnection().host.toLocal8Bit().data());    
00226     conn->SetAttribute("port", profile.getConnection().port.toLocal8Bit().data()); 
00227     prof->LinkEndChild( conn );
00228         
00229     // create jreHome element
00230     TiXmlElement *jreHome = new TiXmlElement ("jre-home"); 
00231     TiXmlText *jreHomeText = new TiXmlText (profile.getJreHome().toLocal8Bit().data());
00232     jreHome->LinkEndChild(jreHomeText);
00233     prof->LinkEndChild( jreHome );  
00234 
00235     // create java options element
00236     TiXmlElement *javaOptions = new TiXmlElement ("java-options"); 
00237     TiXmlText *javaOptionsText = new TiXmlText (profile.getJavaOptions().toLocal8Bit().data());
00238     javaOptions->LinkEndChild(javaOptionsText);
00239     prof->LinkEndChild( javaOptions );  
00240     
00241     // create application args element
00242     TiXmlElement *applicationArgs = new TiXmlElement ("application-args"); 
00243     TiXmlText *applicationArgsText = new TiXmlText (profile.getApplicationArgs().toLocal8Bit().data());
00244     applicationArgs->LinkEndChild(applicationArgsText);
00245     prof->LinkEndChild( applicationArgs ); 
00246 
00247     // create java entry element
00248     TiXmlElement *applicationEntry = new TiXmlElement ("application-entry"); 
00249     TiXmlText *applicationEntryText = new TiXmlText (profile.getApplicationEntry().toLocal8Bit().data());
00250     applicationEntry->LinkEndChild(applicationEntryText);
00251     prof->LinkEndChild( applicationEntry );
00252         
00253     // create jar file element
00254     TiXmlElement *jarFile = new TiXmlElement ("jar-file"); 
00255     TiXmlText *jarFileText = new TiXmlText (profile.isJarFile() ? "true" : "false");
00256     jarFile->LinkEndChild(jarFileText);
00257     prof->LinkEndChild( jarFile );
00258     
00259     // create tomcatApp element
00260     TiXmlElement *tomcatApp = new TiXmlElement ("tomcat-application"); 
00261     TiXmlText *tomcatAppText = new TiXmlText (profile.isTomcatApp() ? "true" : "false");
00262     tomcatApp->LinkEndChild(tomcatAppText);
00263     prof->LinkEndChild( tomcatApp );    
00264     
00265     // create external launch element
00266     TiXmlElement *externalLaunch = new TiXmlElement ("external-launch"); 
00267     TiXmlText *externalLaunchText = new TiXmlText (profile.isExternalLaunch() ? "true" : "false");
00268     externalLaunch->LinkEndChild(externalLaunchText);
00269     prof->LinkEndChild( externalLaunch );    
00270         
00271     // create classpath element and entries
00272     TiXmlElement *classPath = new TiXmlElement ("classpath");
00273     TiXmlElement *classPathEntry;
00274     TiXmlText *classPathText;
00275     QStringList cpList = profile.getClassPath();
00276     for (int i = 0; i < cpList.size(); ++i) {
00277         classPathEntry = new TiXmlElement ("entry");
00278         classPathText = new TiXmlText(cpList.at(i).toLocal8Bit().data());
00279         classPathEntry->LinkEndChild(classPathText);
00280         classPath->LinkEndChild(classPathEntry);
00281     }
00282     prof->LinkEndChild( classPath );  
00283 
00284     // create classfilter element and entries
00285     TiXmlElement *classFilter = new TiXmlElement ("classfilter");
00286     TiXmlElement *classFilterEntry;
00287     TiXmlText *classFilterText;
00288     QStringList filterList = profile.getClassFilters();
00289     for (int i = 0; i < filterList.size(); ++i) {
00290         classFilterEntry = new TiXmlElement ("entry");
00291         classFilterText = new TiXmlText(filterList.at(i).toLocal8Bit().data());
00292         classFilterEntry->LinkEndChild(classFilterText);
00293         classFilter->LinkEndChild(classFilterEntry);
00294     }
00295     prof->LinkEndChild( classFilter ); 
00296     
00297     QString filePath = dir.append(QDir::separator());
00298     QString fileName = profile.getFileName();
00299     if (fileName.isEmpty()) {
00300         fileName = profile.getName();
00301     }
00302     filePath.append(fileName);
00303     return doc.SaveFile(filePath.toLocal8Bit().data());
00304 
00305 }
00306 
00307 
00308 
00309 }
00310 }

Generated on Sun Aug 19 17:07:54 2007 for inspectorJ by  doxygen 1.5.1