GenerateWrapperConf.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  *
00022  * --------------------------------------------------------------------------
00023  * $Id: GenerateWrapperConf.java,v 1.1 2003/12/04 21:26:30 ehardesty Exp $
00024  * --------------------------------------------------------------------------
00025  */
00026 
00027 package org.objectweb.jonas.tools;
00028 
00029 import java.util.StringTokenizer;
00034 public class GenerateWrapperConf
00035 {
00036 
00062   String propertyName = null;
00063   int index = 1;
00064 
00068   void syntax()
00069   {
00070     System.err.println("syntax: GenerateWrapperConf [-d <delimiters>] [-i <indx>] property.name args");
00071     System.exit(1);
00072   }
00073 
00077   void syntax(String arg)
00078   {
00079     System.err.println("GenerateWrapperConf: unrecognized argument '" + arg + "'");
00080     syntax();
00081   }
00082 
00086   void syntax(Exception e)
00087   {
00088     System.err.println(e.toString());
00089     syntax();
00090   }
00091 
00095   void generateKey(String val)
00096   {
00097     System.out.println (propertyName + "." + index + "=" + val);
00098     index += 1;
00099   }
00100 
00105         void run(String[] args)
00106         {
00107     String delimiter = null;
00108     int i = 0; // index into args[]
00109 
00110     for ( ; i < args.length; i++)
00111     {
00112       if (args[i].charAt(0) != '-') break;
00113       try {
00114         switch(args[i].charAt(1))
00115         {
00116           case 'h':
00117           case '?':
00118             usage();
00119 
00120           case 'd':
00121             delimiter = args[++i];
00122             break;
00123 
00124           case 'i':
00125             index = Integer.parseInt(args[++i]);
00126             break;
00127 
00128           default:
00129             syntax(args[i]);
00130         }
00131       }
00132       catch (StringIndexOutOfBoundsException e) {
00133         syntax(args[i]);
00134       }
00135       catch (NumberFormatException e) {
00136         syntax(e);
00137       }
00138     }
00139 
00140     // first positional arg after -d is the property.name
00141     if ((args.length - i) < 2) syntax();
00142     propertyName = args[i];
00143     i += 1;
00144 
00145     if (delimiter == null)  // process array of individual args
00146     {
00147       for ( ; i < args.length; ++i) generateKey(args[i]);
00148     }
00149 
00150     else  // use StringTokenizer to parse single string
00151     {
00152       StringTokenizer st = new StringTokenizer(args[i], delimiter);
00153       while (st.hasMoreTokens()) generateKey(st.nextToken());
00154       i += 1;
00155     }
00156 
00157     if ((args.length - i) > 0) syntax();
00158         }
00159 
00163   public static void main(String[] args)
00164   {
00165     if (args.length == 0)
00166       usage();
00167     else
00168       new GenerateWrapperConf().run(args);
00169   }
00170 
00174   private static void usage()
00175   {
00176     System.out.println(
00177       "\nUsage: java org.objectweb.java.tools.GenerateWrapperConf [-h | -?]\n" +
00178       "           [-d <delimiters>] [-i <index>] property.name args\n" +
00179       "\n" +
00180       "  -h or -? display this help message.\n" +
00181       "  -d <delimiters> specifies a string of delimiters used to parse\n" +
00182       "                  args into individual tokens.\n" +
00183       "  -i <index>      specifies the initial index for generated property\n" +
00184       "                  values.  The default value is 1.\n" +
00185       "  property.name   specifies the property name to be generated.\n" +
00186       "                  Property names for the individual tokens are formed\n" +
00187       "                  as 'property.name.index' where 'index' is incremented\n" +
00188       "                  for each token.\n" +
00189       "  args            Either a single string to be parsed using StringTokenizer\n" +
00190       "                  and the delimiter specified by the -d option.\n" +
00191       "                  This form is used to process the CLASSPATH variable.\n\n" +
00192       "                  Or, an array of strings to be processed as individual tokens.\n" +
00193       "                  This form is used to process JAVA_OPTS style variables.\n"
00194     );
00195     System.exit(1); 
00196   }
00197 }

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