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
14 from toscaparser.elements.statefulentitytype import StatefulEntityType
17 class DataType(StatefulEntityType):
18 '''TOSCA built-in and user defined complex data type.'''
20 def __init__(self, datatypename, custom_def=None):
21 super(DataType, self).__init__(datatypename, self.DATATYPE_PREFIX,
23 self.custom_def = custom_def
26 def parent_type(self):
27 '''Return a datatype this datatype is derived from.'''
28 ptype = self.derived_from(self.defs)
30 return DataType(ptype, self.custom_def)
35 '''Return 'type' section in the datatype schema.'''
36 return self.entity_value(self.defs, 'type')
38 def get_all_properties_objects(self):
39 '''Return all properties objects defined in type and parent type.'''
40 props_def = self.get_properties_def_objects()
41 ptype = self.parent_type
43 props_def.extend(ptype.get_properties_def_objects())
44 ptype = ptype.parent_type
47 def get_all_properties(self):
48 '''Return a dictionary of all property definition name-object pairs.'''
49 return {prop.name: prop
50 for prop in self.get_all_properties_objects()}
52 def get_all_property_value(self, name):
53 '''Return the value of a given property name.'''
54 props_def = self.get_all_properties()
55 if props_def and name in props_def.key():
56 return props_def[name].value