Fornax-Platform
Forum

[JSF uml2 cartridge] interface troubles

View: New views
6 Messages — Rating Filter:   Alert me  

[JSF uml2 cartridge] interface troubles

by Asgaar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi there, i'm testing jsf cartridge 1.2 to use it in a new project...
i'll try to explain the problem i'm facing:
i've modelled a concrete class "Document" which is associated many-to-many to an interface "DocAssociable", the association in navigable on the "Document" end; the interface is implemented by 2 concrete classes "User" and "Project"...

The problem concern how the constraints are generated:

    alter table DOCASSOCIABLE_DOCUMENT
        add constraint FKDF8F1BD440B969CD
        foreign key (docsid)
        references TB_DOCUMENT;

    alter table DOCASSOCIABLE_DOCUMENT
        add constraint FKDF8F1BD4B6FB8C70
        foreign key (docownersid)      <-- This docownersid references two tables at the same time
        references TB_PROJECT;


    alter table DOCASSOCIABLE_DOCUMENT
        add constraint FKDF8F1BD499B9E45A
        foreign key (docownersid)      <-- This docownersid references two tables at the same time
        references TB_USER;


I've found another problem which is raised if i declare the association bidirectional:

The ComponentFactory contains this wrong code related to the concrete classes which implements the interface "DocAssociable":

   /**
    * @return The User entity als prototype with all attributes
    */
    public final User getUserWithFullAttributes(final long id,
        final String dac, final String username,
        final Set<DocAssociable> docOwners, final Set<Project> projects,
        final Set<Document> docs) {
        User bean = (User) context.getBean("user");
        bean.setId(id);
        bean.setUsername(username);
        bean.setDocOwners(docOwners); <-- This is the interface implemented by the User class
        bean.setProjects(projects);
        bean.setDocs(docs);
        return bean;

    }

    /**
    * @return The Project entity als prototype with all attributes
    */
    public final Project getProjectWithFullAttributes(final long id,
        final String dac, final Set<DocAssociable> docOwners,
        final String code, final Set<User> users, final Set<Document> docs) {
        Project bean = (Project) context.getBean("project");
        bean.setId(id);
        bean.setDocOwners(docOwners); <-- This is the interface implemented by the Project class
        bean.setCode(code);
        bean.setUsers(users);
        bean.setDocs(docs);
        return bean;

    }

=====

The interface has been generated because i added in the workflow a call to this template:

«IMPORT uml»
«IMPORT Spring2»
«IMPORT Persistence»

«EXTENSION org::fornax::cartridges::uml2::javabasic::extensions::DataType»
«EXTENSION org::fornax::cartridges::uml2::javabasic::extensions::Helper»
«EXTENSION org::fornax::cartridges::uml2::hibernate::extensions::Naming»
«EXTENSION org::fornax::cartridges::uml2::spring::extensions::Spring»
«EXTENSION org::fornax::cartridges::uml2::spring::extensions::DaoOperationsHelper»

/**
* The entry point for the generation
*/
«DEFINE Root FOR uml::Model»
    «EXPAND Root FOREACH (List[uml::Package])ownedElement»
«ENDDEFINE»
 
/**
* Creates all packages
*/
«DEFINE Root FOR uml::Package»
    «EXPAND org::fornax::cartridges::uml2::javabasic::m2t::Interface::interface FOREACH ownedType.typeSelect(uml::Interface)»
    «EXPAND Root FOREACH nestedPackage»
«ENDDEFINE»


/**
* Dummy DEFINE for all elements with no generation purposes
*/
«DEFINE Root FOR Object»
«ENDDEFINE»

