# Path: tmapi/constants.py
# AUTOMERGE_FEATURE_STRING = TMAPI_FEATURE_STRING_BASE + 'automerge'
# 
# XSD_ANY_URI = XSD + 'anyURI'
# 
# XSD_FLOAT = XSD + 'float'
# 
# XSD_INT = XSD + 'int'
# 
# XSD_LONG = XSD + 'long'
# 
# XSD_STRING = XSD + 'string'
# 
# Path: tmapi/exceptions.py
# class IdentityConstraintException (ModelConstraintException):
# 
#     """This exception is used to report identity constraint
#     violations. Assigning an item identifier, a subject identifier, or
#     a subject locator to different objects causes an
#     `IdentityConstraintException` to be raised."""
# 
#     def __init__ (self, reporter, existing, locator, message):
#         """Creates a new `IdentityConstraintException` with the
#         specified message.
# 
#         :param reporter: the construct to which the identity should
#           have been assigned
#         :type reporter: `Construct`
#         :param existing: the construct that has the same identity
#         :type existing: `Construct`
#         :param locator: the locator representing the identity
#         :type locator: `Locator`
#         :param message: the detail message
#         :type message: string
# 
#         """
#         super(IdentityConstraintException, self).__init__(reporter, message)
#         self._existing = existing
#         self._locator = locator
# 
#     def get_existing (self):
#         """Returns the `Construct` which already has the identity
#         represented by the locator get_locator().
# 
#         :rtype: `Construct`
# 
#         """
#         return self._existing
# 
#     def get_locator (self):
#         """Returns the `Locator` representing the identity that caused
#         the exception.
# 
#         :rtype: `Locator`
# 
#         """
#         return self._locator
# 
# class ModelConstraintException (TMAPIRuntimeException):
# 
#     """This exception is used to report Topic Maps - Data Model
#     constraint violations."""
# 
#     def __init__ (self, reporter, message):
#         """Creates a new ModelConstraintException with the specified
#         message.
# 
#         :param reporter: the construct which has thrown this exception
#         :type reporter: `Construct`
#         :param message: the detail message
#         :type message: string
# 
#         """
#         self._reporter = reporter
#         self._message = message
#     
#     def get_reporter (self):
#         """Return the `Construct` which has thrown the exception.
# 
#         :rtype: `Construct`
# 
#         """
#         return self._reporter
# 
# class TopicInUseException (ModelConstraintException):
# 
#     """Thrown when an attempt is made to remove a `Topic` which is
#     being used as a type, as a reifier, or as a role player in an
#     association, or in a scope."""
#     
#     def __init__ (self, topic, message):
#         """Creates a new `TopicInUseException` with the specified message.
# 
#         :param topic: the topic which is not removable
#         :type topic: `Topic`
#         :param message: the detail message
#         :type message: string
# 
#         """
#         super(TopicInUseException, self).__init__(topic, message)


from django.db import models
from tmapi.constants import AUTOMERGE_FEATURE_STRING, XSD_ANY_URI, XSD_FLOAT, XSD_INT, XSD_LONG, XSD_STRING
from tmapi.exceptions import IdentityConstraintException, \
    ModelConstraintException, TopicInUseException
from construct import Construct
from construct_fields import ConstructFields
from item_identifier import ItemIdentifier
from locator import Locator
from name import Name
from subject_identifier import SubjectIdentifier
from subject_locator import SubjectLocator
from occurrence import Occurrence
from merge_utils import handle_existing_construct, \
    move_role_characteristics, move_variants
from signature import generate_association_signature, \
    generate_name_signature, generate_occurrence_signature

    def create_occurrence (self, type, value, scope=None, datatype=None,
                           proxy=Occurrence):
        """Creates an `Occurrence` for this topic with the specified
        `type`, `value`, and `scope`.

        If `datatype` is not None, the newly created `Occurrence` will
        have the datatype specified by `datatype`.

        :param type: the occurrence type
        :type type: `Topic`
        :param value: the value of the occurrence
        :type value: String or `Locator`
        :param scope: optional list of themes
        :type scope: list of `Topic`s
        :param datatype: optional locator indicating the datatype of `value`
        :type datatype: `Locator`
        :param proxy: Django proxy model
        :type proxy: class
        :rtype: `Occurrence`

        """
        if type is None:
            raise ModelConstraintException(self, 'The type may not be None')
        if value is None:
            raise ModelConstraintException(self, 'The value may not be None')
        if datatype is None:
            if isinstance(value, Locator):
                datatype = Locator(XSD_ANY_URI)
            elif isinstance(value, float):

