1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
13 from toscaparser.dataentity import DataEntity
14 from toscaparser.elements.constraints import Schema
15 from toscaparser.functions import is_function
16 from org.openecomp.sdc.toscaparser.jython import JyProperty
19 class Property(JyProperty):
20 '''TOSCA built-in Property type.'''
23 TYPE, REQUIRED, DESCRIPTION, DEFAULT, CONSTRAINTS
25 'type', 'required', 'description', 'default', 'constraints'
29 ENTRYTYPE, ENTRYPROPERTIES
34 def __init__(self, property_name, value, schema_dict, custom_def=None):
35 self.name = property_name
37 self.custom_def = custom_def
38 self.schema = Schema(property_name, schema_dict)
46 def getJyValueClassName(self):
47 return self.value.__class__.__name__
52 def isJyRequired(self):
55 def getJyDescription(self):
56 return self.description
60 return self.schema.type
64 return self.schema.required
67 def description(self):
68 return self.schema.description
72 return self.schema.default
75 def constraints(self):
76 return self.schema.constraints
79 def entry_schema(self):
80 return self.schema.entry_schema
83 '''Validate if not a reference property.'''
84 if not is_function(self.value):
85 if self.type == Schema.STRING:
86 self.value = str(self.value)
87 self.value = DataEntity.validate_datatype(self.type, self.value,
91 self._validate_constraints()
93 def _validate_constraints(self):
95 for constraint in self.constraints:
96 constraint.validate(self.value)