Java Reference
In-Depth Information
4.4.2 Optionally Replaceable Module
The optionally replaceable module approach implies that your JAR
includes more than a single implementation of the required module
(see Figure 4.10). The solution design is similar to the previous case
but there is a fallback mechanism and the run-time module can be
replaced by more than one implementation, so more than one module
implementation would reside in the JAR.
Impl 2
Interface
App core
Im p l1
Java ME
JSR 1
JSR 2
Figure 4.10 Implementation of optionally replaceable module
A possible usage of this solution is to implement the model-view-
controller (MVC) design pattern with more than one view module. In
the JAR, there would be two or more implementations of the application
view, each using a different JSR. For example, one implementation may
use JSR-226 SVG, another implementation may use JSR-184 3D Graphics,
and a third implementation may use Canvas:
private void loadUiModule() {
// first attempt - JSR-226 SVG
try {
Class c = Class.forName("javax.microedition.m2g.SVGAnimator");
// TODO: load SVG implementation of UI
ui = new UiModuleSVG();
} catch (ClassNotFoundException e)
{
// JSR-226 SVG is not supported
} // fallback option 1 - JSR-184 3D
if (ui == null)
{
try {
Class c = Class.forName("javax.microedition.m3g.Graphics3D");
// TODO: load 3D implementation of UI
ui = new UiModule3D();
} catch (ClassNotFoundException e) {
// JSR-184 3D is not supported (unlikely in Symbian OS!)
}
} // last fallback option - MIDP LCDUI
if (ui == null) {
ui = new UiModuleLCD();
}
}
 
Search WWH ::




Custom Search