OSDN Git Service

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