diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java b/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java index 377966ca3f..2de80bc046 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java @@ -60,7 +60,7 @@ public final class ComponentConfig { * we will need to use synchronization code because there is no concurrent implementation of LinkedHashMap. */ private static final ComponentConfigCache componentConfigCache = new ComponentConfigCache(); - private static final Map> serverWebApps = new LinkedHashMap>(); + private static final Map> serverWebApps = new LinkedHashMap<>(); public static Boolean componentExists(String componentName) { Assert.notEmpty("componentName", componentName); @@ -72,7 +72,7 @@ public final class ComponentConfig { } public static List getAllClasspathInfos(String componentName) { - List classpaths = new ArrayList(); + List classpaths = new ArrayList<>(); for (ComponentConfig cc : getAllComponents()) { if (componentName == null || componentName.equals(cc.getComponentName())) { classpaths.addAll(cc.getClasspathInfos()); @@ -90,7 +90,7 @@ public final class ComponentConfig { } public static List getAllConfigurations(String componentName) { - List configurations = new ArrayList(); + List configurations = new ArrayList<>(); for (ComponentConfig cc : getAllComponents()) { if (componentName == null || componentName.equals(cc.getComponentName())) { configurations.addAll(cc.getConfigurations()); @@ -104,7 +104,7 @@ public final class ComponentConfig { } public static List getAllEntityResourceInfos(String type, String componentName) { - List entityInfos = new ArrayList(); + List entityInfos = new ArrayList<>(); for (ComponentConfig cc : getAllComponents()) { if (componentName == null || componentName.equals(cc.getComponentName())) { List ccEntityInfoList = cc.getEntityResourceInfos(); @@ -127,7 +127,7 @@ public final class ComponentConfig { } public static List getAllKeystoreInfos(String componentName) { - List keystoreInfos = new ArrayList(); + List keystoreInfos = new ArrayList<>(); for (ComponentConfig cc : getAllComponents()) { if (componentName == null || componentName.equals(cc.getComponentName())) { keystoreInfos.addAll(cc.getKeystoreInfos()); @@ -141,7 +141,7 @@ public final class ComponentConfig { } public static List getAllServiceResourceInfos(String type, String componentName) { - List serviceInfos = new ArrayList(); + List serviceInfos = new ArrayList<>(); for (ComponentConfig cc : getAllComponents()) { if (componentName == null || componentName.equals(cc.getComponentName())) { List ccServiceInfoList = cc.getServiceResourceInfos(); @@ -164,7 +164,7 @@ public final class ComponentConfig { } public static List getAllTestSuiteInfos(String componentName) { - List testSuiteInfos = new ArrayList(); + List testSuiteInfos = new ArrayList<>(); for (ComponentConfig cc : getAllComponents()) { if (componentName == null || componentName.equals(cc.getComponentName())) { testSuiteInfos.addAll(cc.getTestSuiteInfos()); @@ -178,7 +178,7 @@ public final class ComponentConfig { } public static List getAllWebappResourceInfos(String componentName) { - List webappInfos = new ArrayList(); + List webappInfos = new ArrayList<>(); for (ComponentConfig cc : getAllComponents()) { if (componentName == null || componentName.equals(cc.getComponentName())) { webappInfos.addAll(cc.getWebappInfos()); @@ -201,9 +201,9 @@ public final class ComponentConfig { Map tm = null; // use a TreeMap to sort the components alpha by title if (comp != null) { - tm = new TreeMap(comp); + tm = new TreeMap<>(comp); } else { - tm = new TreeMap(); + tm = new TreeMap<>(); } for (ComponentConfig cc : getAllComponents()) { for (WebappInfo wInfo : cc.getWebappInfos()) { @@ -219,7 +219,7 @@ public final class ComponentConfig { } } } - webInfos = new ArrayList(tm.size()); + webInfos = new ArrayList<>(tm.size()); webInfos.addAll(tm.values()); webInfos = Collections.unmodifiableList(webInfos); synchronized (serverWebApps) { @@ -240,7 +240,7 @@ public final class ComponentConfig { } public static ComponentConfig getComponentConfig(String globalName, String rootLocation) throws ComponentException { - ComponentConfig componentConfig = null; + ComponentConfig componentConfig; if (globalName != null && !globalName.isEmpty()) { componentConfig = componentConfigCache.fromGlobalName(globalName); if (componentConfig != null) { @@ -253,23 +253,19 @@ public final class ComponentConfig { return componentConfig; } } - if (rootLocation != null) { - componentConfig = new ComponentConfig(globalName, rootLocation); - if (componentConfig.enabled()) { - componentConfigCache.put(componentConfig); - } - return componentConfig; - } else { + if (rootLocation == null) { // Do we really need to do this? throw new ComponentException("No component found named : " + globalName); } + componentConfig = new ComponentConfig(globalName, rootLocation); + if (componentConfig.enabled()) { + componentConfigCache.put(componentConfig); + } + return componentConfig; } public static String getFullLocation(String componentName, String resourceLoaderName, String location) throws ComponentException { ComponentConfig cc = getComponentConfig(componentName, null); - if (cc == null) { - throw new ComponentException("Could not find component with name: " + componentName); - } return cc.getFullLocation(resourceLoaderName, location); } @@ -288,25 +284,16 @@ public final class ComponentConfig { public static String getRootLocation(String componentName) throws ComponentException { ComponentConfig cc = getComponentConfig(componentName); - if (cc == null) { - throw new ComponentException("Could not find component with name: " + componentName); - } return cc.getRootLocation(); } public static InputStream getStream(String componentName, String resourceLoaderName, String location) throws ComponentException { ComponentConfig cc = getComponentConfig(componentName); - if (cc == null) { - throw new ComponentException("Could not find component with name: " + componentName); - } return cc.getStream(resourceLoaderName, location); } public static URL getURL(String componentName, String resourceLoaderName, String location) throws ComponentException { ComponentConfig cc = getComponentConfig(componentName); - if (cc == null) { - throw new ComponentException("Could not find component with name: " + componentName); - } return cc.getURL(resourceLoaderName, location); } @@ -327,9 +314,6 @@ public final class ComponentConfig { public static boolean isFileResourceLoader(String componentName, String resourceLoaderName) throws ComponentException { ComponentConfig cc = getComponentConfig(componentName); - if (cc == null) { - throw new ComponentException("Could not find component with name: " + componentName); - } return cc.isFileResourceLoader(resourceLoaderName); } @@ -382,7 +366,7 @@ public final class ComponentConfig { // resource-loader - resourceLoaderInfos List childElements = UtilXml.childElementList(ofbizComponentElement, "resource-loader"); if (!childElements.isEmpty()) { - Map resourceLoaderInfos = new LinkedHashMap(); + Map resourceLoaderInfos = new LinkedHashMap<>(); for (Element curElement : childElements) { ResourceLoaderInfo resourceLoaderInfo = new ResourceLoaderInfo(curElement); resourceLoaderInfos.put(resourceLoaderInfo.name, resourceLoaderInfo); @@ -394,7 +378,7 @@ public final class ComponentConfig { // classpath - classpathInfos childElements = UtilXml.childElementList(ofbizComponentElement, "classpath"); if (!childElements.isEmpty()) { - List classpathInfos = new ArrayList(childElements.size()); + List classpathInfos = new ArrayList<>(childElements.size()); for (Element curElement : childElements) { ClasspathInfo classpathInfo = new ClasspathInfo(this, curElement); classpathInfos.add(classpathInfo); @@ -406,7 +390,7 @@ public final class ComponentConfig { // entity-resource - entityResourceInfos childElements = UtilXml.childElementList(ofbizComponentElement, "entity-resource"); if (!childElements.isEmpty()) { - List entityResourceInfos = new ArrayList(childElements.size()); + List entityResourceInfos = new ArrayList<>(childElements.size()); for (Element curElement : childElements) { EntityResourceInfo entityResourceInfo = new EntityResourceInfo(this, curElement); entityResourceInfos.add(entityResourceInfo); @@ -418,7 +402,7 @@ public final class ComponentConfig { // service-resource - serviceResourceInfos childElements = UtilXml.childElementList(ofbizComponentElement, "service-resource"); if (!childElements.isEmpty()) { - List serviceResourceInfos = new ArrayList(childElements.size()); + List serviceResourceInfos = new ArrayList<>(childElements.size()); for (Element curElement : childElements) { ServiceResourceInfo serviceResourceInfo = new ServiceResourceInfo(this, curElement); serviceResourceInfos.add(serviceResourceInfo); @@ -430,7 +414,7 @@ public final class ComponentConfig { // test-suite - serviceResourceInfos childElements = UtilXml.childElementList(ofbizComponentElement, "test-suite"); if (!childElements.isEmpty()) { - List testSuiteInfos = new ArrayList(childElements.size()); + List testSuiteInfos = new ArrayList<>(childElements.size()); for (Element curElement : childElements) { TestSuiteInfo testSuiteInfo = new TestSuiteInfo(this, curElement); testSuiteInfos.add(testSuiteInfo); @@ -442,7 +426,7 @@ public final class ComponentConfig { // keystore - (cert/trust store infos) childElements = UtilXml.childElementList(ofbizComponentElement, "keystore"); if (!childElements.isEmpty()) { - List keystoreInfos = new ArrayList(childElements.size()); + List keystoreInfos = new ArrayList<>(childElements.size()); for (Element curElement : childElements) { KeystoreInfo keystoreInfo = new KeystoreInfo(this, curElement); keystoreInfos.add(keystoreInfo); @@ -454,7 +438,7 @@ public final class ComponentConfig { // webapp - webappInfos childElements = UtilXml.childElementList(ofbizComponentElement, "webapp"); if (!childElements.isEmpty()) { - List webappInfos = new ArrayList(childElements.size()); + List webappInfos = new ArrayList<>(childElements.size()); for (Element curElement : childElements) { WebappInfo webappInfo = new WebappInfo(this, curElement); webappInfos.add(webappInfo); @@ -467,7 +451,7 @@ public final class ComponentConfig { try { Collection configurations = ContainerConfig.getConfigurations(xmlUrl); if (!configurations.isEmpty()) { - this.configurations = Collections.unmodifiableList(new ArrayList(configurations)); + this.configurations = Collections.unmodifiableList(new ArrayList<>(configurations)); } else { this.configurations = Collections.emptyList(); } @@ -632,9 +616,9 @@ public final class ComponentConfig { // so this class encapsulates the Maps and synchronization code required to do that. private static final class ComponentConfigCache { // Key is the global name. - private final Map componentConfigs = new LinkedHashMap(); + private final Map componentConfigs = new LinkedHashMap<>(); // Root location mapped to global name. - private final Map componentLocations = new HashMap(); + private final Map componentLocations = new HashMap<>(); private synchronized ComponentConfig fromGlobalName(String globalName) { return componentConfigs.get(globalName); @@ -656,7 +640,7 @@ public final class ComponentConfig { } private synchronized Collection values() { - return Collections.unmodifiableList(new ArrayList(componentConfigs.values())); + return Collections.unmodifiableList(new ArrayList<>(componentConfigs.values())); } } @@ -701,12 +685,10 @@ public final class ComponentConfig { public KeyStore getKeyStore() { ComponentResourceHandler rh = this.createResourceHandler(); - if (rh != null) { - try { - return KeyStoreUtil.getStore(rh.getURL(), this.getPassword(), this.getType()); - } catch (Exception e) { - Debug.logWarning(e, module); - } + try { + return KeyStoreUtil.getStore(rh.getURL(), this.getPassword(), this.getType()); + } catch (Exception e) { + Debug.logWarning(e, module); } return null; } @@ -892,7 +874,7 @@ public final class ComponentConfig { // load the virtual hosts List virtHostList = UtilXml.childElementList(element, "virtual-host"); if (!virtHostList.isEmpty()) { - List virtualHosts = new ArrayList(virtHostList.size()); + List virtualHosts = new ArrayList<>(virtHostList.size()); for (Element e : virtHostList) { virtualHosts.add(e.getAttribute("host-name")); } @@ -903,7 +885,7 @@ public final class ComponentConfig { // load the init parameters List initParamList = UtilXml.childElementList(element, "init-param"); if (!initParamList.isEmpty()) { - Map initParameters = new LinkedHashMap(); + Map initParameters = new LinkedHashMap<>(); for (Element e : initParamList) { initParameters.put(e.getAttribute("name"), e.getAttribute("value")); } @@ -922,7 +904,7 @@ public final class ComponentConfig { } public String[] getBasePermission() { - return this.basePermission; + return this.basePermission.clone(); } public String getContextRoot() {