aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-02-19 12:35:04 +0200
committerMichael Lando <ml636r@att.com>2017-02-19 12:35:04 +0200
commitf5f13c4f6b6fe3b4d98e349dfd7db59339803436 (patch)
tree72caffc93fab394ffa3b761505775331f1c559b9 /openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib
parent451a3400b76511393c62a444f588a4ed15f4a549 (diff)
push addional code
Change-Id: Ia427bb3460cda3a896f8faced2de69eaf3807b74 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/pom.xml31
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/api/AbstractFactory.java81
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/AbstractFactoryBase.java212
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/pom.xml36
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/AbstractContextFactory.java27
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoriesConfigImpl.java61
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoryConfig.java46
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/AbstractComponentFactory.java105
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/FactoriesConfiguration.java29
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/pom.xml34
10 files changed, 662 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/pom.xml b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/pom.xml
new file mode 100644
index 0000000000..ccb3db833e
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/pom.xml
@@ -0,0 +1,31 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-lib</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../../..</relativePath>
+ </parent>
+
+ <name>openecomp-facade-api</name>
+ <artifactId>openecomp-facade-api</artifactId>
+ <groupId>org.openecomp.core</groupId>
+
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-utilities-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-common-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+</project> \ No newline at end of file
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
new file mode 100644
index 0000000000..53b8f00fc0
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/api/AbstractFactory.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============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:
+ * <pre>
+ * AbstractFactory&lt;IUnknown&gt;
+ * ^
+ * |
+ * Application code ----> ConcreteFactory
+ * ^
+ * |
+ * +---------+---------+
+ * | |
+ * 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>
+ * </ul> </ul> The normal concrete factory class may look like:
+ * <pre>
+ * public abstract class ConcreteFactory extends AbstractFactory&lt;IUnknown&gt; {
+ * static {
+ * registerFactory(ConcreteFactory.class, BaselineFactoryImpl.class);
+ * }
+ * public static ConcreteFactory getInstance() {
+ * return AbstractFactory.&lt;IUnknown, ConcreteFactory.class&gt;getInstance(ConcreteFactory.class);
+ * }
+ * }
+ * </pre>
+ *
+ * @param <I> Java interface type created by the factory.
+ */
+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();
+
+} // 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
new file mode 100644
index 0000000000..e19d9e972f
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/AbstractFactoryBase.java
@@ -0,0 +1,212 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.factory.impl;
+
+import static org.openecomp.core.utilities.CommonMethods.isEmpty;
+import static org.openecomp.core.utilities.CommonMethods.newInstance;
+
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * The type Abstract factory base.
+ */
+public abstract class AbstractFactoryBase {
+
+ /**
+ * 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 static Map<String, String> registry = new ConcurrentHashMap<String, String>();
+
+ /**
+ * Cached factory instances.
+ */
+ private static Map<String, AbstractFactoryBase> factoryMap =
+ new ConcurrentHashMap<String, AbstractFactoryBase>();
+
+ /**
+ * Registers implementor for an abstract factory. The method accepts Java classes rather
+ * then class names to ensure type safety at compilation time.
+ *
+ * @param <I> Java interface type instantiated by abstract factory
+ * @param <F> Type specific abstract factory for concrete Java interface
+ * @param factory Java class of a type specific abstract factory
+ * @param impl Java class of type specific factory implementor
+ */
+ public static <I, F extends AbstractFactoryBase> void registerFactory(Class<F> factory,
+ Class<? extends F> impl) {
+ if (factory == null) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withId("E0001").withMessage("Mandatory input factory.")
+ .withCategory(ErrorCategory.SYSTEM).build());
+ }
+
+ if (impl == null) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withId("E0001").withMessage("Mandatory input impl.")
+ .withCategory(ErrorCategory.SYSTEM).build());
+ }
+ if (factoryMap != null && factoryMap.containsKey(factory.getName())) {
+ factoryMap.remove(factory.getName());
+ }
+ registry.put(factory.getName(), impl.getName());
+ } // registerFactory
+
+ /**
+ * Register factory.
+ *
+ * @param factoryName the factory name
+ * @param implName the impl name
+ */
+ // TODO: Remove
+ protected static void registerFactory(String factoryName, String implName) {
+ registry.put(factoryName, implName);
+ } // registerFactory
+
+ /**
+ * Unregister factory.
+ *
+ * @param <F> the type parameter
+ * @param factory the factory
+ */
+ public static <F extends AbstractFactoryBase> void unregisterFactory(Class<F> factory) {
+ if (factory == null) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withId("E0001").withMessage("Mandatory input factory.")
+ .withCategory(ErrorCategory.SYSTEM).build());
+ }
+ if (factoryMap != null) {
+ factoryMap.remove(factory.getName());
+ }
+ }
+
+ /**
+ * Instantiates the configured implementation of an abstract factory.
+ *
+ * @param <I> Java interface type instantiated by 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
+ */
+ @SuppressWarnings("unchecked")
+ public static <I, F extends AbstractFactoryBase> F getInstance(Class<F> factoryType) {
+ if (factoryType == null) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withId("E0001")
+ .withMessage("Mandatory input factory type.").withCategory(ErrorCategory.SYSTEM)
+ .build());
+
+ }
+ // Pick up factory instance from cache
+ F factory = (F) factoryMap.get(factoryType.getName());
+ // Check for the first time access
+ if (factory == null) {
+ // Synchronize factory instantiation
+ synchronized (factoryType) {
+ // Re-check the factory instance
+ factory = (F) factoryMap.get(factoryType.getName());
+ if (factory == null) {
+ // Get the implementation class name
+ String implName = registry.get(factoryType.getName());
+
+ if (isEmpty(implName)) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withId("E0001")
+ .withMessage("Mandatory input factory implementation.")
+ .withCategory(ErrorCategory.SYSTEM).build());
+ }
+
+ factory = newInstance(implName, factoryType);
+
+ factory.init();
+
+ // Cache the instantiated singleton
+ factoryMap.put(factoryType.getName(), factory);
+ }
+ }
+ }
+
+ return factory;
+
+ } // getInstance
+
+
+ /**
+ * Is factory registered boolean.
+ *
+ * @param <F> the type parameter
+ * @param factoryType the factory type
+ * @return the boolean
+ */
+ public static <F extends AbstractFactoryBase> boolean isFactoryRegistered(Class<F> factoryType) {
+ boolean isFactoryRegistered = false;
+ if (factoryType == null) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withId("E0001")
+ .withMessage("Mandatory input factory type.").withCategory(ErrorCategory.SYSTEM)
+ .build());
+ }
+ // Pick up factory instance from cache
+ F factory = (F) factoryMap.get(factoryType.getName());
+ // Check for the first time access
+ if (factory != null) {
+ isFactoryRegistered = true;
+ } else {
+ // Get the implementation class name
+ String implName = registry.get(factoryType.getName());
+ if (!isEmpty(implName)) {
+ isFactoryRegistered = true;
+ }
+ }
+ return isFactoryRegistered;
+ }
+
+ /**
+ * Stop all.
+ */
+ public static void stopAll() {
+ Collection<AbstractFactoryBase> factorylist = factoryMap.values();
+ for (AbstractFactoryBase factory : factorylist) {
+ factory.stop();
+ }
+ }
+
+ /**
+ * Init.
+ */
+ protected void init() {
+ }
+
+ /**
+ * Stop.
+ */
+ protected void stop() {
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/pom.xml b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/pom.xml
new file mode 100644
index 0000000000..0c5d36abcc
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/pom.xml
@@ -0,0 +1,36 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>openecomp-sdc-lib</artifactId>
+ <groupId>org.openecomp.sdc</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../../..</relativePath>
+ </parent>
+
+ <artifactId>openecomp-facade-core</artifactId>
+ <name>openecomp-facade-core</name>
+ <groupId>org.openecomp.core</groupId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-utilities-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-common-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-facade-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+
+
+</project> \ No newline at end of file
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
new file mode 100644
index 0000000000..f4e1a85fee
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/AbstractContextFactory.java
@@ -0,0 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============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);
+}
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
new file mode 100644
index 0000000000..173f9b15b1
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoriesConfigImpl.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+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 java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public final class FactoriesConfigImpl implements FactoriesConfiguration {
+
+
+ private static final String FACTORY_CONFIG_FILE_NAME = "factoryConfiguration.json";
+ private static Map factoryMap = new HashMap();
+ private static boolean initialized = false;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map<String, String> getFactoriesMap() {
+ synchronized (this) {
+ if (!initialized) {
+ init();
+ initialized = true;
+ }
+ }
+ return factoryMap;
+ }
+
+ private void init() {
+ List<InputStream> factoryConfigIsList = FileUtils.getFileInputStreams(FACTORY_CONFIG_FILE_NAME);
+ for (InputStream factoryConfigIs : factoryConfigIsList) {
+ factoryMap.putAll(JsonUtil.json2Object(factoryConfigIs, Map.class));
+ }
+ }
+
+
+}
+
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
new file mode 100644
index 0000000000..d664cbee38
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoryConfig.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.factory;
+
+import org.openecomp.core.factory.api.FactoriesConfiguration;
+import org.openecomp.core.utilities.CommonMethods;
+
+import java.util.Map;
+
+public final class FactoryConfig {
+
+ private static final FactoriesConfiguration INSTANCE;
+
+ static {
+
+ try {
+ INSTANCE = CommonMethods.newInstance(
+ "org.openecomp.core.factory.FactoriesConfigImpl", FactoriesConfiguration.class);
+ } catch (Exception exception) {
+ exception.printStackTrace();
+ throw exception;
+ }
+ }
+
+ 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
new file mode 100644
index 0000000000..9cd7749f55
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/AbstractComponentFactory.java
@@ -0,0 +1,105 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.factory.api;
+
+import org.openecomp.core.factory.FactoryConfig;
+import org.openecomp.core.factory.impl.AbstractFactoryBase;
+import org.openecomp.core.utilities.CommonMethods;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+
+import java.util.Map;
+
+public abstract class AbstractComponentFactory<I> extends AbstractFactory<I> {
+
+ static {
+ Registry registry = new RegistryImpl();
+ InitializationHelper.registerFactoryMapping(registry);
+ }
+
+ interface Registry {
+ void register(String factory, String impl);
+ }
+
+ private static class RegistryImpl implements Registry {
+ @Override
+ public void register(String factory, String impl) {
+ AbstractFactoryBase.registerFactory(factory, impl);
+ }
+ }
+
+ static class InitializationHelper {
+
+
+ private static boolean isRegistered = false;
+
+ private InitializationHelper() {
+ }
+
+ static synchronized boolean registerFactoryMapping(Registry registry) {
+
+ boolean done = !isRegistered;
+
+ if (!isRegistered) {
+ registerFactoryMappingImpl(registry);
+ isRegistered = true;
+ }
+
+ return done;
+ }
+
+ private static void registerFactoryMappingImpl(Registry registry) {
+ Map<String, String> factoryMap = FactoryConfig.getFactoriesMap();
+
+ try {
+ for (Map.Entry<String, String> entry : factoryMap.entrySet()) {
+ String abstractClassName = entry.getKey();
+ String concreteTypeName = entry.getValue();
+
+ if (CommonMethods.isEmpty(concreteTypeName)) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withId("E0003")
+ .withMessage("Missing configuration value:" + concreteTypeName + ".")
+ .withCategory(ErrorCategory.SYSTEM).build());
+
+ }
+
+ registry.register(abstractClassName, concreteTypeName);
+ }
+ } catch (RuntimeException exception) {
+ throw exception;
+ } catch (Exception exception) {
+ throw new RuntimeException(exception);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> Class<T> unsecureCast(Class<?> cls) {
+ return (Class<T>) cls;
+ }
+
+ private static String nameOf(Class<?> clazz) {
+ return (clazz != null) ? clazz.getName() : "null";
+ }
+ }
+
+}
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
new file mode 100644
index 0000000000..8086181204
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/FactoriesConfiguration.java
@@ -0,0 +1,29 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.factory.api;
+
+import java.util.Map;
+
+
+public interface FactoriesConfiguration {
+
+ Map<String, String> getFactoriesMap();
+}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/pom.xml b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/pom.xml
new file mode 100644
index 0000000000..29e9cce688
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/pom.xml
@@ -0,0 +1,34 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>openecomp-core-lib</artifactId>
+ <groupId>org.openecomp.core</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <packaging>pom</packaging>
+ <artifactId>openecomp-facade-lib</artifactId>
+ <name>openecomp-facade-lib</name>
+
+ <modules>
+ <module>openecomp-facade-api</module>
+ <module>openecomp-facade-core</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-facade-api</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-facade-core</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+</project> \ No newline at end of file