Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/ibatis/sqlmap/client/SqlMapClientBuilder.java


1   /*
2    *  Copyright 2004 Clinton Begin
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  package com.ibatis.sqlmap.client;
17  
18  import com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser;
19  
20  import java.io.Reader;
21  import java.util.Properties;
22  
23  /**
24   * Builds SqlMapClient instances from a supplied resource (e.g. XML configuration file)
25   * <p/>
26   * The SqlMapClientBuilder class is responsible for parsing configuration documents
27   * and building the SqlMapClient instance.  Its current implementation works with
28   * XML configuration files (e.g. sql-map-config.xml).
29   * <p/>
30   * Example:
31   * <pre>
32   * Reader reader = Resources.getResourceAsReader("properties/sql-map-config.xml");
33   * SqlMapClient client = SqlMapClientBuilder.buildSqlMapClient (reader);
34   * </pre>
35   * <p/>
36   * Examples of the XML document structure used by SqlMapClientBuilder can
37   * be found at the links below.
38   * <p/>
39   * Note: They might look big, but they're mostly comments!
40   * <ul>
41   * <li> <a href="sql-map-config.txt">The SQL Map Config File</a>
42   * <li> <a href="sql-map.txt">An SQL Map File</a>
43   * <ul>
44   */
45  public class SqlMapClientBuilder {
46  
47    /**
48     * No instantiation allowed.
49     */
50    private SqlMapClientBuilder() {
51    }
52  
53    /**
54     * Builds an SqlMapClient using the specified reader.
55     *
56     * @param reader A Reader instance that reads an sql-map-config.xml file.
57     *               The reader should read an well formed sql-map-config.xml file.
58     * @return An SqlMapClient instance.
59     */
60    public static SqlMapClient buildSqlMapClient(Reader reader) {
61  //    return new XmlSqlMapClientBuilder().buildSqlMap(reader);
62      return new SqlMapConfigParser().parse(reader);
63    }
64  
65    /**
66     * Builds an SqlMapClient using the specified reader and properties file.
67     * <p/>
68     *
69     * @param reader A Reader instance that reads an sql-map-config.xml file.
70     *               The reader should read an well formed sql-map-config.xml file.
71     * @param props  Properties to be used to provide values to dynamic property tokens
72     *               in the sql-map-config.xml configuration file.  This provides an easy way to
73     *               achieve some level of programmatic configuration.
74     * @return An SqlMapClient instance.
75     */
76    public static SqlMapClient buildSqlMapClient(Reader reader, Properties props) {
77  //    return new XmlSqlMapClientBuilder().buildSqlMap(reader, props);
78      return new SqlMapConfigParser().parse(reader, props);
79    }
80  
81  }