| 1 55 package org.lateralnz.common.cli; 56 57 import java.io.*; 58 import java.util.HashMap ; 59 60 import org.lateralnz.common.util.Constants; 61 62 public class CLInterfaceFactory implements Constants { 63 private static final CLInterfaceFactory clif = new CLInterfaceFactory(); 64 65 private HashMap interfaces = new HashMap (); 66 67 private CLInterfaceFactory() { 68 } 69 70 public static final CLInterfaceFactory getInstance() { 71 return clif; 72 } 73 74 75 public final CLInterface getCLInterface(String name, String prompt, CLIOHandler ioh) { 76 String key = name + UNDERSCORE + prompt; 77 if (!interfaces.containsKey(key)) { 78 synchronized (interfaces) { 79 if (!interfaces.containsKey(key)) { 80 interfaces.put(key, new CLInterface(prompt, ioh)); 81 } 82 } 83 } 84 return (CLInterface)interfaces.get(key); 85 } 86 87 88 public static final void main(String [] args) { 89 try { 90 CLIOHandler ioh = new CLStdIOHandler(); 91 ioh.setPrompt(">"); 92 93 CLInterface cli = CLInterfaceFactory.getInstance().getCLInterface("main", ">", ioh); 94 95 CLTemplate template = cli.parse("test.xml"); 96 97 HashMap hm = new HashMap (); 98 template.process(new BufferedReader(new InputStreamReader(System.in)), System.out, hm, new VStdString(), false); 99 100 } 101 catch (Exception e) { 102 e.printStackTrace(); 103 } 104 } 105 } 106 | Popular Tags |