svn commit: r1867499 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1867499 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java

mthl
Author: mthl
Date: Tue Sep 24 22:23:59 2019
New Revision: 1867499

URL: http://svn.apache.org/viewvc?rev=1867499&view=rev
Log:
Improved: Refactor ‘ComponentContainer#loadComponentFromConfig’
(OFBIZ-11192)

The unnecessary declared ‘ContainerException’ exception has been removed. A
switch statement has been used and the javadoc has been rewritten.

Additionally the method has been renamed to ‘ComponentContainer#loadComponent’.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java?rev=1867499&r1=1867498&r2=1867499&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java Tue Sep 24 22:23:59 2019
@@ -74,7 +74,7 @@ public class ComponentContainer implemen
         // load the components from framework/base/config/component-load.xml (root components)
         try {
             for (ComponentLoaderConfig.ComponentDef def: ComponentLoaderConfig.getRootComponents()) {
-                loadComponentFromConfig(Start.getInstance().getConfig().ofbizHome, def);
+                loadComponent(Start.getInstance().getConfig().ofbizHome, def);
             }
         } catch (IOException | ComponentException e) {
             throw new ContainerException(e);
@@ -110,25 +110,26 @@ public class ComponentContainer implemen
     }
 
     /**
-     * Checks if <code>ComponentDef.type</code> is a directory or a single component.
-     * If it is a directory, load the directory, otherwise load a single component
+     * Loads any kind of component definition.
      *
-     * @param parentPath the parent path of what is being loaded
-     * @param def the component or directory loader definition
-     * @throws IOException
-     * @throws ContainerException
-     * @throws ComponentException
-     */
-    private void loadComponentFromConfig(Path parentPath, ComponentLoaderConfig.ComponentDef def) throws IOException, ContainerException, ComponentException {
-        Path location = def.location.isAbsolute() ? def.location : parentPath.resolve(def.location);
-
-        if (def.type.equals(ComponentLoaderConfig.ComponentType.COMPONENT_DIRECTORY)) {
+     * @param dir  the location where the component should be loaded
+     * @param component  a single component or a component directory definition
+     * @throws IOException when component directory loading fails.
+     * @throws ComponentException when retrieving component configuration files fails.
+     */
+    private void loadComponent(Path dir, ComponentLoaderConfig.ComponentDef component)
+            throws IOException, ComponentException {
+        Path location = component.location.isAbsolute() ? component.location : dir.resolve(component.location);
+        switch (component.type) {
+        case COMPONENT_DIRECTORY:
             loadComponentDirectory(location);
-        } else if (def.type.equals(ComponentLoaderConfig.ComponentType.SINGLE_COMPONENT)) {
+            break;
+        case SINGLE_COMPONENT:
             ComponentConfig config = retrieveComponentConfig(null, location);
             if (config != null) {
-                loadComponent(config);
+                loadSingleComponent(config);
             }
+            break;
         }
     }
 
@@ -141,7 +142,7 @@ public class ComponentContainer implemen
      * @throws ContainerException
      * @throws ComponentException
      */
-    private void loadComponentDirectory(Path directoryName) throws IOException, ContainerException, ComponentException {
+    private void loadComponentDirectory(Path directoryName) throws IOException, ComponentException {
         Debug.logInfo("Auto-Loading component directory : [" + directoryName + "]", module);
         if (Files.exists(directoryName) && Files.isDirectory(directoryName)) {
             Path componentLoad = directoryName.resolve(ComponentLoaderConfig.COMPONENT_LOAD_XML_FILENAME);
@@ -167,13 +168,13 @@ public class ComponentContainer implemen
      * @throws IOException
      * @throws ContainerException
      */
-    private void loadComponentsInDirectoryUsingLoadFile(Path directoryPath, Path componentLoadFile) throws IOException, ContainerException {
+    private void loadComponentsInDirectoryUsingLoadFile(Path directoryPath, Path componentLoadFile) throws IOException {
         URL configUrl = null;
         try {
             configUrl = componentLoadFile.toUri().toURL();
             List<ComponentLoaderConfig.ComponentDef> componentsToLoad = ComponentLoaderConfig.getComponentsFromConfig(configUrl);
             for (ComponentLoaderConfig.ComponentDef def: componentsToLoad) {
-                loadComponentFromConfig(directoryPath, def);
+                loadComponent(directoryPath, def);
             }
         } catch (MalformedURLException e) {
             Debug.logError(e, "Unable to locate URL for component loading file: " + componentLoadFile.toAbsolutePath(), module);
@@ -209,7 +210,7 @@ public class ComponentContainer implemen
         }
         for (ComponentConfig componentConfig : componentConfigs) {
             if (componentConfig != null) {
-                loadComponent(componentConfig);
+                loadSingleComponent(componentConfig);
             }
         }
         loadComponentWithDependency();
@@ -277,7 +278,7 @@ public class ComponentContainer implemen
      * @throws IOException
      * @throws ComponentException
      */
-    private void loadComponent(ComponentConfig config) throws IOException, ComponentException {
+    private void loadSingleComponent(ComponentConfig config) throws IOException, ComponentException {
         if (config.enabled()) {
             List<ComponentConfig.DependsOnInfo> dependencyList = checkDependencyForComponent(config);
             if (UtilValidate.isEmpty(dependencyList)) {