Implementing the connector

In previous steps, you declared a new model connector to MDWorkbench. Now you have to provide the implementation of this connector using Java code.

To define the connector implementation:

  1. Click on File > New > Class
  2. Type a package name (e.g. com.sodius.mdw.example.library) in the Package name field.
  3. Type a class name (e.g. MyReader) in the Name field. This is the name of the Java class that will define the implementation of your model connector.
  4. Click on Add..., on the right of the Interfaces list.
  5. Type ModelReader (or ModelWriter) and click OK.
  6. Back in the Java class wizard, click on Finish.
  7. Change the body of the created Java class and click on File > Save.
    package com.sodius.mdw.example.library;
    
    import com.sodius.mdw.core.CoreException;
    import com.sodius.mdw.core.model.Model;
    import com.sodius.mdw.core.model.io.ConnectorContext;
    import com.sodius.mdw.core.model.io.ModelReader;
    import com.sodius.mdw.metamodel.library.Book;
    import com.sodius.mdw.metamodel.library.Writer;
    
    public class MyReader implements ModelReader {
    
        public void read(String uri, Model model, ConnectorContext context)
                throws CoreException {
    
            // create a Writer
            Writer writer = (Writer) model.create("Writer");
            writer.setName("William Shakespeare");
    		
            // create a Book
            Book book = (Book) model.create("Book");
            book.setTitle("King Lear");
            book.setAuthor(writer);
        }
    }
  8. Refer to the Javadoc of ModelReader or ModelWriter for details on the contents of a model connector.

Related reference
ModelReader API
ModelWriter API