How to include packages with Java code generation?

General discussions about code engineering

Moderator: Moderators

How to include packages with Java code generation?

Postby dave.brown@seecago.com » Mon Oct 18, 2010 6:15 pm

Hi,

My apologies if this is a duplicate posting. It seems that the initial posting got lost somewhere in cyberspace.

I am having a little challenge when generating Java classes from a class diagram that includes packages.

As in the example below, I have a class SessionManager in the package com.acme.saturnus.uimanager.

Code: Select all
----------------------------------------------------
Java code generation report
----------------------------------------------------
writing to file:/Users/dave/work/Projects/Saturnus/trunk/CommHandler/src/com.acme.saturnus.uimanager/SessionManager.java


Eclipse doesn't like this a single bit, and when I replace the dots in the package names with '/', the file names are correct, but now the package definition inside the classes contain a '/'.

I cannot figure out how to get around this.

Any help is highly appreciated,

Cheers,

Dave
dave.brown@seecago.com
Forum Newbie
Forum Newbie
 
Posts: 2
Posts Rating:0
Joined: Mon Oct 18, 2010 4:01 pm

Re: How to include packages with Java code generation?

Postby egiva » Wed Oct 27, 2010 4:33 am

Hello,

You need to create nested UML package structure for each directory, instead of single package with a name "com.acme.saturnus.uimanager". SessionManager class must be located inside UML package uimanager and this package must be located inside UML package named saturnus and saturnus is located insside acme, acme - in com
Such structure should be generated correctly by MagicDraw.
Best Regards,
Egidijus Vaisnora
egiva
Customer Support
Customer Support
 
Posts: 37
Posts Rating:0
Joined: Tue Jan 05, 2010 6:32 am

Re: How to include packages with Java code generation?

Postby lonniev » Mon Nov 08, 2010 4:38 pm

The reply is a bit weak (basically RTFM) and the manual is insufficient in detail.

I have a similar reverse engineering task: I want to reverse engineer the 1700 files of the Android Froyo distribution so that I can use the key classes (e.g. "android.Activity") in my UML model.

If I create a Code Engineering Set for Java and set its Working Directory to the unpacked Java sources for Froyo and Add Recursively, I get a long set of file-like model elements under the CES. I also gain a "File View" package with the folder hierarchy from the distribution wherein there is a UML Component for each of the *.java files. These can be added to UML Class Diagrams--but they lack any structure or relationship information. So, I believe these aren't intended for diagramming.

If I chose a "file" element from the CES and right-click the Reverse option, it creates a suitable UML Class (with Java Profile annotations) in the model--but fails to resolve all the references to peer Java Classes and creates all the UML Classes it believes are missing in a separate Package named "Default". I am expecting that it would find the source implementations for the peer classes in the same source hierarchy and either reverse the peers or ask me if I would like to skip reversing the peers because I only selected one file from the CES.

A practical example with a real JAR or with a real set of dependent files would help the original author of this posting; I'd probably benefit, too!
lonniev
Customer Support
Customer Support
 
Posts: 12
Posts Rating:1
Joined: Mon Nov 01, 2010 12:53 pm

Re: How to include packages with Java code generation?

Postby lonniev » Mon Nov 08, 2010 4:52 pm

To be fair to the NoMagic staff, I meant for my flame to go with dave.brown's other posting on how to use external jars in MD. However, the advice remains the same: we users need a bit more practical guidance in the manuals.
lonniev
Customer Support
Customer Support
 
Posts: 12
Posts Rating:1
Joined: Mon Nov 01, 2010 12:53 pm

Re: How to include packages with Java code generation?

Postby lonniev » Mon Nov 08, 2010 5:00 pm

By the way, what _is_ the intent for File View? I see that the file elements in CES provide a handle to the resource out in the filesystem and I see that reversed classes get stored in suitable Packages elsewhere in the model (if I can figure out how to configure the CES reverser correctly) but what are modelers supposed to do with "File View" elements?
lonniev
Customer Support
Customer Support
 
Posts: 12
Posts Rating:1
Joined: Mon Nov 01, 2010 12:53 pm

Re: How to include packages with Java code generation?

