KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > sql > SQLClose


1 package com.icl.saxon.sql;
2 import com.icl.saxon.*;
3 import com.icl.saxon.om.NodeInfo;
4 import com.icl.saxon.style.*;
5 import com.icl.saxon.expr.*;
6 import org.xml.sax.SAXException JavaDoc;
7 import org.xml.sax.AttributeList JavaDoc;
8 import java.sql.*;
9 import javax.xml.transform.TransformerException JavaDoc;
10 import javax.xml.transform.TransformerConfigurationException JavaDoc;
11
12 /**
13 * An sql:close element in the stylesheet.<BR>
14 */

15
16 public class SQLClose extends StyleElement {
17
18     Expression database;
19     Expression driver;
20     Expression user;
21     Expression password;
22
23     /**
24     * Determine whether this node is an instruction.
25     * @return true - it is an instruction
26     */

27
28     public boolean isInstruction() {
29         return true;
30     }
31
32     /**
33     * Determine whether this type of element is allowed to contain a template-body
34     * @return true: yes, it may contain a template-body
35     */

36
37     public boolean mayContainTemplateBody() {
38         return true;
39     }
40
41     public void prepareAttributes() throws TransformerConfigurationException JavaDoc {
42     }
43
44     public void validate() throws TransformerConfigurationException JavaDoc {
45         checkWithinTemplate();
46     }
47
48     public void process( Context context ) throws TransformerException JavaDoc {
49
50         // Prepare the SQL statement
51

52         NodeInfo sourceDoc = (context.getCurrentNodeInfo()).getDocumentRoot();
53         Connection connection = (Connection)context.getController().getUserData(
54                                               sourceDoc, "sql:connection");
55         if (connection==null) {
56             throw styleError("No SQL connection has been established");
57         }
58         
59         try {
60             connection.close();
61         } catch (SQLException ex) {
62             throw styleError("(SQL) Failed to close connection: " + ex.getMessage());
63         }
64     }
65 }
66
67 //
68
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
69
// you may not use this file except in compliance with the License. You may obtain a copy of the
70
// License at http://www.mozilla.org/MPL/
71
//
72
// Software distributed under the License is distributed on an "AS IS" basis,
73
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
74
// See the License for the specific language governing rights and limitations under the License.
75
//
76
// The Original Code is: all this file.
77
//
78
// The Initial Developer of the Original Code is
79
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
80
//
81
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
82
//
83
// Additional Contributor(s): Rick Bonnett [rbonnett@acadia.net]
84
//
85
Popular Tags