def _write_model(self, specification):
if specification.allowed_job_commands and not (set(specification.allowed_job_commands).issubset(self.job_commands)):<EOL><INDENT>raise Exception("<STR_LIT>" % (specification.allowed_job_commands, specification.entity_name))<EOL><DEDENT>specification.supportsAlarms = len(filter(lambda child_api : child_api.rest_name == "<STR_LIT>", specification.child_apis)) == <NUM_LIT:1><EOL>specification.supportsPermissions = len(filter(lambda child_api : child_api.rest_name == "<STR_LIT>" or child_api.rest_name == "<STR_LIT>", specification.child_apis)) > <NUM_LIT:0><EOL>specification.supportsDeploymentFailures = len(filter(lambda child_api : child_api.rest_name == "<STR_LIT>", specification.child_apis)) == <NUM_LIT:1><EOL>filename = "<STR_LIT>" % (self._class_prefix, specification.entity_name)<EOL>self.model_list.append("<STR_LIT>" %(self._class_prefix, specification.entity_name))<EOL>isNamedEntity = self._isNamedEntity(attributes=specification.attributes) if specification.rest_name else False<EOL>superclass_name = "<STR_LIT>" if specification.rest_name == self.api_root else "<STR_LIT>" if isNamedEntity  else "<STR_LIT>" if not specification.rest_name else "<STR_LIT>"<EOL>specification.attributes_modified = [attribute for attribute in specification.attributes if (attribute.name not in self.base_attrs and (not isNamedEntity or attribute.name not in self.named_entity_attrs))]<EOL>enum_attributes=[attribute for attribute in specification.attributes_modified if attribute.allowed_choices]<EOL>enum_attrs_to_import = enum_attributes[:]<EOL>generic_enum_attrs_in_entity = {}<EOL>generic_enum_attributes_to_import = []<EOL>for attr in enum_attributes:<EOL><INDENT>if attr.local_type == "<STR_LIT:list>" and attr.subtype == "<STR_LIT>" and attr.default_value:<EOL><INDENT>attr.default_value = attr.default_value.translate({ord(i): None for i in '<STR_LIT>'}).split("<STR_LIT:U+002C>")<EOL>if not all(defval in attr.allowed_choices for defval in attr.default_value):<EOL><INDENT>raise Exception("<STR_LIT>" % (attr.name, specification.entity_name))<EOL><DEDENT><DEDENT>if specification.rest_name in self.overide_generic_enums and  attr.name in self.overide_generic_enums[specification.rest_name]:<EOL><INDENT>continue<EOL><DEDENT>for generic_enum_attr in self.generic_enum_attrs:<EOL><INDENT>if set(attr.allowed_choices) & set(generic_enum_attr.allowed_choices):<EOL><INDENT>generic_enum_attrs_in_entity[attr.name] = generic_enum_attr<EOL>enum_attrs_to_import.remove(attr)<EOL>generic_enum_attributes_to_import.append(generic_enum_attr.name)<EOL><DEDENT><DEDENT><DEDENT>self._write_enums(entity_name=specification.entity_name, attributes=enum_attrs_to_import)<EOL>self.generic_enum_attrs_for_locale[specification.entity_name] = generic_enum_attrs_in_entity.values()<EOL>object_subtypes = set([attribute.subtype for attribute in specification.attributes if (attribute.local_type == "<STR_LIT:object>"  and attribute.subtype)])<EOL>invalid_object_attributes=[attribute.name for attribute in specification.attributes_modified if (attribute.local_type == "<STR_LIT:object>" and not attribute.subtype in self.entity_names)]<EOL>if invalid_object_attributes:<EOL><INDENT>Printer.log("<STR_LIT>" % (filename, invalid_object_attributes, object_subtypes))<EOL><DEDENT>list_subtypes = set([attribute.subtype for attribute in specification.attributes if (attribute.local_type == "<STR_LIT:list>" and attribute.subtype not in self.list_subtypes_generic)])<EOL>invalid_list_attributes=[attribute.name for attribute in specification.attributes_modified if (attribute.local_type == "<STR_LIT:list>" and not attribute.subtype in self.entity_names and not attribute.subtype in self.list_subtypes_generic)]<EOL>if invalid_list_attributes:<EOL><INDENT>Printer.log("<STR_LIT>" % (filename, invalid_list_attributes, list_subtypes))<EOL><DEDENT>if '<STR_LIT:object>' in list_subtypes:<EOL><INDENT>list_subtypes.remove('<STR_LIT:object>')<EOL><DEDENT>if '<STR_LIT>' in list_subtypes:<EOL><INDENT>list_subtypes.remove('<STR_LIT>')<EOL><DEDENT>self.write(destination = self.model_directory,<EOL>filename = filename,<EOL>template_name = "<STR_LIT>",<EOL>class_prefix = self._class_prefix,<EOL>specification = specification,<EOL>superclass_name = superclass_name,<EOL>enum_attrs_to_import = enum_attrs_to_import,<EOL>generic_enum_attributes = generic_enum_attrs_in_entity,<EOL>generic_enum_attributes_to_import = set(generic_enum_attributes_to_import),<EOL>subtypes_for_import = object_subtypes.union(list_subtypes))<EOL>
This method writes the ouput for a particular specification.