Sudoku Generator (Example for the OSGi Lab)

From CDOT Wiki
Revision as of 20:02, 13 February 2011 by Selmys (talk | contribs) (Sudoku Generator (Example for the OSGi Lab))
Jump to: navigation, search

Sudoku Generator (Example for the OSGi Lab)

This is my first attempt to build a simple Java application using the OSGi framework.

Some time ago I wrote a Sudoku Generator program using BASH version 4. You can find the code on my blog at selmys.wordpress.com. I've chosen this same example to rewrite in Java/OSGi.

Yes, I know my code (and lack of documentation) is sloppy. That's because I tried to focus on trying to figure out what goes into each bundle. I'm sure I got many things wrong but on the positive side, the code works and actually generates a 9x9 Sudoku puzzle, albeit on the console in text mode. Perhaps in the future I'll produce a GUI output - or maybe someone can do it for me?

Design and Implementation

First, let me say that I followed Jordan's Voting System example, for both the code as well as the writeup on this wiki.

1. Define the Service

Create the bundle ca.on.senecac.scs.sudoku

1.1 Create SudokuGenerator.java
package ca.on.senecac.scs.sudoku;

/**
 * Defines the interface to the Sudoku Generator OSGi-based
 * application.
 *
 * @author John Selmys
 *
 */
public interface SudokuGenerator {
    void generate(int row, int col);
}
1.2 Define the MANIFEST.MF for the service
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Sudoku
Bundle-SymbolicName: ca.on.senecac.scs.sudoku
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: ca.on.senecac.scs.sudoku