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

1 / 40
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功