private void insertEJBRefInEJBJar ( Element ejb , EJBInfo ei , String ejbLinkValue , Document ejbDoc ) { List ejbRefArray = DomUtils . getChildElementsByName ( ejb , "ejb-ref" ) ; String insertedEjbRefName = ei . getRefName ( ) ; Node nextSibling = null ; for ( int j = ejbRefArray . size ( ) - 1 ; j >= 0 ; j -- ) { Element ejbRef = ( Element ) ejbRefArray . get ( j ) ; String ejbRefName = DomUtils . getChildElementText ( ejbRef , "ejb-ref-name" ) ; if ( insertedEjbRefName . equals ( ejbRefName ) ) { nextSibling = ejbRef . getNextSibling ( ) ; ejb . removeChild ( ejbRef ) ; break ; } } // insert a new <ejb-ref> entry and fill in the values Element insertedEjbRef = ejbDoc . createElement ( "ejb-ref" ) ; if ( nextSibling != null ) { ejb . insertBefore ( insertedEjbRef , nextSibling ) ; } else { ejb . insertBefore ( insertedEjbRef , findEjbRefInsertPoint ( ejb ) ) ; } Element ejbRefName = ejbDoc . createElement ( "ejb-ref-name" ) ; ejbRefName . setTextContent ( insertedEjbRefName ) ; insertedEjbRef . appendChild ( ejbRefName ) ; Element ejbRefType = ejbDoc . createElement ( "ejb-ref-type" ) ; ejbRefType . setTextContent ( ei . getBeanType ( ) ) ; insertedEjbRef . appendChild ( ejbRefType ) ; Element homeType = ejbDoc . createElement ( "home" ) ; homeType . setTextContent ( ei . getHomeInterface ( ) . getName ( ) ) ; insertedEjbRef . appendChild ( homeType ) ; Element remoteType = ejbDoc . createElement ( "remote" ) ; remoteType . setTextContent ( ei . getBeanInterface ( ) . getName ( ) ) ; insertedEjbRef . appendChild ( remoteType ) ; Element ejbLink = ejbDoc . createElement ( "ejb-link" ) ; ejbLink . setTextContent ( ejbLinkValue ) ; insertedEjbRef . appendChild ( ejbLink ) ; }
Insert a remote ejb - ref into the specified EJB s descriptor if an ejb - ref already exists with the same name remove it before adding a new ref .