Showing the changes to java/pkg/com/sun/tools/hat/internal/server/OQLQuery.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,113 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | |||
| 27 | /* | ||
| 28 | * The Original Code is HAT. The Initial Developer of the | ||
| 29 | * Original Code is Bill Foote, with contributions from others | ||
| 30 | * at JavaSoft/Sun. | ||
| 31 | */ | ||
| 32 | |||
| 33 | package com.sun.tools.hat.internal.server; | ||
| 34 | |||
| 35 | import com.sun.tools.hat.internal.model.*; | ||
| 36 | import com.sun.tools.hat.internal.oql.*; | ||
| 37 | import com.sun.tools.hat.internal.util.ArraySorter; | ||
| 38 | import com.sun.tools.hat.internal.util.Comparer; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * This handles Object Query Language (OQL) queries. | ||
| 42 | * | ||
| 43 | * @author A. Sundararajan | ||
| 44 | */ | ||
| 45 | |||
| 46 | class OQLQuery extends QueryHandler { | ||
| 47 | |||
| 48 | public OQLQuery(OQLEngine engine) { | ||
| 49 | this.engine = engine; | ||
| 50 | } | ||
| 51 | |||
| 52 | public void run() { | ||
| 53 | startHtml("Object Query Language (OQL) query"); | ||
| 54 | String oql = null; | ||
| 55 | if (query != null && !query.equals("")) { | ||
| 56 | int index = query.indexOf("?query="); | ||
| 57 | if (index != -1 && query.length() > 7) { | ||
| 58 | oql = query.substring(index + 7); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | out.println("<p align='center'><table>"); | ||
| 62 | out.println("<tr><td><b>"); | ||
| 63 | out.println("<a href='/'>All Classes (excluding platform)</a>"); | ||
| 64 | out.println("</b></td>"); | ||
| 65 | out.println("<td><b><a href='/oqlhelp/'>OQL Help</a></b></td></tr>"); | ||
| 66 | out.println("</table></p>"); | ||
| 67 | out.println("<form action='/oql/' method='get'>"); | ||
| 68 | out.println("<p align='center'>"); | ||
| 69 | out.println("<textarea name='query' cols=80 rows=10>"); | ||
| 70 | if (oql != null) { | ||
| 71 | out.println(oql); | ||
| 72 | } | ||
| 73 | out.println("</textarea>"); | ||
| 74 | out.println("</p>"); | ||
| 75 | out.println("<p align='center'>"); | ||
| 76 | out.println("<input type='submit' value='Execute'></input>"); | ||
| 77 | out.println("</p>"); | ||
| 78 | out.println("</form>"); | ||
| 79 | if (oql != null) { | ||
| 80 | executeQuery(oql); | ||
| 81 | } | ||
| 82 | endHtml(); | ||
| 83 | } | ||
| 84 | |||
| 85 | private void executeQuery(String q) { | ||
| 86 | try { | ||
| 87 | out.println("<table border='1'>"); | ||
| 88 | engine.executeQuery(q, new ObjectVisitor() { | ||
| 89 | public boolean visit(Object o) { | ||
| 90 | out.println("<tr><td>"); | ||
| 91 | try { | ||
| 92 | out.println(engine.toHtml(o)); | ||
| 93 | } catch (Exception e) { | ||
| 94 | out.println(e.getMessage()); | ||
| 95 | out.println("<pre>"); | ||
| 96 | e.printStackTrace(out); | ||
| 97 | out.println("</pre>"); | ||
| 98 | } | ||
| 99 | out.println("</td></tr>"); | ||
| 100 | return false; | ||
| 101 | } | ||
| 102 | }); | ||
| 103 | out.println("</table>"); | ||
| 104 | } catch (OQLException exp) { | ||
| 105 | out.println(exp.getMessage()); | ||
| 106 | out.println("<pre>"); | ||
| 107 | exp.printStackTrace(out); | ||
| 108 | out.println("</pre>"); | ||
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | private OQLEngine engine; | ||
| 113 | } | ||