OSDN Git Service

Remove Id tag
[stigmata/stigmata.git] / src / main / java / jp / sourceforge / stigmata / birthmarks / extractors / AbstractBirthmarkExtractorService.java
1 package jp.sourceforge.stigmata.birthmarks.extractors;
2
3 import java.lang.reflect.Constructor;
4 import java.lang.reflect.InvocationTargetException;
5 import java.util.Locale;
6
7 import jp.sourceforge.stigmata.BirthmarkExtractor;
8 import jp.sourceforge.stigmata.spi.AbstractServiceProvider;
9 import jp.sourceforge.stigmata.spi.BirthmarkExtractorSpi;
10 import jp.sourceforge.stigmata.spi.BirthmarkSpi;
11 import jp.sourceforge.stigmata.utils.LocalizedDescriptionManager;
12
13 /**
14  * Birthmark Service Provider Interface.
15  *
16  * @author Haruaki TAMADA
17  */
18 public abstract class AbstractBirthmarkExtractorService extends AbstractServiceProvider implements BirthmarkExtractorSpi{
19     /**
20      * returns a type of the birthmark this service provides.
21      */
22     @Override
23     public abstract String getType();
24
25     /**
26      * returns a localized description of the birthmark this service provides.
27      */
28     @Override
29     public String getDescription(Locale locale){
30         return LocalizedDescriptionManager.getInstance().getDescription(
31             locale, getType(), LocalizedDescriptionManager.ServiceCategory.extractor
32         );
33     }
34
35     /**
36      * returns a localized description of the birthmark in default locale.
37      */
38     @Override
39     public String getDescription(){
40         return getDescription(Locale.getDefault());
41     }
42
43     @Override
44     public abstract String getExtractorClassName();
45
46     /**
47      * returns a extractor for the birthmark of this service.
48      */
49     @Override
50     public BirthmarkExtractor getExtractor(BirthmarkSpi service){
51         try{
52             Class<?> c = Class.forName(getExtractorClassName());
53             Class<? extends BirthmarkExtractor> clazz = c.asSubclass(BirthmarkExtractor.class);
54             Constructor<? extends BirthmarkExtractor> constructor = clazz.getConstructor(BirthmarkSpi.class);
55             return constructor.newInstance(service);
56         } catch(NoSuchMethodException e){
57         } catch(InstantiationException e){
58         } catch(InvocationTargetException e){
59         } catch(ClassNotFoundException e){
60         } catch(IllegalAccessException e){
61         }
62         return null;
63     }
64 }
65