using this tag right after the jsf cartridge tag:

        <component id="generator" class="oaw.xpand2.Generator" skipOnErrors="true">
                <metaModel class="oaw.type.emf.EmfMetaModel"
                        metaModelPackage="org.eclipse.emf.ecore.EcorePackage"/>
                <metaModel class="oaw.uml2.UML2MetaModel"/>
                <metaModel class="org.openarchitectureware.uml2.profile.ProfileMetaModel">
                       
                        <profile value="${profile.persistence.file}" />
                </metaModel>
                <fileEncoding value="ISO-8859-1"/>
               
                <globalVarDef name="java_version" value="${java.version}" />
                <globalVarDef name="java.version" value="${java.version}" />
               
                <globalVarDef name="generate_additional_collection_methods" value="${generate.additional.collection.methods}" />
               
                <expand value="templates::SpecialCases::Root FOR model" />
               
                <outlet path="${outlet.src.dir}">
                        <postprocessor class="org.hybridlabs.source.formatter.JavaImportBeautifier"
                        organizeImports="true"  
  format="true" />
                </outlet>
               
                <outlet name="outletSrcOnceDir"
                        path="${outlet.src.once.dir}" overwrite="false">
                        <postprocessor class="org.hybridlabs.source.formatter.JavaImportBeautifier"
                        organizeImports="true"  
  format="true" />
                </outlet>

                <prSrcPaths value="${outlet.res.dir}" />
                <prDefaultExcludes value="true" />
               
        </component>  


Could someone help me find a solution?
thank you very much.

Carlo

Re: [JSF uml2 cartridge] interface troubles

by pdoorr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Same problem here. Please help us!

Fabio

Asgaar wrote:
hi there, i'm testing jsf cartridge 1.2 to use it in a new project...
i'll try to explain the problem i'm facing:
i've modelled a concrete class "Document" which is associated many-to-many to an interface "DocAssociable", the association in navigable on the "Document" end; the interface is implemented by 2 concrete classes "User" and "Project"...

The problem concern how the constraints are generated:

    alter table DOCASSOCIABLE_DOCUMENT
        add constraint FKDF8F1BD440B969CD
        foreign key (docsid)
        references TB_DOCUMENT;

    alter table DOCASSOCIABLE_DOCUMENT
        add constraint FKDF8F1BD4B6FB8C70
        foreign key (docownersid)      <-- This docownersid references two tables at the same time
        references TB_PROJECT;


    alter table DOCASSOCIABLE_DOCUMENT
        add constraint FKDF8F1BD499B9E45A
        foreign key (docownersid)      <-- This docownersid references two tables at the same time
        references TB_USER;


I've found another problem which is raised if i declare the association bidirectional:

The ComponentFactory contains this wrong code related to the concrete classes which implements the interface "DocAssociable":

   /**
    * @return The User entity als prototype with all attributes
    */
    public final User getUserWithFullAttributes(final long id,
        final String dac, final String username,
        final Set<DocAssociable> docOwners, final Set<Project> projects,
        final Set<Document> docs) {
        User bean = (User) context.getBean("user");
        bean.setId(id);
        bean.setUsername(username);
        bean.setDocOwners(docOwners); <-- This is the interface implemented by the User class
        bean.setProjects(projects);
        bean.setDocs(docs);
        return bean;

    }

    /**
    * @return The Project entity als prototype with all attributes
    */
    public final Project getProjectWithFullAttributes(final long id,
        final String dac, final Set<DocAssociable> docOwners,
        final String code, final Set<User> users, final Set<Document> docs) {
        Project bean = (Project) context.getBean("project");
        bean.setId(id);
        bean.setDocOwners(docOwners); <-- This is the interface implemented by the Project class
        bean.setCode(code);
        bean.setUsers(users);
        bean.setDocs(docs);
        return bean;

    }

=====

The interface has been generated because i added in the workflow a call to this template:

«IMPORT uml»
«IMPORT Spring2»
«IMPORT Persistence»

«EXTENSION org::fornax::cartridges::uml2::javabasic::extensions::DataType»
«EXTENSION org::fornax::cartridges::uml2::javabasic::extensions::Helper»
«EXTENSION org::fornax::cartridges::uml2::hibernate::extensions::Naming»
«EXTENSION org::fornax::cartridges::uml2::spring::extensions::Spring»
«EXTENSION org::fornax::cartridges::uml2::spring::extensions::DaoOperationsHelper»

/**
* The entry point for the generation
*/
«DEFINE Root FOR uml::Model»
    «EXPAND Root FOREACH (List[uml::Package])ownedElement»
«ENDDEFINE»
 
/**
* Creates all packages
*/
«DEFINE Root FOR uml::Package»
    «EXPAND org::fornax::cartridges::uml2::javabasic::m2t::Interface::interface FOREACH ownedType.typeSelect(uml::Interface)»
    «EXPAND Root FOREACH nestedPackage»
