2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 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.onap.sdc.tosca.services;
23 import org.yaml.snakeyaml.constructor.Constructor;
24 import org.yaml.snakeyaml.nodes.MappingNode;
25 import org.yaml.snakeyaml.parser.ParserException;
27 import java.util.AbstractMap;
31 public class StrictMapAppenderConstructor extends Constructor {
33 * Instantiates a new Strict map appender constructor.
35 * @param theRoot the the root
37 public StrictMapAppenderConstructor(Class<?> theRoot) {
42 protected Map<Object, Object> createDefaultMap(int initSize) {
43 final Map<Object, Object> delegate = super.createDefaultMap(initSize);
44 return new AbstractMap<>() {
46 public Object put(Object key, Object value) {
47 if (delegate.containsKey(key)) {
48 throw new IllegalStateException("duplicate key: " + key);
50 return delegate.put(key, value);
54 public Set<Entry<Object, Object>> entrySet() {
55 return delegate.entrySet();
61 protected Map<Object, Object> constructMapping(MappingNode node) {
63 return super.constructMapping(node);
64 } catch (IllegalStateException exception) {
65 throw new ParserException("while parsing MappingNode",
66 node.getStartMark(), exception.getMessage(),