1 package com.tapina.robe.swi.clib.stdio.printf;
2
3 import com.tapina.robe.runtime.Environment;
4 import com.tapina.robe.swi.clib.VarArgs;
5
6 import java.util.logging.Logger;
7
8 /***
9 * Created by IntelliJ IDEA.
10 * User: gareth
11 * Date: 17-May-2005
12 * Time: 20:01:14
13 * To change this template use File | Settings | File Templates.
14 */
15 public abstract class PrintfEngine {
16 final Logger log = Logger.getLogger(getClass().getName());
17
18 private static PrintfEngine instance;
19
20 public abstract void printf(String formatString, VarArgs va);
21 public abstract String sprintf(String formatString, VarArgs va);
22
23 /***
24 * This method finds the printf implementation by reflection.
25 * This allows us to have multiple implementations which will only load successfully if their required
26 * dependencies are present. Otherwise, they will not load but in all cases the rest of the application
27 * remains decoupled from the dependencies and so will load and run correctly.
28 * @return implementation
29 */
30 public final static PrintfEngine getInstance() {
31 if (instance == null) {
32 synchronized (PrintfEngine.class) {
33 Class impl;
34 try {
35 impl = Class.forName("com.tapina.robe.swi.clib.stdio.printf.Lava3Printf");
36 if (impl != null) {
37 instance = (PrintfEngine) impl.newInstance();
38 }
39 } catch (Exception e) {
40 Logger.getAnonymousLogger().severe("Cannot find printf implementation");
41 throw new RuntimeException(e);
42 }
43 }
44 }
45 return instance;
46 }
47 }