# Example

1. Creating Express Project
2. Creating Express File
3. Writing Express-schema
4. Compiling and generating JAR
5. Setting up Java Project
6. Running
7. Validate p21

## Creating Express Project

Follow the routine to create an Express Project:

- Click the (create new Express project) button on the Eclipse tool bar (Express Perspective must be activated). The New Express Project dialog window appears (see Figure 1).
- Enter the word 'Family', which specifies a project name into the Project name field.
- Click the Finish button to create a project with the default settings. The created Express Project appears in the Navigator Panel (see Figure 2).

Figure 1. Create new Express Project wizard dialog window
Figure 2. Created Express project ('Family')
To top

## Creating Express File

Follow the routine to create an express file:

- Click the Family project node and then the (create new Express file with .exp extension) button on the Eclipse tool bar (Express Perspective must be activated). The New Express File wizard dialog window appears (see Figure 3).
- Enter a name of the file 'Family.exp' into the File name field and click the Finish button. The created Express file appears under the Express files node in the Family project (see Figure 4) and the Express Editor is activated on the right side of the workbench.

Figure 3. New Express file wizard dialog window
Figure 4. Created Express file
To top

## Writing Express-schema

After a new Express file (.exg) is created and opened, enter the following Express-schema into the Express Editor panel:
SCHEMA Family;
ENTITY Person
ABSTRACT SUPERTYPE OF (ONEOF (Male, Female));
name: STRING;
mother: OPTIONAL Female;
father: OPTIONAL Male;
WHERE
WR1: exists(mother) OR exists(father);
END_ENTITY;
ENTITY Female
SUBTYPE OF (Person);
END_ENTITY;
ENTITY Male
SUBTYPE OF (Person);
END_ENTITY;
END_SCHEMA;
Save file after you finish.
To top

## Compiling and generating JAR

Now you have to compile the Family.exp file:

- Select any folder or file in the Family project area.
- Click the (compile the Express files in the project) button. If any errors encountered, they are highlighted in the Express Editor. You can check and fix them. You can find detailed description of errors in the Console panel (see Figure 5).
- After the successful compilation you should see the following generated files in the root of the Family project (see Figure 6):

- Family.exd,
- Family.jar.

Figure 1. Highlighted errors in Express editor panel and descriptions in Console panel.
Figure 6. Generated files
To top

## Setting up Java Project

Create a java project FamilyJava: File -> New -> JSDAI Java Project. The New Java Project wizard dialog window appears (see Figure 7):

- Enter FamilyJava into the Project name field.
- Click Next button to go to the next page.

Figure 7. New Java Project wizard dialog window

- The following wizard dialog window appears to define Java build settings and click the Libraries tab to activate the panel (see Figure 8):

- You have to specify the jar file, created by Express Compiler. Click Add JARs button. The JAR selection dialog window appears (see Figure 9).
- Select the Family.jar in the presented tree and click OK button.

Figure 8. New Java Project wizard dialog window, Libraries panel
Figure 9. JAR Selection dialog window

- Click Finish button to create the JSDAI Java project.

- Create a java file FamilyJava (File -> New -> Other -> Java -> Class) with the following class:

import jsdai.lang.*;
import jsdai.SFamily.*;
public class FamilyJava {
public static void main(String[] args) throws SdaiException {
// TODO Auto-generated method stub
SdaiSession session = SdaiSession.openSession();
SdaiTransaction trans = session.startTransactionReadWriteAccess();
SdaiRepository repo = session.createRepository("", null);
repo.openRepository();
SdaiModel mod_world = repo.createSdaiModel("mod_world", SFamily.class);
mod_world.startReadWriteAccess();
EPerson p1 = (EPerson)mod_world.createEntityInstance(CMale.definition);
p1.setName(null, "Jack");
String s = p1.getName(null);
System.out.println("Hi " + s);
repo.exportClearTextEncoding("family1.p21");
trans.endTransactionAccessAbort();
System.out.println("Good bye");
session.closeSession();
}
}
Figure 10. Editor panel with java file
To top

## Running Java

Now you may run the java application: Run -> Run As -> Java Application.
It should print in the Console panel (see Figure 11):
Hi Jack
Good bye
Figure 11. Console panel view

- Click Refresh key (F5) on the FamilyJava project to view recently created files (for example family1.p21) (see Figure 12).

Figure 12. Navigator panel, FamilyJava project files.

- Double click on the family1.p21 node to open file in the Editor panel (see Figure 13).

Figure 13. Editor panel, family1.p21 file
To top

## Validate p21

Run validation of the created family1.p21 file:

- Right click on the Express project Family node and select the Validate against Express menu item.
- The dialog window to select the part21 file you want to validate appears (see Figure 14).
- Select family1.p21 file from JSDAI Java project ('FamilyJava') and click Open button.

Figure 14. Select the part21 file to validate dialog window

- The lits of errors if any is presented in the:

- Problems panel (see Figure 15). Click on the error line to view the line in the Editor panel.
- Console panel (see Figure 16).

Figure 15. Problems panel with provided validation errors
Figure 16. Console panel with validation results
To top

Copyright © 2005-2008 LKSoftWare GmbH. All Rights Reserved. JSDAI is a registered trade mark of LKSoftWare GmbH.