KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > ontology > OntologyFactory


1 /* Copyright (c) 2004 michael j pan. All rights reserved. */
2 /* Use subject to the same conditions as Nutch. */
3 /* see http://www.nutch.org/LICENSE.txt. */
4
5 package net.nutch.ontology;
6
7 import net.nutch.plugin.*;
8 import net.nutch.util.NutchConf;
9 import java.util.logging.Logger JavaDoc;
10 import net.nutch.util.LogFormatter;
11
12 /**
13  * A factory for retrieving {@link Ontology} extensions.
14  *
15  * @author Michael Pan
16  * @version $Id: OntologyFactory.java,v 1.1 2004/11/30 06:36:00 johnnx Exp $
17  */

18 public class OntologyFactory {
19   public final static Logger JavaDoc LOG =
20     LogFormatter.getLogger(OntologyFactory.class.getName());
21
22   private final static ExtensionPoint X_POINT =
23     PluginRepository.getInstance().getExtensionPoint(Ontology.X_POINT_ID);
24
25   private OntologyFactory() {}
26
27   /**
28   * @return Returns the online ontology extension specified
29   * in nutch configuration's key
30   * <code>extension.ontology.extension-name</code>.
31   * If the name is empty (no preference),
32   * the first available ontology extension is returned.
33   */

34   public static Ontology getOntology() throws PluginRuntimeException {
35
36     if (X_POINT == null) {
37       // not even an extension point defined.
38
return null;
39     }
40
41     String JavaDoc extensionName = NutchConf.get("extension.ontology.extension-name");
42     if (extensionName != null) {
43       Extension extension = findExtension(extensionName);
44       if (extension != null) {
45         LOG.info("Using ontology extension: " + extensionName);
46         return (Ontology) extension.getExtensionInstance();
47       }
48       LOG.warning("Ontology extension not found: '" + extensionName
49         + "', trying the default");
50       // not found, fallback to the default, if available.
51
}
52
53     Extension[] extensions = X_POINT.getExtentens();
54     if (extensions.length > 0) {
55       LOG.info("Using the first ontology extension found: "
56         + extensions[0].getId());
57       return (Ontology) extensions[0].getExtensionInstance();
58     } else {
59       return null;
60     }
61
62   }
63
64   private static Extension findExtension(String JavaDoc name)
65     throws PluginRuntimeException {
66
67     Extension[] extensions = X_POINT.getExtentens();
68
69     for (int i = 0; i < extensions.length; i++) {
70       Extension extension = extensions[i];
71
72       if (name.equals(extension.getId()))
73         return extension;
74     }
75
76     return null;
77   }
78
79 }
80
Popular Tags