Fixed issue 16868. ComponentProviders will be matched with modules via the javapackage smartly:
authorAntonio Moreno <antonio.moreno@openbravo.com>
Mon, 13 Feb 2012 17:58:29 +0100
changeset 15483 f52dabf2bdc4
parent 15482 d573ede8052e
child 15484 cffed2981aae
Fixed issue 16868. ComponentProviders will be matched with modules via the javapackage smartly:
- A class will be matched to a module if its javapackage starts with the javapackage of the module (we no longer require the matching to be exact).
- If more than one module matches, the one with the longest Javapackage will be picked. This is to resolve situations in which, for example, both org.openbravo and org.openbravo.client.kernel match.
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelUtils.java
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelUtils.java	Mon Feb 13 16:34:12 2012 +0100
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelUtils.java	Mon Feb 13 17:58:29 2012 +0100
@@ -214,13 +214,30 @@
    *           if the module can not be found.
    */
   public Module getModule(String javaPackage) {
+    Module chosenModule = null;
+    String chosenPackage = null;
     for (Module module : getModulesOrderedByDependency()) {
       // do trim to handle small typing errors, consider to do lowercase also
-      if (module.getJavaPackage().trim().equalsIgnoreCase(javaPackage.trim())) {
-        return module;
+      if (javaPackage.trim().startsWith(module.getJavaPackage().trim())) {
+        // We pick a module if:
+        // - Its javapackage is a prefix of the javapackage of the class
+        // - We don't have a module yet, or the javapackage is longer than the previously picked
+        // module
+        // We do this length check, in order to prioritize javapackages which better fit the class.
+        // This is to avoid situations in which, for example, org.openbravo is chosen over
+        // org.openbravo.client.kernel
+        if (chosenModule == null
+            || module.getJavaPackage().trim().length() > chosenPackage.length()) {
+          chosenModule = module;
+          chosenPackage = module.getJavaPackage().trim();
+        }
       }
     }
-    throw new OBException("No module found for java package " + javaPackage);
+    if (chosenModule == null) {
+      throw new OBException("No module found for java package " + javaPackage);
+    } else {
+      return chosenModule;
+    }
   }
 
   /**