protected static CollectorConfiguration loadConfig ( String uri , String type ) { final CollectorConfiguration config = new CollectorConfiguration ( ) ; if ( type == null ) { type = DEFAULT_TYPE ; } uri += java . io . File . separator + type ; File f = new File ( uri ) ; if ( ! f . isAbsolute ( ) ) { if ( f . exists ( ) ) { uri = f . getAbsolutePath ( ) ; } else if ( System . getProperties ( ) . containsKey ( "jboss.server.config.dir" ) ) { uri = System . getProperty ( "jboss.server.config.dir" ) + java . io . File . separatorChar + uri ; } else { try { URL url = Thread . currentThread ( ) . getContextClassLoader ( ) . getResource ( uri ) ; if ( url != null ) { uri = url . getPath ( ) ; } else { log . severe ( "Failed to get absolute path for uri '" + uri + "'" ) ; } } catch ( Exception e ) { log . log ( Level . SEVERE , "Failed to get absolute path for uri '" + uri + "'" , e ) ; uri = null ; } } } if ( uri != null ) { String [ ] uriParts = uri . split ( Matcher . quoteReplacement ( File . separator ) ) ; int startIndex = 0 ; // Remove any file prefix if ( uriParts [ 0 ] . equals ( "file:" ) ) { startIndex ++ ; } try { Path path = getPath ( startIndex , uriParts ) ; Files . walkFileTree ( path , new FileVisitor < Path > ( ) { @ Override public FileVisitResult postVisitDirectory ( Path path , IOException exc ) throws IOException { return FileVisitResult . CONTINUE ; } @ Override public FileVisitResult preVisitDirectory ( Path path , BasicFileAttributes attrs ) throws IOException { return FileVisitResult . CONTINUE ; } @ Override public FileVisitResult visitFile ( Path path , BasicFileAttributes attrs ) throws IOException { if ( path . toString ( ) . endsWith ( ".json" ) ) { String json = new String ( Files . readAllBytes ( path ) ) ; CollectorConfiguration childConfig = mapper . readValue ( json , CollectorConfiguration . class ) ; if ( childConfig != null ) { config . merge ( childConfig , false ) ; } } return FileVisitResult . CONTINUE ; } @ Override public FileVisitResult visitFileFailed ( Path path , IOException exc ) throws IOException { return FileVisitResult . CONTINUE ; } } ) ; } catch ( Throwable e ) { log . log ( Level . SEVERE , "Failed to load configuration" , e ) ; } } return config ; }
This method loads the configuration from the supplied URI .