KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > clustering > OnlineClustererFactory


1 /* Copyright (c) 2003 The Nutch Organization. All rights reserved. */
2 /* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
3
4 package net.nutch.clustering;
5
6 import net.nutch.plugin.*;
7 import net.nutch.util.NutchConf;
8 import java.util.logging.Logger JavaDoc;
9 import net.nutch.util.LogFormatter;
10
11 /**
12  * A factory for retrieving {@link OnlineClusterer} extensions.
13  *
14  * @author Dawid Weiss
15  * @version $Id: OnlineClustererFactory.java,v 1.1 2004/08/09 23:23:52 johnnx Exp $
16  */

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

33   public static OnlineClusterer getOnlineClusterer()
34     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.clustering.extension-name");
42     if (extensionName != null) {
43       Extension extension = findExtension(extensionName);
44       if (extension != null) {
45         LOG.info("Using clustering extension: " + extensionName);
46         return (OnlineClusterer) extension.getExtensionInstance();
47       }
48       LOG.warning("Clustering 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 clustering extension found: "
56         + extensions[0].getId());
57       return (OnlineClusterer) extensions[0].getExtensionInstance();
58     } else {
59       return null;
60     }
61   }
62
63   private static Extension findExtension(String JavaDoc name)
64     throws PluginRuntimeException {
65
66     Extension[] extensions = X_POINT.getExtentens();
67
68     for (int i = 0; i < extensions.length; i++) {
69       Extension extension = extensions[i];
70
71       if (name.equals(extension.getId()))
72         return extension;
73     }
74     return null;
75   }
76
77 }
78
Popular Tags