KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ExternalConnection


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ExternalConnection.java,v 1.6 2004/02/17 19:14:20 minchau Exp $
18  */

19 // Imported TraX classes
20
import javax.xml.transform.TransformerFactory JavaDoc;
21 import javax.xml.transform.Transformer JavaDoc;
22 import javax.xml.transform.stream.StreamSource JavaDoc;
23 import javax.xml.transform.stream.StreamResult JavaDoc;
24 import javax.xml.transform.TransformerException JavaDoc;
25 import javax.xml.transform.TransformerConfigurationException JavaDoc;
26
27 import org.apache.xalan.lib.sql.DefaultConnectionPool;
28 import org.apache.xalan.lib.sql.ConnectionPoolManager;
29
30
31 // Imported java classes
32
import java.io.StringReader JavaDoc;
33 import java.io.FileOutputStream JavaDoc;
34 import java.io.FileNotFoundException JavaDoc;
35 import java.io.IOException JavaDoc;
36
37 /**
38  * Use the TraX interface to perform a transformation in the simplest manner possible
39  * (3 statements).
40  */

41 public class ExternalConnection
42 {
43     public static void main(String JavaDoc[] args)
44     throws TransformerException JavaDoc, TransformerConfigurationException JavaDoc,
45            FileNotFoundException JavaDoc, IOException JavaDoc
46   {
47
48   // Create a connection to the database server
49
// Up the connection pool count for testing
50
DefaultConnectionPool cp = new DefaultConnectionPool();
51   cp.setDriver("org.enhydra.instantdb.jdbc.idbDriver");
52   cp.setURL("jdbc:idb:../../instantdb/sample.prp");
53   //cp.setUser("sa");
54
//cp.setPassword("");
55
cp.setMinConnections(10);
56   cp.setPoolEnabled(true);
57
58   // Now let's register our connection pool so we can use
59
// in a stylesheet
60
ConnectionPoolManager pm = new ConnectionPoolManager();
61   pm.registerPool("extpool", cp);
62
63
64   // Use the static TransformerFactory.newInstance() method to instantiate
65
// a TransformerFactory. The javax.xml.transform.TransformerFactory
66
// system property setting determines the actual class to instantiate --
67
// org.apache.xalan.transformer.TransformerImpl.
68
TransformerFactory JavaDoc tFactory = TransformerFactory.newInstance();
69
70     // Use the TransformerFactory to instantiate a Transformer that will work with
71
// the stylesheet you specify. This method call also processes the stylesheet
72
// into a compiled Templates object.
73
Transformer JavaDoc transformer = tFactory.newTransformer(
74         new StreamSource JavaDoc("dbtest.xsl"));
75
76     // For this transformation, all the required information is in the stylesheet, so generate
77
// a minimal XML source document for the input.
78
// Note: the command-line processor (org.apache.xalan.xslt.Process) uses this strategy when
79
// the user does not provide an -IN parameter.
80
StringReader JavaDoc reader =
81               new StringReader JavaDoc("<?xml version=\"1.0\"?> <doc/>");
82
83   // Use the Transformer to apply the associated Templates object to an XML document
84
// and write the output to a file.
85
transformer.transform(
86         new StreamSource JavaDoc(reader),
87         new StreamResult JavaDoc(new FileOutputStream JavaDoc("dbtest-out.html")));
88
89     System.out.println("************* The result is in dbtest-out.html *************");
90   
91   cp.setPoolEnabled(false);
92   }
93 }
94
Popular Tags