Class NamespaceManager

  • All Implemented Interfaces:
    CommonManager

    public final class NamespaceManager
    extends AbstractManager
    This class is responsible for managing namespaces (add and remove).
    • Constructor Detail

      • NamespaceManager

        public NamespaceManager​(SQLiteDataSource dataSource)
        Instantiates a Namespace Manager that uses the Namespace DB in the provided path.
        Parameters:
        dataSource - Manager/service name.
    • Method Detail

      • newNamespace

        public NamespaceID newNamespace​(Namespace newNamespace)
        This operation creates a new namespace.
        Parameters:
        newNamespace - Namespace to create
        Returns:
        namespaceID of the new namespace if the it was successfully created.
        Throws:
        Exception - if an exception occurs:
        NamespaceExistsException if the namespace already exists
      • getNamespaceLang

        public CommonMessages.Langs getNamespaceLang​(String namespaceName)
        Returns the language of the specified namespace name
        Parameters:
        namespaceName - the name of the namespace
        Returns:
        the language of the namespace
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
      • getNamespaceID

        public NamespaceID getNamespaceID​(String namespaceName)
        Returns the namespaceID of the specified namespace name
        Parameters:
        namespaceName - the name of the namespace
        Returns:
        the id of the namespace
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
      • removeNamespace

        public void removeNamespace​(NamespaceID namespaceID)
        This operation removes the indicated namespace
        Parameters:
        namespaceID - NamespaceID of the namespace to be removed
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
      • getNamespacesInfo

        public Map<NamespaceID,​Namespace> getNamespacesInfo​(Set<NamespaceID> namespacesIDs)
        This operation retrieves the info of the given namespace
        Parameters:
        namespacesIDs - IDs of the namespaces to be retrieved
        Returns:
        the info of the namespaces
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
      • getNamespaceInfo

        public Namespace getNamespaceInfo​(NamespaceID namespaceID)
        This operation retrieves the info of the given namespace
        Parameters:
        namespaceID - IDs of the namespace to be retrieved
        Returns:
        the info of the namespace
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
      • checkNamespaceResponsibleAndGetInfo

        public Namespace checkNamespaceResponsibleAndGetInfo​(NamespaceID namespaceID,
                                                             AccountID responsible)
        This operation checks whether an account is responsible for a namespace
        Parameters:
        responsible - AccountID of the responsible to be checked
        namespaceID - ID of the namespace to be checked
        Returns:
        true if accountID is responsible for namespaceID, false if not.
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
      • importInterfaces

        public void importInterfaces​(NamespaceID namespaceID,
                                     Set<ImportedInterface> newImportedInterfaces)
        Register a set of new imported interfaces in the namespace
        Parameters:
        namespaceID - ID of the namespace in which the interface is imported
        newImportedInterfaces - Improted interfaces to register
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
        InterfaceAlreadyImportedException: If interface was already imported
      • removeImportedInterfaces

        public void removeImportedInterfaces​(NamespaceID namespaceID,
                                             Set<ImportedInterface> importedInterfaces)
        Removes the imported interface in contract with IDs provided in the Namespace with ID specified.
        Parameters:
        namespaceID - ID of the namespace containing the import
        importedInterfaces - the imported interfaces to be removed
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
        InterfaceNotImportedException: If interface with Name provided does not exist
      • checkImportsOfClassAreNotUsedAndGet

        public HashSet<ImportedInterface> checkImportsOfClassAreNotUsedAndGet​(NamespaceID namespaceID,
                                                                              String className)
        Verify that there is an imported interface in contract with IDs provided and it is not used by any property, operation or implementation and is not the parent class of any other class.
        Parameters:
        namespaceID - ID of the namespace that imports
        className - name of the class
        Returns:
        The info of the imports of the class in namespace, which are not in use
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
        ImportedInterfaceInUseException: If an imported interface of the classname in namespace is in use
      • getImportedInterfaces

        public HashSet<ImportedInterface> getImportedInterfaces​(NamespaceID namespaceID,
                                                                String className)
        This operation gets information of the imported interfaces for a specific class in a specific namespace
        Parameters:
        namespaceID - ID of the namespace that imports
        className - the class to be checked
        Returns:
        The information of the imported interfaces
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
      • getImportedInterfacesForMetaclasses

        public Map<MetaClassID,​Set<ImportedInterface>> getImportedInterfacesForMetaclasses​(NamespaceID namespaceID,
                                                                                                 Set<MetaClassID> metaClassIDs)
        This operation gets information of the imported interfaces in the namespace specified for the given metaclasses
        Parameters:
        namespaceID - the id of the namespace
        metaClassIDs - the ids of the metaclasses
        Returns:
        indexed table of the import information for every class
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
        ClassNotImportedException: if the class is not imported in namespace provided
      • getImportsOfAccount

        public HashSet<ImportedInterface> getImportsOfAccount​(AccountID accountID)
        Get all the information of all the imports in the namespaces of the account with ID provided
        Parameters:
        accountID - ID of the account
        Returns:
        A set of import specifications of the imports in the namespaces of the account with ID provided. It can be empty.
        Throws:
        Exception - if an exception occurs.
      • getNamespaceNamesThatImportsMetaClass

        public Set<String> getNamespaceNamesThatImportsMetaClass​(MetaClassID classID)
        Get namespace names that import the metaclass with id provided
        Parameters:
        classID - ID of the class
        Returns:
        Set of names of namespaces that import the metaclass with id provided
        Throws:
        Exception - if some exception occurs.
      • getNamespacesNames

        public Set<String> getNamespacesNames()
        Get all names of namespaces
        Returns:
        set of namespaces names
      • getImportsOfAccountInNamespace

        public HashSet<ImportedInterface> getImportsOfAccountInNamespace​(AccountID accountID,
                                                                         NamespaceID namespaceID)
        Get all the information of the imports in the given namespace of the account with ID provided
        Parameters:
        accountID - ID of the account
        namespaceID - ID of the namespace
        Returns:
        A set of import specifications of the imports in the namespace of the account with ID provided. It can be empty.
        Throws:
        Exception - if an exception occurs.
      • registerPropertiesUsingImportedClass

        public void registerPropertiesUsingImportedClass​(NamespaceID namespaceID,
                                                         Set<PropertyID> propertiesIDs,
                                                         Map<ContractID,​InterfaceID> interfacesInContractOfImportedClass)
        Registers the properties with IDs provided as using an imported class
        Parameters:
        namespaceID - ID of the namespace that imports
        propertiesIDs - IDs of the properties using the import
        interfacesInContractOfImportedClass - the interfaces in contract of imported class
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
        InterfaceNotImportedException: If interface was not imported
      • registerOperationsUsingImportedClass

        public void registerOperationsUsingImportedClass​(NamespaceID namespaceID,
                                                         Set<OperationID> operationsIDs,
                                                         Map<ContractID,​InterfaceID> interfacesInContractOfImportedClass)
        Registers the operations with IDs provided as using an imported class
        Parameters:
        namespaceID - ID of the namespace that imports
        operationsIDs - IDs of the operations using the import
        interfacesInContractOfImportedClass - the interfaces in contract of imported class
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
        InterfaceNotImportedException: If interface was not imported
      • registerImplementationsUsingImportedClass

        public void registerImplementationsUsingImportedClass​(NamespaceID namespaceID,
                                                              Set<ImplementationID> implementationsIDs,
                                                              Map<ContractID,​InterfaceID> interfacesInContractOfImportedClass)
        Registers the implementations with IDs provided as using an imported class
        Parameters:
        namespaceID - ID of the namespace that imports
        implementationsIDs - IDs of the implementations using the import
        interfacesInContractOfImportedClass - the interfaces in contract of imported class
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
        InterfaceNotImportedException: If interface was not imported
      • registerSubClassesUsingImportedClass

        public void registerSubClassesUsingImportedClass​(NamespaceID namespaceID,
                                                         Set<MetaClassID> metaClassesIDs,
                                                         Map<ContractID,​InterfaceID> interfacesInContractOfImportedClass)
        Registers the classes with IDs provided as extending from an imported class
        Parameters:
        namespaceID - ID of the namespace that imports
        metaClassesIDs - IDs of the classes extending the import
        interfacesInContractOfImportedClass - the interfaces in contract of imported class
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
        InterfaceNotImportedException: If interface was not imported
      • unregisterOperationsFromUsingAnyImportedClassInNamespace

        public void unregisterOperationsFromUsingAnyImportedClassInNamespace​(NamespaceID namespaceID,
                                                                             Set<OperationID> operationsIDs)
        Unregisters the operations with IDs provided from using any imports of the specified namespace
        Parameters:
        namespaceID - ID of the namespace that imports
        operationsIDs - IDs of the operations using the import
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
      • unregisterImplementationsFromUsingAnyImportedClassInNamespace

        public void unregisterImplementationsFromUsingAnyImportedClassInNamespace​(NamespaceID namespaceID,
                                                                                  Set<ImplementationID> implementationsIDs)
        Unregisters the implementations with IDs provided from using any imports of the specified namespace
        Parameters:
        namespaceID - ID of the namespace that imports
        implementationsIDs - IDs of the implementations using the import
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
      • unregisterSubClassesFromUsingAnyImportedClassInNamespace

        public void unregisterSubClassesFromUsingAnyImportedClassInNamespace​(NamespaceID namespaceID,
                                                                             Set<MetaClassID> metaClassesIDs)
        Unregisters the classes with IDs provided as using (by extension) from any imports of the specified namespace
        Parameters:
        namespaceID - ID of the namespace that imports
        metaClassesIDs - IDs of the classes extending the import
        Throws:
        Exception - if an exception occurs:
        NamespaceDoesNotExistException: if the namespace does not exist
      • getDbHandler

        public NamespaceManagerDB getDbHandler()
        Method used for unit testing.
        Returns:
        The db handler reference of this manager.