001: /*
002: * Copyright 2004 Clinton Begin
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package com.ibatis.sqlmap.client;
017:
018: import com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser;
019:
020: import java.io.InputStream;
021: import java.io.Reader;
022: import java.util.Properties;
023:
024: /**
025: * Builds SqlMapClient instances from a supplied resource (e.g. XML configuration file)
026: * <p/>
027: * The SqlMapClientBuilder class is responsible for parsing configuration documents
028: * and building the SqlMapClient instance. Its current implementation works with
029: * XML configuration files (e.g. sql-map-config.xml).
030: * <p/>
031: * Example:
032: * <pre>
033: * Reader reader = Resources.getResourceAsReader("properties/sql-map-config.xml");
034: * SqlMapClient client = SqlMapClientBuilder.buildSqlMapClient (reader);
035: * </pre>
036: * <p/>
037: * Examples of the XML document structure used by SqlMapClientBuilder can
038: * be found at the links below.
039: * <p/>
040: * Note: They might look big, but they're mostly comments!
041: * <ul>
042: * <li> <a href="sql-map-config.txt">The SQL Map Config File</a>
043: * <li> <a href="sql-map.txt">An SQL Map File</a>
044: * <ul>
045: */
046: public class SqlMapClientBuilder {
047:
048: /**
049: * No instantiation allowed.
050: */
051: protected SqlMapClientBuilder() {
052: }
053:
054: /**
055: * Builds an SqlMapClient using the specified reader.
056: *
057: * @param reader A Reader instance that reads an sql-map-config.xml file.
058: * The reader should read an well formed sql-map-config.xml file.
059: * @return An SqlMapClient instance.
060: */
061: public static SqlMapClient buildSqlMapClient(Reader reader) {
062: // return new XmlSqlMapClientBuilder().buildSqlMap(reader);
063: return new SqlMapConfigParser().parse(reader);
064: }
065:
066: /**
067: * Builds an SqlMapClient using the specified reader and properties file.
068: * <p/>
069: *
070: * @param reader A Reader instance that reads an sql-map-config.xml file.
071: * The reader should read an well formed sql-map-config.xml file.
072: * @param props Properties to be used to provide values to dynamic property tokens
073: * in the sql-map-config.xml configuration file. This provides an easy way to
074: * achieve some level of programmatic configuration.
075: * @return An SqlMapClient instance.
076: */
077: public static SqlMapClient buildSqlMapClient(Reader reader,
078: Properties props) {
079: // return new XmlSqlMapClientBuilder().buildSqlMap(reader, props);
080: return new SqlMapConfigParser().parse(reader, props);
081: }
082:
083: /**
084: * Builds an SqlMapClient using the specified input stream.
085: *
086: * @param inputStream An InputStream instance that reads an sql-map-config.xml file.
087: * The stream should read a well formed sql-map-config.xml file.
088: * @return An SqlMapClient instance.
089: */
090: public static SqlMapClient buildSqlMapClient(InputStream inputStream) {
091: return new SqlMapConfigParser().parse(inputStream);
092: }
093:
094: /**
095: * Builds an SqlMapClient using the specified input stream and properties file.
096: * <p/>
097: *
098: * @param inputStream An InputStream instance that reads an sql-map-config.xml file.
099: * The stream should read an well formed sql-map-config.xml file.
100: * @param props Properties to be used to provide values to dynamic property tokens
101: * in the sql-map-config.xml configuration file. This provides an easy way to
102: * achieve some level of programmatic configuration.
103: * @return An SqlMapClient instance.
104: */
105: public static SqlMapClient buildSqlMapClient(
106: InputStream inputStream, Properties props) {
107: return new SqlMapConfigParser().parse(inputStream, props);
108: }
109: }
|