Home > Android, Java, Softwate Development, Uncategorized > Application Engineering – Requirements Gathering Part 5

Application Engineering – Requirements Gathering Part 5

Model Implementation and Testing

This post is in reference to Project Assignment 4 for my graduate course COT6930; Android Components.

As the previous three parts on this series, this post is also based on the book “EMF Eclipse Modeling Framework”.

Links for the other parts are: Part one, Part two, Part three and Part four.

On Part four of this series, we had our model ready to produce java code with the EMF generator model (see Part 4). Now we will produce the java classes described in our System Class Diagram.  This process will also follows the excellent EMF tutorial by Vogella.com.

Right click on the root node of the .genmodel file ans select “Generate Model Code”.  After generating the java classes, there are some adjustments to place the android.graphics.Bitmap reference on the path. The following steps is required to compile the new classes:

  • Select: Project->Properties->Java Build Path->Libraries->Add Library->Android Classpath Container
  • Then set the path to the android.jar of the correct target platform. See screen shot below.
  • An error may still remain about the proper android target. Create a new file on the project root named project.properties, and add a single line in the file with “target=android-10”. Or with the correct target version.

Adding the android library

Adding Android Library

Steps to add the android.jar library to the project

Important details that caused me a lot of aggravation with ‘Access Restrictions’.

Do not export the ‘required plug-in dependencies’ container, nor the android.jar library on Project->Properties->Java Build Path->Order and Export. Instead add the android jar on each plug-in on created projects.

Do not export the plug-in dependencies

Do not export the plug-in dependencies

Also make sure all the classes from your model are exported. Double click on MANIFEST.MF and click on ‘Runtime’.

Export all generated classes

Export all generated classes

Below is the resulting Java classes.

EMF Generated Java Classes

EMF Generated Java Classes

Testing the model code

Finally we run a verification of the generated code to be certain that the model works. This test, as everything else, continues to follow Vogella.com tutorial.

I created the following test class on a new project called edu.fau.emf.ocr.model.usingmodel:

package edu.fau.emf.ocr.model.usingmodel;

import edu.fau.emf.ocr.model.ocr.OcrApi;
import edu.fau.emf.ocr.model.ocr.OcrFactory;
import edu.fau.emf.ocr.model.ocr.ProcessOcr;
import edu.fau.emf.ocr.model.ocr.impl.OcrPackageImpl;

/**
 * Test of EMF Model <a class="zem_slink" title="Optical character recognition" href="http://en.wikipedia.org/wiki/Optical_character_recognition" rel="wikipedia" target="_blank">OCR</a>
 * <p> This class exercises the model creation inside a plug-in project
 * @author "Gabriel Novak"
 *
 */
public class UsingEMFModel {

	public static void main(String[] args) {
		OcrPackageImpl.init();
		// Retrieve the default factory singleton
		OcrFactory factory = OcrFactory.eINSTANCE;

		// Create instance of OcrAPi
		OcrApi ocr = factory.createOcrApi();
		ocr.setResultText("Hello From OCR API");

		// Create instance of ProcessOcr
		ProcessOcr process = factory.createProcessOcr();
		process.setResultText("Hello From Process OCR");

		//Display values
		System.out.println("Sample Display from OCR EMF Model");
		System.out.println(ocr.getResultText());
		System.out.println(process.getResultText());
		System.out.println("THE END");
	}
}

This is the resulting console after running the project:

Sample Display from OCR EMF Model
Hello From OCR API
Hello From Process OCR
THE END

This is the end of this phase on this phase. The model works, now the job will became more intense with the actual Android implementation. To be continued.

  1. August 9, 2012 at 10:04 am

    Hi Gabriel,

    Thanks for sharing how to load the android.jar

    That’s the only way I could seem to get it to work, Thanks again!
    -Rich

    • August 9, 2012 at 12:34 pm

      You are welcome Rich. Glad to be of help, after all that is the purpose of our posts, right?
      Hope that you had a good grade on the course.

  1. May 6, 2014 at 10:23 pm
  2. August 3, 2012 at 12:08 am
  3. July 30, 2012 at 11:55 pm

Leave a comment