Documentation Archive Developer
Search
PATH  WebObjects 4.0 Documentation > EOF Tools and Techniques

Table of Contents Previous Section

Generating Source Files

Once you finish specifying an enterprise object class, you can generate source files for it. However, at this stage of the development process, you may want to first create your project and design your application's user interface. Once you've created a project using Project Builder and included a model file in it, you can generate your source files and save them into the project.

You can create your enterprise object classes in either Objective-C or Java. To create an Objective-C class, use Property Generate Obj-C Files. To create a Java class, use Property Generate Java Files.

Additionally, there's a Property Generate Client Java Files. This command generates a Java class for use in the client-side of a Java Client web application.

Each command is described in more detail in the following sections.

Generating Objective-C Source Files

To generate Objective-C code files for your enterprise object class:

  1. In the Model Editor, select the entity for which you have specified a class in the Entity Inspector.

    EOModeler only permits you to create source files for entities for which you have specified a custom enterprise object class. In other words, you can't generate source files for EOGenericRecord.

  2. Choose Property Generate Obj-C Files or click the button in the toolbar.

    EOModeler displays a Choose Class Name panel. If the model file is in a project, the Choose Class Name panel displays the project as the default destination.

  3. Choose a destination, supply a name for the files if you want, and click Save.

    If you don't supply a name, the source files are named after the enterprise object class for which they are being generated and are given the appropriate extensions.

    If you opened the model file from a project, an additional panel appears, confirming that you want to insert the files in your project.

    Also, if you generate source files for an entity and files of the same name already exist, a panel is displayed asking if you want to cancel, overwrite, or merge the files. If you choose merge, the File Merge application starts with the old and new files displayed. You can then merge the files.

The end result of the Generate Obj-C Files command is:

For example, suppose you define an enterprise object class Movie. The instance variable declarations in the generated header file might resemble the following:

NSString *category;
NSCalendarDate *dateReleased;
NSDecimalNumber *language;
NSString *posterName;
NSDecimalNumber *revenue;
NSString *title;
id plotSummary;
Studio *studio;
NSMutableArray *directors;
NSMutableArray *roles;
Note that:

The corresponding implementation (.m) file for Movie includes an implementation for each of the accessor methods declared in the header file. For example, the methods for setting and returning the value of the instance variable title are:

- (void)setTitle:(NSString *)value
{
[self willChange];
[title autorelease];
title = [value retain];
}
- (NSString *)title { return title; }

Generating Java Source Files

Generate Java Files is similar to generating Objective-C files. To generate a Java (.java) file for your enterprise object class, follow the steps in Generating Objective-C Source Files, except that you choose Property Generate Java Files or click the button in the toolbar.

As with the Objective-C source files, a Java source file declares instance variables and provides basic implementations of accessor methods for those variables. And in Java:

Generate Client Java Files

Generate Client Java Files is similar to the other source generation commands. However, you only use this command when you're creating enterprise object classes to run on the client-side of a Java Client web application. (For a description of a Java Client application, see the chapter "What's Enterprise Objects Framework" in the book Enterprise Objects Framework Developer's Guide).

Using this and one of the other two source generation commands (either Objective-C or Java), you can create two versions of your enterprise object class. The different versions can have different class properties. For example, for security reasons, you might want to include social security number attribute in the server-side version of an enterprise object but exclude it from the client-side version.

To enable this distinction, you can specify whether an attribute is a Class Property () to be included in the server-side enterprise objects and also whether an attribute is a Client-Side Class Property () to be included in the client-side objects. For more information on setting these characteristics, see the chapter Working with Attributes.

To generate a Java (.java) file for a client-side version of your enterprise object class, follow the steps in Generating Objective-C Source Files, except that you choose Property Generate Client Java Files.

As with the source files generated by the other commands, a Java source file declares instance variables and provides basic implementations of accessor methods for those variables. The client-side Java files are generated exactly like the server-side Java files, except:

Customizing Source File Generation

When you create a project with the type "EOApplication," it inserts three files into the project's Supporting Files suitcase: EOInterfaceFile.template, EOImplementationFile.template, and EOJavaClass.template. You can use these files to customize your .h, .m, and .java file output, respectively. In their unmodified form these files match the source file generation scheme used by EOModeler.

Table of Contents Next Section