Tải bản đầy đủ - 0 (trang)
Chapter 20. Developing EJBs with WSAD

Chapter 20. Developing EJBs with WSAD

Tải bản đầy đủ - 0trang

20.1TheJ2EEPerspective

BeforeyoubeginbuildingEJBs,itisnecessarytounderstandthe

environmentinwhichthisisdone.RememberthatwithinWSAD,

perspectivesprovideagroupingofviewsandeditorsthatmakes

developmentortestingofaparticulartechnologyeasier.WSADprovides

theJ2EEperspective,whichmakesdeveloping,assembling,andtesting

ofJ2EEapplicationsandmodulessimpler.Figure20.2showsthebasic

viewsthataregroupedtoproducetheJ2EEperspective.Thekeyviews

areJ2EEHierarchy,J2EENavigator,andServers.



Figure20.2.J2EEperspective.



20.1.1J2EEHierarchyView

TheJ2EEHierarchyviewisalogicalobjectrepresentationofthe

enterpriseapplications,J2EEmodules,EJBschemas,andserversthat



arecurrentlyloadedwithintheworkspace.Thecontentsofthisviewdo

notnecessarilymaptoindividualworkspacefiles.Theviewissplitinto

eightgroupings:EnterpriseApplications,ApplicationClientModules,

ConnectorModules,WebModules,EJBModules,Databases,Servers,

andServerConfigurations.Eachgroupprovidesatreeviewofthe

structureofeachrootelementofthegroupsuchasanapplication,EJB

JAR,ordatabase.

TheJ2EEHierarchyviewisusedprimarilytoopenthespecializededitor

fortheselectedobjectsuchastheEJBdeploymentdescriptoreditor,

applicationdeploymentdescriptoreditor,serverconfigurationeditor,

databasetableeditor,amongothers.Theviewalsoprovidesdelete

actionsforvirtuallyeveryobjectintheviewaswellascreationactionsfor

manyofthemainelementsintheviewsuchasEJBs,database

schemas,andtables,servers,andserverconfigurations,J2EEmodule

projects.ItiseasytoexecuteaJ2EEobjectontheserverfromthisview

sincebothRunonServerandDebugonServeractionsareavailablefor

mostelementssuchasanEJB.

Thisviewgroupseachtypeofmoduleseparatefromtheenterprise

applicationbecauseamodulemaybeaddedtomultipleenterprise

applications.Likeeachenterpriseapplication,eachmoduletypeelement

alsodisplaysatreeviewofthemaincomponentsinitsdeployment

descriptor.Forexample,anEJBmodulewilldisplaytheEJBJAR,the

EJBswithintheEJBJAR,EJBclasses,andcmppropertiesforeachCMP

entity.Therewillalsobeanentryforeachofthemapswhichrelatethe

contentsoftheEJBJARtoasetofdatabasetables.

Figure20.3showstheexpandedviewoftheTimeSheetGroupEJB

moduleusedinthecasestudy.Youcaneasilyseefromthefigurethat

theEJBJAR(TimeSheetGroup)andallofthedifferentEJBs,the

AssemblyDescriptor,andthesetofMapsareclearlypresented.Also

noticethattheEJBJARandeachEJBhaveaversionnumber(e.g.,2.0)

displayedinitscorrespondingiconinthetreeview.ThisistheEJB

specificationnumber.Thisisalsotrueoftheothergroups.



Figure20.3.EJBModulesgroup.



Thedatabasegroupdisplaystheobjectrepresentationofadatabasethat

haseitherbeenimportedintotheworkspaceorcreatedmanually.The

serversandserverconfigurationsgohandinhand.Theydisplaythe

currentsetofserversdefinedintheworkspaceaswellaseachserver

configurationthathasbeendefined.Aserverconfigurationmodel

providesthespecificserversettingstotestenterpriseapplications.

Normallythereisaone-to-onerelationshipbetweenaserveranda

serverconfigurationbutitispossibletoshareconfigurationsamong

servers,whichiswhytheyaredisplayedasseparategroups.



20.1.2J2EENavigatorView

TheJ2EENavigatorviewisatabbedtreeviewinthesamepaneofthe

J2EEperspectiveastheJ2EEHierarchyview.UnliketheJ2EEHierarchy

view,theJ2EENavigatorviewshowstheunderlyingresourcesthatexist

ondiskforeachoftheJ2EEprojectsintheworkspace.Wewillgointo

moredetailaboutJ2EEprojectslaterinthischapter.Figure20.4showsa

portionoftheexpandedJ2EENavigatorviewwiththeTimeSheetGroup

projectwhichwasalsoshowninFigure20.3butintheJ2EEHierarchy



view.



Figure20.4.J2EENavigatorview.



ThinkofthisviewasacombinationofthebaseNavigatorviewandthe

JavaPackageExplorer.LikethetraditionalNavigatorview,theJ2EE

Navigatorviewshowsallprojectswithintheworkspaceandtheir

containedresources.

LiketheJavaPackageExplorer,theJ2EENavigatorviewdisplaysall

