1 21 22 package org.apache.derby.impl.tools.ij; 23 24 import org.apache.derby.tools.JDBCDisplayUtil; 25 import org.apache.derby.iapi.tools.i18n.LocalizedResource; 26 import org.apache.derby.iapi.tools.i18n.LocalizedInput; 27 import org.apache.derby.iapi.tools.i18n.LocalizedOutput; 28 29 import java.io.FileInputStream ; 30 import java.io.BufferedInputStream ; 31 import java.io.BufferedReader ; 32 import java.io.FileOutputStream ; 33 import java.io.FileNotFoundException ; 34 import java.io.InputStream ; 35 import java.io.Reader ; 36 import java.io.PrintStream ; 37 import java.io.UnsupportedEncodingException ; 38 import java.io.IOException ; 39 40 import java.sql.Connection ; 41 import java.sql.SQLException ; 42 43 import java.util.*; 44 45 60 public class Main { 61 private utilMain utilInstance; 62 63 69 public static void main(String [] args) 70 throws IOException 71 { 72 mainCore(args, new Main(true)); 73 } 74 75 public static void mainCore(String [] args, Main main) 76 throws IOException 77 { 78 LocalizedInput in = null; 79 InputStream in1 = null; 80 Main me; 81 String file; 82 String inputResourceName; 83 boolean gotProp; 84 Properties connAttributeDefaults = null; 85 86 LocalizedResource langUtil = LocalizedResource.getInstance(); 87 LocalizedOutput out = langUtil.getNewOutput(System.out); 88 89 if (util.invalidArgs(args)) { 91 util.Usage(out); 92 return; 93 } 94 95 gotProp = util.getPropertyArg(args); 97 98 connAttributeDefaults = util.getConnAttributeArg(args); 100 101 langUtil.init(); 104 out = langUtil.getNewOutput(System.out); 105 main.initAppUI(); 106 107 file = util.getFileArg(args); 108 inputResourceName = util.getInputResourceNameArg(args); 109 if (inputResourceName != null) { 110 in = langUtil.getNewInput(util.getResourceAsStream(inputResourceName)); 111 if (in == null) { 112 out.println(langUtil.getTextMessage("IJ_IjErroResoNo",inputResourceName)); 113 return; 114 } 115 } else if (file == null) { 116 in = langUtil.getNewInput(System.in); 117 out.flush(); 118 } else { 119 try { 120 in1 = new FileInputStream (file); 121 if (in1 != null) { 122 in1 = new BufferedInputStream (in1, utilMain.BUFFEREDFILESIZE); 123 in = langUtil.getNewInput(in1); 124 } 125 } catch (FileNotFoundException e) { 126 if (Boolean.getBoolean("ij.searchClassPath")) { 127 in = langUtil.getNewInput(util.getResourceAsStream(file)); 128 } 129 if (in == null) { 130 out.println(langUtil.getTextMessage("IJ_IjErroFileNo",file)); 131 return; 132 } 133 } 134 } 135 136 String outFile = util.getSystemProperty("ij.outfile"); 137 if (outFile != null && outFile.length()>0) { 138 LocalizedOutput oldOut = out; 139 try { 140 out = langUtil.getNewOutput(new FileOutputStream (outFile)); 141 } 142 catch (IOException ioe) { 143 oldOut.println(langUtil.getTextMessage("IJ_IjErroUnabTo",outFile)); 144 } 145 } 146 147 String maxDisplayWidth = util.getSystemProperty("maximumDisplayWidth"); 149 if (maxDisplayWidth==null) 150 maxDisplayWidth = util.getSystemProperty("ij.maximumDisplayWidth"); 151 if (maxDisplayWidth != null && maxDisplayWidth.length() > 0) { 152 try { 153 int maxWidth = Integer.parseInt(maxDisplayWidth); 154 JDBCDisplayUtil.setMaxDisplayWidth(maxWidth); 155 } 156 catch (NumberFormatException nfe) { 157 out.println(langUtil.getTextMessage("IJ_IjErroMaxiVa", maxDisplayWidth)); 158 } 159 } 160 161 167 me = main.getMain(out); 168 169 170 me.go(in, out, connAttributeDefaults); 171 in.close(); out.close(); 172 } 173 174 180 public Main getMain(LocalizedOutput out) 181 { 182 return new Main(out); 183 } 184 185 191 public utilMain getutilMain(int numConnections, LocalizedOutput out) 192 { 193 return new utilMain(numConnections, out); 194 } 195 196 200 private void go(LocalizedInput in, LocalizedOutput out , 201 Properties connAttributeDefaults) 202 { 203 LocalizedInput[] inA = { in } ; 204 utilInstance.go(inA, out,connAttributeDefaults); 205 } 206 207 210 public Main() { 211 this(null); 212 } 213 214 public Main(LocalizedOutput out) { 215 if (out == null) { 216 out = LocalizedResource.getInstance().getNewOutput(System.out); 217 } 218 utilInstance = getutilMain(1, out); 219 utilInstance.initFromEnvironment(); 220 } 221 222 230 public Main(boolean trash) 231 { 232 } 233 private void initAppUI(){ 234 239 LocalizedResource.getInstance(); 241 } 242 } 243 | Popular Tags |