2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.sdc.tosca.services;
19 import org.yaml.snakeyaml.constructor.Constructor;
20 import org.yaml.snakeyaml.introspector.Property;
21 import org.yaml.snakeyaml.introspector.PropertyUtils;
22 import org.yaml.snakeyaml.nodes.MappingNode;
23 import org.yaml.snakeyaml.nodes.NodeId;
25 import java.beans.IntrospectionException;
28 public class ToscaExtensionYamlUtil extends YamlUtil {
31 public <T> Constructor getConstructor(Class<T> typClass) {
32 return new ToscaWithHeatExtensionConstructor(typClass);
36 protected PropertyUtils getPropertyUtils() {
37 return new ToscaPropertyUtilsWithHeatExtension();
40 public class ToscaPropertyUtilsWithHeatExtension extends MyPropertyUtils {
42 public Property getProperty(Class<? extends Object> type, String name)
43 throws IntrospectionException {
44 Class<? extends Object> classType = type;
47 .equals(Class.forName("org.onap.sdc.tosca.datatypes.model.ParameterDefinition"))) {
49 .forName("org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt");
51 } catch (ClassNotFoundException ex) {
52 throw new RuntimeException(ex);
54 return super.getProperty(classType, name);
58 protected class ToscaWithHeatExtensionConstructor extends StrictMapAppenderConstructor {
59 public ToscaWithHeatExtensionConstructor(Class<?> theRoot) {
61 yamlClassConstructors.put(NodeId.mapping, new MyPersistentObjectConstruct());
64 class MyPersistentObjectConstruct extends Constructor.ConstructMapping {
66 protected Object constructJavaBean2ndStep(MappingNode node, Object object) {
67 Class type = node.getType();
70 Class.forName("org.onap.sdc.tosca.datatypes.model.ParameterDefinition"))) {
71 Class extendHeatClass = Class.forName(
72 "org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt");
73 Object extendHeatObject = extendHeatClass.newInstance();
75 return super.constructJavaBean2ndStep(node, extendHeatObject);
78 return super.constructJavaBean2ndStep(node, object);
80 } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
81 throw new RuntimeException(ex);