CrescentCollectionHandler { private void loadFromXML() { XStream stream = new XStream(); stream.processAnnotations(CrescentCollections.class); stream.alias( "collections", CrescentCollections.class ); stream.addImplicitCollection( CrescentCollections.class, "crescentCollections" ); logger.info("collectionsXmlLocation : {}", collectionsXmlLocation); ResourceLoader resourceLoader = new ResourceLoader(collectionsXmlLocation); InputStream inputStream = resourceLoader.getInputStream(); crescentCollections = (CrescentCollections)stream.fromXML(inputStream); if(crescentCollections == null) { String errorMsg = "Crescent Collections is not loaded from xml : ["+collectionsXmlLocation+"]"; logger.error(errorMsg); throw new IllegalStateException(errorMsg); } List<CrescentCollection> list = crescentCollections.getCrescentCollections(); for (CrescentCollection collection : list) { String path = collection.getIndexingDirectory(); File file = new File(path); if (!file.isAbsolute()) { String webRoot = System.getProperty("webapp.root"); if (webRoot != null) collection.setIndexingDirectory(webRoot + path); } } try { inputStream.close(); } catch (Exception e) { logger.error("stream close error ; ", e); } for (CrescentCollection collection : list) { List<CrescentAnalyzerHolder> analyzerHolders = collection.getAnalyzers(); for(CrescentAnalyzerHolder analyzerHolder : analyzerHolders) { String type = analyzerHolder.getType(); String className = analyzerHolder.getClassName(); String constructorArgs = analyzerHolder.getConstructorArgs(); Analyzer analyzer = null; try { @SuppressWarnings("unchecked") Class<Analyzer> analyzerClass = (Class<Analyzer>) Class.forName(className); if(constructorArgs == null || constructorArgs.trim().length() == 0) { analyzer = analyzerClass.newInstance(); } else if ("true".equals(constructorArgs.toLowerCase()) || "false".equals(constructorArgs.toLowerCase())) { boolean booleanStr = Boolean.valueOf(constructorArgs); Class<?>[] intArgsClass = new Class<?>[] {boolean.class}; Object[] intArgs = new Object[] {booleanStr}; Constructor<Analyzer> intArgsConstructor = analyzerClass.getConstructor(intArgsClass); analyzer = (Analyzer) intArgsConstructor.newInstance(intArgs); } else { Class<?> initArgClass = Class.forName(constructorArgs); Class<?>[] intArgsClass = new Class<?>[] {initArgClass.getClass()}; Object[] intArgs = new Object[] {initArgClass.newInstance()}; Constructor<Analyzer> intArgsConstructor = analyzerClass.getConstructor(intArgsClass); analyzer = (Analyzer) intArgsConstructor.newInstance(intArgs); } if("indexing".equals(type)) { collection.setIndexingModeAnalyzer(analyzer); } else if("search".equals(type)) { collection.setSearchModeAnalyzer(analyzer); } else { throw new IllegalStateException("정의되지 않은 Analyzer type 입니다. ["+type+"]"); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } }  CrescentCollections getCrescentCollections(); void writeToXML(); void reloadCollectionsXML();  }
@Test public void loadFromXML() { CrescentCollectionHandler collectionHandler = SpringApplicationContext.getBean("crescentCollectionHandler", CrescentCollectionHandler.class); CrescentCollections collections = collectionHandler.getCrescentCollections(); System.out.println(collections); Assert.assertNotNull(collections); List<CrescentCollection> collectionList = collections.getCrescentCollections(); Assert.assertTrue(collectionList.size() > 0); }