Project

General

Profile

Download (1.87 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
		Map<UUID,DefinedTermBase> terms = new HashMap<UUID,DefinedTermBase>();
32
		
33
//		for(Class<? extends DefinedTermBase<?>> clazz : classesToInitialize) {
34
		for(VocabularyEnum vocabularyEnum : VocabularyEnum.values()) {
35
//			Class<? extends DefinedTermBase<?>> clazz = vocabularyEnum.getClazz();
36
			TermVocabulary<?> voc  = termLoader.loadTerms(vocabularyEnum, terms);
37
			setDefinedTerms(vocabularyEnum.getClazz(),voc);
38
		}		
39
	}
40
	
41
	protected void setDefinedTerms(Class<? extends DefinedTermBase<?>> clazz, TermVocabulary<?> vocabulary) {
42
		DefinedTermBase newInstance;
43
		try {
44
			newInstance = clazz.newInstance();
45
			newInstance.setDefaultTerms(vocabulary);
46
		} catch (InstantiationException e) {
47
			// TODO Exception type
48
			throw new RuntimeException("NewInstance could not be initialized in term initializer", e);
49
		} catch (IllegalAccessException e) {
50
			// TODO Exception type
51
			throw new RuntimeException("NewInstance could not be accessed in term initializer", e);
52
		}
53
		
54
	}
55

    
56

    
57
}
(7-7/62)