OSDN Git Service

change package name. jp.naist.se.stigmata -> jp.sourceforge.stigmata
[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  * @version $Revision$ $Date$
22  */
23 abstract class AbstractBirthmarkExtractorService extends AbstractServiceProvider implements BirthmarkExtractorSpi{
24     /**
25      * returns a type of the birthmark this service provides.
26      */
27     public abstract String getType();
28
29     /**
30      * returns a localized description of the birthmark this service provides.
31      */
32     public String getDescription(Locale locale){
33         return LocalizedDescriptionManager.getInstance().getDescription(
34             locale, getType(), LocalizedDescriptionManager.ServiceCategory.extractor
35         );
36     }
37
38     /**
39      * returns a localized description of the birthmark in default locale.
40      */
41     public String getDescription(){
42         return getDescription(Locale.getDefault());
43     }
44
45     public abstract String getExtractorClassName();
46
47     /**
48      * returns a extractor for the birthmark of this service.
49      */
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