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 ; 7 import org.xml.sax.AttributeList ; 8 import java.sql.*; 9 import javax.xml.transform.TransformerException ; 10 import javax.xml.transform.TransformerConfigurationException ; 11 12 15 16 public class SQLClose extends StyleElement { 17 18 Expression database; 19 Expression driver; 20 Expression user; 21 Expression password; 22 23 27 28 public boolean isInstruction() { 29 return true; 30 } 31 32 36 37 public boolean mayContainTemplateBody() { 38 return true; 39 } 40 41 public void prepareAttributes() throws TransformerConfigurationException { 42 } 43 44 public void validate() throws TransformerConfigurationException { 45 checkWithinTemplate(); 46 } 47 48 public void process( Context context ) throws TransformerException { 49 50 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 | Popular Tags |