diff options
author | 2017-07-18 19:45:38 +0300 | |
---|---|---|
committer | 2017-07-18 19:45:38 +0300 | |
commit | b8e2faf476202b6ffe61bc3a9a37df1304881d40 (patch) | |
tree | f78b8c0517d8e16c5ae610bf8b49f68ea8a312a1 /common/openecomp-tosca-datatype/src/main/java/org | |
parent | 75aacbbe1acf78fa53378f07f0a8c7769449a17e (diff) |
[SDC] Onboarding 1710 rebase.
Change-Id: If3b6b81d221fde13908f1e8160db6f7d9433c535
Signed-off-by: Avi Ziv <avi.ziv@amdocs.com>
Diffstat (limited to 'common/openecomp-tosca-datatype/src/main/java/org')
2 files changed, 73 insertions, 0 deletions
diff --git a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/ToscaExtensionYamlUtil.java b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/ToscaExtensionYamlUtil.java new file mode 100644 index 0000000000..e6360461ef --- /dev/null +++ b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/ToscaExtensionYamlUtil.java @@ -0,0 +1,69 @@ +package org.openecomp.sdc.tosca.services; + +import org.yaml.snakeyaml.constructor.Constructor; +import org.yaml.snakeyaml.introspector.Property; +import org.yaml.snakeyaml.introspector.PropertyUtils; +import org.yaml.snakeyaml.nodes.MappingNode; +import org.yaml.snakeyaml.nodes.NodeId; + +import java.beans.IntrospectionException; + + +public class ToscaExtensionYamlUtil extends YamlUtil { + + @Override + public <T> Constructor getConstructor(Class<T> typClass) { + return new ToscaWithHeatExtensionConstructor(typClass); + } + + @Override + protected PropertyUtils getPropertyUtils() { + return new ToscaPropertyUtilsWithHeatExtension(); + } + + public class ToscaPropertyUtilsWithHeatExtension extends MyPropertyUtils { + @Override + public Property getProperty(Class<? extends Object> type, String name) + throws IntrospectionException { + try { + if (type + .equals(Class.forName("org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition"))) { + type = Class + .forName("org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt"); + } + } catch (ClassNotFoundException ex) { + throw new RuntimeException(ex); + } + return super.getProperty(type, name); + } + } + + protected class ToscaWithHeatExtensionConstructor extends StrictMapAppenderConstructor { + public ToscaWithHeatExtensionConstructor(Class<?> theRoot) { + super(theRoot); + yamlClassConstructors.put(NodeId.mapping, new MyPersistentObjectConstruct()); + } + + class MyPersistentObjectConstruct extends Constructor.ConstructMapping { + @Override + protected Object constructJavaBean2ndStep(MappingNode node, Object object) { + Class type = node.getType(); + try { + if (type.equals( + Class.forName("org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition"))) { + Class extendHeatClass = Class.forName( + "org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt"); + Object extendHeatObject = extendHeatClass.newInstance(); + // create JavaBean + return super.constructJavaBean2ndStep(node, extendHeatObject); + } else { + // create JavaBean + return super.constructJavaBean2ndStep(node, object); + } + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { + throw new RuntimeException(ex); + } + } + } + } +} diff --git a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/YamlUtil.java b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/YamlUtil.java index 7d0bcfeb83..755f02a4f8 100644 --- a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/YamlUtil.java +++ b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/services/YamlUtil.java @@ -48,6 +48,10 @@ public class YamlUtil { return yamlObj; } + public InputStream loadYamlFileIs(String yamlFullFileName) { + return YamlUtil.class.getResourceAsStream(yamlFullFileName); + } + /** * Yaml to object t. * |