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.be.datatypes.elements;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
27 import java.util.Map.Entry;
28 import org.apache.commons.collections4.CollectionUtils;
29 import org.apache.commons.collections4.MapUtils;
30 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
33 * Schema allows to create new types that can be used along TOSCA definitions.
35 public class SchemaDefinition extends ToscaDataDefinition {
37 private String derivedFrom;
38 private List<String> constraints;
39 private Map<String, PropertyDataDefinition> properties;
41 private PropertyDataDefinition property;
44 public SchemaDefinition() {
47 public SchemaDefinition(String derivedFrom, List<String> constraints,
48 Map<String, PropertyDataDefinition> properties) {
49 this.setDerivedFrom(derivedFrom);
50 this.setConstraints(constraints);
51 this.setProperties(properties);
54 public SchemaDefinition(final SchemaDefinition schemaDefinition) {
55 if (schemaDefinition == null) {
58 this.derivedFrom = schemaDefinition.getDerivedFrom();
59 if (CollectionUtils.isNotEmpty(schemaDefinition.getConstraints())) {
60 this.constraints = new ArrayList<>(schemaDefinition.getConstraints());
62 if (schemaDefinition.getProperty() != null) {
63 this.property = new PropertyDataDefinition(schemaDefinition.getProperty());
65 if (MapUtils.isNotEmpty(schemaDefinition.getProperties())) {
66 this.properties = new HashMap<>();
67 for (final Entry<String, PropertyDataDefinition> propertyEntry : schemaDefinition.getProperties().entrySet()) {
68 this.properties.put(propertyEntry.getKey(), new PropertyDataDefinition(propertyEntry.getValue()));
73 public String getDerivedFrom() {
77 public void setProperty(PropertyDataDefinition property) {
78 this.property = property;
81 public PropertyDataDefinition getProperty() {
85 public void setDerivedFrom(String derivedFrom) {
86 this.derivedFrom = derivedFrom;
89 public List<String> getConstraints() {
93 public void setConstraints(List<String> constraints) {
94 this.constraints = constraints;
97 public Map<String, PropertyDataDefinition> getProperties() {
101 public void setProperties(Map<String, PropertyDataDefinition> properties) {
102 this.properties = properties;
105 public void addProperty(String key, PropertyDataDefinition property) {
107 properties.put(key, property);
111 public int hashCode() {
112 final int prime = 31;
114 result = prime * result + ((constraints == null) ? 0 : constraints.hashCode());
115 result = prime * result + ((derivedFrom == null) ? 0 : derivedFrom.hashCode());
116 result = prime * result + ((properties == null) ? 0 : properties.hashCode());
117 result = prime * result + ((property == null) ? 0 : property.hashCode());
122 public boolean equals(Object obj) {
129 if (getClass() != obj.getClass()) {
132 SchemaDefinition other = (SchemaDefinition) obj;
133 if (constraints == null) {
134 if (other.constraints != null) {
137 } else if (!constraints.equals(other.constraints)) {
140 if (derivedFrom == null) {
141 if (other.derivedFrom != null) {
144 } else if (!derivedFrom.equals(other.derivedFrom)) {
147 if (properties == null) {
148 if (other.properties != null) {
151 } else if (!properties.equals(other.properties)) {
154 if (property == null) {
155 return other.property == null;
157 return property.equals(other.property);
162 public String toString() {
163 return "SchemaDefinition [" + "derivedFrom='" + derivedFrom + ", constraints=" + constraints + ", properties="
164 + properties + ", property=" + property + ']';