Skip to content

unable to resolve the reference #18

@1000Amper

Description

@1000Amper

using basic company example during deserializing created UMU.xmi file unable to get reference from one of the fields:

Company_ptr umu (::ecore::as< Company >(eobj));
const auto& lDepartments = umu->getDepartments();
std::cout<<lDepartments.size()<<std::endl;
const auto& manager = lDepartments[0]->getManager();

getManager() return NULL ptr;

UMU.xmi:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<company:Company xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:company="http:///com.example.company.ecore" name="UMU">
<departments number="8515" manager="//@departments.0/@employees.1">
<employees name="Andres Senac">
<phonebookEntry/>
</employees>
<employees name="Diego Sevilla"/>
</departments>
</company:Company>

edited for parsing basic example:

int main(int argc, char* argv[])
{
    CompanyPackage_ptr companyPackage = CompanyPackage::_instance();
    CompanyFactory_ptr companyFactory = CompanyFactory::_instance();

    {
		Company_ptr umu ( companyFactory->createCompany());
        umu->setName("UMU");

        Department_ptr catedraSAES = companyFactory->createDepartment();
        catedraSAES->setNumber(8515);

        Employee_ptr asenac = companyFactory->createEmployee();
        asenac->setName("Andres Senac");

		/* Check if a containment relation properly sets the eContainer() attribute. */
        catedraSAES->getEmployees().push_back(asenac);
		assert( asenac->eContainer() == catedraSAES );

		catedraSAES->getEmployees().remove(asenac);
		assert( asenac->eContainer() == nullptr );

        catedraSAES->getEmployees().push_back(asenac);
		assert( asenac->eContainer() == catedraSAES );
		
        Employee_ptr dsevilla = companyFactory->createEmployee();
        dsevilla->setName("Diego Sevilla");
        catedraSAES->getEmployees().push_back(dsevilla);

		/* Check if a containment relation properly sets the eContainer() attribute. */
		assert( asenac->eContainer() == dsevilla->eContainer() );

		/* Initially there is always no eContainer. */
		PhonebookEntry_ptr phone = companyFactory->createPhonebookEntry();
		assert( phone->eContainer() == nullptr );

		/* Check if a containment relation properly sets the eContainer() attribute. */
		asenac->setPhonebookEntry(phone);
		assert( phone->eContainer() == asenac );

        catedraSAES->setManager(dsevilla);

        umu->getDepartments().push_back(catedraSAES);

        umu->_initialize();

        std::ofstream outfile ("UMU.xmi");
        ecorecpp::serializer::serializer _ser(outfile);
        _ser.serialize(umu);
        outfile.close();
        std::cout<<"Test Passed"<<std::endl;
    }


    ::ecorecpp::MetaModelRepository::_instance()->load(companyPackage);

    ecorecpp::parser::parser _dser;
    EObject_ptr eobj = _dser.load ("UMU.xmi");

    {
		Company_ptr umu (::ecore::as< Company >(eobj));
        const auto& lDepartments = umu->getDepartments();
        std::cout<<lDepartments.size()<<std::endl;
        const auto& manager = lDepartments[0]->getManager();
        
        if (!manager)
            std::cout<<"manager null"<<std::endl;
        const auto& lemployees = lDepartments[0]->getEmployees();
        std::cout<<lemployees.size()<<std::endl;
        std::cout<<lemployees[0]->getName()<<std::endl;
        std::cout<<lemployees[1]->getName()<<std::endl;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions