Project

General

Profile

Download (1.96 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.model.common;
10

    
11
import java.util.HashMap;
12
import java.util.Map;
13
import java.util.UUID;
14

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.model.common.init.ITermInitializer;
18
import eu.etaxonomy.cdm.model.common.init.ITermLoader;
19
import eu.etaxonomy.cdm.model.common.init.TermLoader;
20

    
21
/**
22
 * @author a.mueller
23
 *
24
 */
25
public class DefaultTermInitializer implements ITermInitializer {
26
	@SuppressWarnings("unused")
27
	private static final Logger logger = Logger.getLogger(DefaultTermInitializer.class);
28
	protected ITermLoader termLoader = new TermLoader();
29
	
30
	public void initialize() {
31
		termLoader.unloadAllTerms();
32
		doInitialize();
33
	}
34
	
35
	protected void doInitialize(){
36
		Map<UUID,DefinedTermBase> terms = new HashMap<UUID,DefinedTermBase>();
37
		
38
//		for(Class<? extends DefinedTermBase<?>> clazz : classesToInitialize) {
39
		for(VocabularyEnum vocabularyEnum : VocabularyEnum.values()) {
40
//			Class<? extends DefinedTermBase<?>> clazz = vocabularyEnum.getClazz();
41
			TermVocabulary<?> voc  = termLoader.loadTerms(vocabularyEnum, terms);
42
			setDefinedTerms(vocabularyEnum.getClazz(),voc);
43
		}				
44
	}
45
	
46
	protected void setDefinedTerms(Class<? extends DefinedTermBase<?>> clazz, TermVocabulary<?> vocabulary) {
47
		DefinedTermBase newInstance;
48
		try {
49
			newInstance = clazz.newInstance();
50
			newInstance.setDefaultTerms(vocabulary);
51
		} catch (InstantiationException e) {
52
			// TODO Exception type
53
			throw new RuntimeException("NewInstance could not be initialized in term initializer", e);
54
		} catch (IllegalAccessException e) {
55
			// TODO Exception type
56
			throw new RuntimeException("NewInstance could not be accessed in term initializer", e);
57
		}
58
		
59
	}
60

    
61

    
62
}
(8-8/63)