Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)?
[Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1265583] Thu, 06 March 2014 09:25 Go to next message
Joost Kraaijeveld is currently offline Joost Kraaijeveld
Messages: 173
Registered: July 2009
Senior Member
Hi,

I have a Papyrus model in which a class has an attribute with of the
type String from the UML Primitive Types. Based on the getting started
tutorial I expected the following to work and to result in "String
attributeName":

[for (p: Property | aClass.attribute) separator('\n')]
[p.type.name/] [p.name/];
[/for]

But "[p.type.name/]" does not result in any output. Am I missing
something? What should I do?

TIA


Joost
Re: [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1402835 is a reply to message #1265583] Thu, 17 July 2014 17:37 Go to previous messageGo to next message
Béla Boda is currently offline Béla Boda
Messages: 1
Registered: July 2014
Junior Member
Yes you do.

Saidly it is a bit ugly, but you need to do as it is described here:
https://wiki.eclipse.org/MDT/UML2/FAQ#What.27s_required_to_load_a_UML_.28.uml.29_resource_from_a_standalone_application.3F

Don't forget the
@generated NOT


It works for me, customize your eclipse location and the versions:
    /**
     * This can be used to update the resource set's package registry with all needed EPackages.
     * 
     * @param resourceSet
     *            The resource set which registry has to be updated.
     * @generated NOT
     */
    @Override
    public void registerPackages(ResourceSet resourceSet) {
        super.registerPackages(resourceSet);
        if (!isInWorkspace(org.eclipse.uml2.uml.UMLPackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.uml.UMLPackage.eINSTANCE);
        }
        
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
        Map uriMap = resourceSet.getURIConverter().getURIMap();
        URI uri = URI.createURI("jar:file:/c:/eclipse/eclipse-modeling-luna-R-win32-x86_64/plugins/org.eclipse.uml2.uml.resources_5.0.0.v20140602-0749.jar!/"); // for example
        uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
        uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
        uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
...
}
Re: [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1402841 is a reply to message #1402835] Thu, 17 July 2014 18:44 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4046
Registered: July 2009
Senior Member
Hi

As of Luna UMLReourcesUtil.init(ResourceSet) does all the setup scanning
the classpath top discover the JAR spelling. Acceleo could call it for
you but it doesn't.

(In Kepler the pathmap assignments were still needed.)

Regards

Ed Willink


On 17/07/2014 19:12, Béla Boda wrote:
> Yes you do.
>
> Saidly it is a bit ugly, but you need to do as it is described here:
> https://wiki.eclipse.org/MDT/UML2/FAQ#What.27s_required_to_load_a_UML_.28.uml.29_resource_from_a_standalone_application.3F
>
>
> Don't forget the @generated NOT
>
> It works for me, customize your eclipse location and the versions:
>
> /**
> * This can be used to update the resource set's package registry
> with all needed EPackages.
> * * @param resourceSet
> * The resource set which registry has to be updated.
> * @generated NOT
> */
> @Override
> public void registerPackages(ResourceSet resourceSet) {
> super.registerPackages(resourceSet);
> if (!isInWorkspace(org.eclipse.uml2.uml.UMLPackage.class)) {
> resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(),
> org.eclipse.uml2.uml.UMLPackage.eINSTANCE);
> }
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> Map uriMap = resourceSet.getURIConverter().getURIMap();
> URI uri =
> URI.createURI("jar:file:/c:/eclipse/eclipse-modeling-luna-R-win32-x86_64/plugins/org.eclipse.uml2.uml.resources_5.0.0.v20140602-0749.jar!/");
> // for example
> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
> uri.appendSegment("libraries").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
> uri.appendSegment("metamodels").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
> uri.appendSegment("profiles").appendSegment(""));
> ..
> }
>
Re: [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1405548 is a reply to message #1402841] Thu, 07 August 2014 15:44 Go to previous messageGo to next message
Ol Reak is currently offline Ol Reak
Messages: 2
Registered: August 2014
Junior Member
Hi,

I have exactly the same problem but the given solution did not solve the problem for me.
Below, the code of my "registerPackages" function (with suggested moficiations):
    /**
     * This can be used to update the resource set's package registry with all needed EPackages.
     * 
     * @param resourceSet
     *            The resource set which registry has to be updated.
     * @generated NOT
     */
    @Override
    public void registerPackages(ResourceSet resourceSet) {
        super.registerPackages(resourceSet);

        if (!isInWorkspace(org.eclipse.uml2.uml.UMLPackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.uml.UMLPackage.eINSTANCE);
            
            resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(org.eclipse.uml2.uml.resource.UMLResource.FILE_EXTENSION, org.eclipse.uml2.uml.resource.UMLResource.Factory.INSTANCE);
            Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
            URI uri = URI.createURI("jar:file:/C:/Users/.../eclipse/plugins/org.eclipse.uml2.uml.resources.source_5.0.0.v20140519-1951.jar!/"); // for example
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
        }

        if (!isInWorkspace(org.eclipse.papyrus.C_Cpp.C_CppPackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.papyrus.C_Cpp.C_CppPackage.eINSTANCE.getNsURI(), org.eclipse.papyrus.C_Cpp.C_CppPackage.eINSTANCE);
            
            resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(org.eclipse.uml2.uml.resource.UMLResource.FILE_EXTENSION, org.eclipse.uml2.uml.resource.UMLResource.Factory.INSTANCE);
            Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
            URI uri = URI.createURI("jar:file:/C:/Users/.../eclipse/plugins/org.eclipse.papyrus.cpp.profile_1.0.0.v201406250859.jar!/"); // for example
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
        }

        if (!isInWorkspace(org.eclipse.emf.ecore.EcorePackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.emf.ecore.EcorePackage.eINSTANCE.getNsURI(), org.eclipse.emf.ecore.EcorePackage.eINSTANCE);
            
            resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(org.eclipse.uml2.uml.resource.UMLResource.FILE_EXTENSION, org.eclipse.uml2.uml.resource.UMLResource.Factory.INSTANCE);
            Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
            URI uri = URI.createURI("jar:file:/C:/Users/.../eclipse/plugins/org.eclipse.emf.ecore.source_2.10.0.v20140514-1158.jar!/"); // for example
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
        }

         /*
         * If you want to change the content of this method, do NOT forget to change the "@generated"
         * tag in the Javadoc of this method to "@generated NOT". Without this new tag, any compilation
         * of the Acceleo module with the main template that has caused the creation of this class will
         * revert your modifications.
         */
        
        /*
         * If you need additional package registrations, you can register them here. The following line
         * (in comment) is an example of the package registration for UML.
         * 
         * You can use the method  "isInWorkspace(Class c)" to check if the package that you are about to
         * register is in the workspace.
         * 
         * To register a package properly, please follow the following conventions:
         *
         * If the package is located in another plug-in, already installed in Eclipse. The following content should
         * have been generated at the beginning of this method. Do not register the package using this mechanism if
         * the metamodel is located in the workspace.
         *  
         * if (!isInWorkspace(UMLPackage.class)) {
         *     // The normal package registration if your metamodel is in a plugin.
         *     resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
         * }
         * 
         * If the package is located in another project in your workspace, the plugin containing the package has not
         * been register by EMF and Acceleo should register it automatically. If you want to use the generator in
         * stand alone, the regular registration (seen a couple lines before) is needed.
         * 
         * To learn more about Package Registration, have a look at the Acceleo documentation (Help -> Help Contents).
         */
    }


Any other idea?

Thanks
Re: [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1405940 is a reply to message #1405548] Fri, 08 August 2014 15:00 Go to previous message
Ol Reak is currently offline Ol Reak
Messages: 2
Registered: August 2014
Junior Member
Hi,

I finally found how to make it works. I am not sure how I did it, but here is the code of my "registerPackages" function now:
    /**
     * This can be used to update the resource set's package registry with all needed EPackages.
     * 
     * @param resourceSet
     *            The resource set which registry has to be updated.
     * @generated NOT
     */
    @Override
    public void registerPackages(ResourceSet resourceSet) {
        super.registerPackages(resourceSet);
        if (!isInWorkspace(org.eclipse.uml2.types.TypesPackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.uml2.types.TypesPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.types.TypesPackage.eINSTANCE);
        }
        if (!isInWorkspace(org.eclipse.uml2.uml.UMLPackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.uml.UMLPackage.eINSTANCE);
        }
        if (!isInWorkspace(org.eclipse.papyrus.C_Cpp.C_CppPackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.papyrus.C_Cpp.C_CppPackage.eINSTANCE.getNsURI(), org.eclipse.papyrus.C_Cpp.C_CppPackage.eINSTANCE);
        }
        if (!isInWorkspace(org.eclipse.emf.ecore.EcorePackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.emf.ecore.EcorePackage.eINSTANCE.getNsURI(), org.eclipse.emf.ecore.EcorePackage.eINSTANCE);
        }
        
        
        Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
        URI uri = URI.createURI("jar:file:/C:/Users/.../eclipse/plugins/org.eclipse.uml2.uml.resources_5.0.0.v20140519-1951.jar!/");
        uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
        uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
        uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
    }


I have also modified the "registerResourceFactories" function (because I am loading .uml files, not .xmi files), I do not know if it has really an effect:
    /**
     * This can be used to update the resource set's resource factory registry with all needed factories.
     * 
     * @param resourceSet
     *            The resource set which registry has to be updated.
     * @generated NOT
     */
    @Override
    public void registerResourceFactories(ResourceSet resourceSet) {
        super.registerResourceFactories(resourceSet);
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("uml", new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl());
    }
Previous Topic:[Xpand] Extension: class is not responsible for java type
Next Topic:[Acceleo] query problem
Goto Forum:
  


Current Time: Sun Sep 21 10:10:32 GMT 2014

Powered by FUDForum. Page generated in 0.09193 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software