/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* The Original Code is HAT. The Initial Developer of the
* Original Code is Bill Foote, with contributions from others
*/
/**
* This is Object Query Language Interpreter
*
*/
public class OQLEngine {
static {
try {
// Do we have javax.script support?
// create ScriptEngineManager
// create JavaScript engine
oqlSupported = false;
}
}
// check OQL is supported or not before creating OQLEngine
public static boolean isOQLSupported() {
return oqlSupported;
}
if (!isOQLSupported()) {
throw new UnsupportedOperationException("OQL not supported");
}
}
/**
Query is of the form
select <java script code to select>
[ from [instanceof] <class name> [<identifier>]
[ where <java script boolean expression> ]
]
*/
throws OQLException {
if (st.hasMoreTokens()) {
// Query does not start with 'select' keyword.
// Just treat it as plain JavaScript and eval it.
try {
} catch (Exception e) {
throw new OQLException(e);
}
return;
}
} else {
throw new OQLException("query syntax error: no 'select' clause");
}
boolean seenFrom = false;
while (st.hasMoreTokens()) {
seenFrom = true;
break;
}
}
throw new OQLException("query syntax error: 'select' expression can not be empty");
}
boolean isInstanceOf = false;
if (seenFrom) {
if (st.hasMoreTokens()) {
isInstanceOf = true;
if (! st.hasMoreTokens()) {
throw new OQLException("no class name after 'instanceof'");
}
} else {
}
} else {
throw new OQLException("query syntax error: class name must follow 'from'");
}
if (st.hasMoreTokens()) {
throw new OQLException("query syntax error: identifier should follow class name");
}
if (st.hasMoreTokens()) {
throw new OQLException("query syntax error: 'where' clause expected after 'from' clause");
}
whereExpr = "";
while (st.hasMoreTokens()) {
}
throw new OQLException("query syntax error: 'where' clause cannot have empty expression");
}
}
} else {
throw new OQLException("query syntax error: identifier should follow class name");
}
}
}
throws OQLException {
}
}
if (q.identifier != null) {
}
buf = new StringBuffer();
}
// compile select expression and where condition
try {
}
while (objects.hasMoreElements()) {
if (!b) {
} else {
}
}
if (b) {
}
}
} else {
// simple "select <expr>" query
}
} catch (Exception e) {
throw new OQLException(e);
}
}
}
}
}
}
}
try {
// create ScriptEngineManager
// create JavaScript engine
// initialize engine with init file (hat.js)
// initialize ScriptEngine.eval(String) and
// Invocable.invokeFunction(String, Object[]) methods.
// initialize ScriptEngine.put(String, Object) method
// call ScriptEngine.put to initialize built-in heap object
});
} catch (Exception e) {
if (debug) e.printStackTrace();
throw new RuntimeException(e);
}
}
}
private static boolean debug = false;
private static boolean oqlSupported;
}