Postby egiva » Thu Nov 11, 2010 9:32 am

Hi,

File View contains components for every file in code engineering set, additionally this component contains information what model element is attached to file (by realization link) and provides UML package structure for directory structure, counting from working directory. In most cases File View is not needed for modeler, and only needed to code engineering set. If you perform java quick reverse (from Tools menu) these File Views will not be created. However in some languages, components could be used for specific mappings ( like includes in Corba IDL or XML Schema).

We have added request to extend manual about how to import jar files and it will be considered for future releases.
Best Regards,
Egidijus Vaisnora
egiva
Customer Support
Customer Support
 
Posts: 37
Posts Rating:0
Joined: Tue Jan 05, 2010 6:32 am

Re: How to include packages with Java code generation?

Postby lonniev » Thu Nov 11, 2010 3:02 pm

So, really, I should ignore the File View when modeling; I should not relate my domain-specific Classifiers to the elements within File View. Right?

Returning to my immediate concern, how do I reverse the files in the Code Engineering Set so that internal references resolve to model elements in the same package hierarchy--rather than to new elements created and placed into the Default package?
lonniev
Customer Support
Customer Support
 
Posts: 12
Posts Rating:1
Joined: Mon Nov 01, 2010 12:53 pm

Re: How to include packages with Java code generation?

Postby egiva » Fri Nov 12, 2010 2:16 am

File View contains class to the physical files deployment information and they are not needed in modeling. But if you want to include new class into code engineering set and arrange to generate this new class to the specific java file, then you will need to "assign" this class to specific component, "saying" that this class must go to this component (java file). By default each new class added to the Java code engineering set is arranged to the new file.

In second issue the right solution could be to reverse whole code engineering set in order to avoid classes added to default. Java reverse searches for references in existing UML model, then in source files which are participating in reverse process and then in classpath (defined in MagicDraw properties). Thus, if you are reversing just single source file, references are not searched in rest of CES files and Default package is created.
Another solution could be to add you binaries to the classpath at Options-> Project-> Code engineering-> Java Code engineering.
Best Regards,
Egidijus Vaisnora
egiva
Customer Support
Customer Support
 
Posts: 37
Posts Rating:0
Joined: Tue Jan 05, 2010 6:32 am

Re: How to include packages with Java code generation?

Postby lonniev » Mon Nov 15, 2010 3:46 pm

egiva,

Ok, I'm starting to understand File View: I'm used to UML/MDA tools which impose a one-to-one mapping between UML Classes and filesystem Files. You are implying that MD supports a many-to-one mapping of Classes to Components to Files. Ok. I may use that later, elsewhere.

Remarking on your suggestions for reversing and the Default package, I'd like to just reverse everything and use only what I need. However, with a 1700-file source base, I assume that I'm going to needlessly create a hugh amount of model content, most of which will never appear in a model because the domain-specific models will only need to reference the facade of the class library. Ideally, I could limit the amount of reversed code.

Tell me more about setting the CLASSPATH for the Project. If I point the project to a class-file-containing jar and configure the CES for the entire source code base, then if I select one class (e.g. android.AboutDialog) does the reverser resolve all references to types which are outside the scope of the single file to the types within the jar(s)?
lonniev
Customer Support
Customer Support
 
Posts: 12
Posts Rating:1
Joined: Mon Nov 01, 2010 12:53 pm

Re: How to include packages with Java code generation?

Postby egiva » Tue Nov 16, 2010 4:12 am

Hi,

Yes, MagicDraw will resolve references from the jars if it finds them. When you are reversing on empty project java classes, all Java type references are found in this reverse CLASSPATH and are placed in your working package in the model. For example, if you are referencing java.lang.String, then it is found in "md.jar" (this jar is by default included in classpath) and places in working package, under md.jar package. If you include your binaries into reverse CLASSPATH, then it will be target for reference searching.
Best Regards,
Egidijus Vaisnora
egiva
Customer Support
Customer Support
 
Posts: 37
Posts Rating:0
Joined: Tue Jan 05, 2010 6:32 am

Next

Return to Code engineering

Who is online

Users browsing this forum: No registered users and 0 guests