Javaprojectswiththeirpackagestructureexposed.Theviewalsohas

uniqueJ2EEfeaturessuchasthespecificdeploymentdescriptorentry

placedwithintherootoftheproject.Thisisusedasaconvenience

mechanismtoquicklyopenthedeploymentdescriptoreditorfortheJ2EE

project.Theviewalsocontainsspecializedfilterssothatyoucanfilterout

projectsthatarenotJ2EEprojects.



20.1.3ServersView

TheServersviewissimplyaviewthathasalistingofthedefinedlocal

andremoteapplicationservers.Withinthisviewyoucanstartaparticular

serverinoneofthreedifferentmodes:normal,debug,andprofiling.

Otheractionsavailableinthisviewincluderestartingaserver,stoppinga

server,disconnectingfromaserver,andpublishingtoaserver.When

testingEJBs,youwilltypicallyliketostarttheUTC.TheUTCcanbe

launchedfromtheServerviewbyselectingtheRununiversaltestclient

contextmenuforaparticularrunningserver.ConsulttheWSAD

documentationformoredetailsoneachoftheseactions.



20.1.4DBServersView

TheDBServersview,showninFigure20.5,isaviewoflivedatabase

connectionswhichallowsyoutoviewthetablesinadatabase,viewthe

datainatable,andimportdatabasetablestoafolderintheworkbench.

ConsulttheWSADdocumentationformoreinformationaboutcreating

databaseconnectionsorusetheF1Helpprovidedforthisview.



Figure20.5.DBServersview.



Oneofthemostimportantfeaturesofthisviewistheabilitytoimport

databases,schemas,and/ortablestoaspecificfolder.Forexample,if

youselectaspecifictable,youcanimportthattabledefinitionintoan

EJBprojectbyselectingtheImporttoFoldercontextmenuaction.This

actionwillopenadialog,showninFigure20.6,toenterthefolderin

whichyouwanttoimportthetabledefinition.Ifyouareimportingtoan

EJBproject,justbrowsefortheEJBprojectandensurethattheUse

defaultschemafolderforEJBprojectsischecked.Thiswillensurethat

thetabledefinitionsareimportedtotheproperback-endfolderlocation

sothattheycanbeusedbytheEJBmodule.AnEJBprojectstoresits

tabledefinitionsinaspecificfolderundertheejbModule/META-INF/backendsfolder.Tabledefinitionsoutsideofthislocationcannotbeusedfor

object-to-relational(O/R)mappingsforCMPs.



Figure20.6.Importstofolderdialog.



Ifyouwouldliketoimportdatabasetablestoanexistingback-endfolder

withinanEJBproject,deselecttheUsedefaultschemafolderforEJB

projectscheckboxandbrowsetothespecificback-endfolder.Ifyoudo

notdeselectthischeckbox,anewback-endfolderwillbecreatedwithin

theEJBprojectforthetablesthatyouhaveselectedtoimport.This

meansthatthetabledefinitionsfortheselectedtableswillbeimported

intoanewback-endfolderfortheEJBmodule.Iftheoptionis

deselected,youcanthenimportthetabledefinitionsoftheselected

tablesintoanexistingback-endfolderthatexistsfortheEJBmodule.

Importingadatabaseintotheback-endfoldercreatesasubfolderand

populatesitwithanumberofXMLMetadataInterchange(XMI)filesthat

containinformationaboutthedatabaseconnection,thedatabaseitself,

itsschema,andthetablesinthedatabase.Thesefileswillbeusedwhen

mappingCMPbeanstoarelationaldatabase.



20.2J2EEProjects

BeforewecantalkaboutJ2EEprojects,letuspresentagentlereminder

ofwhataprojectis.AsdescribedinChapter7,aprojectisastructurein

theworkbenchthatisusedtostoreresources.Itactuallymapstoa

physicaldirectoryondiskinanylocationthatyouwish.Aprojectcanbea

simpleprojectwhichisnothingmorethanjustacontaineroritcanhave

specificbehavior.Anexampleofaspecifictypeofprojectwithinthe

workbenchwouldbeaJavaproject.AJavaprojectisasimpleproject

withspecificactionsandbehaviorsfordealingwithJavafiles.For

example,aJavaprojectwillhavethenotionofaJavabuildpathor

classpath.Also,aJavaprojectcanhaveoneormoresourcefoldersthat

contain.javafilesthataretobecompiledwhenoneofthemchangesora

buildisperformed.Thecompiled.classfileswillbecopiedtotheprojects

outputlocationwhichisalsospecifictoaJavaproject.

J2EEprojects,likeJavaprojects,arespecializedprojectsthathave

additionalsemanticsthatmaptoconceptsfromtheJ2EEspecification.

Forexample,anenterpriseapplicationprojectmapstoanenterprise

applicationintheJ2EEspecification.TheotherJ2EEprojectsinclude

EJBprojects,applicationclientprojects,Webprojects,andconnector

projects.EachprojecttypeisrepresentedasagroupwithintheJ2EE

Hierarchyview.Also,alloftheseprojects,exceptfortheenterprise

