private Node insertEndpointBefore ( Node camel ) { // if there is endpoints then the cut-off is after the last Node endpoint = null ; for ( int i = 0 ; i < camel . getChildNodes ( ) . getLength ( ) ; i ++ ) { Node found = camel . getChildNodes ( ) . item ( i ) ; String name = found . getNodeName ( ) ; if ( "endpoint" . equals ( name ) ) { endpoint = found ; } } if ( endpoint != null ) { return endpoint ; } Node last = null ; // if no endpoints then try to find cut-off according the XSD rules for ( int i = 0 ; i < camel . getChildNodes ( ) . getLength ( ) ; i ++ ) { Node found = camel . getChildNodes ( ) . item ( i ) ; String name = found . getNodeName ( ) ; if ( "dataFormats" . equals ( name ) || "redeliveryPolicyProfile" . equals ( name ) || "onException" . equals ( name ) || "onCompletion" . equals ( name ) || "intercept" . equals ( name ) || "interceptFrom" . equals ( name ) || "interceptSendToEndpoint" . equals ( name ) || "restConfiguration" . equals ( name ) || "rest" . equals ( name ) || "route" . equals ( name ) ) { return found ; } if ( found . getNodeType ( ) == Node . ELEMENT_NODE ) { last = found ; } } return last ; }
To find the closet node that we need to insert the endpoints before so the Camel schema is valid .