[ofbiz-framework] branch trunk updated: Improved: Enforce noninstantiability to ServiceGroupReader Class. (#177)

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

[ofbiz-framework] branch trunk updated: Improved: Enforce noninstantiability to ServiceGroupReader Class. (#177)

surajk
This is an automated email from the ASF dual-hosted git repository.

surajk pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new e92becb  Improved: Enforce noninstantiability to ServiceGroupReader Class. (#177)
e92becb is described below

commit e92becb0fd99aac54529b21e87b0308c87c2f1e6
Author: Suraj Khurana <[hidden email]>
AuthorDate: Thu Jun 4 14:38:22 2020 +0530

    Improved: Enforce noninstantiability to ServiceGroupReader Class. (#177)
   
    (OFBIZ-11750)
    Made class as final, added private constructor and corrected private data member name as per naming convention.
---
 .../org/apache/ofbiz/service/group/ServiceGroupReader.java | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/group/ServiceGroupReader.java b/framework/service/src/main/java/org/apache/ofbiz/service/group/ServiceGroupReader.java
index 4315970..9913df3 100644
--- a/framework/service/src/main/java/org/apache/ofbiz/service/group/ServiceGroupReader.java
+++ b/framework/service/src/main/java/org/apache/ofbiz/service/group/ServiceGroupReader.java
@@ -35,12 +35,14 @@ import org.w3c.dom.Element;
 /**
  * ServiceGroupReader.java
  */
-public class ServiceGroupReader {
+public final class ServiceGroupReader {
 
     private static final String MODULE = ServiceGroupReader.class.getName();
+    // using a cache is dangerous here because if someone clears it the groups won't work at all:
+    // public static UtilCache GROUPS_CACHE = new UtilCache("service.ServiceGroups", 0, 0, false);
+    private static final Map<String, GroupModel> GROUPS_CACHE = new ConcurrentHashMap<>();
 
-    // using a cache is dangerous here because if someone clears it the groups won't work at all: public static UtilCache groupsCache = new UtilCache("service.ServiceGroups", 0, 0, false);
-    private static final Map<String, GroupModel> groupsCache = new ConcurrentHashMap<>();
+    protected ServiceGroupReader() { }
 
     public static void readConfig() {
         List<ServiceGroups> serviceGroupsList = null;
@@ -79,7 +81,7 @@ public class ServiceGroupReader {
                 Debug.logError("XML Parsing error: <group> element 'name' attribute null or empty", MODULE);
                 continue;
             }
-            groupsCache.put(groupName, new GroupModel(group));
+            GROUPS_CACHE.put(groupName, new GroupModel(group));
             numDefs++;
         }
         if (Debug.infoOn()) {
@@ -94,9 +96,9 @@ public class ServiceGroupReader {
     }
 
     public static GroupModel getGroupModel(String serviceName) {
-        if (groupsCache.size() == 0) {
+        if (GROUPS_CACHE.size() == 0) {
             ServiceGroupReader.readConfig();
         }
-        return groupsCache.get(serviceName);
+        return GROUPS_CACHE.get(serviceName);
     }
 }