«ENDDEFINE»


/**
* Dummy DEFINE for all elements with no generation purposes
*/
«DEFINE Root FOR Object»
«ENDDEFINE»

using this tag right after the jsf cartridge tag:

        <component id="generator" class="oaw.xpand2.Generator" skipOnErrors="true">
                <metaModel class="oaw.type.emf.EmfMetaModel"
                        metaModelPackage="org.eclipse.emf.ecore.EcorePackage"/>
                <metaModel class="oaw.uml2.UML2MetaModel"/>
                <metaModel class="org.openarchitectureware.uml2.profile.ProfileMetaModel">
                       
                        <profile value="${profile.persistence.file}" />
                </metaModel>
                <fileEncoding value="ISO-8859-1"/>
               
                <globalVarDef name="java_version" value="${java.version}" />
                <globalVarDef name="java.version" value="${java.version}" />
               
                <globalVarDef name="generate_additional_collection_methods" value="${generate.additional.collection.methods}" />
               
                <expand value="templates::SpecialCases::Root FOR model" />
               
                <outlet path="${outlet.src.dir}">
                        <postprocessor class="org.hybridlabs.source.formatter.JavaImportBeautifier"
                        organizeImports="true"  
  format="true" />
                </outlet>
               
                <outlet name="outletSrcOnceDir"
                        path="${outlet.src.once.dir}" overwrite="false">
                        <postprocessor class="org.hybridlabs.source.formatter.JavaImportBeautifier"
                        organizeImports="true"  
  format="true" />
                </outlet>

                <prSrcPaths value="${outlet.res.dir}" />
                <prDefaultExcludes value="true" />
               
        </component>  


Could someone help me find a solution?
thank you very much.

Carlo

Re: [JSF uml2 cartridge] interface troubles

by Asgaar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, it seems that with my template i instruct only the javabasic cartridge to generate interfaces without any specific stereotype... however it is necessary to instruct also the Hibernate cartridge to generate correct inheritance mapping files for those classes that implement the interface...

Can someone give me some hints and guidance on which templates should be modified in hibernate cartridge in order to model interfaces?

Thank you.
Carlo

Asgaar wrote:
hi there, i'm testing jsf cartridge 1.2 to use it in a new project...
i'll try to explain the problem i'm facing:
i've modelled a concrete class "Document" which is associated many-to-many to an interface "DocAssociable", the association in navigable on the "Document" end; the interface is implemented by 2 concrete classes "User" and "Project"...

The problem concern how the constraints are generated:

    alter table DOCASSOCIABLE_DOCUMENT
        add constraint FKDF8F1BD440B969CD
        foreign key (docsid)
        references TB_DOCUMENT;

    alter table DOCASSOCIABLE_DOCUMENT
        add constraint FKDF8F1BD4B6FB8C70
        foreign key (docownersid)      <-- This docownersid references two tables at the same time
        references TB_PROJECT;


    alter table DOCASSOCIABLE_DOCUMENT
        add constraint FKDF8F1BD499B9E45A
        foreign key (docownersid)      <-- This docownersid references two tables at the same time
        references TB_USER;


I've found another problem which is raised if i declare the association bidirectional:

The ComponentFactory contains this wrong code related to the concrete classes which implements the interface "DocAssociable":

   /**
    * @return The User entity als prototype with all attributes
    */
    public final User getUserWithFullAttributes(final long id,
        final String dac, final String username,
        final Set<DocAssociable> docOwners, final Set<Project> projects,
        final Set<Document> docs) {
        User bean = (User) context.getBean("user");
        bean.setId(id);
        bean.setUsername(username);
        bean.setDocOwners(docOwners); <-- This is the interface implemented by the User class
        bean.setProjects(projects);
        bean.setDocs(docs);
        return bean;

    }

    /**
    * @return The Project entity als prototype with all attributes
    */
    public final Project getProjectWithFullAttributes(final long id,
        final String dac, final Set<DocAssociable> docOwners,
        final String code, final Set<User> users, final Set<Document> docs) {
        Project bean = (Project) context.getBean("project");
        bean.setId(id);
        bean.setDocOwners(docOwners); <-- This is the interface implemented by the Project class
        bean.setCode(code);
        bean.setUsers(users);
        bean.setDocs(docs);
        return bean;

    }

