1 2 3 4 5 package net.nutch.ontology; 6 7 import net.nutch.plugin.*; 8 import net.nutch.util.NutchConf; 9 import java.util.logging.Logger ; 10 import net.nutch.util.LogFormatter; 11 12 18 public class OntologyFactory { 19 public final static Logger 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 34 public static Ontology getOntology() throws PluginRuntimeException { 35 36 if (X_POINT == null) { 37 return null; 39 } 40 41 String 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 } 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 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 |