Installation and User Guide for the tool “EJB Wizard
For Code Generation”
Introduction to the tool
This tool is meant for generation of Enterprise Java Bean Source
code files with a minimum effort of coding. Generally most of the
industries leading IDEs offer such a wizard, but not many free
IDEs like JBuilder Foundation, Forte For Java etc. give such
features, because they offer such features in their
Enterprise versions. But the EJB programmers who are learning EJB
or using EJB for their personal use, they are in need of such a
tool through which they can generate EJBs without much coding.
This tool can be used with free EJB servers like the one that
comes with Sun’s J2EE SDK. Even it can be used with many
open source EJB servers are available for free on the internet.
Why a Wizard is needed for EJB code generation?
EJB is such a framework where a lot of mappings between the
classes are to be done at the source code level. For example
every create method of Home interface should have a corresponding
ejbCreate method in the Bean Class with a related signature. It
is nothing but a coding complexity to create such related methods
with a proper matching. Another reason is that many EJB classes
will have the same code for the EJB framework methods which
should follow some rules to qualify as a valid EJB. Next come the
case of Entity beans where a huge volume of code should be
written for accomplishing the database tasks. And there are many
more complexities in the coding of EJB classes.
Each of the above mentioned complexities can be handled by a tool
if it can intelligently generate the code by taking a fewer
inputs from the user. With such a tool, EJB developer can
concentrate on what fields and business logic methods the Bean
should have rather than coding the same repetitive code again and
again for each bean. Once such code is ready , he/she can
concentrate on the business logic rather than meddling with the
code to follow EJB framework rules.
What features can this tool offer?
- This tool
can generate the following types of EJBs following the
EJB 1. 1 specification.
- Statefull
Session Beans
- Stateless
Session Beans
- Entity
Beans with Bean Managed Persistence (uses
Database code)
- Entity
Beans with Container Managed Persistence
- This tool
can generate the EJBs that are to be coded from the
scratch. It can generate only the new EJBs and it wont
offer the maintenance or modification of existing beans.
- This tool
offers the validations required for EJBs and generic Java
classes like duplication of methods in a class, mandatory
primary key for entity beans etc. But it doesn’t do
the validations following the Java Language Specification
to 100%. In near future such validations will be done.
- Code for
all the methods common to EJB framework like ejbCreate,
finders etc will be completely written by this tool.
Since this tool is generating the code for generic
implementation of EJBs, neither the user’s
requirements not the business logic can be obtained as an
input in an intuitive manner. Hence this tool generates
only that code related to EJB framework and the code
common to any application. User has to write the
application specific code using some IDE or text editor.
- Depending
upon the specification of the bean that is going to be
generated, unto 70% of the bean’s code can be
generated through the wizard if used cautiously.
- Some
restrictions are imposed in usage of the tool while
following EJB specification to achieve a balance between
the effort user has to put for using the tool and the
efficiency of the code generation.
A Few Words from the Author
In
future this tool may support creation of the Entity beans from
the existing database.Since this tool is in the pre matured
stage, it may have bugs or areas of improvement. This is “the
tool for you” and it is going to evolve from your
requirements and suggestions. Please keep sending the bugs so
that I can fix them as soon as possible , to make the tool bug
free. Please feel free to send your suggestions and comments so
that I can improve the tool. I am available at nphanindrakumar@yahoo.com.
Installation and Startup of the tool
1.
Copy the EjbGenerator.zip file into the local machine
2.
Extract the contents into some folder.
3.
Check your classpath so that Java 1.2.*/1.3 SDK and J2EE SDK
libraries are available for execution of the tool. Even the
alternate SDKs for Java and EJB can be used.
4.
On Windows Operating system, double click the batch file
RunEjbGenerator.bat for execution of the tool.
5.
On other Platforms you can run the tool by directly invoking the
java interpreter with the command “java ejbgen.gui.Driver”.
This can be used on Windows also.
6.
Then start using the tool to Generate EJBs
How to use the tool
Startup Screen
This tool starts with a screen shown as
below.
Click “Create Session Bean” button
for creating the Session Bean.
Click “Create Entity Bean” button
for creating the Entity Bean.
Click “EXIT” button to Quit.
Creating Session Bean
On Clicking Click “Create Session Bean”
button in the Startup screen the “Basic Info” screen
appears as below, where the session bean specification
should be given.
In the “Basic Info” screen enter
the primary information for the session bean.
- For
“Bean Package Name” enter the package to which
the generated bean classes should belong to.
- For
“Bean Class Name” enter the name of the Session
Bean class. While entering it, both home interface and
remote interface names will be generated automatically.
If needed those class names can be modified.
- Select
the “Session Bean Type” from the radio button.
The next coming screens, validations and bean code
generation will be done according to the bean type
selected.
- “JNDI
Name for Database” and “Name of the Table”
fields don’t need any input while generating Session
Beans.
- Enter the
directory or path where the Session Bean Files are to be
created. “Browse” button can be used for
selecting the directory using GUI.
- Enter the
description for the class, which will be used as the
JavaDoc comment for the class. Each line of text entered
into it will become a line of JavaDoc comment for the
class description.
- Selecting
the check box “Create Console Messages For Every
Method Entry & Exit” will result in generation
of Log code into the methods created by the tool. Log
will be generated with System.out.println statements at
the beginning and ending of each method’s code
generated. Unselecting it won’t generate the log
statements.
- Click
next to add the fields and methods required for the
session bean. Refer to the sections “Adding Bean
Methods” and “Adding Bean Fields” for
information on how to add fields and methods for a
session bean.
- Here is
the example screen with data entered into it for creation
of a session bean.
Creating Entity Bean
On Clicking “Create
Entity Bean” button in the Startup screen the “Basic
Info” screen appears as below, where the entity bean
specification should be given.
In the “Basic Info” screen enter
the primary information for the entity bean.
- For
“Bean Package Name” enter the package to which
the generated bean classes should belong to.
- For
“Bean Class Name” enter the name of the Entity
Bean class. While entering it, both home interface and
remote interface names will be generated automatically.
If needed those class names can be modified.
- Select
the “Persistence Type” of the bean from the
radio button. The next coming screens, validations and
bean code generation will be done according to the
persistence type selected.
- If the
persistence type is selected as Bean Managed, enter
“JNDI Name for Database” and “Name of the
Table” fields. This data will be used with an
assumption that the Entity Bean data will be store in the
specified Table, which belongs to the Database mentioned.
- If the
persistence type is selected as Container Managed, the
EJB container will provide persistence and database
mapping code and its specification will be provided at
the time of bean deployment. So no need to input the
Database and Table names.
- Enter the
directory or path where the Entity Bean Files are to be
created. “Browse” button can be used for
selecting the directory using GUI.
- Enter the
description for the class, which will be used as the
JavaDoc comment for the class. Each line of text entered
into it will become a line of JavaDoc comment for the
class description.
- Selecting
the check box “Create Console Messages For Every
Method Entry & Exit” will result in generation
of Log code into the methods created by the tool. Log
will be generated with System.out.println statements at
the beginning and ending of each method’s code
generated. Unselecting it, wont generate the log
statements.
- Click
next to add the fields and methods required for the
session bean. Refer to the sections “Adding Bean
Methods” and “Adding Bean Fields” for
information on how to add fields and methods for an
entity bean.
- Here is
the example screen with data entered into it for creation
of an entity bean.
Adding Bean Fields
“Field Editor” screen will appear
by clicking “Next” button in the “Basic Info”
Screen. The screen looks as follows for Container managed
persistent entity bean.
Here the fields or the bean class data
members can be added and the fields can be marked for their
related methods or additional behavior. The screen when used for
different beans, it appears a little different according to type
of the bean. Here is the description for using the “Field
Editor”.
- Upper
portion of the screen has the widgets to be used for
inputting the field details. Lower portion of it has the
Table that shows the important details of the fields
added to the bean.
- For
adding a new field, enter data into the input fields and
then click “Add New Field” button.
- For
editing/modifying an existing field, select the field
from the table by clicking the field (it shows the field
details in the widgets), then modify that data and
finally click “Edit Selected Field” button.
- For
deleting an existing field, select the field from the
table by clicking the field and then click “Delete
Selected Field” button.
- Data for
“Field Name”, “Datatype” and “Scope”
is used for creating the field/data member for the bean
class. This data is mandatory for any field’s
definition. “Description” is used for making
the JavaDoc comments for a field and it is optional.
- “Create
Set Method” and “Create Get Method”
checkboxes are to be used for creating get and set
methods(relating to the field) in the bean and the
required methods to the remote interface.
- “Persistent”
checkbox is to be used to tell that the field is
persistent, and tool will generate the code appropriately.
- “Primary
Key” checkbox is to tell that the field will be the
primary key of the database table corresponding to the
bean.
- “Create
Find Method” and “Create Find-In-Range Method”
checkboxes are to tell the tool to generate the methods
to search/query the beans based upon the value or range
of values that matches the bean’s field value.
- Among the
field input widgets, some may not be available depending
on the bean types and accordingly, the table may contain
reduced number of columns. Here are the details on it.
- Stateless
Session Bean won’t have any of the check
boxes as the bean will have neither state nor the
persistence.
- Statefull
session beans will have the “Create Set
Method” and “Create Get Method”
checkboxes for setting/getting the state of the
session bean. Rest of the check boxes wont be
available as Statefull session beans don’t
need persistence.
- Container
Managed Persistent Entity beans will have the all
the checkboxes except the “Persistent”
checkbox. It is so because, for such beans
Container should know the persistence policy
through deployment descriptor and not from the
bean code. For such bean there should be exactly
one primary key.
- Bean
Managed Persistent Entity beans will have the all
the checkboxes including the “Persistent”
checkbox. It is so because for such beans, the
code will have the persistence policy. If a
particular bean is not selected to be “Persistent”,
then it can’t be designated as primary key
and it cant have finder methods. For such bean
there should be exactly one primary key.
After giving the proper inputs for the
fields, click next to enter the “Method Editor” Screen
where the methods can be provided for the bean.
Adding Bean Methods
“Method Editor” screen will appear
by clicking “Next” button in the “Field Editor”
Screen. The screen looks as follows for Container managed
persistent entity bean.
Here the methods for the bean class(and in
turn to the home and remote interfaces) can be added. The screen
when used for different beans, it appears a little different
according to type of the bean. Here is the description for using
the “Method Editor”.
- Upper
portion of the screen has the table showing the methods
required by EJB framework to qualify the bean to be a
valid EJB. Lower portion of it has the Table that shows
Business Logic methods that are required for the actual
functionality of the bean.
- Framework
methods come with standard definitions and can’t be
modified/deleted. But for some kinds of beans
additional ejbCreate methods can be added but with only
different method parameters. For that use “Add
Create” button.
- For
viewing or modifying any method select the method from
appropriate table and then click “View/Modify”
button of that table. It will show “Method Maker”
screen as below.
If the method is a Framework one,
then some/all of the widgets may not be editable. But if it is a
framework one, the existing content can be changed. Then click
“OK” button to confirm the changes or else click “Cancel”
button to discard the changes. This closes the “Method Maker”
screen and reflects the changes in “Method Editor”
screen.
- To delete
a particular method, select the method from appropriate
table and then click “Delete” button of that
table.
- To add a
new overloaded “ejbCreate” method, click “Add
Create Method” which will show “Method Maker”
screen. There enter the parameters for the new “ejbCreate”
method. Clicking OK will add a new “ejbCreate”
method.
- To add a
new Business Logic method, click “New Method”
which will show “Method Maker” screen. There
enter the method specification along with the “Description”(which
becomes method’s JavaDoc comments). Clicking OK will
add a new Business Logic method.
Creating the EJB Code
Necessary changes in any screen can be made
by navigating to different screens using “Next” and
“Prev” buttons.
After completion of defining the methods in
the “Method Editor” screen, click “Finish”
button which will show the following message.
This message confirms that the EJB classes’
source code is generated in the path specified. Clicking
“Yes” shows the opening screen of the tool, where the
next bean can be generated. Clicking “No” will
terminate your session with this tool and the tool execution ends
there.