applicationproject,areJavaprojectsbecausetheymaycontain.java

files.Theenterpriseapplicationprojectdoesnotcontainany.javafilesso

itisnotaJavaproject.

J2EEprojectshavespecificbehaviorsfordealingwiththedeployment

descriptoranditscontents.Toensurethattherearenoproblemswiththe

contentsoftheseprojectsvalidationsareperformedonthecontents.The

validationsaredonebyspecializedobjectscalledvalidatorsandeach

knowshowtovalidateaspecificobject.Thisvalidationmaybesyntax

validationorsemanticvalidation.Forexample,theEJBvalidatorwill

validatethesemanticoftheEJBdeploymentdescriptorbuttheEJBXML

validatorwillvalidatethesyntaxoftheEJBdeploymentdescriptorbased

ontheejb-jar.dtd.Validatorsrunduringeachbuildoftheworkbench



whichusuallyhappensaftersavingchangestoaneditor.Itmaybe

desirabletodisableoneormorevalidatorsifyouarenotconcernedwith

theresultsofthevalidation.Thiscanbedonebychangingthe

Validationpropertyforaspecificproject.Youmayalsodisable

validatorsforallprojectsbychangingtheWindow>Preferences>

Validationpreferences.

Let'stakeasimpleexampleofhowtocreateanEJBproject.Wewillgo

throughthestepsofcreatingtheTimeSheetGroupEJBprojectthatwas

usedinthecasestudy.

1. SelectFile>New.SelectEJBfromtheleftlistoftheNewwizard

andselectEJBProjectfromtherightlist.

ClicktheNextbuttontoproceedtotheEJBProjectwizard.

SelectCreate2.0EJBProjecttocreatea2.0EJBmodule.EachEJB

projectandallotherJ2EEprojects,areassociatedwithadeployment

descriptorspecificationversion.

ClicktheNextbutton.

EnterTimeSheetGroupfortheProjectnameasshowninFigure20.8.

TheDirectoryistheoneonyoursystemthatwillphysicallycontainthe

contentsoftheEJBproject.Bydefault,anewdirectorywiththesame

nameasyourprojectiscreatedinyourcurrentworkspacedirectory.



Figure20.8.Enterpriseapplicationsgroup.



SelectNewfortheenterpriseapplicationprojectandenterwasbook

fortheNewprojectname.Thisistheenterpriseapplicationprojectthat

thisnewEJBprojectshouldbeaddedto.Youmusteithercreatean

enterpriseapplicationoruseanexistingonetoassociatethenewEJB

projectoranyJ2EEmoduleproject.ThisisrequiredsinceanEJBproject

oranyothermoduleprojectmustbetestedwithinthecontextofan

enterpriseapplication.

ClickFinish.Twonewprojectswillbecreated,TimeSheetGroupand

wasbook,bothofwhichwillappearintheJ2EENavigatorviewandthe

J2EEHierarchyviewwiththeirspecificiconsandversions.Notethatthe

enterpriseapplicationversionis1.3sincethisisthelowestJ2EEversion

thatsupportsthenew2.0EJBprojectthatwascreated.

WhenyouexpandthewasbookenterpriseapplicationfromtheJ2EE

Hierarchyview,asshowninFigure20.7,theTimeSheetGroup.jarEJB

moduleappearsunderthemodulestreegroup.ThisEJBmodulemaps

directlytotheTimeSheetGroupEJBprojectthatwasjustcreated.Ifyou

selecttheTimeSheetGroup.jarentry,youcanthenselecttheGoto

deploymentdescriptorcontextmenuitemwhichwillmovethecurrent

selectiontotheTimeSheetGroupentryundertheEJBModulesgroup.

ThisisaconvenienceactiontofindtheactualmodulewithintheJ2EE

Hierarchyviewsothatyoumayedititscontentsoropenthedeployment

descriptoreditor.



Figure20.7.EJBprojectwizard.



WhenthisnewEJBprojectisaddedtotheenterpriseapplicationasan

EJBmodule,themoduleURIusedisderivedfromthenameofthe

project.ThismoduleURIwillthenbeusedwhentheenterprise

applicationisexportedtocreatethemoduleJARfile.Tochangethe

moduleURI,youwillneedtoopentheenterpriseapplicationdeployment

descriptoreditor.Dothisbyexpandingtheenterpriseapplicationfromthe

J2EEHierarchyviewanddouble-clickingontheEARDeployment

Descriptorentrytoopentheeditor.OntheModulespageofthe

deploymentdescriptoreditor,youwillnoticealistofallthemodules.

Figure20.9showstheupperportionofthemodulepage.Ifyouselectthe

TimeSheetGroup.jarmodule,detailinformationfortheURIandthe

projectisdisplayedinthetextareastotheright.Youcannowupdatethe

URItoanothernamethatyouwouldliketouse.Ifforsomereasonyou

needtochangetheprojectthattheselectedmodulerepresents,youcan

dosobyclickingontheBrowsebuttonnexttotheprojecttextfield.You



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 20. Developing EJBs with WSAD

Tải bản đầy đủ ngay(0 tr)

×