您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > eclipse画UML类图 (1)
MDT/UML2/GettingStartedwithUML2MDT|UML2Copyright©2004,2014InternationalBusinessMachinesCorp.,CEA,andothers.Contents[hide]1Summary2Prerequisites3Introduction4GettingStarted5CreatingModels6CreatingPackages7CreatingPrimitiveTypes8CreatingEnumerations9CreatingEnumerationLiterals10CreatingClasses11CreatingGeneralizations12CreatingAttributes13CreatingAssociations14SavingModels15Conclusion16ReferencesSummaryThisarticledescribeshowtogetstartedwiththeUML2plug-insforEclipse.Inparticular,itgivesanoverviewofhowtocreatemodels(andtheircontents)bothprogrammaticallyandbyusingthesampleUMLeditor.KennHusseyandJamesBruckLastUpdated:January21,2014PrerequisitesTostartusingUML2(andtofollowalongwiththeexampleinthisarticle),youmusthaveEclipse,EMF,andUML2installed.YoucaneitherdownloadtheModelingToolsPackageorfollowthesesteps:DownloadandrunEclipse.SelecttheHelpInstallNewSoftware…menuitem.Selectasoftwaresitetoworkwith,e.g.,Luna-ExpandtheModelingtreeitem.SelectUML2ExtenderSDKandpresstheNextbutton.ReviewtheinstalldetailsandpresstheNextbutton.AcceptthetermsofthelicenseagreementandpresstheFinishbutton.RestartEclipsewhenpromptedtodoso.Atthisstage,UML2andalldependenciesshouldbeinstalled.IntroductionThisarticlewillwalkyouthroughthebasicsofcreatingmodelsusingUML2.Usingasimplemodel(theExtendedPO2model,shamelessly“borrowed”fromtheEMF“bible”[1])asanexample,we’lllookatwhat’sinvolvedincreatingsomeofthemorecommonelementsthatmakeupamodel.Foreachtypeofelement,we’llfirstexplainthecreationprocessusingthesampleUMLeditorandthenexplorehowtoaccomplishthesamethingusingJavacode.TheExtendedPO2modelisshownbelow.GettingStartedReaderswhodon'twanttofolloweverystepofthistutorialmayinstallaworkingsolutionfromtheNew→Example...wizard,selectingtheUML2ExampleProjects→GettingStartedwithUML2sample.ThiswillbeavailablewhenEnhancement382342isresolvedandreleasedinaUML2build.Thisincludesthefinishedmodel,completesourcecode,andalaunchconfigurationthatrunsthestand-aloneJavaapplicationwhichcreatesthemodelintherootfolderoftheexampleproject.Beforegettingstarted,you’llneedtocreateasimpleprojectinyourworkspace.Thisprojectwillserveasthecontainerforthemodelthatwe’llcreateusingtheUMLeditor.Tocreateasimpleprojectforthisarticle,followthesesteps:SelecttheWindowOpenPerspectiveOther…menuitem.SelecttheResourceperspectiveandpresstheOKbutton.SelecttheFileNewProject...menuitem.SelecttheProjectwizardfromtheGeneralcategoryandpresstheNextbutton.Enteraprojectname(e.g.“GettingStartedwithUML2”)andpresstheFinishbutton.Atthispointyourworkspaceshouldlooksomethinglikethis:OK,thatshouldbeenoughtogetusgoingwiththeUMLeditor.Now,tofollowalongwiththeprogrammaticapproachtocreatingmodels,we’llassumethatyou’vecreatedaclass(named,say,“GettingStartedWithUML2”)inwhichyoucanwritesomecodetoconstructoursamplemodel.Thecodesnippetswe’llshowassumeyou’vedefinedthefollowingutilitymethodstogivetheuserinformationontheprogram’sstatus:publicstaticbooleanDEBUG=true;protectedstaticvoidout(Stringformat,Object...args){if(DEBUG){System.out.printf(format,args);if(!format.endsWith(%n)){System.out.println();}}}protectedstaticvoiderr(Stringformat,Object...args){System.err.printf(format,args);if(!format.endsWith(%n)){System.err.println();}}Astaticdebugflagcanbeusedtoenableordisableverboseinformationprintedtothesystem’soutputstream.Errorswillalwaysbeprintedtothesystem’serrorstream.Allright,then!Ineachofthefollowingsubsections,we’lllookathowtocreateadifferentkindofUMLelement,startingwithmodels.CreatingModelsAttherootofatypicalUMLmodelisamodelelement.Itcontainsa(hierarchical)setofelementsthattogetherdescribethephysicalsystembeingmodeled.TocreateamodelusingtheUMLeditor,followthesesteps:Selectaproject(e.g.,GettingStartedwithUML2)intheProjectExplorerviewandselecttheFileNewOther...menuitem.SelecttheUMLModelwizardfromtheExampleEMFModelCreationWizardscategoryandpresstheNextbutton.Enterafilename(e.g.,“ExtendedPO2.uml”)andpresstheNextbutton.SelectModelforthemodelobjectandpresstheFinishbutton.SelecttheWindowShowViewPropertiesmenuitem.SelecttheModelelementintheUMLeditor.Enteravalue(e.g.,“epo2”)fortheNamepropertyinthePropertiesview.Atthispointyourworkspaceshouldlooksomethinglikethis:Let’slookathowtoperformthesametaskusingJavacode.Thecodesnippetbelowshowsamethodthatprogrammaticallycreatesandreturnsamodelwithaspecifiedname.protectedstaticModelcreateModel(Stringname){Modelmodel=UMLFactory.eINSTANCE.createModel();model.setName(name);out(Model'%s'created.,model.getQualifiedName());returnmodel;}First,weasktheUMLfactorysingletontocreateamodel,andwesetitsname.Then,weoutputinformationtolettheuserknowthatthemodelhasbeensuccessfullycreated.Finally,wereturnthemodel.You’llnoticemost,ifnotall,ofthecodesnippetsinthisarticlewillfollowthispattern–createtheelement(andsetsomepropertiesonit),informtheuser,andreturnit.Allnamedelements(amodelisatypeofnamedelement)havea“simple”nameandaqualifiedname.Thequalifiednameisthe“simple”nameprefixedwiththe“simple”namesofallofthenamedelement’sco
本文标题:eclipse画UML类图 (1)
链接地址:https://www.777doc.com/doc-3390808 .html