Difference between revisions of "Sudoku Generator (Example for the OSGi Lab)"
(Created page with '== 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 …') |
(→Sudoku Generator (Example for the OSGi Lab)) |
||
Line 5: | Line 5: | ||
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? | 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. | ||
+ | |||
+ | <h4>1. Define the Service</h4> | ||
+ | Create the bundle ''ca.on.senecac.scs.sudoku'' | ||
+ | <h6>1.1 Create SudokuGenerator.java</h6> | ||
+ | <source lang="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); | ||
+ | } | ||
+ | </source> | ||
+ | <h6>1.2 Define the MANIFEST.MF for the service</h6> | ||
+ | <source lang="xml"> | ||
+ | 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 | ||
+ | </source> |
Revision as of 19:02, 13 February 2011
Contents
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