OSDN Git Service

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