Book a Demo

Author Topic: Java Source Code Generation  (Read 7328 times)

angel-o-sphere

  • EA User
  • **
  • Posts: 112
  • Karma: +0/-0
    • View Profile
Java Source Code Generation
« on: March 08, 2004, 06:29:35 am »
Hi,

I have two/three problems in generating java source code.

a) no import statements (analogous in some way to #include in C/C++) are generated, so classes used as parameters etc. cause Java Errors, because the package is not known

c) aggregations only generate one identifier: either the role if present ...

c) ... or only the referenced type if no role is present

I'm sure for both problems is a way to configure it somewhere.

Regards,
  angel'o'sphere

Correction: the import statement is generated for classes required in attributes etc. but not for parameters. I used the correct way to specify the type of the parameter, I used the [...] button.
« Last Edit: March 08, 2004, 08:45:47 am by aos »

angel-o-sphere

  • EA User
  • **
  • Posts: 112
  • Karma: +0/-0
    • View Profile
How to configure prefered way of aggregation?
« Reply #1 on: March 08, 2004, 06:33:45 am »
Hi,

while generating Java source code I like to be able to define what type a generated aggregation should be mapped to:

E.G. User [0..*] <>---> [0..*] UserProfile

So the class User should e.g. use an ArrayList or something for maintaning a list of UserProfiles, however I can not figure how to do that.

If possible a stereotype should be used. However a tagged value might be more appropriated.


Regards,
  angel'o'sphere

P.S. if I could use Java Generics here :D it would be even better!

Correction: I found the tools/options.. way for configuring the usage of appropriated classes: probably the tool should generate default code looking like this: "configure the container classes in tools/options ..." :D
« Last Edit: March 08, 2004, 08:43:35 am by aos »

angel-o-sphere

  • EA User
  • **
  • Posts: 112
  • Karma: +0/-0
    • View Profile
Generating additional methods to aggregations
« Reply #2 on: March 08, 2004, 06:38:29 am »
Hi,

one further problem regarding aggregations etc.

If I have an aggregation like this:
User [0..*] <>---> [0..*] UserProfile, I would like to have some management methods added to the class User:
add(UserProfile p);
remove(UserProfile p);
and probably:
UserProfile select(UserProfileCriteria c);

How can that be done? If possible a stereotype should be used. However a tagged value might be more appropriated.

Regards,
  angel'o'sphere

eric914

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java Source Code Generation
« Reply #3 on: March 17, 2005, 06:05:52 am »
Quote
a) no import statements (analogous in some way to #include in C/C++) are generated, so classes used as parameters etc. cause Java Errors, because the package is not known


I had the same problem here:  Each class should've had the header of
"package com.namespace1.namespace2.project"
I had the project in folder:
"src/com/namespace1/namespace2/project"

The problem turned out to be I imported the project from the project directory.  I tried importing from the src directory, and this fixed it.

It seems EA uses the directory structure as defining the package namespace, I guess.


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Java Source Code Generation
« Reply #4 on: March 17, 2005, 01:59:48 pm »
Since angel-o-sphere wrote the original post the generation of import statements was improved to generate for all parameter types.

Also, generics are now able to be used with Java.  For using them or classes such as ArrayList set up the Collection classes (see the help) for either the language or the class you want a collection of.

Finally, EA will use the directory structure for the package if you do a directory import and use the 'Create Package per Directory' option.  Recently (but not really recent) the 'Create Package per Namespace' option was made available for Java imports.  As this takes the package structure from the package statement it is really the best way of importing.

Simon