Class ClassManager

  • All Implemented Interfaces:
    CommonManager

    public final class ClassManager
    extends AbstractManager
    This class is responsible to manage Classes, Operations, Properties and Implementations, and Properties: add, remove and modify.
    Version:
    2.0
    • Field Detail

      • DEBUG_ENABLED

        protected static final boolean DEBUG_ENABLED
        Indicates if debug is enabled.
    • Constructor Detail

      • ClassManager

        public ClassManager​(SQLiteDataSource dataSource)
        Instantiates an Class Manager that uses the Backend configuration provided.
        Parameters:
        dataSource - data source
    • Method Detail

      • newJavaEnrichment

        public void newJavaEnrichment​(MetaClass newEnrichmentClass)
        Apply new enrichment to class specified
        Parameters:
        newEnrichmentClass - Enrichment metaclass information
      • newClass

        public MetaClass newClass​(AccountID accountID,
                                  NamespaceID namespaceID,
                                  String namespace,
                                  MetaClass metaClass,
                                  CommonMessages.Langs lang)
        This operation creates a new MetaClass in the Namespace specified by namespaceID using the provided specifications.
        Parameters:
        accountID - ID of the account registering the class for associating it with implementations of setters and getters
        namespaceID - ID of the namespace within we will create the MetaClass
        namespace - Namespace of the class
        metaClass - New Class specifications
        lang - Language of the class
        Returns:
        All information of the new MetaClass if it was successfully created.
      • removeClass

        public void removeClass​(MetaClassID metaClassID)
        This function removes the MetaClass identified by metaClassID. It also remove its associated operations, properties, implementations and types.
        Parameters:
        metaClassID - ID of the MetaClass of the Property to remove
      • checkNamespaceHasNothing

        public boolean checkNamespaceHasNothing​(NamespaceID namespaceID)
        This operation verifies if the namespace provided has some class associated in the System.
        Parameters:
        namespaceID - ID of the namespace
        Returns:
        TRUE if the provided Namespace has no classes in the database.FALSE otherwise.
        Throws:
        Exception - if an internal error occurred while working with Database.
      • newProperty

        public Property newProperty​(AccountID accountID,
                                    NamespaceID namespaceID,
                                    MetaClassID metaClassID,
                                    Property newProperty)
        This operation creates a new Property in the System, its Types specified and associates it to the MetaClass identified by the metaClassID provided. It also creates new Getter and Setter Operations for the Property provided.
        Parameters:
        accountID - ID of the account registering the property to be associated with the corresponding setter and getter implementations
        namespaceID - ID of the namespace in which the property is created
        newProperty - Specifications of the Property to add
        metaClassID - ID of the MetaClass that will contain the Property
        Returns:
        information of the new Property.
      • newOperation

        public Operation newOperation​(NamespaceID namespaceID,
                                      MetaClassID metaClassID,
                                      Operation newOperation)
        This operation creates a new Operation in the System, its Implementations and Types (arguments) specified and associates it to the MetaClass identified by the metaClassID provided.
        Parameters:
        namespaceID - ID of the namespace in which the operation is created
        newOperation - Specification of the operation
        metaClassID - ID of the MetaClass that will contain the operation.
        Returns:
        information of the new Operation.
      • removeOperation

        public Operation removeOperation​(OperationID operationID)
        This function deletes an Operation identified by the operationID provided, and its associated arguments and implementations. The operation's MetaClass is updated.
        Parameters:
        operationID - ID of the operation to remove
        Returns:
        Info of the removed operation
      • getImplementationsOfOperation

        public LinkedList<ImplementationID> getImplementationsOfOperation​(OperationID operationID)
        This function gets the list of Implementation IDs of an Operation identified by the OperationID provided.
        Parameters:
        operationID - ID of the Operation.
        Returns:
        The list of Implementation IDs of the Operation
        Throws:
        Exception - If the Operation identified by operationID does not exist or if an internal error occurred while working with Database.
      • newImplementation

        public Implementation newImplementation​(AccountID accountID,
                                                NamespaceID namespaceID,
                                                MetaClassID metaClassID,
                                                OperationID operationID,
                                                NamespaceID namespaceIDofOperation,
                                                Implementation newImplementation)
        This function creates a new Implementation in the System and associates it to the Operation identified by the operationID provided.
        Parameters:
        accountID - ID of the account responsible of the implementation
        namespaceID - ID of the namespace in which the implementation is created
        metaClassID - ID of the class containing the operation
        newImplementation - Specification of the Implementation
        operationID - ID of the Operation that will contain the Implementation.
        namespaceIDofOperation - the namespace ID of the operation
        Returns:
        information of the new Implementation.
        Throws:
        Exception - If the Operation identified by operationID does not exist or does not belong to the class with ID provided, If implementation is not compatible or if an internal error occurred while working with Database.
      • removeImplementation

        public void removeImplementation​(ImplementationID implementationID)
        This function removes an Implementation with the implementationID provided from the System and updates the associated Operation.
        Parameters:
        implementationID - ID of the Implementation to remove
        Throws:
        Exception - If the Implementation identified by implementationID does not exist, If the Operation associated to the Implementation does not exist, If the implementation cannot be removed because the Operation only has this implementation or if an internal error occurred while working with Database.
      • getRequirementsOfMethod

        public List<Feature> getRequirementsOfMethod​(ImplementationID implementationID)
        This function gets the list of Requirements of an Implementation identified by the ImplementationID provided.
        Parameters:
        implementationID - ID of the Implementation.
        Returns:
        The list of Features (requirements) of the Implementation
        Throws:
        Exception - If the Implementation identified by implementationID does not exist or if an internal error occurred while working with Database.
      • getInfoOfImplementations

        public Map<ImplementationID,​Implementation> getInfoOfImplementations​(Set<ImplementationID> implementationsIDs)
        This function retrieves the information of the given implementations
        Parameters:
        implementationsIDs - IDs of the implementations
        Returns:
        the information about every implementation
        Throws:
        Exception - if any of the implementations does not exist
      • getMetaClassByNameAndNamespace

        public MetaClass getMetaClassByNameAndNamespace​(String namespace,
                                                        String className)
        This function gets the MetaClass with name className and Namespace provided
        Parameters:
        namespace - Namespace of the MetaClass to look for
        className - Name of the class to look for
        Returns:
        theMetaClass with name and namespace ID provided or NULL if not found.
      • getMetaClassID

        public MetaClassID getMetaClassID​(NamespaceID namespaceID,
                                          String className)
        Retrieves the ID of a class given its name
        Parameters:
        namespaceID - ID of the namespace containing the class
        className - Name of the MetaClass
        Returns:
        The ID of the class or NULL if class does not exist
      • getPropertyID

        public PropertyID getPropertyID​(String metaClassName,
                                        String namespace,
                                        String propertyName)
        Retrieves the id of a property given its name, name of the class containing the property and the namespace where it belongs to.
        Parameters:
        metaClassName - Name of the class
        namespace - Namespace of the class
        propertyName - the name of the property
        Returns:
        The ID of the property
      • getPropertyID

        public PropertyID getPropertyID​(MetaClassID metaClassID,
                                        String propertyName)
        Retrieves the id of a property given its name, name of the class containing the property and the namespace where it belongs to.
        Parameters:
        metaClassID - ID of the class
        propertyName - the name of the property
        Returns:
        The ID of the property
      • getPropertiesNames

        public Map<PropertyID,​String> getPropertiesNames​(Set<PropertyID> propertiesIDs)
        Retrieves the names of the properties with IDs provided.
        Parameters:
        propertiesIDs - IDs of the properties
        Returns:
        Return the names of the properties with IDs provided
      • getOperationID

        public OperationID getOperationID​(MetaClassID metaClassID,
                                          String operationSignature)
        Retrieves the id of an operation given its signature, id of the namespace of the operation and id of the class containing the operation and the namespace where it belongs to
        Parameters:
        metaClassID - ID of the class
        operationSignature - the signature of the operation
        Returns:
        The ID of the operation
        Throws:
        Exception - If operation does not exist
      • getOperationID

        public OperationID getOperationID​(String metaClassName,
                                          String namespace,
                                          String operationSignature)
        Retrieves the id of an operation given its signature, id of the namespace of the operation and id of the class containing the operation and the namespace where it belongs to
        Parameters:
        metaClassName - Name of the class
        namespace - Namespace of the class
        operationSignature - the signature of the operation
        Returns:
        The ID of the operation
        Throws:
        Exception - If operation does not exist
      • getClassname

        public String getClassname​(MetaClassID metaClassID)
        Returns the name of the MetaClass identified by ID provided
        Parameters:
        metaClassID - ID of the MetaClass
        Returns:
        The name of the MetaClass identified by the ID provided
      • getClassNameAndNamespace

        public Tuple<String,​String> getClassNameAndNamespace​(MetaClassID metaClassID)
        Returns the name and namespace of the MetaClass identified by ID provided
        Parameters:
        metaClassID - ID of the MetaClass
        Returns:
        The name and namespace of the MetaClass identified by the ID provided
      • generateStubs

        public Map<MetaClassID,​Triple<String,​byte[],​byte[]>> generateStubs​(CommonMessages.Langs language,
                                                                                             Map<MetaClassID,​StubInfo> stubInfos)
        Generate a set of Java stubs with the provided informations
        Parameters:
        language - Language of the stub to generate
        stubInfos - Information associated to each stub (names, contract IDs, interface IDs...)
        Returns:
        Byte code of the stubs of the classes with information provided and its aspect
        Throws:
        Exception - if an internal error occurred while working with Database.
      • generateStubsForEnrichment

        public Map<MetaClassID,​byte[]> generateStubsForEnrichment​(CommonMessages.Langs language,
                                                                        Map<MetaClassID,​StubInfo> stubInfos)
        Generate a set of Java stubs for Enrichments with the provided informations
        Parameters:
        language - Language of the stub to generate
        stubInfos - Information associated to each stub (names, contract IDs, interface IDs...)
        Returns:
        Byte code of the stubs of the stubs for enrichment with information provided
        Throws:
        Exception - if an internal error occurred while working with Database.
      • checkClassNotInIncludesAndGetID

        public MetaClassID checkClassNotInIncludesAndGetID​(String newClassName,
                                                           NamespaceID newNamespaceID)
        Checks that there is no operation, implementation or property that includes the class with name and Namespace specified.
        Parameters:
        newClassName - Name of the class
        newNamespaceID - ID of the namespace of the class
        Returns:
        The ID of the class with Name and Namespace specified. If no class with this name and namespace exists NULL is returned and the check is skipped.
        Throws:
        Exception - if an internal error occurred while working with Database.
      • getOperationsAndPropertiesNotInNamespaceOfClass

        public Tuple<Set<PropertyID>,​Set<OperationID>> getOperationsAndPropertiesNotInNamespaceOfClass​(MetaClassID metaClassID,
                                                                                                             Set<PropertyID> propertyIDs,
                                                                                                             Set<OperationID> operationIDs)
        For each property and operation ID provided verify they belong to the Namespace of the Class with ID provided. Return those that do not belong to the Namespace.
        Parameters:
        metaClassID - ID of the MetaClass
        propertyIDs - IDs of the properties
        operationIDs - IDs of the operations
        Returns:
        IDs of operations and IDs of properties that do not belong to the MetaClass with ID provided.
        Throws:
        Exception - if an internal error occurred while working with Database.
      • getClassIncludesOfOperationsPropsAndImpls

        public Tuple<Set<MetaClass>,​Set<MetaClass>> getClassIncludesOfOperationsPropsAndImpls​(Map<OperationID,​Set<ImplementationID>> operationsAndImpls,
                                                                                                    Set<PropertyID> propertyIDs,
                                                                                                    NamespaceID namespaceID,
                                                                                                    MetaClassID parentClassID)
        Get the includes of the operations and properties provided and for those that belongs to the Namespace with ID provided return all its information.
        Parameters:
        operationsAndImpls - IDs of the operations and implementations
        propertyIDs - IDs of the properties
        namespaceID - ID of the namespace
        parentClassID - ID of the parent class
        Returns:
        A set of MetaClass information with only Class ID and Namespace ID corresponding to imported classes, and a set of MetaClass information with all information corresponding to the non imported classes.
        Throws:
        Exception - if an internal error occurred while working with Database.
      • getIncludesInDifferentNamespaces

        public Triple<String,​NamespaceID,​Set<MetaClassID>> getIncludesInDifferentNamespaces​(MetaClassID metaClassID,
                                                                                                        Set<PropertyID> propertiesIDs,
                                                                                                        Map<OperationID,​Set<ImplementationID>> operationsIDsAndImplementationsIDs,
                                                                                                        NamespaceID namespaceID)
        Get the Class name, Namespace ID and the IDs of the included classes in different Namespaces than the one specified of the class with ID provided.
        Parameters:
        metaClassID - ID of the class
        propertiesIDs - properties to be analyzed
        operationsIDsAndImplementationsIDs - operations and their implementations to be analyzed
        namespaceID - ID of the namespace
        Returns:
        The class name, Namespace ID of class and a set of included classes that are not in the namespace provided.
        Throws:
        Exception - if an internal error occurred while working with Database.
      • existsImplementationAccessingOperation

        public boolean existsImplementationAccessingOperation​(OperationID operationID)
        Verify if there is some implementation accessing the operation with ID provided
        Parameters:
        operationID - ID of the operation
        Returns:
        TRUE if there is some implementation accessing the operation. FALSE otherwise.
        Throws:
        Exception - if an internal error occurred while working with Database.
      • getEnrichmentsInNamespaceOfClass

        public Tuple<Set<PropertyID>,​Map<OperationID,​Set<ImplementationID>>> getEnrichmentsInNamespaceOfClass​(MetaClassID metaClassID,
                                                                                                                          NamespaceID namespaceIDofEnrichments)
        Get the properties, operations and implementations created as enrichments of the specified class in the given namespace.
        Parameters:
        metaClassID - ID of the class
        namespaceIDofEnrichments - ID of the namespace of the enrichments
        Returns:
        the set of properties, operations and implementations that enrich the class in the given namespace. If there is no enrichment in the specified namespace, return the corresponding empty sets.
        Throws:
        Exception - if an internal error occurred while working with Database.
      • getClassInfo

        public MetaClass getClassInfo​(MetaClassID metaClassID)
        Return all information of a class
        Parameters:
        metaClassID - ID of the metaclass
        Returns:
        Information of the class
        Throws:
        Exception - if an internal error occurred while working with Database.
      • getClassIDFromProperty

        public MetaClassID getClassIDFromProperty​(PropertyID propertyID)
        Return ID of class of the type of the property or NULL if type is not user type.
        Parameters:
        propertyID - ID of the property
        Returns:
        ID of class of the type or NULL if type is not user type.
        Throws:
        Exception - if an internal error occurred while working with Database.
      • getInfoOfClassesInNamespace

        public Map<MetaClassID,​MetaClass> getInfoOfClassesInNamespace​(NamespaceID namespaceID)
        Return information of classes in the given namespace.
        Parameters:
        namespaceID - ID of the namespace of the classes to be retrieved
        Returns:
        the info of the classes in the namespace provided.
        Throws:
        Exception - if an internal error occurred while working with Database.
      • getOperationInfo

        public Operation getOperationInfo​(OperationID operationID)
        Return all information of an operation
        Parameters:
        operationID - ID of the operation
        Returns:
        Information of the operation
        Throws:
        Exception - if an internal error occurred while working with Database.
      • getPropertyInfo

        public Property getPropertyInfo​(PropertyID propertyID)
        Return all information of a property
        Parameters:
        propertyID - ID of the property
        Returns:
        Information of the property
      • getOperationsAndPropertiesAndImplInNamespace

        public Tuple<Set<PropertyID>,​Map<OperationID,​Set<ImplementationID>>> getOperationsAndPropertiesAndImplInNamespace​(MetaClassID metaClassID,
                                                                                                                                      NamespaceID namespaceID)
        For each property and operation ID of the metaclass with ID provided return all those that belong to the namespace with ID specified
        Parameters:
        metaClassID - ID of the MetaClass
        namespaceID - ID of the namespace
        Returns:
        IDs of operations and IDs of properties that belong to the Namespace with ID provided and class with ID specified.
        Throws:
        Exception - if an internal error occurred while working with Database.
      • getOperationsIDsOfGettersAndSetters

        public Set<OperationID> getOperationsIDsOfGettersAndSetters​(MetaClassID metaClassID,
                                                                    Set<PropertyID> propertiesIDs)
        Return the operations IDs of the default getters and setters of the given properties IDs
        Parameters:
        metaClassID - ID of the class of the properties
        propertiesIDs - IDs of the properties
        Returns:
        The set of operations IDs corresponding to the getters and setters of the specified properties.
        Throws:
        Exception - if an internal error occurred while working with Database.
      • getImplementationsOfGettersAndSetters

        public Map<PropertyID,​Map<OperationID,​ImplementationID>> getImplementationsOfGettersAndSetters​(Map<MetaClassID,​Set<PropertyID>> propertiesInClass)
        Return the implementations of the operations of the getters and setters of the given properties
        Parameters:
        propertiesInClass - Properties which implementations of getters ands settes have to be retrieved.
        Returns:
        The implementations of the operations of the getters and setters of the given properties
        Throws:
        Exception - if an internal error occurred while working with Database.
      • generateJavaExecutionClass

        public Tuple<byte[],​byte[]> generateJavaExecutionClass​(MetaClass metaClass)
        Generate execution class for Java MetaClasses. This function should be used to install a class in DataService.
        Parameters:
        metaClass - ID of the class
        Returns:
        The bytes of the generated execution class and its aspects.
        Throws:
        Exception - If some exception occurs.
      • getDbHandler

        public ClassManagerDB getDbHandler()
        Method for unit testing.
        Returns:
        the db handler reference of this manager.