You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by co...@apache.org on 2012/07/13 20:07:55 UTC

svn commit: r1361313 - /opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java

Author: colen
Date: Fri Jul 13 18:07:54 2012
New Revision: 1361313

URL: http://svn.apache.org/viewvc?rev=1361313&view=rev
Log:
OPENNLP-500: To validate the tool factory specified in the model the validateArtifactMap was trying to load the factory using reflection. Now it will try using the ExtensionLoader

Modified:
    opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java

Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java?rev=1361313&r1=1361312&r2=1361313&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java Fri Jul 13 18:07:54 2012
@@ -26,7 +26,6 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.net.URI;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
@@ -38,6 +37,7 @@ import java.util.zip.ZipOutputStream;
 import opennlp.tools.util.BaseToolFactory;
 import opennlp.tools.util.InvalidFormatException;
 import opennlp.tools.util.Version;
+import opennlp.tools.util.ext.ExtensionLoader;
 
 /**
  * This model is a common based which can be used by the components
@@ -434,14 +434,20 @@ public abstract class BaseModel implemen
       throw new InvalidFormatException("Missing " + LANGUAGE_PROPERTY + " property in " +
       		MANIFEST_ENTRY + "!");
     
-    // validate the factory
+    // Validate the factory. We try to load it using the ExtensionLoader. It
+    // will return the factory, null or raise an exception 
     String factoryName = getManifestProperty(FACTORY_NAME);
     if (factoryName != null) {
       try {
-        Class.forName(factoryName);
-      } catch (ClassNotFoundException e) {
+        if (ExtensionLoader.instantiateExtension(BaseToolFactory.class,
+            factoryName) == null) {
+          throw new InvalidFormatException(
+              "Could not load an user extension specified by the model: "
+                  + factoryName);
+        }
+      } catch (Exception e) {
         throw new InvalidFormatException(
-            "The model could not load a user extension because it is missing on the classpath: "
+            "Could not load an user extension specified by the model: "
                 + factoryName, e);
       }
     }