OSDN Git Service

40a9bf8bf52783cbdbd21d8866c4731cdbbefa90
[stigmata/stigmata.git] / src / main / java / jp / sourceforge / stigmata / birthmarks / AbstractBirthmarkService.java
1 package jp.sourceforge.stigmata.birthmarks;
2
3 /*
4  * $Id$
5  */
6
7 import java.util.Locale;
8
9 import jp.sourceforge.stigmata.Birthmark;
10 import jp.sourceforge.stigmata.BirthmarkComparator;
11 import jp.sourceforge.stigmata.BirthmarkElement;
12 import jp.sourceforge.stigmata.BirthmarkExtractor;
13 import jp.sourceforge.stigmata.BirthmarkPreprocessor;
14 import jp.sourceforge.stigmata.spi.BirthmarkSpi;
15 import jp.sourceforge.stigmata.utils.LocalizedDescriptionManager;
16
17 /**
18  * Abstract class for {@link BirthmarkSpi <code>BirthmarkSpi</code>}
19  *
20  * @author Haruaki TAMADA
21  * @version $Revision$ 
22  */
23 public abstract class AbstractBirthmarkService implements BirthmarkSpi{
24     public String getDisplayType(){
25         return getDisplayType(Locale.getDefault());
26     }
27
28     public String getDisplayType(Locale locale){
29         LocalizedDescriptionManager manager = LocalizedDescriptionManager.getInstance();
30         String type = manager.getDisplayType(locale, getType());
31         if(type == null){
32             type = getType();
33         }
34         return type;
35     }
36
37     public String getDescription(){
38         return getDescription(Locale.getDefault());
39     }
40
41     public String getDescription(Locale locale){
42         LocalizedDescriptionManager manager = LocalizedDescriptionManager.getInstance();
43         String description = manager.getDescription(locale, getType());
44         if(description == null){
45             description = getDefaultDescription();
46         }
47         return description;
48     }
49
50     public abstract BirthmarkComparator getComparator();
51
52     public String getComparatorClassName(){
53         return getComparator().getClass().getName();
54     }
55
56     public abstract BirthmarkExtractor getExtractor();
57
58     public String getExtractorClassName(){
59         return getExtractor().getClass().getName();
60     }
61
62     public BirthmarkPreprocessor getPreprocessor(){
63         return null;
64     }
65
66     public String getPreprocessorClassName(){
67         BirthmarkPreprocessor preprocessor = getPreprocessor();
68         String name = null;
69         if(preprocessor != null){
70             name = preprocessor.getClass().getName();
71         }
72         return name;
73     }
74
75     public abstract String getType();
76
77     public abstract String getDefaultDescription();
78
79     public boolean isExpert(){
80         return true;
81     }
82
83     public boolean isUserDefined(){
84         return true;
85     }
86
87     public String getVersion(){
88         return getClass().getPackage().getImplementationVersion();
89     }
90
91     public String getVendorName(){
92         return getClass().getPackage().getImplementationVendor();
93     }
94
95     public Birthmark buildBirthmark(){
96         return getExtractor().createBirthmark();
97     }
98
99     public BirthmarkElement buildBirthmarkElement(String value){
100         if(value == null || value.equals("<null>")){
101                 return NullBirthmarkElement.getInstance();
102         }
103                 return new BirthmarkElement(value);
104     }
105 }