KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > xslt > ConfigWritter


1
2 package org.enhydra.dods.xslt;
3
4 import java.io.*;
5
6 public class ConfigWritter {
7
8   
9   public void writeDefaultsToConfig(String JavaDoc outputPath) {
10     try {
11 // String outputName = "transform_output.conf";
12
if( !(outputPath.endsWith("\\") || outputPath.endsWith("/")) )
13         outputPath+="/";
14 // File file = new File(outputPath+outputName);
15
File file = new File(outputPath);
16         if(!file.exists())
17           file.createNewFile();
18      RandomAccessFile fileConf = new RandomAccessFile(file , "rw");
19      fileConf.seek(fileConf.length());
20      fileConf.writeBytes("\r\n");
21      fileConf.writeBytes( "DatabaseManager.defaults.lazyLoading=false" );
22      fileConf.writeBytes("\r\n");
23      fileConf.writeBytes( "DatabaseManager.defaults.maxExecuteTime=0" );
24      fileConf.writeBytes("\r\n");
25      fileConf.writeBytes( "DatabaseManager.defaults.AllReadOnly=false" );
26      fileConf.writeBytes("\r\n");
27      
28      fileConf.writeBytes( "DatabaseManager.defaults.TransactionCheck=false" );
29      fileConf.writeBytes("\r\n");
30      fileConf.writeBytes( "DatabaseManager.defaults.DeleteCheckVersion=false" );
31      fileConf.writeBytes("\r\n");
32      fileConf.writeBytes( "DatabaseManager.defaults.AutoWrite=false" );
33      fileConf.writeBytes("\r\n");
34      fileConf.writeBytes( "DatabaseManager.defaults.TransactionCaches=false" );
35      fileConf.writeBytes("\r\n");
36      fileConf.writeBytes( "DatabaseManager.defaults.AutoSave=false" );
37      fileConf.writeBytes("\r\n");
38      fileConf.writeBytes( "DatabaseManager.defaults.AutoSaveCreateVirgin=false" );
39      fileConf.writeBytes("\r\n");
40      fileConf.writeBytes( "DatabaseManager.defaults.DefaultFetchSize=-1" );
41      fileConf.writeBytes("\r\n");
42      fileConf.writeBytes( "DatabaseManager.defaults.MainCacheLockTimeout=100" );
43      fileConf.writeBytes("\r\n");
44      fileConf.writeBytes( "DatabaseManager.defaults.CacheLockTimeout=0" );
45      fileConf.writeBytes("\r\n");
46      fileConf.writeBytes( "DatabaseManager.defaults.CacheLockRetryCount=0" );
47      fileConf.writeBytes("\r\n");
48      fileConf.writeBytes( "DatabaseManager.defaults.QueryTimeout=0" );
49      fileConf.writeBytes("\r\n");
50      fileConf.writeBytes( "DatabaseManager.defaults.MaxConnectionUsages=-1" );
51      fileConf.writeBytes("\r\n");
52       
53      fileConf.writeBytes( "DatabaseManager.defaults.cache.maxCacheSize=0" );
54      fileConf.writeBytes("\r\n");
55      fileConf.writeBytes( "DatabaseManager.defaults.cache.maxSimpleCacheSize=0" );
56      fileConf.writeBytes("\r\n");
57      fileConf.writeBytes( "DatabaseManager.defaults.cache.maxComplexCacheSize=0" );
58      fileConf.writeBytes("\r\n");
59      fileConf.writeBytes( "DatabaseManager.defaults.cache.maxMultiJoinCacheSize=0" );
60      fileConf.writeBytes("\r\n");
61      fileConf.writeBytes( "DatabaseManager.defaults.cache.reserveFactor=0" );
62      fileConf.writeBytes("\r\n");
63      fileConf.writeBytes( "DatabaseManager.defaults.cache.CachePercentage=-1.0" );
64      fileConf.writeBytes("\r\n");
65      fileConf.writeBytes( "DatabaseManager.defaults.cache.initAllCaches=false" );
66      fileConf.writeBytes("\r\n");
67      fileConf.close();
68     }catch(Exception JavaDoc e) {
69       e.printStackTrace();
70     }
71   }
72   
73   public void writeToConfig(String JavaDoc outputPath, String JavaDoc databaseName, String JavaDoc tableName, String JavaDoc attrName, String JavaDoc attrValue) {
74     try {
75          
76 // String outputName = "transform_output.conf";
77
if( !(outputPath.endsWith("\\") || outputPath.endsWith("/")) )
78         outputPath+="/";
79 // File file = new File(outputPath+outputName);
80
File file = new File(outputPath);
81         if(!file.exists())
82           file.createNewFile();
83           
84      RandomAccessFile fileConf = new RandomAccessFile(file , "rw");
85      fileConf.seek(fileConf.length());
86      fileConf.writeBytes("\r\n");
87      if (attrName.equals("isLazyLoading")) {
88         if (attrValue.equals("true")) {
89           fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".lazyLoading=true");
90           fileConf.writeBytes("\r\n");
91         }
92      }
93      if (attrName.equals("caching")) {
94         if (attrValue.equals("full")) {
95           fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".cache.maxCacheSize=-1");
96           fileConf.writeBytes("\r\n");
97           fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".cache.initialCondition=*");
98           fileConf.writeBytes("\r\n");
99         }
100         if (attrValue.equals("partial")) {
101             fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".cache.maxCacheSize=-1");
102             fileConf.writeBytes("\r\n");
103          }
104         if (attrValue.equals("none")) {
105             fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".cache.maxCacheSize=0");
106             fileConf.writeBytes("\r\n");
107          }
108      }
109      fileConf.close();
110     }catch(Exception JavaDoc e) {
111       e.printStackTrace();
112     }
113   }
114   
115   public void writeToConfigDefault(String JavaDoc outputPath, String JavaDoc databaseName, String JavaDoc tableName, String JavaDoc attrName, String JavaDoc defaultValue) {
116     try {
117
118 // String outputName = "transform_output.conf";
119
if( !(outputPath.endsWith("\\") || outputPath.endsWith("/")) )
120         outputPath+="/";
121 // File file = new File(outputPath+outputName);
122
File file = new File(outputPath);
123         if(!file.exists())
124           file.createNewFile();
125
126      RandomAccessFile fileConf = new RandomAccessFile(file , "rw");
127      fileConf.seek(fileConf.length());
128      fileConf.writeBytes("\r\n");
129      if (attrName.equals("isLazyLoading")) {
130         if (defaultValue.equals("true")) {
131           fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".lazyLoading=true");
132           fileConf.writeBytes("\r\n");
133         }
134         if(defaultValue.equals("false")) {
135           fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".lazyLoading=false");
136           fileConf.writeBytes("\r\n");
137         }
138         if(defaultValue.equals("${defaultLazyLoading}")) {
139           fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".lazyLoading=");
140           fileConf.writeBytes("\r\n");
141         }
142      }
143      if (attrName.equals("caching")) {
144         if (defaultValue.equals("full")) {
145           fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".cache.maxCacheSize=-1");
146           fileConf.writeBytes("\r\n");
147           fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".cache.initialCondition=*");
148           fileConf.writeBytes("\r\n");
149         }
150         if (defaultValue.equals("partial")) {
151             fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".cache.maxCacheSize=-1");
152             fileConf.writeBytes("\r\n");
153         }
154         if (defaultValue.equals("none")) {
155             fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".cache.maxCacheSize=0");
156             fileConf.writeBytes("\r\n");
157         }
158         if (defaultValue.equals("${defaultCaching}")) {
159             fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".cache.maxCacheSize=");
160             fileConf.writeBytes("\r\n");
161             fileConf.writeBytes( "DatabaseManager.DB."+databaseName+"."+tableName+".cache.initialCondition=");
162             fileConf.writeBytes("\r\n");
163         }
164      }
165      fileConf.close();
166     }catch(Exception JavaDoc e ) {
167       e.printStackTrace();
168     }
169   }
170   
171    
172 }
Popular Tags