Developing with the SDK > Using and Writing Data Models > JavaBeans Example > The Phenol Molecule Data Source

The classes and methods of the Molecule example represent a molecule so that the diagram component can display it. To display a specific molecule, you need to load the Molecule instance from a data source.

Code Sample 2.7 shows a data source that contains a Phenol molecule. This class is a subclass of IlvDiagrammerDataSource.

public class PhenolMoleculeDataSource extends IlvDiagrammerDataSource
{ ...

Code Sample 2.7 The Data Source Class

The Read Method

To load a data source into a diagram component, call its read method, which is shown in Code Sample 2.8.

public void read(IlvDiagrammer diagrammer) throws IlvDiagrammerException
  {
    Molecule phenol = Molecule.createPhenolMolecule();
    MoleculeModel model = new MoleculeModel(phenol);
    diagrammer.getEngine().setModel(model);
  }

Code Sample 2.8 A Method to Read a Data Source

The code lines in the read method are as follows:

  1. Create the phenol Molecule instance with a static method for this purpose.
  2. Wrap the Molecule instance into the molecule model.
  3. Load the new model into the diagram component.

Empty Methods

The data source class has other methods which must be implemented because they are abstract, but they do nothing. Code Sample 2.9 shows these methods.

  public void write(IlvDiagrammer diagrammer)
          throws IlvDiagrammerException
  {
  }

  protected void serializeImpl(Element element) 
          throws IlvDiagrammerException
  {
  }

  protected void deserializeImpl(Element element)
          throws IlvDiagrammerException
  {
  }

Code Sample 2.9 Implementation of Unused Abstract Methods

The write method is not needed because the molecule data cannot be written.

The serialize method is not needed because there is no need to write any additional information to define the data source in a project file.

The deserialize method is not needed because there is no need to read any additional information to load the data source from a project file.