# Path: tmapi/constants.py
# AUTOMERGE_FEATURE_STRING = TMAPI_FEATURE_STRING_BASE + 'automerge'
# 
# XSD_ANY_URI = XSD + 'anyURI'
# 
# XSD_FLOAT = XSD + 'float'
# 
# XSD_INT = XSD + 'int'
# 
# XSD_LONG = XSD + 'long'
# 
# XSD_STRING = XSD + 'string'
# 
# Path: tmapi/exceptions.py
# class IdentityConstraintException (ModelConstraintException):
# 
#     """This exception is used to report identity constraint
#     violations. Assigning an item identifier, a subject identifier, or
#     a subject locator to different objects causes an
#     `IdentityConstraintException` to be raised."""
# 
#     def __init__ (self, reporter, existing, locator, message):
#         """Creates a new `IdentityConstraintException` with the
#         specified message.
# 
#         :param reporter: the construct to which the identity should
#           have been assigned
#         :type reporter: `Construct`
#         :param existing: the construct that has the same identity
#         :type existing: `Construct`
#         :param locator: the locator representing the identity
#         :type locator: `Locator`
#         :param message: the detail message
#         :type message: string
# 
#         """
#         super(IdentityConstraintException, self).__init__(reporter, message)
#         self._existing = existing
#         self._locator = locator
# 
#     def get_existing (self):
#         """Returns the `Construct` which already has the identity
#         represented by the locator get_locator().
# 
#         :rtype: `Construct`
# 
#         """
#         return self._existing
# 
#     def get_locator (self):
#         """Returns the `Locator` representing the identity that caused
#         the exception.
# 
#         :rtype: `Locator`
# 
#         """
#         return self._locator
# 
# class ModelConstraintException (TMAPIRuntimeException):
# 
#     """This exception is used to report Topic Maps - Data Model
#     constraint violations."""
# 
#     def __init__ (self, reporter, message):
#         """Creates a new ModelConstraintException with the specified
#         message.
# 
#         :param reporter: the construct which has thrown this exception
#         :type reporter: `Construct`
#         :param message: the detail message
#         :type message: string
# 
#         """
#         self._reporter = reporter
#         self._message = message
#     
#     def get_reporter (self):
#         """Return the `Construct` which has thrown the exception.
# 
#         :rtype: `Construct`
# 
#         """
#         return self._reporter
# 
# class TopicInUseException (ModelConstraintException):
# 
#     """Thrown when an attempt is made to remove a `Topic` which is
#     being used as a type, as a reifier, or as a role player in an
#     association, or in a scope."""
#     
#     def __init__ (self, topic, message):
#         """Creates a new `TopicInUseException` with the specified message.
# 
#         :param topic: the topic which is not removable
#         :type topic: `Topic`
#         :param message: the detail message
#         :type message: string
# 
#         """
#         super(TopicInUseException, self).__init__(topic, message)


# Path: tmapi/models/topic.py
from django.db import models
from tmapi.constants import AUTOMERGE_FEATURE_STRING, XSD_ANY_URI, XSD_FLOAT, XSD_INT, XSD_LONG, XSD_STRING
from tmapi.exceptions import IdentityConstraintException, \
    ModelConstraintException, TopicInUseException
from construct import Construct
from construct_fields import ConstructFields
from item_identifier import ItemIdentifier
from locator import Locator
from name import Name
from subject_identifier import SubjectIdentifier
from subject_locator import SubjectLocator
from occurrence import Occurrence
from merge_utils import handle_existing_construct, \
    move_role_characteristics, move_variants
from signature import generate_association_signature, \
    generate_name_signature, generate_occurrence_signature


    def create_occurrence (self, type, value, scope=None, datatype=None,
                           proxy=Occurrence):
        """Creates an `Occurrence` for this topic with the specified
        `type`, `value`, and `scope`.

        If `datatype` is not None, the newly created `Occurrence` will
        have the datatype specified by `datatype`.

        :param type: the occurrence type
        :type type: `Topic`
        :param value: the value of the occurrence
        :type value: String or `Locator`
        :param scope: optional list of themes
        :type scope: list of `Topic`s
        :param datatype: optional locator indicating the datatype of `value`
        :type datatype: `Locator`
        :param proxy: Django proxy model
        :type proxy: class
        :rtype: `Occurrence`

        """
        if type is None:
            raise ModelConstraintException(self, 'The type may not be None')
        if value is None:
            raise ModelConstraintException(self, 'The value may not be None')
        if datatype is None:
            if isinstance(value, Locator):
                datatype = Locator(XSD_ANY_URI)
            elif isinstance(value, float):

                datatype = Locator(XSD_FLOAT)