Skip to content
Permalink
Browse files

Improved: Rewrite ‘AbstractEngine#createLocationMap’ (OFBIZ-10810)

This adds some documentation and uses the ‘forEach’ method instead of
a ‘for’ loop.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1854659 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Mar 2, 2019
1 parent 9833660 commit 7c5cebbc55d33a210f16dc3e0d04fed69c6f3254
Showing with 13 additions and 12 deletions.
  1. +13 −12 framework/service/src/main/java/org/apache/ofbiz/service/engine/AbstractEngine.java
@@ -37,32 +37,33 @@
public abstract class AbstractEngine implements GenericEngine {

public static final String module = AbstractEngine.class.getName();
/** Map containing aliases for service implementation locations. */
protected static final Map<String, String> locationMap = createLocationMap();

protected ServiceDispatcher dispatcher = null;
protected ServiceDispatcher dispatcher;

protected AbstractEngine(ServiceDispatcher dispatcher) {
this.dispatcher = dispatcher;
}

// creates the location alias map
/**
* Instantiates the location map.
*
* @return an immutable location map.
*/
protected static Map<String, String> createLocationMap() {
Map<String, String> tmpMap = new HashMap<>();

List<ServiceLocation> locationsList = null;
Map<String, String> tmp = new HashMap<>();
List<ServiceLocation> locations;
try {
locationsList = ServiceConfigUtil.getServiceEngine().getServiceLocations();
locations = ServiceConfigUtil.getServiceEngine().getServiceLocations();
} catch (GenericConfigException e) {
// FIXME: Refactor API so exceptions can be thrown and caught.
Debug.logError(e, module);
throw new RuntimeException(e.getMessage());
}
for (ServiceLocation e: locationsList) {
tmpMap.put(e.getName(), e.getLocation());
}

Debug.logInfo("Loaded Service Locations: " + tmpMap, module);
return Collections.unmodifiableMap(tmpMap);
locations.forEach(loc -> tmp.put(loc.getName(), loc.getLocation()));
Debug.logInfo("Loaded Service Locations: " + tmp, module);
return Collections.unmodifiableMap(tmp);
}

/**

0 comments on commit 7c5cebb

Please sign in to comment.
You can’t perform that action at this time.