View Javadoc

1   /*
2    * db2sa: DB2 Syntax Assistant
3    * Copyright (C) Andres Gomez Casanova
4    *
5    * This file is part of db2sa.
6    *
7    * db2sa is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as published by
9    * the Free Software Foundation; either version 3 of the License, or
10   * (at your option) any later version.
11   *
12   * db2sa is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public License
18   * along with this library; if not, see <http://www.gnu.org/licenses/>.
19   *
20   * Contact:
21   * a n g o c a  at  y a h o o  dot  c o m
22   * Cra. 45 No 61 - 31, Bogota, Colombia.
23   *
24   * Author:   $LastChangedBy: angoca $:
25   * Date:     $LastChangedDate: 2009-06-11 23:42:19 +0200 (Thu, 11 Jun 2009) $:
26   * Revision: $LastChangedRevision: 223 $:
27   * URL:      $HeadURL: https://db2sa.svn.sourceforge.net/svnroot/db2sa/branches/db2sa_beta/source-code/src/main/java/name/angoca/db2sa/core/InterfaceCore.java $:
28   */
29  package name.angoca.db2sa.core;
30  
31  import name.angoca.db2sa.ExecutionState;
32  import name.angoca.db2sa.cli.OutputWriter;
33  import name.angoca.db2sa.core.executer.Executer;
34  import name.angoca.db2sa.core.lexical.ImplLexicalAnalyzer;
35  import name.angoca.db2sa.exceptions.AbstractDB2SAException;
36  
37  /**
38   * This class is the interface with other upper layers. This is the only class
39   * that the other layers have to use.<br/>
40   * <b>Control Version</b><br />
41   * <ul>
42   * <li>0.0.1 Class creation.</li>
43   * <li>0.0.2</li>
44   * <li>0.1.0 Organized.</li>
45   * <li>0.1.1 Executer as a singleton.</li>
46   * <li>0.2.0 Execution state.</li>
47   * <li>0.2.1 Enum.</li>
48   * <li>1.0.0 Moved to version 1.</li>
49   * </ul>
50   * 
51   * @author Andres Gomez Casanova <a
52   *         href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a>
53   * @version 1.0.0 2009-07-19
54   */
55  public final class InterfaceCore {
56  
57      /**
58       * Hidden default constructor.
59       */
60      private InterfaceCore() {
61          // Nothing to do. No tests.
62      }
63  
64      /**
65       * Process the phrase written by the user and prints its result.
66       * 
67       * @param phrase
68       *            Phrase to analyze.
69       * @return An object that represents the command completed or the options
70       *         for the current command.
71       * @throws AbstractDB2SAException
72       *             There is a problem in the application.
73       */
74      public static ReturnOptions analyzePhrase(final String/* ! */phrase)
75              throws AbstractDB2SAException {
76          final ReturnOptions ret = ImplLexicalAnalyzer.getInstance()
77                  .processPhrase(phrase);
78          return ret;
79      }
80  
81      /**
82       * Execute the given command. Here, the application does not make a phrase
83       * analyzes and it passes directly the command to the interpreter, that in
84       * this case is DB2.
85       * 
86       * @param command
87       *            The complete command to execute.
88       * @param writer
89       *            The output's writer.
90       * @return The state of the execution of the command.
91       * @throws AbstractDB2SAException
92       *             If any exception occurred while executing.
93       */
94      public static ExecutionState executeCommand(final String/* ! */command,
95              final OutputWriter/* ! */writer) throws AbstractDB2SAException {
96          return Executer.getInstance().execute(command, writer);
97      }
98  }