You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2014/02/21 16:34:26 UTC
svn commit: r1570608 -
/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinkerFactory.java
Author: joern
Date: Fri Feb 21 15:34:25 2014
New Revision: 1570608
URL: http://svn.apache.org/r1570608
Log:
OPENNLP-631 Replaced Class.forName with ExtensionLoader
Modified:
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinkerFactory.java
Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinkerFactory.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinkerFactory.java?rev=1570608&r1=1570607&r2=1570608&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinkerFactory.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinkerFactory.java Fri Feb 21 15:34:25 2014
@@ -15,6 +15,8 @@
*/
package opennlp.tools.entitylinker;
+import opennlp.tools.util.ext.ExtensionLoader;
+
/**
* Generates an EntityLinker implementation via properties file configuration
*
@@ -32,21 +34,19 @@ public class EntityLinkerFactory {
* init(..) method, so it is an appropriate place to put additional resources.
* @return an EntityLinker impl
*/
- public static synchronized EntityLinker getLinker(String entityType, EntityLinkerProperties properties)throws Exception {
+ public static synchronized EntityLinker<?> getLinker(String entityType, EntityLinkerProperties properties) throws Exception {
if (entityType == null || properties == null) {
throw new IllegalArgumentException("Null argument in entityLinkerFactory");
}
- EntityLinker linker = null;
- try {
- String linkerImplFullName = properties.getProperty("linker." + entityType, "");
- Class theClass = Class.forName(linkerImplFullName);
- linker = (EntityLinker) theClass.newInstance();
- System.out.println("EntityLinker factory instantiated: " + linker.getClass().getName());
- linker.init(properties);
-
- } catch (Exception ex) {
- throw new Exception("Error in EntityLinker factory. Check the entity linker properties file. The entry must be formatted as linker.<type>=<fullclassname>, i.e linker.person=org.my.company.MyPersonLinker",ex);
+
+ String linkerImplFullName = properties.getProperty("linker." + entityType, "");
+
+ if (linkerImplFullName == null) {
+ throw new IllegalArgumentException("linker." + entityType + " property must be set!");
}
+
+ EntityLinker<?> linker = ExtensionLoader.instantiateExtension(EntityLinker.class, linkerImplFullName);
+ linker.init(properties);
return linker;
}
}