2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.tosca.services.yamlutil;
23 import org.openecomp.core.utilities.yaml.YamlUtil;
24 import org.yaml.snakeyaml.constructor.Constructor;
25 import org.yaml.snakeyaml.introspector.Property;
26 import org.yaml.snakeyaml.introspector.PropertyUtils;
27 import org.yaml.snakeyaml.nodes.MappingNode;
28 import org.yaml.snakeyaml.nodes.NodeId;
30 import java.beans.IntrospectionException;
32 public class ToscaExtensionYamlUtil extends YamlUtil {
35 public <T> Constructor getConstructor(Class<T> typClass) {
36 return new ToscaWithHeatExtensionConstructor(typClass);
40 protected PropertyUtils getPropertyUtils() {
41 return new ToscaPropertyUtilsWithHeatExtension();
44 public class ToscaPropertyUtilsWithHeatExtension extends MyPropertyUtils {
46 public Property getProperty(Class<? extends Object> type, String name)
47 throws IntrospectionException {
50 .equals(Class.forName("org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition"))) {
52 .forName("org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt");
54 } catch (ClassNotFoundException ex) {
55 throw new RuntimeException(ex);
57 return super.getProperty(type, name);
61 protected class ToscaWithHeatExtensionConstructor extends StrictMapAppenderConstructor {
62 public ToscaWithHeatExtensionConstructor(Class<?> theRoot) {
64 yamlClassConstructors.put(NodeId.mapping, new MyPersistentObjectConstruct());
67 class MyPersistentObjectConstruct extends ConstructMapping {
69 protected Object constructJavaBean2ndStep(MappingNode node, Object object) {
70 Class type = node.getType();
73 Class.forName("org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition"))) {
74 Class extendHeatClass = Class.forName(
75 "org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt");
76 Object extendHeatObject = extendHeatClass.newInstance();
78 return super.constructJavaBean2ndStep(node, extendHeatObject);
81 return super.constructJavaBean2ndStep(node, object);
83 } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
84 throw new RuntimeException(ex);