Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Java Generator is generating spaces in the package names
Java Generator is generating spaces in the package names [message #1803540] Sun, 03 March 2019 20:46 Go to next message
Mohamed Ismail is currently offline Mohamed IsmailFriend
Messages: 9
Registered: March 2019
Junior Member
Hi,

I am using papyrus 2018-12 (4.10) and the designer update site: http://download.eclipse.org/modeling/mdt/papyrus/components/designer/. I have created a UML model and I have managed to generate Java Project however, I have two issues:
1- The package names have spaces in them
e.g.
package com.reservation.model.Common Business Entities Domain.Calendar ABE;


2- the prefix which i have defined in the project stereotype of the package is defined as per the below. This means that other packages are not referenced correctly.
import com.reservation.model.;


I have looked everywhere for hints but I couldn't find any. Appreciate, your support Ansgar.

Thanks
Re: Java Generator is generating spaces in the package names [message #1804010 is a reply to message #1803540] Fri, 15 March 2019 16:15 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 461
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Sorry for the late reply.
1. Right now, spaces in package names are not escaped (e.g. replaced by underscores). While this could be done, it is also problematic e.g. with respect to model / code coherence. So, my recommendation is to avoid UML package names that are non Java compliant. An option would be to use the international feature by using a label with spaces while keeping package name without spaces.

2. It's not clear for me how you applied the Project stereotype, i.e. which attributes did you fill? The objective is to control in which plugin/source folder the generated file are placed, but not to use a different package name than the one defined at the UML level.
Re: Java Generator is generating spaces in the package names [message #1804055 is a reply to message #1804010] Sat, 16 March 2019 21:06 Go to previous message
Mohamed Ismail is currently offline Mohamed IsmailFriend
Messages: 9
Registered: March 2019
Junior Member
Hi Ansgar,

Thanks for your reply. I like the option of using a label with space while keeping the package names without space. I've written a perl script to rename all of the packages to remove the spaces between name attribute. HYG.

use strict;
use warnings;
#use XML::Simple;
use XML::LibXML;

my $filename = $ARGV[0];

my $dom = XML::LibXML->load_xml(location => $filename);

my $e= $dom->findnodes( "//packagedElement");

foreach my $e (@$e)
{ print $e->nodeName;

if($e->nodeName eq "packagedElement")
{
# text needs to be trimmed or line returns show up in the output
my $text= $e->textContent;
$text=~s{^\s*}{};
$text=~s{\s*$}{};

# if( ! $e->getChildrenByTagName( '*') && $text)
# {
# print "=$text"; }
print "\n";

my @attrs= $e->findnodes( "./@*");
my $arrLength = scalar @attrs;
# print "the number of attributes found is $arrLength";
# or, as suggested by Borodin below, $e->attributes

foreach my $attr ($e->attributes)
{
# print "attribute: $attr \n";

if($attr->nodeName eq "name" and ($attr->value =~ / /) )
{

#print $e->nodeName, " ", $attr->nodeName. "=", $attr->value, "\n"; }
my $string = $attr->value ;
$string =~ s/\s+//g;

my $originalString = $attr->value;
print "$originalString will be replaced with $string\n";
$attr->setValue($string);
}
}

}
}
$dom->toFile("output.xml",1);
Previous Topic:Support for OMG DD?
Next Topic:SysML parametric diagram issues
Goto Forum:
  


Current Time: Tue Apr 23 08:02:55 GMT 2024

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

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

Back to the top