RAConfig.java

00001 
00030 package org.objectweb.jonas_rar.raconfig;
00031 
00032 import java.io.BufferedReader;
00033 import java.io.File;
00034 import java.io.FileInputStream;
00035 import java.io.FileNotFoundException;
00036 import java.io.FileOutputStream;
00037 import java.io.FileReader;
00038 import java.io.FileWriter;
00039 import java.io.IOException;
00040 import java.io.InputStream;
00041 import java.io.PrintStream;
00042 import java.util.Enumeration;
00043 import java.util.Iterator;
00044 import java.util.Properties;
00045 import java.util.zip.ZipEntry;
00046 import java.util.zip.ZipFile;
00047 import java.util.zip.ZipOutputStream;
00048 
00049 import org.objectweb.jonas.security.realm.lib.Base64;
00050 import org.objectweb.jonas_rar.deployment.xml.Connector;
00051 import org.objectweb.jonas_rar.deployment.api.ConfigPropertyDesc;
00052 import org.objectweb.jonas_rar.deployment.xml.ConfigProperty;
00053 import org.objectweb.jonas_rar.deployment.api.RarDeploymentDesc;
00054 import org.objectweb.jonas_rar.deployment.lib.RarDeploymentDescManager;
00055 import org.objectweb.jonas_rar.deployment.xml.Activationspec;
00056 import org.objectweb.jonas_rar.deployment.xml.Adminobject;
00057 import org.objectweb.jonas_rar.deployment.xml.ConnectionDefinition;
00058 import org.objectweb.jonas_rar.deployment.xml.InboundResourceadapter;
00059 import org.objectweb.jonas_rar.deployment.xml.JdbcConnParams;
00060 import org.objectweb.jonas_rar.deployment.xml.JonasActivationspec;
00061 import org.objectweb.jonas_rar.deployment.xml.JonasAdminobject;
00062 import org.objectweb.jonas_rar.deployment.xml.JonasConfigProperty;
00063 import org.objectweb.jonas_rar.deployment.xml.JonasConnectionDefinition;
00064 import org.objectweb.jonas_rar.deployment.xml.JonasConnector;
00065 import org.objectweb.jonas_rar.deployment.xml.JonasSecurityMapping;
00066 import org.objectweb.jonas_rar.deployment.xml.Messageadapter;
00067 import org.objectweb.jonas_rar.deployment.xml.Messagelistener;
00068 import org.objectweb.jonas_rar.deployment.xml.OutboundResourceadapter;
00069 import org.objectweb.jonas_rar.deployment.xml.PoolParams;
00070 import org.objectweb.jonas_rar.deployment.xml.RequiredConfigProperty;
00071 import org.objectweb.jonas_rar.deployment.xml.Resourceadapter;
00072 import org.objectweb.jonas_rar.deployment.xml.SecurityEntry;
00073 
00082 public class RAConfig {
00083 
00087     private static final int BUFFER_SIZE = 500;
00088 
00090     private static final double JCA_1_5 = 1.5;
00092     private static final double JCA_1_0 = 1.0;
00093 
00094     RarDeploymentDesc rarDD = null;
00095 
00099     static boolean validation = true;
00100 
00101     static String outputFile = "META-INF/jonas-ra.xml";
00102 
00103     private static final String xmlVers = "<?xml version = \"1.0\" encoding = \"UTF-8\"?>\n";
00104 
00105     // Constructor
00106     public RAConfig(String fileName) throws RAConfigException {
00107         ClassLoader curLoader = Thread.currentThread().getContextClassLoader();
00108 
00109         try {
00110             RarDeploymentDescManager.setParsingWithValidation(validation);
00111             rarDD = RarDeploymentDescManager.getInstance(fileName, curLoader);
00112         } catch (Exception e) {
00113             throw new RAConfigException(e);
00114         }
00115 
00116     }
00117 
00118     public RarDeploymentDesc getRarDeploymentDesc() {
00119         return rarDD;
00120     }
00121 
00137     private static void buildXML(String fileInputName, String jndiname, String rarlink, Properties dbProps,
00138             boolean encrypt, String securityfile, String path,
00139             boolean isVerbose) throws RAConfigException {
00140 
00141         RAConfig raxml = new RAConfig(fileInputName);
00142         Connector conn = raxml.getRarDeploymentDesc().getConnector();
00143         double specVersion = 0.0;
00144         ConfigPropertyDesc[] raProps = raxml.getRarDeploymentDesc().getRaConfigPropTags();
00145         if (raProps == null) {
00146             throw new RAConfigException("RAR file doesn't contain ra.xml");
00147         }
00148         if (conn.getSpecVersion().equals("1.0")) {
00149             specVersion = JCA_1_0;
00150         } else if (conn.getSpecVersion().equals("1.5")) {
00151             specVersion = JCA_1_5;
00152         } else {
00153             throw new RAConfigException("ra.xml doesn't correct spec version");
00154         }
00155 
00156         JonasConnector jConn = new JonasConnector();
00157         PoolParams jPool = new PoolParams();
00158         JdbcConnParams jConnParams = new JdbcConnParams();
00159         JonasConfigProperty jCfg = null;
00160 
00161         String val = "";
00162         String str = "";
00163         jPool.setPoolInit("0");
00164 
00165         val = "0";
00166         if (dbProps.getProperty("jdbc.minconpool") != null && dbProps.getProperty("jdbc.minconpool").length() > 0) {
00167             val = dbProps.getProperty("jdbc.minconpool").trim();
00168         }
00169         jPool.setPoolMin(val);
00170 
00171         val = "-1";
00172         if (dbProps.getProperty("jdbc.maxconpool") != null && dbProps.getProperty("jdbc.maxconpool").length() > 0) {
00173             val = dbProps.getProperty("jdbc.maxconpool").trim();
00174         }
00175         jPool.setPoolMax(val);
00176 
00177         val = "0";
00178         if (dbProps.getProperty("jdbc.connmaxage") != null && dbProps.getProperty("jdbc.connmaxage").length() > 0) {
00179             val = dbProps.getProperty("jdbc.connmaxage").trim();
00180         }
00181         jPool.setPoolMaxAgeMinutes(val);
00182 
00183         jPool.setPstmtMax("10");
00184 
00185         val = "0";
00186         if (dbProps.getProperty("jdbc.maxopentime") != null && dbProps.getProperty("jdbc.maxopentime").length() > 0) {
00187             val = dbProps.getProperty("jdbc.maxopentime").trim();
00188         }
00189         jPool.setPoolMaxOpentime(val);
00190 
00191         val = "0";
00192         if (dbProps.getProperty("jdbc.maxwaiters") != null && dbProps.getProperty("jdbc.maxwaiters").length() > 0) {
00193             val = dbProps.getProperty("jdbc.maxwaiters").trim();
00194         }
00195         jPool.setPoolMaxWaiters(val);
00196 
00197         val = "0";
00198         if (dbProps.getProperty("jdbc.maxwaittime") != null && dbProps.getProperty("jdbc.maxwaittime").length() > 0) {
00199             val = dbProps.getProperty("jdbc.maxwaittime").trim();
00200         }
00201         jPool.setPoolMaxWaittime(val);
00202 
00203         val = "30";
00204         if (dbProps.getProperty("jdbc.samplingperiod") != null && dbProps.getProperty("jdbc.samplingperiod").length() > 0) {
00205             val = dbProps.getProperty("jdbc.samplingperiod").trim();
00206         }
00207         jPool.setPoolSamplingPeriod(val);
00208 
00209 
00210         jConn.setLogEnabled("false");
00211         jConn.setLogTopic("");
00212         jConn.setNativeLib("");
00213         if (jndiname.length() == 0) {
00214             jndiname = dbProps.getProperty("datasource.name", "").trim();
00215         }
00216 
00217         val = "0";
00218         if (dbProps.getProperty("jdbc.connchecklevel") != null
00219                 && dbProps.getProperty("jdbc.connchecklevel").length() > 0) {
00220             val = dbProps.getProperty("jdbc.connchecklevel").trim();
00221         }
00222         jConnParams.setJdbcCheckLevel(val);
00223 
00224         val = "";
00225         if (dbProps.getProperty("jdbc.connteststmt") != null && dbProps.getProperty("jdbc.connteststmt").length() > 0) {
00226             val = dbProps.getProperty("jdbc.connteststmt").trim();
00227             jConnParams.setJdbcTestStatement(val);
00228         }
00229 
00230         if (specVersion == 1.0) {
00231             jConn.setJndiName(jndiname);
00232         }
00233         jConn.setRarlink(rarlink);
00234         jConn.setPoolParams(jPool);
00235         jConn.setJdbcConnParams(jConnParams);
00236 
00237         if (specVersion == JCA_1_0) {
00238             val = "";
00239             str = "";
00240             for (int i = 0; i < raProps.length; i++) {
00241                 jCfg = new JonasConfigProperty();
00242                 str = raProps[i].getConfigPropertyName();
00243                 jCfg.setJonasConfigPropertyName(str);
00244                 if (dbProps.size() > 0) {
00245                     val = getProp(dbProps, str);
00246                 } else {
00247                     val = "";
00248                 }
00249                 jCfg.setJonasConfigPropertyValue(val);
00250                 jConn.addJonasConfigProperty(jCfg);
00251             }
00252         } else if (specVersion == JCA_1_5) {
00253             Resourceadapter rAdapter = conn.getResourceadapter();
00254             ConfigProperty cProperty = null;
00255             // TODO rProperty never used !!!
00256             RequiredConfigProperty rProperty = null;
00257             // Process config properties if they exist
00258             for (Iterator i = rAdapter.getConfigPropertyList().iterator(); i.hasNext();) {
00259                 cProperty = (ConfigProperty) i.next();
00260                 jCfg = new JonasConfigProperty();
00261                 str = cProperty.getConfigPropertyName();
00262                 jCfg.setJonasConfigPropertyName(str);
00263                 if (dbProps.size() > 0) {
00264                     val = getProp(dbProps, str);
00265                 } else {
00266                     val = "";
00267                 }
00268                 jCfg.setJonasConfigPropertyValue(val);
00269                 jConn.addJonasConfigProperty(jCfg);
00270             }
00271             // Now process the outbound-resourceadapter
00272             OutboundResourceadapter oRes = rAdapter.getOutboundResourceadapter();
00273             if (oRes != null) {
00274                 ConnectionDefinition cDef = null;
00275                 JonasConnectionDefinition jcDef = null;
00276                 for (Iterator it = oRes.getConnectionDefinitionList().iterator(); it.hasNext();) {
00277                     cDef = (ConnectionDefinition) it.next();
00278                     jcDef = new JonasConnectionDefinition();
00279                     jcDef.setId(cDef.getId());
00280                     jcDef.addDescription(cDef.getManagedconnectionfactoryClass());
00281                     jcDef.setJndiName("");
00282                     for (Iterator i = cDef.getConfigPropertyList().iterator(); i.hasNext();) {
00283                         cProperty = (ConfigProperty) i.next();
00284                         jCfg = new JonasConfigProperty();
00285                         str = cProperty.getConfigPropertyName();
00286                         jCfg.setJonasConfigPropertyName(str);
00287                         jCfg.setJonasConfigPropertyValue("");
00288                         jcDef.addJonasConfigProperty(jCfg);
00289                     }
00290                     jConn.addJonasConnectionDefinition(jcDef);
00291                 }
00292             }
00293             // Now process the inbound-resourceadapter
00294             InboundResourceadapter iRes = rAdapter.getInboundResourceadapter();
00295             if (iRes != null) {
00296                 Messageadapter mAdapter = iRes.getMessageadapter();
00297                 if (mAdapter != null) {
00298                     Messagelistener mList = null;
00299                     JonasActivationspec jaSpec = null;
00300                     Activationspec aSpec = null;
00301                     for (Iterator it = mAdapter.getMessagelistenerList().iterator(); it.hasNext();) {
00302                         mList = (Messagelistener) it.next();
00303                         aSpec = mList.getActivationspec();
00304                         if (aSpec != null) {
00305                             jaSpec = new JonasActivationspec();
00306                             jaSpec.setId(mList.getId());
00307                             jaSpec.addDescription(mList.getMessagelistenerType());
00308                             jaSpec.setJndiName("");
00309                             jConn.addJonasActivationspec(jaSpec);
00310                         }
00311                     }
00312                 }
00313             }
00314             // Now process the adminobject
00315             for (Iterator it = rAdapter.getAdminobjectList().iterator(); it.hasNext();) {
00316                 Adminobject aObj = (Adminobject) it.next();
00317                 JonasAdminobject jaObj = null;
00318                 if (aObj != null) {
00319                     jaObj = new JonasAdminobject();
00320                     jaObj.setId(aObj.getId());
00321                     jaObj.addDescription(aObj.getAdminobjectClass());
00322                     jaObj.setJndiName("");
00323                     // Process config properties if they exist
00324                     for (Iterator i = aObj.getConfigPropertyList().iterator(); i.hasNext();) {
00325                         cProperty = (ConfigProperty) i.next();
00326                         jCfg = new JonasConfigProperty();
00327                         str = cProperty.getConfigPropertyName();
00328                         jCfg.setJonasConfigPropertyName(str);
00329                         jCfg.setJonasConfigPropertyValue("");
00330                         jaObj.addJonasConfigProperty(jCfg);
00331                     }
00332                     jConn.addJonasAdminobject(jaObj);
00333                 }
00334             }
00335         }
00336 
00337         if (securityfile != null) {
00338             Properties secProps = new Properties();
00339             File f = null;
00340             try {
00341                 f = new File(securityfile);
00342                 FileInputStream is = new FileInputStream(f);
00343                 secProps.load(is);
00344             } catch (FileNotFoundException e) {
00345                 System.err.println("Cannot find security properties file: " + securityfile);
00346                 System.err.println("Continuing with creation of jonas-ra.xml");
00347             } catch (IOException e) {
00348                 System.err.println(e);
00349             }
00350 
00351             JonasSecurityMapping jsMap = new JonasSecurityMapping();
00352             String pName = null;
00353             String user = null;
00354             String pass = null;
00355             String tmp = null;
00356             int offset = 0;
00357             SecurityEntry sEnt = null;
00358             for (Enumeration e = secProps.propertyNames(); e.hasMoreElements();) {
00359                 pName = (String) e.nextElement();
00360                 tmp = secProps.getProperty(pName);
00361                 offset = tmp.indexOf("::");
00362                 if (offset < 0) {
00363                     System.err.println("Error in format of file:  principalName = user::password");
00364                     continue;
00365                 }
00366                 user = tmp.substring(0, offset);
00367                 pass = tmp.substring(offset + 2);
00368 
00369                 sEnt = new SecurityEntry();
00370                 sEnt.setPrincipalName(pName);
00371                 sEnt.setUser(user);
00372                 if (encrypt) {
00373                     try {
00374                         pass = new String(Base64.encode(pass.getBytes()));
00375                         sEnt.setEncrypted("" + encrypt);
00376                     } catch (Exception ex) {
00377                         System.err.println("Unable to encrypt the password.");
00378                     }
00379                 }
00380                 sEnt.setPassword(pass);
00381                 jsMap.addSecurityEntry(sEnt);
00382             }
00383             jConn.setJonasSecurityMapping(jsMap);
00384         }
00385 
00386         try {
00387             String tmpDir = (path.length() > 0 ? path : System.getProperty("java.io.tmpdir"));
00388             String fileName = tmpDir + File.separator + "jonas-ra.xml";
00389             FileWriter fw = new FileWriter(fileName);
00390             fw.write(xmlVers);
00391             fw.write(jConn.toXML());
00392             fw.close();
00393             if (isVerbose) {
00394                 System.out.println("Build Jonas Specific DD File '" + fileName + "' OK");
00395             }
00396 
00397         } catch (Exception e) {
00398             throw new RAConfigException("Error writing output", e);
00399         }
00400     }
00401 
00409     private static String getProp(Properties prop, String str) {
00410         String[][] mapping = {{"connCheckLevel", "jdbc.connchecklevel"}, {"connMaxAge", "jdbc.connmaxage"},
00411                 {"connTestStmt", "jdbc.connteststmt"}, {"URL", "datasource.url"}, {"dsClass", "datasource.classname"},
00412                 {"user", "datasource.username"}, {"password", "datasource.password"},
00413                 {"isolationLevel", "datasource.isolationlevel"}, {"mapperName", "datasource.mapper"}, };
00414 
00415         String ret = "";
00416         for (int i = 0; i < mapping.length; i++) {
00417             if (mapping[i][0].equalsIgnoreCase(str)) {
00418                 ret = (prop.getProperty(mapping[i][1]) == null ? "" : prop.getProperty(mapping[i][1]).trim());
00419             }
00420         }
00421 
00422         return ret;
00423     }
00424 
00433     private static void updateRAR(String infile, String outfile, String updatename, String rarlink)
00434             throws RAConfigException {
00435 
00436         ZipOutputStream zipOutput = null;
00437         ZipFile zipFile = null;
00438         Enumeration zippedFiles = null;
00439         ZipEntry currEntry = null;
00440         ZipEntry entry = null;
00441         byte[] buffer = new byte[BUFFER_SIZE];
00442         int num = 0;
00443 
00444         String filename = infile;
00445         String outfilename = infile;
00446         boolean outNew = false;
00447         if (outfile != null && outfile.length() != 0) {
00448             outfilename = outfile;
00449             outNew = true;
00450         }
00451 
00452         try {
00453             File file = new File(filename);
00454             if (file.exists()) {
00455                 zipFile = new ZipFile(file.getAbsolutePath());
00456                 //get an enumeration of all existing entries
00457                 zippedFiles = zipFile.entries();
00458                 //create your output zip file
00459                 if (!outNew) {
00460                     zipOutput = new ZipOutputStream(new FileOutputStream(new File(file.getAbsolutePath() + "NEW")));
00461                 } else {
00462                     File ofile = new File(outfilename);
00463                     if (ofile.exists()) {
00464                         ofile.delete();
00465                     }
00466 
00467                     zipOutput = new ZipOutputStream(new FileOutputStream(new File(outfilename)));
00468                 }
00469                 //Get all the data out of the previously zipped files and
00470                 // write
00471                 // it to a new ZipEntry to go into a new file archive
00472                 if ((outfile == null || outfile.length() == 0) && rarlink.length() == 0) {
00473                     while (zippedFiles.hasMoreElements()) {
00474                         //Retrieve entry of existing files
00475                         currEntry = (ZipEntry) zippedFiles.nextElement();
00476                         if (currEntry.getName().equalsIgnoreCase(outputFile)) {
00477                             continue;
00478                         }
00479                         //Read data from existing file
00480                         zipOutput.putNextEntry(new ZipEntry(currEntry.getName()));
00481                         InputStream reader = zipFile.getInputStream(currEntry);
00482                         while ((num = reader.read(buffer)) != -1) {
00483                             zipOutput.write(buffer, 0, num);
00484                         }
00485                         //Commit the data
00486                         zipOutput.flush();
00487                         zipOutput.closeEntry();
00488                     }
00489                 }
00490                 //Close the old zip file
00491                 zipFile.close();
00492 
00493                 //Write the 'new' file to the archive, commit, and close
00494                 entry = new ZipEntry(outputFile);
00495                 zipOutput.putNextEntry(entry);
00496 
00497                 //Read data from existing file
00498                 try {
00499                     BufferedReader reader = new BufferedReader(new FileReader(updatename));
00500                     int ch = 0;
00501                     while ((ch = reader.read()) != -1) {
00502                         zipOutput.write(ch);
00503                     }
00504                 } catch (Exception ex) {
00505                     System.out.println("Error reading input file: " + updatename + " " + ex);
00506                     //Commit the data
00507                     zipOutput.flush();
00508                     zipOutput.closeEntry();
00509                     zipOutput.finish();
00510                     zipOutput.close();
00511                 }
00512                 //Commit the data
00513                 zipOutput.flush();
00514                 zipOutput.closeEntry();
00515                 zipOutput.finish();
00516                 zipOutput.close();
00517 
00518                 if (!outNew) {
00519                     //delete the old file and rename the new one
00520                     File toBeDeleted = new File(file.getAbsolutePath());
00521                     toBeDeleted.delete();
00522                     File toBeRenamed = new File(file.getAbsolutePath() + "NEW");
00523                     toBeRenamed.renameTo(file);
00524                 }
00525             } else {
00526                 //create your output zip file
00527                 zipOutput = new ZipOutputStream(new FileOutputStream(new File(outfilename)));
00528 
00529                 //Write the file to the archive, commit, and close
00530                 entry = new ZipEntry(outputFile);
00531                 zipOutput.putNextEntry(entry);
00532                 //Read data from existing file
00533                 BufferedReader reader = new BufferedReader(new FileReader(updatename));
00534                 int ch = 0;
00535                 while ((ch = reader.read()) != -1) {
00536                     zipOutput.write(ch);
00537                 }
00538 
00539                 //Commit the data
00540                 zipOutput.flush();
00541                 zipOutput.closeEntry();
00542                 zipOutput.finish();
00543                 zipOutput.close();
00544             }
00545             // finally, we delete generated jonas-ra.xml
00546             new File(updatename).delete();
00547         } catch (Exception ex) {
00548             throw new RAConfigException(ex);
00549         }
00550 
00551     }
00552 
00558     private static String indent(int count) {
00559         String front = "";
00560         String indentChars = "    ";
00561         for (int i = 0; i < count; i++) {
00562             front += indentChars;
00563         }
00564         return front;
00565     }
00566 
00571     public static void usage() {
00572         System.out.println("");
00573         System.out.println("Usage: java org.objectweb.jonas.resource.RAConfig <Options> <Input_File> [Output_File]");
00574         System.out.println("     to generate the jonas-ra.xml file for a Resource Adapter.");
00575         System.out.println("");
00576         System.out.println("       With Options:");
00577         System.out.println("         -? or -help                print this help message");
00578         System.out.println("         -DM,-DS,-PC,-XA            DriverManager, Datasource, PooledConnection,");
00579         System.out.println("                                    XAConnection only used with -p");
00580         System.out.println("         -Jndiname <jndiname>       specifies the jndiname RA");
00581         System.out.println("         -Property <property file>  specifies the database property file");
00582         System.out.println("                                     to process");
00583         System.out.println("         -Rarlink <rarlink>         specifies the rar file to link to");
00584         System.out.println("         -Update <input name>       update the input rar with the specified file");
00585         System.out.println("                                    unless an output_file named is specified");
00586         System.out.println("         -ENcrypt                   used with -sf to encrypt the passwords ");
00587         System.out.println("         -SecurityFile              security xml file to add to jonas-ra.xml ");
00588         System.out.println("         -Verbose                   output the contents of the  deployment descriptor ");
00589         System.out.println("         -NoValidation              turn off xml dtd/schema validation ");
00590         System.out.println("         -PATH <path>               path where jonas-ra.xml should be written to ");
00591         System.out.println("                                     default is System.property('java.io.tmpdir')");
00592         System.out.println("");
00593         System.out.println("       Input_File     Resource Adapter RAR file");
00594         System.out.println("       Output_File    Resource Adapter RAR file only used with ");
00595         System.out.println("                          -p(required) or -u(optional)");
00596         System.out.println("");
00597     }
00598 
00599     // Main Method
00605     public static void main(String[] args) throws RAConfigException {
00606         PrintStream out = null;
00607         boolean isHelp = false;
00608         boolean isVerbose = false;
00609         boolean doProperty = false;
00610         boolean doUpdate = false;
00611         boolean encrypt = false;
00612         String fileInputName = null;
00613         String fileOutputName = null;
00614         String securityfile = null;
00615         String jndiname = "";
00616         String rarlink = "";
00617         String updatename = "";
00618         String jdbcRarLink = "";
00619         String jonasRarStr = "JOnASJDBC_";
00620         String propertyFile = "";
00621         String path = "";
00622         // Get command args
00623 
00624         Properties dbProps = null;
00625 
00626         if (args.length < 1) {
00627             isHelp = true;
00628         }
00629         for (int argn = 0; argn < args.length; argn++) {
00630             String arg = args[argn].toLowerCase();
00631             if (arg.equals("-help") || arg.equals("-?")) {
00632                 isHelp = true;
00633                 continue;
00634             }
00635             if (arg.equals("-verbose") || arg.equals("-v")) {
00636                 isVerbose = true;
00637                 continue;
00638             }
00639             if (arg.equals("-encrypt") || arg.equals("-en")) {
00640                 encrypt = true;
00641                 continue;
00642             }
00643             if (arg.equals("-securityfile") || arg.equals("-sf")) {
00644                 if (argn + 1 == args.length || args[++argn].startsWith("-")) {
00645                     usage();
00646                     throw new RAConfigException("Error with -sf input");
00647                 }
00648                 securityfile = args[argn];
00649                 continue;
00650             }
00651             if (arg.equals("-novalidation") || arg.equals("-nv")) {
00652                 validation = false;
00653                 continue;
00654             }
00655             if (arg.equals("-update") || arg.equals("-u")) {
00656                 doUpdate = true;
00657                 if (argn + 1 == args.length || args[++argn].startsWith("-")) {
00658                     usage();
00659                     throw new RAConfigException("Error with -u input");
00660                 }
00661                 updatename = args[argn];
00662                 continue;
00663             }
00664             if (arg.equals("-jndiname") || arg.equals("-j")) {
00665                 if (argn + 1 == args.length || args[++argn].startsWith("-")) {
00666                     usage();
00667                     throw new RAConfigException("Error with -j input");
00668                 }
00669                 jndiname = args[argn];
00670                 continue;
00671             }
00672             if (arg.equals("-rarlink") || arg.equals("-r")) {
00673                 if (argn + 1 == args.length || args[++argn].startsWith("-")) {
00674                     usage();
00675                     throw new RAConfigException("Error with -r input");
00676                 }
00677                 rarlink = args[argn];
00678                 continue;
00679             }
00680             if (arg.equals("-property") || arg.equals("-p")) {
00681                 doProperty = true;
00682                 if (argn + 1 == args.length || args[++argn].startsWith("-")) {
00683                     usage();
00684                     throw new RAConfigException("Error with -p input");
00685                 }
00686                 propertyFile = args[argn];
00687                 continue;
00688             }
00689             if (arg.equals("-dm")) {
00690                 jdbcRarLink = jonasRarStr + "DM";
00691                 continue;
00692             }
00693             if (arg.equals("-ds")) {
00694                 jdbcRarLink = jonasRarStr + "DS";
00695                 continue;
00696             }
00697             if (arg.equals("-xa")) {
00698                 jdbcRarLink = jonasRarStr + "XA";
00699                 continue;
00700             }
00701             if (arg.equals("-pc")) {
00702                 jdbcRarLink = jonasRarStr + "PC";
00703                 continue;
00704             }
00705             if (arg.equals("-path")) {
00706                 if (argn + 1 == args.length || args[++argn].startsWith("-")) {
00707                     usage();
00708                     throw new RAConfigException("Error with -path");
00709                 }
00710                 path = args[argn];
00711                 continue;
00712             }
00713             if (fileInputName == null) {
00714                 fileInputName = args[argn];
00715                 if (!fileInputName.endsWith(".rar")) {
00716                     fileInputName += ".rar";
00717                 }
00718             } else if (doProperty || doUpdate) {
00719                 if (fileOutputName == null) {
00720                     fileOutputName = args[argn];
00721                     if (!fileOutputName.endsWith(".rar")) {
00722                         fileOutputName += ".rar";
00723                     }
00724                 }
00725             } else {
00726                 usage();
00727                 throw new RAConfigException("Error multiple input files specified without -property or -update");
00728             }
00729         }
00730 
00731         // Usage ?
00732         if (isHelp) {
00733             usage();
00734             System.exit(0);
00735         }
00736         if (fileInputName == null) {
00737             usage();
00738             throw new RAConfigException("Error missing input file");
00739         }
00740         if (doProperty && fileOutputName == null) {
00741             usage();
00742             throw new RAConfigException("Error missing output file");
00743         }
00744         if (fileInputName.equals(fileOutputName)) {
00745             throw new RAConfigException("Input and Output filenames cannot be the same");
00746         }
00747 
00748         dbProps = new Properties();
00749         if (doProperty) {
00750             if (jdbcRarLink.length() > 0 && rarlink.length() == 0) {
00751                 rarlink = jdbcRarLink;
00752             }
00753             try {
00754                 dbProps.load(new FileInputStream(propertyFile));
00755             } catch (Exception ex) {
00756                 if (propertyFile.endsWith(".properties")) {
00757                     System.out.println("Error reading " + propertyFile + " " + ex);
00758                 } else {
00759                     try {
00760                         dbProps.load(new FileInputStream(propertyFile + ".properties"));
00761                     } catch (Exception ex1) {
00762                         System.out.println("Error reading " + propertyFile + " " + ex);
00763                     }
00764                 }
00765             }
00766             buildXML(fileInputName, jndiname, rarlink, dbProps, encrypt, securityfile, path, isVerbose);
00767             if (updatename.length() == 0) {
00768                 updatename = System.getProperty("java.io.tmpdir") + File.separator + "jonas-ra.xml";
00769             }
00770             updateRAR(fileInputName, fileOutputName, updatename, rarlink);
00771         } else if (doUpdate) {
00772             updateRAR(fileInputName, fileOutputName, updatename, rarlink);
00773         } else {
00774             buildXML(fileInputName, jndiname, rarlink, dbProps, encrypt, securityfile, path, isVerbose);
00775         }
00776     }
00777 }

Generated on Tue Feb 15 15:05:57 2005 for JOnAS by  doxygen 1.3.9.1