cancel
Showing results for 
Search instead for 
Did you mean: 

Java class diagram - extending built-in classes

Former Member
0 Kudos

Hi all,

I'm a new user to PowerDesigner, and I am starting with a basic class diagram. I've created some classes that should extend the built-in class java.lang.Exception. However, when I try to select a class to inherit from, I cannot find Exception; the only classes that are listed are the ones that I have created myself.

Is there something special I must do to be able to use the built-in Java classes? I've read the product manual trying to figure this out, and had no luck. I'd appreciate any help figuring this out.

Accepted Solutions (1)

Accepted Solutions (1)

GeorgeMcGeachie
Active Contributor
0 Kudos

David, I've just taken a look at this to see if I can figure it out (it'd be useful to know for a future book), and I also can't find anything about built-in classess in the help file. If you create a class called 'Exception', does that show up correctly in your code? (I'm not a Java programmer, so I can't tell). If you change the 'type' value for the 'Excpetion' to 'Generic', does that give you what you need?

Former Member
0 Kudos

Thanks for the reply. I can  create a class named Exception in my diagram, but it does not work correctly - the class is assumed to be in the same package as the class this is extending it. Code generated:

public class MyException extends Exception {

Using generic will not help either - generics are a special class feature that java.lang.Exception does not use.

I've got it to a point where code generates correctly. In order to do this, I had to create an Exception class in the same package hierarchy as the built-in class: in java.lang. After doing this, code will generate for the class as:

public class MyException extends java.lang.Exception {

And of course, you'll want to set those built-in classes to not generate with everything else. If there is an easier way to do this, I'd love to learn about it. Using built-in Java classes and interfaces is very common in Java. Even if there isn't an easier way, I think this is a topic that could merit some space in the guide under "Working with Java".

GeorgeMcGeachie
Active Contributor
0 Kudos

This isn't ideal, but you could create a model containing the built-in classes in their own package (all with the 'Generate' property set to False), and save it in your templates folder.

Aternatively (I haven't tried this), your template model could contain shortcuts to an OOM you share via the repository library, so every model uses the same classes.

Have you raised this issue with SAP?

Former Member
0 Kudos

That seems like a sensible approach - I'll try that next time I run into this problem.

Ideally, PowerDesigner would have some knowledge of frequently used built-in classes and interfaces, so that the user wouldn't need to create these objects in order to have a complete class diagram. I have not yet suggested this to SAP, though I suppose I have done so indirectly if they read the boards

former_member185199
Contributor
0 Kudos

you are exspecting to much, when you dont open a case it will not change for decades, but maybe George can do it via the ISUG-channel?

GeorgeMcGeachie
Active Contributor
0 Kudos

Please feel free to raise an enhancement request via ISUG (see my recent blog posting on SCN)

former_member185199
Contributor
0 Kudos

Yes George, i´ve read this but i stopped participating on ISUG because of the paymodel

Answers (1)

Answers (1)

c_baker
Employee
Employee
0 Kudos

This is the purpose of Libraries in PD.

PD comes with a JDK 1.5 library OOM.  You can also R.E. the rt.jar from other jvm's (mark classifiers as 'Not Generated') and put the .oom in the _LIBRARY path (C:\Program Files\Sybase\PowerDesigner 16\Library).

You can also check the model into the .Library

Models opened from the library path are opened as RO in the workspace.  Drag the class from the library model to your diagram and it will be added as a shortcut.  This can be generalized as required.

When reverse-engineering Java, you can also add libraries (OOM's representing other components) to your R.E. and have the libraries automatically added with shortcuts from your new model to the libraries (from the Options tab).

This has been in PD since OOM was introduced.

Chris