=====

The interface has been generated because i added in the workflow a call to this template:

«IMPORT uml»
«IMPORT Spring2»
«IMPORT Persistence»

«EXTENSION org::fornax::cartridges::uml2::javabasic::extensions::DataType»
«EXTENSION org::fornax::cartridges::uml2::javabasic::extensions::Helper»
«EXTENSION org::fornax::cartridges::uml2::hibernate::extensions::Naming»
«EXTENSION org::fornax::cartridges::uml2::spring::extensions::Spring»
«EXTENSION org::fornax::cartridges::uml2::spring::extensions::DaoOperationsHelper»

/**
* The entry point for the generation
*/
«DEFINE Root FOR uml::Model»
    «EXPAND Root FOREACH (List[uml::Package])ownedElement»
«ENDDEFINE»
 
/**
* Creates all packages
*/
«DEFINE Root FOR uml::Package»
    «EXPAND org::fornax::cartridges::uml2::javabasic::m2t::Interface::interface FOREACH ownedType.typeSelect(uml::Interface)»
    «EXPAND Root FOREACH nestedPackage»
«ENDDEFINE»


/**
* Dummy DEFINE for all elements with no generation purposes
*/
«DEFINE Root FOR Object»
«ENDDEFINE»

using this tag right after the jsf cartridge tag:

        <component id="generator" class="oaw.xpand2.Generator" skipOnErrors="true">
                <metaModel class="oaw.type.emf.EmfMetaModel"
                        metaModelPackage="org.eclipse.emf.ecore.EcorePackage"/>
                <metaModel class="oaw.uml2.UML2MetaModel"/>
                <metaModel class="org.openarchitectureware.uml2.profile.ProfileMetaModel">
                       
                        <profile value="${profile.persistence.file}" />
                </metaModel>
                <fileEncoding value="ISO-8859-1"/>
               
                <globalVarDef name="java_version" value="${java.version}" />
                <globalVarDef name="java.version" value="${java.version}" />
               
                <globalVarDef name="generate_additional_collection_methods" value="${generate.additional.collection.methods}" />
               
                <expand value="templates::SpecialCases::Root FOR model" />
               
                <outlet path="${outlet.src.dir}">
                        <postprocessor class="org.hybridlabs.source.formatter.JavaImportBeautifier"
                        organizeImports="true"  
  format="true" />
                </outlet>
               
                <outlet name="outletSrcOnceDir"
                        path="${outlet.src.once.dir}" overwrite="false">
                        <postprocessor class="org.hybridlabs.source.formatter.JavaImportBeautifier"
                        organizeImports="true"  
  format="true" />
                </outlet>

                <prSrcPaths value="${outlet.res.dir}" />
                <prDefaultExcludes value="true" />
               
        </component>  


Could someone help me find a solution?
thank you very much.

Carlo

Re: [JSF uml2 cartridge] interface troubles

by Darius Jockel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Carlo.

Asgaar wrote:
Ok, it seems that with my template i instruct only the javabasic cartridge to generate interfaces without any specific stereotype... however it is necessary to instruct also the Hibernate cartridge to generate correct inheritance mapping files for those classes that implement the interface...
The Hibernate Cartridge only generates correct mappings for class-(inheritance).
So, maybe you can change your domain model?
If you model the document as a class and the document and project as subclasses, the Java classes
and Hibernate mappings should be generated correctly.

Asgaar wrote:
Can someone give me some hints and guidance on which templates should be modified in hibernate cartridge in order to model interfaces?
The Hibernate Cartridge has no big Intterface support. If you draw an implementation relation from an
entity 'EntityA' to an interface 'InterfaceA' , the interface of 'EntityA' will be extendet by 'InterfaceA'.
Thats all. No mapping is generated. It will be hard to change the bavahior of the Hibernate Cartridge
to  take care of interfaces. There are two possibilities:
1. Modeltransformation: In front of the Hibernate Cartridge you can transform all needed interfaces to
Classes.
2. Or you have to extend the Cardridge. All the relevant mappings have to be defined also for interfaces.

