J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2005-2006 Sun Microsystems, Inc. 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. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | /* |
| 28 | * The contents of this file are subject to the Sun Public License |
| 29 | * Version 1.0 (the "License"); you may not use this file except in |
| 30 | * compliance with the License. A copy of the License is available at |
| 31 | * http://www.sun.com/, and in the file LICENSE.html in the |
| 32 | * doc directory. |
| 33 | * |
| 34 | * The Original Code is HAT. The Initial Developer of the |
| 35 | * Original Code is Bill Foote, with contributions from others |
| 36 | * at JavaSoft/Sun. Portions created by Bill Foote and others |
| 37 | * at Javasoft/Sun are Copyright (C) 1997-2004. All Rights Reserved. |
| 38 | * |
| 39 | * In addition to the formal license, I ask that you don't |
| 40 | * change the history or donations files without permission. |
| 41 | * |
| 42 | */ |
| 43 | |
| 44 | package com.sun.tools.hat.internal.server; |
| 45 | |
| 46 | import com.sun.tools.hat.internal.model.*; |
| 47 | import com.sun.tools.hat.internal.oql.*; |
| 48 | import com.sun.tools.hat.internal.util.ArraySorter; |
| 49 | import com.sun.tools.hat.internal.util.Comparer; |
| 50 | |
| 51 | /** |
| 52 | * This handles Object Query Language (OQL) queries. |
| 53 | * |
| 54 | * @author A. Sundararajan |
| 55 | */ |
| 56 | |
| 57 | class OQLQuery extends QueryHandler { |
| 58 | |
| 59 | public OQLQuery(OQLEngine engine) { |
| 60 | this.engine = engine; |
| 61 | } |
| 62 | |
| 63 | public void run() { |
| 64 | startHtml("Object Query Language (OQL) query"); |
| 65 | String oql = null; |
| 66 | if (query != null && !query.equals("")) { |
| 67 | int index = query.indexOf("?query="); |
| 68 | if (index != -1 && query.length() > 7) { |
| 69 | oql = query.substring(index + 7); |
| 70 | } |
| 71 | } |
| 72 | out.println("<p align='center'><table>"); |
| 73 | out.println("<tr><td><b>"); |
| 74 | out.println("<a href='/'>All Classes (excluding platform)</a>"); |
| 75 | out.println("</b></td>"); |
| 76 | out.println("<td><b><a href='/oqlhelp/'>OQL Help</a></b></td></tr>"); |
| 77 | out.println("</table></p>"); |
| 78 | out.println("<form action='/oql/' method='get'>"); |
| 79 | out.println("<p align='center'>"); |
| 80 | out.println("<textarea name='query' cols=80 rows=10>"); |
| 81 | if (oql != null) { |
| 82 | out.println(oql); |
| 83 | } |
| 84 | out.println("</textarea>"); |
| 85 | out.println("</p>"); |
| 86 | out.println("<p align='center'>"); |
| 87 | out.println("<input type='submit' value='Execute'></input>"); |
| 88 | out.println("</p>"); |
| 89 | out.println("</form>"); |
| 90 | if (oql != null) { |
| 91 | executeQuery(oql); |
| 92 | } |
| 93 | endHtml(); |
| 94 | } |
| 95 | |
| 96 | private void executeQuery(String q) { |
| 97 | try { |
| 98 | out.println("<table border='1'>"); |
| 99 | engine.executeQuery(q, new ObjectVisitor() { |
| 100 | public boolean visit(Object o) { |
| 101 | out.println("<tr><td>"); |
| 102 | try { |
| 103 | out.println(engine.toHtml(o)); |
| 104 | } catch (Exception e) { |
| 105 | out.println(e.getMessage()); |
| 106 | out.println("<pre>"); |
| 107 | e.printStackTrace(out); |
| 108 | out.println("</pre>"); |
| 109 | } |
| 110 | out.println("</td></tr>"); |
| 111 | return false; |
| 112 | } |
| 113 | }); |
| 114 | out.println("</table>"); |
| 115 | } catch (OQLException exp) { |
| 116 | out.println(exp.getMessage()); |
| 117 | out.println("<pre>"); |
| 118 | exp.printStackTrace(out); |
| 119 | out.println("</pre>"); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | private OQLEngine engine; |
| 124 | } |