of 11
2/11/2016 PluginAnatomyProtegeWiki
http://protegewiki.stanford.edu/wiki/PluginAnatomy 1/11
FromProtegeWiki
Contents
1Introduction2Thevacuousplugininfiveminutes
2.1Build.xml2.2MANIFEST.MF2.3CompileandRun
3WritingViewandTabPlugins3.1AddingaViewPlugintothePlugin.xmlfile3.2LibrariesandtheBundleClasspath3.3TabPluginsandtheViewconfig.xmlFile
3.3.1Step1:Declaretheplugin3.3.2Step2:Layouttheviewsintheplugin3.3.3Step3:Saveaconfigurationfile3.3.4Step4:Testtheresults
4AddingMenuPlugins5UsingaReasoner6AdvancedTopics
6.1AddingNewPluginTypes6.1.1ThePluginConsumer6.1.2ThePluginLoader6.1.3ThePlugin6.1.4ThePluginInstance
6.2Frames,FrameSections,andRows6.2.1FrameListsandFrames6.2.2FrameSections6.2.3FrameSectionRows
7Glossary
Introduction
Thepurposeofthiswebpageistodescribesomeofthekeyingredientsofaplugin.Thepagewillbedirectedbythequickdevelopmentofapluginandcanindeedbeusedasaquickstartguide.InordertofocusattentiononthecorepluginconceptswewillusethelowestcommondenominatorofJavadevelopmenttoolsandthistutorialwillnotuseaJavaIDE.WewillassumethatthereaderhasanunderstandingofJavadevelopmentandknowshowtofollowalonginhisfavoriteIDE.Formoreinformationabouthowtoworkwithprotege4inanIDEIwilldirectthereadertothispage.ItispossibleforanexperienceddevelopertoskiptheantscriptssimplyfollowalonginanIDEbutwewouldstillrecommendabuildfileforthefinalversion.
Thesourcesforthefirstplugin(theexampletab)canbefoundhere(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/plugin/trunk/org.protege.editor.owl.examples.tab).Youcaneitherchecktheseoutfromsvnandusethisasaguideforreadingthetextorbuildthisprojectinaseriesofstepbystepstagesasdescribedbelow.Ifyoustartfromthecheckedoutversionthenyoucanbuildtheprojectbyfollowingthedirectionshere.
Thevacuousplugininfiveminutes
Icreateda(vacuous)pluginfromscratch,installeditandranitinjustunderfourminutes.ThereisalsoanewexpereimentalquickstartguideforstartinganewProtege5pluginwithmavenwhichwillprobablyevolveintothenewrecommendedstrategy.
Thesimplest(trivial)plugincanbebuiltfromsourcesinthefollowinglayout:
build.xmlMETAINFMANIFEST.MFlibresourcessrc
AswewillseeevenwithoutanyjavasourcesthisisasufficientbasisforbuildingapluginthatisrecognizedbyProtege4.Thereareonlytwofilesinthissourcetreethebuild.xmlfileandtheMANIFEST.MF.Thesefilescanbequicklyputtogetherfromtemplates.
Build.xml
Thetemplateforthebuild.xmlfilecanbedownloadedfromhere(http://smiprotege.stanford.edu/repos/protege/protege4/protegebase/trunk/etc/templatepluginbuild.xml).Onlytwothingsneedtobechangedinthisbuildfile.Theycanbefoundbysearchingforthestring"CHANGEME"inthefile.Thefirstthingtochangeisthenameoftheproject.Iwillcalltheprojecttheplugintutoiralproject:
Thenextsettingthatmustalmostalwaysbechangedisthenameoftheplugin.Inthiscase,thebuild.xmlalreadyhastherightnameforthepluginbutthisistheonlypluginforwhichthiswillbetrue:
Withtheseadjustmentsthebuild.xmlfileisready.
MANIFEST.MF
ThetemplatefortheMANIFEST.MFfilecanbedownloadedfromhere(http://smiprotege.stanford.edu/repos/protege/protege4/protegebase/trunk/etc/templatemanifest.mf).Onlyfivethingsneedtobechangedinthisfiletomakeituseableandtwoareoptional.Thesecanbefoundbysearchingforthestring"CHANGEME"inthefile.Thefirstchangeistosetthedisplaynamefortheplugin:
BundleName:TutorialPlugin
ThisisthenamethatisseenwhenProtege4startsupandinseveralpluginconfigurationscreens.Theseccondthingtochangeisthesymbolicnameoftheplugin.Theusualdefaultistousesthesamenameasthepluginnameinthebuild.xmlfile:
BundleSymbolicName:org.protege.editor.owl.examples.tab;singleton:=true
Notethe"singleton:=true"linethisisimportantsincemostProtege4pluginswillonlyworkiftheyareinstantiatedexactlyonce.Thenextthingstochangearethebundledescription,thevendorandthedocumentationurl:
BundleDescription:AsimplepluginforaplugindevelopmenttutorialBundleVendor:TheProtegeDevelopmentTeamBundleDocURL:www.perhaps.i.donthaveoneyet.com
Actuallythevendorandthedocurlareoptionalandcanbedeleted.TheMANIFEST.MFfileisnowready.
2/11/2016 PluginAnatomyProtegeWiki
http://protegewiki.stanford.edu/wiki/PluginAnatomy 2/11
CompileandRun
Beforewecanstart,wemustsetthePROTEGE_HOMEenvironmentvariabletopointtoaProtege4distribution.ThispagehasdirectionsonhowtodothisindifferentoperatingsystemsbutfornowIwillassumethatweareonaunix(orosx)system.Inthatcase,thesystemvariablecanbesetwithasimplecommand
exportPROTEGE_HOME=/Users/tredmond/Desktop/Protege_4.1_beta
Thisvacuouspluginisnowreadytocompileandrun.AssumingthatthePROTEGE_HOMEenvironmentvariableissetcorrectly,thisplugincanbecompiledwiththesimplecommand
antinstall
Thefulltextofthebuildsessionisasfollows:
[[email protected]]$antinstallBuildfile:build.xml
init:[mkdir]Createddir:/private/tmp/org.protege.editor.owl.examples.tab/build[mkdir]Createddir:/private/tmp/org.protege.editor.owl.examples.tab/build/classes[mkdir]Createddir:/private/tmp/org.protege.editor.owl.examples.tab/build/classes/lib[mkdir]Createddir:/private/tmp/org.protege.editor.owl.examples.tab/build/lib
checkProtegeLibs:[echo]UsingProtegeHome=/Andromeda/Users/tredmond/dev/workspaces/protege4/owleditor/build/dist/equinoxtofindprotegejars
checkProtegeLibsAndReport:
buildlibs:[unjar]Expanding:/Andromeda/Users/tredmond/dev/workspaces/protege4/owleditor/build/dist/equinox/bundles/org.protege.common.jarinto/private/tmp/org.protege.editor.owl.examples.tab/build
compile:
build.manifest:[copy]Copying1fileto/private/tmp/org.protege.editor.owl.examples.tab/build
copy.resources:[mkdir]Createddir:/private/tmp/org.protege.editor.owl.examples.tab/build/classes/METAINF[copy]Copying1fileto/private/tmp/org.protege.editor.owl.examples.tab/build/classes/METAINF
jar:[jar]Buildingjar:/private/tmp/org.protege.editor.owl.examples.tab/build/org.protege.editor.owl.examples.tab.jar
install:[delete]Deletingdirectory/Andromeda/Users/tredmond/dev/workspaces/protege4/owleditor/build/dist/equinox/configuration/org.eclipse.core.runtime[delete]Deletingdirectory/Andromeda/Users/tredmond/dev/workspaces/protege4/owleditor/build/dist/equinox/configuration/org.eclipse.osgi[copy]Copying1fileto/Andromeda/Users/tredmond/dev/workspaces/protege4/owleditor/build/dist/equinox/plugins
BUILDSUCCESSFULTotaltime:2seconds[[email protected]]$
IfthePROTEGE_HOMEenvironmentvariableisnotsetcorrectlytheuserwillinsteadseethefollowing:
BUILDFAILED/private/tmp/org.protege.editor.owl.examples.tab/build.xml:74:missingprotegelibraries
Wecannowlookatwhatthebuildhasdonebyexploringtheprojectdirectorytree.
Weseethefollowingelements:
TheClassTreeis(approximately)aflattenedviewoftheplugin(thejarfile).Generallythislargelyconsistsofthe.classfilesthathavebeencompiledfromthejava.Butsincewehavenotwrittenanyjavayetthisisnotfound.Inaddition,thiswillcontainresourcesneededbythepluginandlibrariesthatthepluginneedsbutwhichcannotbefoundinotherProtegeplugins.TheGeneratedLibrarieswhichareextractedfromProtegeplugins.ThisisneededbecauseofadifferencebetweenhowJavaandOSGigetresourcesoutofJarfiles.OSGiallowsabundle(whichisaimplementedasajarfile)tocontainotherjarfiles.Ifthebundleclasspathisconfiguredcorrectly,OSGiwillloadclassesfromthosejarsinjars.ButJavadoesnothavethiscapability.SothebuildscriptextractsthejarfilesoutoftheOSGibundlesthatwillbeneededtocompilethebundle.NotethatthesejarfilesarenotcopiedtotheclasstreebecausetheProtege4/OSGienvironmentwillmaketheclassesandresourcesofthesejarfilesavailable.TheProtege4Pluginthisisthefinalartifactofthebuildprocess.Becausewehaverun"antinstall"ithasalsobeeninstalledintheProtegedistribution.
Ifthedeveloperisstillwithmethenheisnowreadytoruntheplugin.GototheProtegedistribution(theonepointedtobythePROTEGE_HOMEenvironmentvariable)andrunit.Weareparticularlyinterestedintheconsoleoutputbecausethisisgoingtobetheonlyindicationthatthispluginisrecognizedatall.Theconsoleoutputshouldlooklikethis:
StartingProtege4OWLEditor(Version4.1.111)Platform:Java:JVM1.5.0_16b06284Memory:207MLanguage:en,Country:USFramework:Eclipse(1.4.0)OS:MacOSX(10.5.6)Processor:ppcInstalledpluginPelletReasonerInstalledpluginDLQueryTabInstalledpluginOwlvizPluginInstalledpluginowleditorInstalledpluginTutorialPluginInstalledpluginTheOWLAPIInstalledpluginFactplusplusPlugin TutorialPluginPluginhasnoplugin.xmlresource
InthisoutputweseethattheTutorialPluginhasbeenrecognizedandinstalled.Inadditionthereisainformationalmessagethattheplugin.xmlfilehasnotbeenfound.ThisisalmostalwaysindicatesaproblembecausemostProtege4pluginsdependonaplugin.xmlresource.Wewilldescribehowtheplugin.xmlfileisgeneratedinthenextsections.
2/11/2016 PluginAnatomyProtegeWiki
http://protegewiki.stanford.edu/wiki/PluginAnatomy 3/11
WritingViewandTabPlugins
ThepreviouspluginaddednofunctionalitytoProtege4.Wearenowgoingtodescribehowtoremedythissitutaion.SofarwehavenotmissedtheJavaIDEbutitisnowwhenwestartwritingabitofJavacodethattheJavaIDEwouldreallyshine.Buttoillustratethemainconcepts,wewillcontinuetoshowhowtobuildthepluginwithoutanydevelopmentenvironmentotherthanthatprovidedbythecoreJavatools.
AddingaViewPlugintothePlugin.xmlfile
Recallthatpreviouslywhenweranourplugin,Protege4complainedthattherewasnoplugin.xmlfile.Theplugin.xmlfilecontainsadeclarationofthewaysinwhichthepluginwillextendtheProtege4capabilitiesand(moreadvanced)thewaysinwhichtheplugincapabilitiescanbeextendedbyotherplugins.WewillstartbyaddingadeclarationthatthispluginwillimplementaProtegeView.
SofirstwewillgiveadefinitionofaProtegeview.ThepurposeofaProtegeviewistoprovideaviewofsomeaspectofanontology.IntheProtegeinterface,aProtegeviewiseasilyrecognized.Ithasaclearlydefinedborder.AtthetopofaProtegeviewisatitlebarandacollectionofbuttonsallowingtheuserto
splittheprotegeviewintotwocopiesofthesameviewoneabovetheother,splittheprotegeviewintotwocopiesofthesameviewonebesidetheother,floattheviewabovetheProtegeclientsothatitisvisibleinanycontext,closetheviewremovingitfromthetabthatcontainsit.
AnexampleofatypicalProtegeviewisshownbelow.
InordertodeclareourintentthatthispluginimplementaProtegeview,weaddthefollowingplugin.xmlfiletotherootoftheprojecttree:
Thisplugin.xmlfilestatesthatthispluginismakingasingleextensiontotheProtege4capabilities.Wewillcoverthemeaningofthepartsofthisextensiondeclarationlinebyline.Thefirstlinedefinestheidoftheextension.ThisparticularextensioniscalledtheExampleViewComponent.Theseconddecleration,
point="org.protege.editor.core.application.ViewComponent",
stateswhattheextensionistryingtodo.Thisextensionisattemptingtoimplementthefunctionalityrepresentedbytheextensionpointwiththename
org.protege.editor.core.application.ViewComponent.
ThelabeldeclarationtellsProtegewhattoputinthetitlebaroftheview.Theclassdeclarationindicateswhichclassimplementsthefunctionalityneededbythisview.Wewillgointotheimplementationofthatclassshortly.FinallythecategorydeclarationtellsProtegewhichmenuundertheViewmenushouldcontainthisview.
AverysimpleviewcanbewrittenbyextendingtheclassAbstractOWLViewComponentandimplementingthemethodsinitialiseOWLViewanddisposeOWLView.Averysimplesuchimplementationcanbefoundhere(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/plugin/trunk/org.protege.editor.owl.examples.tab/src/org/protege/editor/owl/examples/tab/ExampleViewComponent.java).Nowthisplugindependsonalibrarythatcanbefoundhere(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/plugin/trunk/org.protege.editor.owl.examples.tab/lib/examplelib.jar).Thislibraryshouldbedepositedinthelibdirectoryoftheproject.Thislibraryistrivialanditsonlypurposeistoshowhowtousealibraryinaplugin.Thedirectorytreeoftheprojectshouldnowlooklikethis:
2/11/2016 PluginAnatomyProtegeWiki
http://protegewiki.stanford.edu/wiki/PluginAnatomy 4/11
Atthispointtheantinstalloperationwillcompile,buildandinstallthenewpluginwiththe"antinstall"command.Buttheinstalledpluginwon'truncorrectlyandwewillshowhowtofixthisbelow.
LibrariesandtheBundleClasspath
Afterweinstalltheplugin,wecanstartProtegetotrytousethe"ExampleViewComponent".IfyouclickontheViewmenuandthenselect"OntologyViews"youwillseethe"ExampleViewComponent"listedthere.HoweveronselectingthisviewandtryingtoplaceontheProtegescreen,thefollowingerrorwillarise:
Errorloggedjava.lang.NoClassDefFoundError:org/protege/owl/example/Metrics atjava.lang.Class.getDeclaredConstructors0(NativeMethod) atjava.lang.Class.privateGetDeclaredConstructors(Class.java:2357) atjava.lang.Class.getConstructor0(Class.java:2671) atjava.lang.Class.newInstance0(Class.java:321) atjava.lang.Class.newInstance(Class.java:303)...
Ifwelookattheplugincontentswiththe"jartf"commandthenwewillseethatthebuildfilecorrectlyputtheexamplelib.jarintotheplugin:
[[email protected]]$jartfbuild/org.protege.editor.owl.examples.tab.jarMETAINF/METAINF/MANIFEST.MFlib/org/org/protege/org/protege/owl/org/protege/owl/examples/org/protege/owl/examples/tab/lib/examplelib.jarorg/protege/owl/examples/tab/ExampleViewComponent.classplugin.xml[[email protected]]$
TheproblematthispointisintheMANIFEST.MFfile.TheBundleClasspathlineisasfollows:
BundleClassPath:.
Toincludetheexamplelib.jarinthejarfile,theBundleClasspathlinemustbemodifiedtoincludethislibrary:
BundleClassPath:.,lib/examplelib.jar
Notethatusingacolonorasemicoloninsteadofthecommadoesnotwork.Alsoentering./lib/examplib.jardoesnotworkeither.Thisistheosgimechanismformakingthislibraryavailabletothisplugin.NotethatsincetheMANIFEST.MFfiledoesnothaveanExportPackagedeclaration,theseclasseswillonlybevisiblewithinthepluginandwillnotbeexportedtoanyotherpluginintheProtege4environmeht.ThisispartofthepluginisolationprovidedbyOSGithatallowsdifferentpluginstousedifferentlibrarieswithoutconflicts.
NowthepluginworkscorrectlyandIcaninstalltheviewintotheActiveOntologyTab:
.
TabPluginsandtheViewconfig.xmlFile
TheothermostcommonplugintypeistheProtegetab.InordertomakeaProtegetab,thedeveloperneedstogenerateanduseaviewconfig.xmlfilefortheproject.Inthissectionwewillshowhowtodothis.ItturnsoutthatatabcanusuallybeputtogetherwithoutwritinganyJavacode.Thestepsforwritingatabpluginare
1.addadeclarationofthetabpluginintheplugin.xmlfile.2.startProtegeandgraphicallyconfigurethetabinquestion.3.savetheconfigurationandincludeitwiththesourcefilesforthetab.4.testbyrestartingProtegeandrunningthetabwiththedefaultconfiguration.
Thesestepsaredescribedinmoredetailbelow.
Step1:Declaretheplugin
Thefirstthingthatthatneedstobedoneistodeclarethetabintheplugin.xmlfile.
2/11/2016 PluginAnatomyProtegeWiki
http://protegewiki.stanford.edu/wiki/PluginAnatomy 5/11
AnimportantlineintheabovedeclarationofthetabisthedefaultViewConfigFileName.Thisnamesaresourcethattheprotegepluginwilllookfortocreatethedefaultlayoutofthetab.
Step2:Layouttheviewsintheplugin
Wecannowcompilethispluginandinstallitasbefore.NowwhenwerunProtege4,wewillseeanewtabcalledthe"ExampleTab"inthetabsmenu(Window>Tabs).Enablethistab.SincewehavenotyetcreatedtheviewconfigexampleTab.xmlfile,youwillseethatthetabisempty.
Nowinstallandlayoutsomeviewsintothistab.InmycaseImadetheviewslooklikethis:
Step3:Saveaconfigurationfile
NowintheWindowmenuselect"ExportCurrentTab"andsavethefileas
viewconfigexampleTab.xml
intheprojectdirectory.InmycasetheviewconfigexampleTabfilelookedlikethis:
NowbeforewecompletethisProtegesession,gototheWindowmenuandclick"Resetselectedtabtodefaultstate".Youwillseethatthetabisnowemptyagain.NowexitProtege.
Thedirectorytreeoftheprojectshouldnowlooklikethis:
2/11/2016 PluginAnatomyProtegeWiki
http://protegewiki.stanford.edu/wiki/PluginAnatomy 6/11
Step4:Testtheresults
Installthepluginagain.NotethatthebuildscriptautomaticallyfoundtheviewconfigexampleTab.xmlfileandputitintotheplugin:
[[email protected]]$jartfbuild/org.protege.editor.owl.examples.tab.jarMETAINF/METAINF/MANIFEST.MFlib/org/org/protege/org/protege/owl/org/protege/owl/examples/org/protege/owl/examples/tab/lib/examplelib.jarorg/protege/owl/examples/tab/ExampleViewComponent.classplugin.xmlviewconfigexampleTab.xml[[email protected]]$
RunProtegeandgototheExampleTab.Itisempty?Thereasonforthisisthatthetabhasbeencustomizedtohavenothinginitfromthelastsession.Clickonthetabsmenuandclickon"Resetselectedtabtodefaultstate".Nowyouwillseetheviewsthatweconfiguredinthetabbefore.Thisisnowthedefaultstateforthetabanditwillbewhatotherusersseewhentheyusethispluginforthefirsttime.
AddingMenuPlugins
Ihavecreatedasmallmenuprojecthere(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/org.protege.example.menu/trunk)thatshowshowtocreateseveraldifferentmenutypes.Laterwewillusethisprojectastheexamplethatdrivesthiswikipage.
AddinganewmenutoProtege4.1isveryeasy.Thetwothingsthatthedeveloperneedstoaccomplisharetowritethecodeforthemenuactionandtoaddanentrytotheplugin.xml.Iwilltakearealworldexampletoillustratetheprocess.Inthisexample,IamwritingapluginthatcausesProtegetodisplayanontologythatisstoredinadatabaseformat.IwanttoputthisinthefilemenuofProtege4.1justunderotheritemssuchas"New","Open","OpenRecent"and"OpenfromURL".
Towritethecodeforthemenuplugin,thedevelopermerelyneedstoextendProtegeOWLAction.Thethreemethodsthatthedeveloperneedstowriteareinitialise,disposeandactionPerformed.Ithinkthatthemeaningofthesethreemethodsisprettyclearandthiscanbeaveryeasytask.
Nowthedeveloperneedstoaddanentrytotheplugin.xml(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/org.protege.example.menu/trunk/plugin.xml)file.Inmycasetheentrylookslikethis:
The"id"attributeofloadDatabaseissimplyashortidentifierforthepluginthatisnotseenbytheuser.The"point"attributeindicatesthatthepluginbeingdeclaredhereisamenuplugin.The
lineindicatestheclassthatimplementstheactionthatthismenuperformsandthe
lineindicatesthatthemenuistobeusedinthecontextoftheowleditor.Theonlyotherlineinthisplugin.xml(http://smiprotege/repos/protege/protege4/incubator/v3/org.protege.owlapi.bridge/trunk/plugin.xml)thatisabitmysteriousisthelinethatsays:
Thepurposeofthislineistoindicateexactlywherethemenushouldbeplaced.Thefirstpartofthevalue,
org.protege.editor.core.application.menu.FileMenu
indicatesthattheparentofmy"LoadDatabaseOntology"menuisthefilemenu.Thestringismakingareferencetothefilemenudeclaration
fromtheplugin.xml(http://smiprotege/repos/protege/protege4/plugins/org.protege.editor.core.application/trunk/plugin.xml)filefortheorg.protege.editor.core.applicationplugin.Thefirstpartofthestring
org.protege.editor.core.application.menu.FileMenu
is
org.protege.editor.core.application
whichistheidentifieroftheplugindeclaringthemenuand"menu.FileMenu"istheidofthepluginfromtheplugin.xmlfile.
ButnowIneedtoexplainthemeaningoftheSlotAAZportionofthepathinmyoriginalmenudeclaration:
TheSlotAAZstringindicatesexactlywherethe"LoadDatabaseOntology"shouldappearintheFilemenu.Thisstring(SlotAAZ)isparsedasagroup(SlotAA)andanindex(Z).FirstthegroupandtheindexareusedtosortthechildrenoftheFilemenu.Thechildrenaresortedfirstbygroupbutwhentwochildrenhavethesamegrouptheyarethensortedbygroupindex.Inadditiontothis,childrenwiththesamegrouparegroupedtogetherinthemenu.
2/11/2016 PluginAnatomyProtegeWiki
http://protegewiki.stanford.edu/wiki/PluginAnatomy 7/11
Inparticular,ifItrackdownthedeclarationsofthe"New","Open","OpenRecent"and"OpenfromURL"menusIfindthattheyallhaveagroupidentifierofSlotAA.Thisiswhytheyappearinthefilemenutogetherfollowedbyaseparatorbar.ByspecifyingthatmymenushouldhaveagroupofSlotAA,IamtellingProtegethatIwantmymenutobegroupedwiththesemenus.BygivingmymenuanindexofZIamtellingProtegethatIwantmymenutogoattheendofthelist.
ThealgorithmusedbyProtegetodeterminethelocationoftheplugincanbeobservedbyturningonloggingforthemenubuilder.Thiscaneasilybedonebyeditingthelog4j.xmlintheProtegeinstallationdirectory.Firstmodifythesectionthatsays
tosay
Thisallowstheconsoletoshowdebugmessages.Thenaddthelines
ThiswillcauseProtegetogeneratesomewhatverboselogstotheconsole(theselogsalsoshowupinalogfilein${homedirectory}/.Protege/logs/protege###.log).Therelevantlinesformymenupluginareasfollows.First
Parsed:[Menu:LoadDatabaseOntology]parentId=org.protege.editor.core.application.menu.FileMenu
indicatesthatProtegewasabletoparsethepathformymenupluginanddeterminethattheidoftheparentis
org.protege.editor.core.application.menu.FileMenu
thegroupisSlotAAandthegroupindexisZ.Nextweseetheline
[Menu:File]parentof[Menu:LoadDatabaseOntology]
whichindicatesthatProtegewassuccessfullyabletofindadeclaredmenuwiththerightidtobetheparentofmymenu.ThislinealsoindicatesthatProtegesuccessfullydecipheredthegroup(SlotAA)andtheindex(Z).Finallytherearethelines:
Adding[Menu:File]tomenubarGivingFilethechild[Menu:New...]GivingFilethechild[Menu:Open...]GivingFilethechild[Menu:Openrecent]GivingFilethechild[Menu:OpenfromURL...]GivingFilethechild[Menu:LoadDatabaseOntology]GivingFilethechild[Menu:Save]GivingFilethechild[Menu:Saveas...]GivingFilethechild[Menu:Gatherontologies...]GivingFilethechild[Menu:Exportinferredaxiomsasontology...]GivingFilethechild[Menu:Ontologylibraries...]GivingFilethechild[Menu:Loadedontologysources...]GivingFilethechild[Menu:Checkforplugins...]GivingFilethechild[Menu:Close]
thatindicatethattheFilemenuwassuccessfullypopulated.
UsingaReasoner
Usuallywhenapluginwantstouseareasoner,thepluginshouldusethereasonerthatisinitializedandusedbyProtege.ThisreasonercouldbetheFaCT++,HermiT,Pelletorotherreasonersandisselectedandinitializedattheusersrequest.Toexplainhowthisworkswewillexplainhowthefollowing(nottoouseful)codefromamenupluginworks.
publicvoidactionPerformed(ActionEvente){OWLClasslastSelectedClass=getOWLWorkspace().getOWLSelectionModel().getLastSelectedClass();if(lastSelectedClass!=null){OWLReasonerManagerreasonerManager=getOWLModelManager().getOWLReasonerManager();ReasonerUtilities.warnUserIfReasonerIsNotConfigured(getOWLWorkspace(),reasonerManager);if(reasonerManager.getReasonerStatus()==ReasonerStatus.INITIALIZED){OWLReasonerreasoner=reasonerManager.getCurrentReasoner();SetsubClasses=reasoner.getSubClasses(lastSelectedClass,true).getFlattened();if(!subClasses.isEmpty()){LOGGER.info("Inferredsubclassesof"+getOWLModelManager().getRendering(lastSelectedClass)+"are:");for(OWLClasssubClass:subClasses){LOGGER.info("\t"+getOWLModelManager().getRendering(subClass));}}else{LOGGER.info(getOWLModelManager().getRendering(lastSelectedClass)+"hasnoinferredsubclasses.");}}}}
Thiscodecreatesanactionthatwheninvokedwillprintsomemessagesaboutinferredsubclassestothelog.ThefirstthingtonoticeisthattheOWLReasonerManageristhecentralclassforaccessingtheProtegereasoneranditcanbeobtainedfromtheOWLModelManager.Thisclasscanbeusedtodeterminethestatusofthereasoner,getthecurrentProtegereasonerorgetareasonerfactoryforcreatingnewinstancesofaProtegereasoner.
Oncethereasonermanagerisobtainedcodeaboveinformstheuserifthereasonerisnotinitializedorisininconsistentstate.ThiswarninghasbeenincludedasastandardProtegeutilitysothattheuserwillgetaconsistentmessagewhenthereasonerisnotreadyforinference.ThisistheapproachtakenbytheDLQuerypluginforinstancebecauseitdoesnotmakesensetousetheDLQuerypluginifthereasonerisnotinitialized.Howeveranalternativeapproachistoquietlycheckthestatusofthereasonerandonlyusethereasonerifitisinagoodenoughstate.ThisisthestrategytakenbythecodethatdisplaysinferencessuchastheinferredsuperclassesandtheconsistencyofclassesandpropertiesastheusernavigatesthroughtheProtegeinterface.
ThenextthingthathappensisthatthecodechecksthestatusofthecurrentreasonerwiththecallreasonerManager.getReasonerStatus().ThiscallreturnsaReasonerStatusenumerationwhichcurrentlycantakeonthefollowingvalues:
NO_REASONER_FACTORY_CHOSEN:theuserhasnotyetselectedatypeofreasoner.REASONER_NOT_INITIALIZED:theuserhasselectedwhattypeofreasonerhewantsbuthasnotinitializedityet.INITIALIZATION_IN_PROGRESS:thereasonerisintheprocessofbeinginitialized.Pluginsshouldnotseethisstate.INITIALIZED:thereasonerisreadyforuse.INCONSISTENT:thereasonerwasinitializedbuttheontologyisinconsistent.Inthisstate,reasonersarenotusable.OUT_OF_SYNC:thereasonerisreadybutitisnotuptodatewiththelatestchangesintheontology.Thereasonerisusableinthisstatebutitmayproducemisleadingresults.Itcanbebroughtuptodatewithareasoner.flush()call.
2/11/2016 PluginAnatomyProtegeWiki
http://protegewiki.stanford.edu/wiki/PluginAnatomy 8/11
FinallythecodeaboveobtainstheProtegereasoner(whichimplementstheOWLapiOWLReasonerinterface)andusesOWLapicallstoobtaininformation.
Insomecasestheabovestrategyisnotsufficient.Forexample,theexplanationpluginsneedtocreatetheirownreasonersandsotheyneedareasonerfactory.Inthiscasetheplugincanmakethecall:
reasonerManager.getCurrentReasonerFactory().getReasonerFactory()
toobtainthereasonerfactory(aninstanceoftheOWLapiinterfaceOWLReasonerFactory).
AdvancedTopics
AddingNewPluginTypes
WorkinProgress
OneoftheadvantagesofusingtheOSGi/Eclipseframeworkisthatitnaturallyallowsdeveloperstodefinetheirownplugintypes.Forexample,theSWRLtab,beingwrittenbyMartinO'Connor,delegatestheworkofexecutingtheSWRLrulestoaruleengineplugin.ItisanticipatedthattherewillbetworuleenginepluginsthatarearecompatiblewiththeSWRLtab.OneofthesepluginswillbebasedontheJessruleengineandtheotherpluginwillbebasedontheDROOLSruleengine.
WewillillustratehowthisisdonewithtwoProtegebundles.Thesourcesforthesebundlescanbefound
http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/custom.extension/trunk/consumer
and
http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/custom.extension/trunk/producer
Bothbundlescanbequicklyinstalledthroughtheincludedantscripts.
Theconsumerbundlebehavesasfollows.ItaddsamenuitemtoarunningProtegeenvironment.Thismenuisfoundatthebottomoftheeditmenu.Whentheuserclicksonthismenuitem,theconsumerbundleperformsthefollowingactions:
1.itlooksforallcustom_extension_pointpluginsintherunningProtegeenvironment,2.itinstantiateseachpluginfoundandfinally3.itcallsthedoSomething()methodonthatplugininstance.
Thisbehaviorisprovidedthroughtheinteractionoffourcomponents:
theconsumercodethatisresponsibleforloopingthroughasetofpluginsandinvokingthem.thepluginloaderthatisresponsibleforcalculatingandreturningasetofpluginsthatmatchaspecifiction.thepluginthatisajavaencodingofdataencodedinplugin.xmlfilesprovidedbythebundles.theplugininstancethatisaninstantiationofapluginthatdoestheactualworkoftheplugin.
ThePluginConsumer
ThePluginconsumeressentiallyusesthepluginloader(describedbelow)toloopthroughaseriesofpluginsandinstantiateandinvokethem.ThecodethatdoesthisworkcanbefoundintheMyPluginConsumer(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/custom.extension/trunk/consumer/src/org/protege/example/extension/point/MyPluginConsumer.java)classandlookslikethefollowing:
publicvoidactionPerformed(ActionEvente){MyPluginLoaderloader=newMyPluginLoader(getOWLModelManager());for(MyPluginplugin:loader.getPlugins()){try{MyPluginInstancei=plugin.newInstance();i.doSomething();}catch(Exceptionex){ProtegeApplication.getErrorLog().logError(ex);}}}
Thisisatypicalexampleofhowapluginconsumerwillwork.Itusesapluginloadertofindasetofpluginsthataretheninstantiated(plugin.newInstance())andtheninvoked(i.doSomething()).Forthemostpart,thepluginconsumerdoesnothavetoworrytoomuchaboutthedetailsoftheProtegeplugininfrastructure.ThelogicofthePluginconsumerisdefinedbythetaskathand.
ThePluginLoader
Thepluginloader(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/custom.extension/trunk/consumer/src/org/protege/example/extension/point/MyPluginLoader.java)isresponsibleforsearchingforpluginsofthecustom_extension_pointtype.ThepluginloaderextendstheAbstractPluginLoaderclasswhichhandlesmostofthelogicofcreatingandfindingplugins.Minimally,allthedeveloperneedstodotoimplementthepluginloaderistoimplementaconstructorandacreateinstancemethod.Theconstructorlookslikethis:
publicMyPluginLoader(OWLModelManagerowlModelManager){super(MyPlugin.CONSUMER_ID,MyPlugin.ID);this.owlModelManager=owlModelManager;}
andthisistypical.ThesignificanceofthetwoargumentstothesuperconstructorwillbeexplainedwhenIdescribethePluginimplementation.Essentiallytheydefinewhichtypeofpluginisbeingsearchedforbythisloader.Inaddition,theconstructorforthispluginloadertakesanowlModelManagerargumentsothathecanpassthisargumenttotheconstructorfortheplugins.ThecreateInstancemethodthenisresponsibleforconstructingtheplugin:
protectedMyPlugincreateInstance(IExtensionextension){returnnewMyPlugin(owlModelManager,extension);}
InadditionthereisagetExtensionMatchermethodthatcanbeusedtorestrictthesetofpluginsthatarereturnedbythispluginloader.GenerallyitisnotnecessarytoimplementthegetExtensionMatcherinterface.
ThePlugin
Essentiallytheplugin(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/custom.extension/trunk/consumer/src/org/protege/example/extension/point/MyPlugin.java)isaPOJOrepresentingadeclarationofaplugininaplugin.xmlfile.Tounderstandthisweneedtolookatthetwodeclarationsintwoseparateplugin.xmlfiles.Thefirstdeclarationisfoundinthebundlefortheconsumerplugin.Thisdeclarationrepresentsarequestforaparticulartypeofservice.Inourcasethedeclaration(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/custom.extension/trunk/consumer/plugin.xml)lookslikethis:
2/11/2016 PluginAnatomyProtegeWiki
http://protegewiki.stanford.edu/wiki/PluginAnatomy 9/11
Thisdeclarationdefines
theidentifieroftheplugintype,custom_extension_point,whichisthenamebywhichplugindevelopersrefertothisplugintype,ThisstringcorrespondstotheMyPlugin.IDthatwepassedtotheAbstractPluginLoaderconstructorabove.Notethatitispossiblefordifferentbundlestodeclareanextensionpointtheuserfriendlynameoftheplugintypeandapointertothexmlschemafortheplugintype.
Ibelievethatthelastitem,theschema(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/custom.extension/trunk/consumer/schema/custom_extension_point.exsd),isnotmandatorybutitisextremelyusefulfordevelopersanditiscreatednaturallywhenpluginsaredevelopedusingtheeclipseIDE.
Thepluginproducerprovidedadeclaration(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/custom.extension/trunk/producer/plugin.xml)forhisextensionthatmatchestheextensionpointdeclarationabove.Inourexampletheextensiondeclarationlookslikethis:
Thepluginclass,MyPlugin(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/custom.extension/trunk/consumer/src/org/protege/example/extension/point/MyPlugin.java),extendstheAbstractProtegePluginclass.TheAbstractProtegePluginclassprovidesmanyutilitiesthatmakeiteasytowritethepluginclass.Inparticular,togetthe"type"fieldtheMyPluginclassprovidesanaccessor:
/***getsthedeclaredtypefieldfortheplugin*/publicStringgetType(){returngetPluginProperty(TYPE_PARAM,"nulltype");}
Inaddition,theAbstractProtegePluginclassdoesthetrickyaspectsofinstantiatingthepluginleavingonlythetaskofinitializingtheinstantiatedplugintotheMyPluginclass:
/***Createsaninstanceoftheplugin.Itisexpectedthat*thisinstancewillbe"setup",buttheinstance's*initialisemethodwillnothavebeencalledintheinstantiation*process.*/publicMyPluginInstancenewInstance()throwsClassNotFoundException,IllegalAccessException,InstantiationException{ MyPluginInstancempi=super.newInstance();mpi.setup(modelManager,getType());returnmpi;}
ThePluginInstance
Theplugininstanceclass(http://smiprotege.stanford.edu/repos/protege/protege4/misc/examples/custom.extension/trunk/consumer/src/org/protege/example/extension/point/api/MyPluginInstance.java)isresponsibleforperformingwhatevertaskitisthatthepluginissupposedtoperform.InourcasetheplugininstancewillimplementthedoSomething()method.ThisclassmustimplementtheProtegePluginInstanceinterfacethoughitisnotclearthatthisisreallyneededanymore.TheProtegePluginInstanceinterfacehasonlyonemethod,initialise(),butmanyplugins,suchastheoneinthisexample,havetheirowninitailizationmethodsthatarecalledbythePluginLoader.
Frames,FrameSections,andRows
InProgress
ItisnotclearthatthisneedstobeherebutthisisanextremelycentralProtegeconcept.IngeneralplugindeveloperswillnotneedtobuildcustomFramelistsandcansimplyusethetoplevelOWLFrameListconcepts.
MostofthediscussionwillfocusonasmallerandsmallersectionofthethefollowingProtege4.1screen.ThisdiagramshowsthestandardProtege4.1classestabasitdisplayssomeinformationabouttheselectedclasswhichistheCountryclassinthepizzaontology.
2/11/2016 PluginAnatomyProtegeWiki
http://protegewiki.stanford.edu/wiki/PluginAnatomy 10/11
FrameListsandFrames
ThediagrambelowshowsaFrameListshowingadescriptionoftheCountryclass.TheOWLFrameLististheswingobjectthatisresponsiblefordisplayingsomeobjectcalledtherootobjectfortheOWLFrameList.Inthiscase,therootobjectforthisframelististheCountryOWLclass.FrequentlytherootobjectoftheforaframelistisanOWLentitybutthisisnotrequired.TheconstructorfortheOWLFrameListobjecttakesanOWLFrameobjectwhichmanagesthecontentmodeloftheOWLFrameList.TheassociatedOWLFrameobjectalsohasarootobjectandinthiscasetherootobjectistheCountryclass.
Whileitmaynotbevisuallyimmediatelyapparent,theinformationbeingdisplayedisactuallyarenditionofalistofaxioms.Thusforinstance,theclassexpressionrepresentedinthesectionunderneathEquivalentClassesrepresentstheaxiom
CountrySubClassOfDomainConceptand{America,England,France,Germany,Italy}.
SimilarlythefirstindividualdisplayedunderMembersrepresentstheaxiom
AmericaTypeCountry.
ThefactthatthesearenotdisplayedsimplyastheassociatedaxiomsisankeypartofthepurposeoftheOWLFrameList.ThetaskoftheOWLFrameListbelowistodescribetheCountryclass.ForauseritmakessensethatintheMemberssectionofthatOWLFrameListhewouldseealistoftheindividualsinthatclass.Itwouldmakelesssensetotheuserifasetofaxiomswasdisplayedthere.
FrameSections
OWLFramesaregroupedintoaseriesofsectionseachofwhichshowsaparticulartypeofaxioms.Inthediagrambelowwehaveaframesectionthatisrenderingalistofclassassertionaxioms.
2/11/2016 PluginAnatomyProtegeWiki
http://protegewiki.stanford.edu/wiki/PluginAnatomy 11/11
FrameSectionRows
Glossary
TherearesometermsthatcomeupnaturallyinthediscussionofProtege4plugindevelopmentthatrequireabitofexplanation.TheProtege4pluginmechanismhasthreelayersandthetermsusedtodescribepluginsisslightlydifferentateachoftheselayers:
ExtensionPointistheeclipsetermforwhatProtegefolkoftencallaplugin.OSGi(http://www.osgi.org/Main/HomePage)isthebottomlayeroftheProtegepluginarchitecture.ItisapowerfulindustrystandardframeworkwhichprovidesmodularityandservicesbeyondthatprovidedbytheJavaspecifications.InOSGi,thetermOSGibundleisusedtorepresentaselfcontainedunitofcodethatcanbeintroducedintotheOSGiframeworkandwhichwillimportandexportclassesandresourcesinacontrolledway.AnOSGiBundleiscollectionofsoftwaregroupedintoasinglejarfile.WhenthissoftwarerunsintheOSGienvironment,itrunsinaprotectedspacewhereitcandefineexactlywhatjavaclassesfromthesurroundingenvironmentareneededandwhatjavaclassesareincompatiblewithitsoperation.Bundleshavenames,versionnumbers,developercontactinformationandactivationentrypoints.APluginisadeclaredservicethatimplementssomefunctionalityofusetotheProtegeplatform.TheProtegePluginmechanismisbasedontheEclipsepluginmechanismwherepluginsaredeclaredinafilecalledplugin.xml.TheEclipseRichClientPlatform(http://wiki.eclipse.org/index.php/Rich_Client_Platform)isanenvironmentbuiltontopofOSGiwhichprovidesadditionalfeaturestoeasethebuildingofa"Rich"client.Protege4onlyusessomeofthefeaturesofthisrichclientplatform.Inparticular,Protege4doesnotuseSWTandmanyofthegraphicalrelatedcapabilities.ButProtege4doesusethedeclarativeplugincapabilitiesprovidedbyeclipse.ItisherethatsomeofthepoweroftheOSGiplatformbecomesmanifest,becausewehavebeenabletouseonlythosebundlesfromtheeclipseRichClientplatformthatweneed.Inthissetting,OSGibundlescreatedaccordingtocertainconventionsbecomeEclipsePlugins.TheProtege4PluginlayerprovidessomeadditionalconveniencemethodsovertheEclipsePluginframework.CertaineclipsepluginsthatextendProtege4capabilitiesarecalledProtege4plugins.
Retrievedfrom"http://protegewiki.stanford.edu/index.php?title=PluginAnatomy&oldid=12200"
ThispagewaslastmodifiedonSeptember1,2013,at06:34.