Did I help you?
Regards
Darius

Re: [JSF uml2 cartridge] interface troubles

by Asgaar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Darius,
thanks for you help...

Darius Jockel wrote:
The Hibernate Cartridge only generates correct mappings for class-(inheritance).
So, maybe you can change your domain model?
If you model the document as a class and the document and project as subclasses, the Java classes
and Hibernate mappings should be generated correctly.
Beside the fact that i don't think that it's conceptually correct, is not possible for us to change our domain model because we have the need to implement multiple interfaces on a single class, and the same interface will be implemented by very different domain object.
because is not possible to have multiple inheritance on java classes, using the suggested approach will lead us to have a real mess in our domain model with classes hierarchies conceptually wrong and very hard to maintain...

Darius Jockel wrote:
The Hibernate Cartridge has no big Intterface support. If you draw an implementation relation from an
entity 'EntityA' to an interface 'InterfaceA' , the interface of 'EntityA' will be extendet by 'InterfaceA'.
Thats all. No mapping is generated. It will be hard to change the bavahior of the Hibernate Cartridge
to  take care of interfaces. There are two possibilities:
1. Modeltransformation: In front of the Hibernate Cartridge you can transform all needed interfaces to
Classes.
2. Or you have to extend the Cardridge. All the relevant mappings have to be defined also for interfaces.
The first approach described is not possible for the problems mentioned above...
I think that the second approach is interesting... but i don't want to have a special customized version of the uml2 cartridge detached from the one in the repository (especially now with the exit of OAW 5)...
Said so, is anybody interested in such change/implementation in the cartridge? I think that is extremely important to have such behaviour in the cartridge and i want to contribute in this changes but i'm a newbie in cartridges modification, so i need giudance for the first steps...

Darius Jockel wrote:
Did I help you?
Regards
Darius
You did indeed, thank you very much!
Carlo

Re: [JSF uml2 cartridge] interface troubles

by Asgaar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello again,
i'm trying to extend the Hibernate cartridge using AOP in order to generate an additional mapping for interfaces using the <any> tag.

i've changed the workflow adding this lines:

    <component adviceTarget="hibernateCartridge_mapping_generator"
            id="reflectionAdvice"
            class="oaw.xpand2.GeneratorAdvice" >
        <metaModel class="oaw.uml2.UML2MetaModel"/>
        <advices value="templates::AopTemplate"/>
    </component>

And my template (AopTemplate) is:

«IMPORT ecore»
«IMPORT uml»
«IMPORT persistence»

«AROUND org::fornax::cartridges::uml2::hibernate::templates::HibernateConfig::Mappings FOR uml::Class-»
        «EXPAND finalBlock FOREACH this.interfaceRealization-»
        «targetDef.proceed()-»
«ENDAROUND»

«DEFINE finalBlock FOR uml::InterfaceRealization-»
        «FOREACH (List[uml::Interface])this.supplier AS sup-»
                <any name="«sup.name»" id-type="long" meta-type="string">
                «FOREACH (List[uml::InterfaceRealization])sup.getTargetDirectedRelationships() AS intReal-»
                        «FOREACH (List[uml::Class])intReal.client AS cli-»
                        <meta-value value="«
tableName()» class="«getFQNOfImplementationClass()»"/>
                        «ENDFOREACH-»
                «ENDFOREACH-»
                </any>
        «ENDFOREACH-»
«ENDDEFINE»


My problem regards the use of extensions that are defined in the hibernate cartridge... the "tableName()" and "getFQNOfImplementationClass()" are methods already implemented in the extensions of the hibernate cartridge and i haven't found a way to use them in my template.

Moreover i didn't understood why the objects that are intercepted by my Around function are of type uml::Class and not of type persistence::Entity as defined in the original code of the hibernate cartridge.

I can't found an esaustive documentation for templates and extensions aop.

Ex.:
This should be the resultant mapping for the problem i've exposes in my first post.

<any name="DocAssociable" id-type="long" meta-type="string">
    <meta-value value="TB_USER" class="User"/>
    <meta-value value="TB_PROJECT" class="Project"/>
    <column name="table_name"/>
    <column name="id"/>
</any>

Any help will be very appreciated.
Thanks.
Carlo