diff options
author | vasraz <vasyl.razinkov@est.tech> | 2021-03-22 15:33:06 +0000 |
---|---|---|
committer | Christophe Closset <christophe.closset@intl.att.com> | 2021-03-24 06:59:47 +0000 |
commit | d378c37fbd1ecec7b43394926f1ca32a695e07de (patch) | |
tree | 5c8a085f8732f980d871d966ac49361644efa698 /openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib | |
parent | a6ae7294ecd336d7e88f915710b08e2658eaee00 (diff) |
Reformat openecomp-be
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3449
Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib')
8 files changed, 91 insertions, 122 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/api/AbstractFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/api/AbstractFactory.java index 12956417dd..87da8fc6e4 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/api/AbstractFactory.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/api/AbstractFactory.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,20 +17,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.factory.api; import org.openecomp.core.factory.impl.AbstractFactoryBase; /** - * This class provides generic implementation of an abstract factory. Components exposed as Java - * interfaces should have their own concrete factories derived from the given class. This assures - * code alignment and consistency across all Service Management components. - * The class actually - * uses singleton pattern to instantiate and reuse just one instance of a factory. Therefore, each - * factory implementation has to be <i>thread-safe</i>. - * In a general case, the hierarchy of - * factory objects for an Java interface <tt>IUknown</tt> may look as follows: + * This class provides generic implementation of an abstract factory. Components exposed as Java interfaces should have their own concrete factories + * derived from the given class. This assures code alignment and consistency across all Service Management components. The class actually uses + * singleton pattern to instantiate and reuse just one instance of a factory. Therefore, each factory implementation has to be <i>thread-safe</i>. In + * a general case, the hierarchy of factory objects for an Java interface <tt>IUknown</tt> may look as follows: * <pre> * AbstractFactory<IUnknown> * ^ @@ -42,12 +37,10 @@ import org.openecomp.core.factory.impl.AbstractFactoryBase; * | | * BaselineFactoryImpl CustomFactoryImpl * </pre> - * Where the classes responsibility is: <ul> <li>Abstract factory - common logic to retrieve the - * implementation class name from a central repository.</li> <li>Concrete factory - abstract class - * that only exposes to application layer the type specific API such as: <ul> <li><tt>public static - * ConcreteFactory getInstance()</tt></li> </ul> <li>Baseline factory - out of the box - * implementation of concrete factory (that can be replaced by a custom one depending on customer - * needs) which actually implements method: <ul> <li><tt>public IUnknown createInterface()</tt></li> + * Where the classes responsibility is: <ul> <li>Abstract factory - common logic to retrieve the implementation class name from a central + * repository.</li> <li>Concrete factory - abstract class that only exposes to application layer the type specific API such as: <ul> <li><tt>public + * static ConcreteFactory getInstance()</tt></li> </ul> <li>Baseline factory - out of the box implementation of concrete factory (that can be replaced + * by a custom one depending on customer needs) which actually implements method: <ul> <li><tt>public IUnknown createInterface()</tt></li> * </ul> </ul> The normal concrete factory class may look like: * <pre> * public abstract class ConcreteFactory extends AbstractFactory<IUnknown> { @@ -64,18 +57,15 @@ import org.openecomp.core.factory.impl.AbstractFactoryBase; */ public abstract class AbstractFactory<I> extends AbstractFactoryBase { - - /** - * Returns the interface implementor instance. - * <b>Note</b>: It's up to the concrete factory to decide on the actual - * implementation of the returned interface. Therefore, the call can get the - * same instance per each call in case of singleton implementation or new - * instance otherwise. However, the API consumer may not assume anything - * regarding the underlying logic and has always go through the factory to - * obtain the reference. - * - * @return Implementor of the exposed Java interface. - */ - public abstract I createInterface(); - + /** + * Returns the interface implementor instance. + * <b>Note</b>: It's up to the concrete factory to decide on the actual + * implementation of the returned interface. Therefore, the call can get the same instance per each call in case of singleton implementation or + * new instance otherwise. However, the API consumer may not assume anything regarding the underlying logic and has always go through the factory + * to obtain the reference. + * + * @return Implementor of the exposed Java interface. + */ + public abstract I createInterface(); } // End of class + diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/AbstractFactoryBase.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/AbstractFactoryBase.java index 3a117ef063..41bfeab826 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/AbstractFactoryBase.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/AbstractFactoryBase.java @@ -13,30 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.core.factory.impl; public abstract class AbstractFactoryBase { - /** - * Instantiates the configured implementation of an abstract factory. - * - * @param <F> Type specific abstract factory for concrete Java interface - * @param factoryType Java class of type specific abstract factory - * @return Instance of implementation class - */ - public static <F extends AbstractFactoryBase> F getInstance(Class<F> factoryType) { - return FactoryManager.getInstance().getFactoryInstance(factoryType); - } + /** + * Instantiates the configured implementation of an abstract factory. + * + * @param <F> Type specific abstract factory for concrete Java interface + * @param factoryType Java class of type specific abstract factory + * @return Instance of implementation class + */ + public static <F extends AbstractFactoryBase> F getInstance(Class<F> factoryType) { + return FactoryManager.getInstance().getFactoryInstance(factoryType); + } + + protected void init() { + // allows custom initialization - protected void init() { - // allows custom initialization - // noop by default - } + // noop by default + } - protected void stop() { - // allows custom shutdown - // noop by default - } + protected void stop() { + // allows custom shutdown + // noop by default + } } diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/FactoryManager.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/FactoryManager.java index ec2d93f35b..26816aaafe 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/FactoryManager.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/FactoryManager.java @@ -16,7 +16,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.core.factory.impl; import com.amdocs.zusammen.utils.facade.impl.FactoryConfig; @@ -33,9 +32,8 @@ public class FactoryManager { private static final FactoryManager instance = new FactoryManager(); private static final String ERROR_CODE_E0001 = "E0001"; /** - * Temporary registry of default implementations. The map keeps class names rather then class - * types to allow unloading of those classes from memory by garbage collector if factory is not - * actually used. + * Temporary registry of default implementations. The map keeps class names rather then class types to allow unloading of those classes from + * memory by garbage collector if factory is not actually used. */ private final Map<String, String> factoryRegistry = new ConcurrentHashMap<>(); /** @@ -43,7 +41,6 @@ public class FactoryManager { */ private final Map<String, AbstractFactoryBase> factoryInstanceMap = new ConcurrentHashMap<>(); - private FactoryManager() { initializeFactoryRegistry(); } @@ -54,17 +51,13 @@ public class FactoryManager { private void initializeFactoryRegistry() { final Map<String, String> factoryMap = FactoryConfig.getFactoriesMap(); - for (final Map.Entry<String, String> entry : factoryMap.entrySet()) { final String abstractClassName = entry.getKey(); final String concreteTypeName = entry.getValue(); - if (StringUtils.isEmpty(concreteTypeName)) { throw new CoreException( - new ErrorCode.ErrorCodeBuilder().withId("E0003") - .withMessage("Missing configuration value:" + concreteTypeName + ".") + new ErrorCode.ErrorCodeBuilder().withId("E0003").withMessage("Missing configuration value:" + concreteTypeName + ".") .withCategory(ErrorCategory.SYSTEM).build()); - } registerFactory(abstractClassName, concreteTypeName); } @@ -80,32 +73,26 @@ public class FactoryManager { @SuppressWarnings("unchecked") public <F extends AbstractFactoryBase> F getFactoryInstance(Class<F> factoryType) { if (factoryType == null) { - throw new CoreException( - new ErrorCode.ErrorCodeBuilder().withId(ERROR_CODE_E0001) - .withMessage("Mandatory input factory type.").withCategory(ErrorCategory.SYSTEM) - .build()); - + throw new CoreException(new ErrorCode.ErrorCodeBuilder().withId(ERROR_CODE_E0001).withMessage("Mandatory input factory type.") + .withCategory(ErrorCategory.SYSTEM).build()); } final String factoryTypeName = factoryType.getName(); // Check if the factory is already cached if (factoryInstanceMap.get(factoryTypeName) == null) { //if not, create a new one and cache it + // Get the implementation class name final String implName = factoryRegistry.get(factoryTypeName); - if (StringUtils.isEmpty(implName)) { throw new CoreException( - new ErrorCode.ErrorCodeBuilder().withId(ERROR_CODE_E0001) - .withMessage("Mandatory input factory implementation.") + new ErrorCode.ErrorCodeBuilder().withId(ERROR_CODE_E0001).withMessage("Mandatory input factory implementation.") .withCategory(ErrorCategory.SYSTEM).build()); } - F factory = CommonMethods.newInstance(implName, factoryType); factory.init(); // Cache the instantiated singleton factoryInstanceMap.putIfAbsent(factoryTypeName, factory); } - return (F) factoryInstanceMap.get(factoryTypeName); } @@ -115,6 +102,7 @@ public class FactoryManager { /** * Unregister factory and removes the cached instance if any. + * * @param factoryName the factory name to unregister */ public void unregisterFactory(final String factoryName) { @@ -134,10 +122,9 @@ public class FactoryManager { public <F extends AbstractFactoryBase> void removeFactoryInstance(Class<F> factory) { if (factory == null) { throw new CoreException( - new ErrorCode.ErrorCodeBuilder().withId(ERROR_CODE_E0001).withMessage("Mandatory input factory.") - .withCategory(ErrorCategory.SYSTEM).build()); + new ErrorCode.ErrorCodeBuilder().withId(ERROR_CODE_E0001).withMessage("Mandatory input factory.").withCategory(ErrorCategory.SYSTEM) + .build()); } - factoryInstanceMap.remove(factory.getName()); } diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/AbstractContextFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/AbstractContextFactory.java index f4e1a85fee..a98ba44cf9 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/AbstractContextFactory.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/AbstractContextFactory.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,11 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.factory; import org.openecomp.core.factory.impl.AbstractFactoryBase; public abstract class AbstractContextFactory<I, C> extends AbstractFactoryBase { - public abstract I createInterface(C contextType); + + public abstract I createInterface(C contextType); } diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoriesConfigImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoriesConfigImpl.java index 31df923bdd..cfe50f1619 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoriesConfigImpl.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoriesConfigImpl.java @@ -13,45 +13,41 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.core.factory; - -import org.openecomp.core.factory.api.FactoriesConfiguration; -import org.openecomp.core.utilities.file.FileUtils; -import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.sdc.common.errors.SdcConfigurationException; - import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.openecomp.core.factory.api.FactoriesConfiguration; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.common.errors.SdcConfigurationException; public final class FactoriesConfigImpl implements FactoriesConfiguration { - private final Map factoryConfigurationMap = new HashMap(); + private final Map factoryConfigurationMap = new HashMap(); - public FactoriesConfigImpl() { - init(); - } + public FactoriesConfigImpl() { + init(); + } - @SuppressWarnings("unchecked") - @Override - public Map<String, String> getFactoriesMap() { - return factoryConfigurationMap; - } + @SuppressWarnings("unchecked") + @Override + public Map<String, String> getFactoriesMap() { + return factoryConfigurationMap; + } - private void init() { - final List<URL> factoryConfigUrlList = FileUtils.getAllLocations("factoryConfiguration.json"); - for (final URL factoryConfigUrl : factoryConfigUrlList) { - try (InputStream stream = factoryConfigUrl.openStream()) { - factoryConfigurationMap.putAll(JsonUtil.json2Object(stream, Map.class)); - } catch (final IOException e) { - throw new SdcConfigurationException("Failed to initialize Factory from '" + factoryConfigUrl.getPath() +"'", e); - } + private void init() { + final List<URL> factoryConfigUrlList = FileUtils.getAllLocations("factoryConfiguration.json"); + for (final URL factoryConfigUrl : factoryConfigUrlList) { + try (InputStream stream = factoryConfigUrl.openStream()) { + factoryConfigurationMap.putAll(JsonUtil.json2Object(stream, Map.class)); + } catch (final IOException e) { + throw new SdcConfigurationException("Failed to initialize Factory from '" + factoryConfigUrl.getPath() + "'", e); + } + } } - } } - diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoryConfig.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoryConfig.java index 7dbf921ebf..0c118fc2c9 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoryConfig.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoryConfig.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.factory; import java.util.Map; @@ -26,14 +25,13 @@ import org.openecomp.core.utilities.CommonMethods; public final class FactoryConfig { - private static final FactoriesConfiguration INSTANCE = CommonMethods.newInstance( - "org.openecomp.core.factory.FactoriesConfigImpl", FactoriesConfiguration.class); - - private FactoryConfig() { + private static final FactoriesConfiguration INSTANCE = CommonMethods + .newInstance("org.openecomp.core.factory.FactoriesConfigImpl", FactoriesConfiguration.class); - } + private FactoryConfig() { + } - public static Map<String, String> getFactoriesMap() { - return INSTANCE.getFactoriesMap(); - } + public static Map<String, String> getFactoriesMap() { + return INSTANCE.getFactoriesMap(); + } } diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/AbstractComponentFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/AbstractComponentFactory.java index 3de0d88f43..0a091c1864 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/AbstractComponentFactory.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/AbstractComponentFactory.java @@ -4,17 +4,17 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.core.factory.api; public abstract class AbstractComponentFactory<I> extends AbstractFactory<I> { + } diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/FactoriesConfiguration.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/FactoriesConfiguration.java index 8086181204..b1da7950ce 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/FactoriesConfiguration.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/FactoriesConfiguration.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,13 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.factory.api; import java.util.Map; - public interface FactoriesConfiguration { - Map<String, String> getFactoriesMap(); + Map<String, String> getFactoriesMap(); } |