KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > mondrian > datasource > DataSourceConfig


1 /*********************************************************************************
2  * The contents of this file are subject to the OpenI Public License Version 1.0
3  * ("License"); You may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.openi.org/docs/LICENSE.txt
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is: OpenI Open Source
12  *
13  * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
14  * Portions created by Loyalty Matrix, Inc. are
15  * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
16  *
17  * Contributor(s): ______________________________________.
18  *
19  ********************************************************************************/

20 package org.openi.mondrian.datasource;
21
22 import org.openi.util.Util;
23 import org.openi.xml.*;
24 import java.io.FileInputStream JavaDoc;
25 import java.io.FileWriter JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29 import javax.xml.transform.TransformerException JavaDoc;
30
31
32 /**
33  * @author Uddhab Pant <br>
34  *
35  * This class is responsible for:
36  * <ul>
37  * <li> transforms mondrian datasources.xml with xsl and initilizes
38  * datasources list using org.openi.xml.BeanStorage.
39  * <li> transforms xml generated by BeanStorage for datasources list with xsl and
40  * saves to a file compatible with mondrian datasources.xml.
41  * </ul>
42  *
43  */

44 public class DataSourceConfig {
45     private String JavaDoc datasourceXmlFile;
46     private String JavaDoc mondrianXslFile;
47     private BeanStorage storage;
48     private XMLTransformer transformer;
49
50     /**
51      * c'tor initializes mondrian datasources.xml file and
52      * xsl file.
53      *
54      * @param mondrianXslFile String
55      * @param datasourceXmlFile String
56      */

57     public DataSourceConfig(String JavaDoc mondrianXslFile, String JavaDoc datasourceXmlFile) {
58         this.datasourceXmlFile = datasourceXmlFile;
59         this.mondrianXslFile = mondrianXslFile;
60         storage = new BeanStorage();
61         transformer = new XMLTransformer();
62     }
63
64     /**
65      *
66      * Initializes datasources from mondrian datasources.xml using xstream and xsl
67      *
68      * @return List
69      * @throws TransformerException
70      * @throws IOException
71      */

72     public List JavaDoc getDataSources() throws TransformerException JavaDoc, IOException JavaDoc {
73         List JavaDoc datasources = null;
74
75         String JavaDoc mondrianXml = transformer.transform(new FileInputStream JavaDoc(
76                     mondrianXslFile), new FileInputStream JavaDoc(datasourceXmlFile));
77
78         // XXX: commented out, not to be implemented for now
79
// datasources = (ArrayList) storage.restoreBeanFromXmlString(mondrianXml);
80
return datasources;
81     }
82
83     /**
84      *
85      * Saves datasources to mondrian datasources.xml using xstream and xsl
86      *
87      * @param datasources List
88      * @throws TransformerException
89      * @throws IOException
90      */

91     public void setDataSources(List JavaDoc datasources)
92         throws TransformerException JavaDoc, IOException JavaDoc {
93         String JavaDoc mondrianXml = storage.toXmlString(datasources);
94
95         String JavaDoc datasourceXml = transformer.transform(Util.getFileContents(
96                     mondrianXslFile), mondrianXml);
97         FileWriter JavaDoc writer = new FileWriter JavaDoc(datasourceXmlFile);
98         writer.write(datasourceXml);
99         writer.flush();
100         writer.close();
101     }
102 }
103
Popular Tags