diff --git a/src/com/obidea/semantika/cli2/Main.java b/src/com/obidea/semantika/cli2/Main.java index 25f6892..d60ba11 100644 --- a/src/com/obidea/semantika/cli2/Main.java +++ b/src/com/obidea/semantika/cli2/Main.java @@ -2,7 +2,9 @@ import java.io.IOException; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import jline.Terminal; @@ -47,27 +49,28 @@ private void initialize(String config) System.out.print("Initializing..."); //$NON-NLS-1$ try { ApplicationManager manager = new ApplicationFactory().configure(config).createApplicationManager(); - openConsole(manager.createQueryEngine(), - manager.getSettings().getPrefixManager(), - manager.getSettings().getApplicationFactoryName()); + openConsole(manager.getApplicationName(), + manager.createQueryEngine(), + manager.getPrefixManager()); } catch (Exception e) { System.err.println(e.getMessage()); } } - private void openConsole(IQueryEngine engine, IPrefixManager pm, String name) throws Exception + private void openConsole(String consoleName, IQueryEngine engine, IPrefixManager pm) throws Exception { - final TerminalFactory terminalFactory = new TerminalFactory(); - Console console = createInteractiveConsole(name, engine, pm, terminalFactory.get()); + TerminalFactory terminalFactory = new TerminalFactory(); + Map prefixes = new HashMap(pm.getPrefixMapper()); + Console console = createInteractiveConsole(consoleName, engine, prefixes, terminalFactory.get()); console.run(); } - private Console createInteractiveConsole(String name, IQueryEngine engine, IPrefixManager pm, + private Console createInteractiveConsole(String name, IQueryEngine engine, Map prefixes, Terminal terminal) throws IOException { showBanner(); - return new Console(name, engine, pm, terminal); + return new Console(name, engine, prefixes, terminal); } private void showBanner() diff --git a/src/com/obidea/semantika/cli2/command/SelectCommand.java b/src/com/obidea/semantika/cli2/command/SelectCommand.java index e618533..48ba55c 100644 --- a/src/com/obidea/semantika/cli2/command/SelectCommand.java +++ b/src/com/obidea/semantika/cli2/command/SelectCommand.java @@ -28,8 +28,8 @@ public Object execute() throws Exception private String createSelectQuery() { StringBuilder sb = new StringBuilder(); - for (String prefix : mSession.getPrefixMapper().keySet()) { - sb.append(format("PREFIX %s: <%s>", prefix, mSession.getPrefixMapper().get(prefix))); + for (String prefix : mSession.getPrefixes().keySet()) { + sb.append(format("PREFIX %s: <%s>", prefix, mSession.getPrefixes().get(prefix))); sb.append("\n"); } sb.append(mCommand); diff --git a/src/com/obidea/semantika/cli2/command/SetPrefixCommand.java b/src/com/obidea/semantika/cli2/command/SetPrefixCommand.java index f5f5bd2..1a2205c 100644 --- a/src/com/obidea/semantika/cli2/command/SetPrefixCommand.java +++ b/src/com/obidea/semantika/cli2/command/SetPrefixCommand.java @@ -32,7 +32,7 @@ public SetPrefixCommand(String command, ConsoleSession session) throws InvalidSy @Override public Object execute() throws Exception { - mSession.getPrefixMapper().put(mPrefix, mNamespace); + mSession.getPrefixes().put(mPrefix, mNamespace); return "Prefix added."; //$NON-NLS-1$ } diff --git a/src/com/obidea/semantika/cli2/command/ShowPrefixesCommand.java b/src/com/obidea/semantika/cli2/command/ShowPrefixesCommand.java index eb2c92b..0502447 100644 --- a/src/com/obidea/semantika/cli2/command/ShowPrefixesCommand.java +++ b/src/com/obidea/semantika/cli2/command/ShowPrefixesCommand.java @@ -18,7 +18,7 @@ public ShowPrefixesCommand(String command, ConsoleSession session) @Override public Object execute() throws Exception { - return mSession.getPrefixMapper(); + return mSession.getPrefixes(); } @Override diff --git a/src/com/obidea/semantika/cli2/runtime/Console.java b/src/com/obidea/semantika/cli2/runtime/Console.java index 0ae590d..27a6fa7 100644 --- a/src/com/obidea/semantika/cli2/runtime/Console.java +++ b/src/com/obidea/semantika/cli2/runtime/Console.java @@ -5,6 +5,7 @@ import java.io.InputStream; import java.io.InterruptedIOException; import java.io.PrintStream; +import java.util.Map; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; @@ -13,7 +14,6 @@ import jline.console.history.FileHistory; import jline.console.history.PersistentHistory; -import com.obidea.semantika.knowledgebase.IPrefixManager; import com.obidea.semantika.queryanswer.IQueryEngine; public class Console @@ -36,20 +36,20 @@ public class Console private ConsoleReader mConsoleReader; private ConsoleSession mConsoleSession; - public Console(String name, IQueryEngine engine, IPrefixManager pm, Terminal terminal) throws IOException + public Console(String name, IQueryEngine engine, Map prefixes, Terminal terminal) throws IOException { - this(name, engine, pm, System.in, System.out, System.err, terminal); + this(name, engine, prefixes, System.in, System.out, System.err, terminal); } - public Console(String name, IQueryEngine engine, IPrefixManager pm, InputStream inputSource, PrintStream outputTarget, - PrintStream errorTarget, Terminal terminal) throws IOException + public Console(String name, IQueryEngine engine, Map prefixes, InputStream inputSource, + PrintStream outputTarget, PrintStream errorTarget, Terminal terminal) throws IOException { mConsoleName = name; mInputStream = inputSource; mOutputStream = outputTarget; mErrorStream = errorTarget; mConsoleReader = createConsoleReader(name, terminal); - mConsoleSession = new ConsoleSession(engine, pm); + mConsoleSession = new ConsoleSession(engine, prefixes); mPipeThread = new Thread(new Pipe()); mPipeThread.setDaemon(true); } diff --git a/src/com/obidea/semantika/cli2/runtime/ConsoleSession.java b/src/com/obidea/semantika/cli2/runtime/ConsoleSession.java index 79eb37c..49b920f 100644 --- a/src/com/obidea/semantika/cli2/runtime/ConsoleSession.java +++ b/src/com/obidea/semantika/cli2/runtime/ConsoleSession.java @@ -1,24 +1,22 @@ package com.obidea.semantika.cli2.runtime; -import java.util.HashMap; import java.util.Map; import com.obidea.semantika.cli2.command.Command; import com.obidea.semantika.cli2.command.CommandFactory; -import com.obidea.semantika.knowledgebase.IPrefixManager; import com.obidea.semantika.queryanswer.IQueryEngine; public class ConsoleSession { private IQueryEngine mQueryEngine; - private Map mPrefixMapper; + private Map mPrefixes; private Command mCommand; - public ConsoleSession(IQueryEngine engine, IPrefixManager prefixManager) + public ConsoleSession(IQueryEngine engine, Map prefixes) { mQueryEngine = engine; - mPrefixMapper = new HashMap(prefixManager.getPrefixMapper()); + mPrefixes = prefixes; } public void start() throws Exception @@ -31,9 +29,9 @@ public IQueryEngine getQueryEngine() return mQueryEngine; } - public Map getPrefixMapper() + public Map getPrefixes() { - return mPrefixMapper; + return mPrefixes; } public Object execute(String command) throws Exception