# JUDE API User Guide

## [How to create models]

We will show you how to create JUDE models with a sample program in this paragraph.
Please refer to JUDE API JavaDoc for details of each interface and method.
Create function of JUDE API is not available in JUDE/Community.

#### [Transaction Operation]

Transaction operation is required when creating or editing models in JUDE API. Please use methods in TransacionManager (e.g. beginTransaction()) to add transaction operations in your program.

#### [Create models in ER Diagram]

Models in ER Diagram (e.g. ER Entity) can be created by using methods in ERModelEditor (e.g. createEREntity()).

#### [Create models in Class Diagram]

Models in Class Diagram (e.g. Class) can be created by using methods in BasicModelEditor (e.g. createClass()).

#### [Create models in UseCase Diagram]

Models in UseCase Diagram (e.g. UseCase) can be created by using methods in UsseCaseModelEditor (e.g. createUseCase()).

#### [Create models in Mind Map]

Topic in Mind Map can be created by using methods in MindmapDiagramEditor (e.g. addChild()).

#### [Example of creating models in Class Diagram]

Create a package and two classes, and then add an association between classes.

    public class APIForEditingModelsSample {

        public static void main(String[] args) {

            try {
                System.out.println("Creating new project...");

                // Create a project and get a root model
                ProjectAccessor prjAccessor = ProjectAccessorFactory.getProjectAccessor();
                prjAccessor.create("./SampleModel.jude");
                IModel project = prjAccessor.getProject();

                System.out.println("Creating new elements in the project...");

                // Begin transaction when creating or editing models
                TransactionManager.beginTransaction();

                // Get model editor to create models in a class diagram
                BasicModelEditor basicModelEditor = ModelEditorFactory.getBasicModelEditor();

                // Create a package
                IPackage packageA = basicModelEditor.createPackage(project, "PackageA");

                // Create a class in the specified package
                IClass classA = basicModelEditor.createClass(packageA, "ClassA");
                // Add a definition to the class
                classA.setDefinition("Definition of ClassA");
                // Add an attribute to the class
                basicModelEditor.createAttribute(classA, "attribute0", "int");
                // Add an operation to the class
                basicModelEditor.createOperation(classA, "operation0", "void");

                // Create a class in the specified package
                IClass classB = basicModelEditor.createClass(packageA, "ClassB");

                // Add an association between classes
                basicModelEditor.createAssociation(classA, classB, "association name",
                        "classA end", "classB end");

                // End transaction
                TransactionManager.endTransaction();

                // Save project
                prjAccessor.save();

                // Close project
                prjAccessor.close();

                System.out.println("Finished");

            } catch (LicenseNotFoundException e) {
                e.printStackTrace();
            } catch (ProjectNotFoundException e) {
                e.printStackTrace();
            } catch (ProjectLockedException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InvalidEditingException e) {
                // Abort transaction
                TransactionManager.abortTransaction();
                // Get an exception message
                System.err.println(e.getMessage());
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }

Home