KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > vladium > util > args > IOptsParser


1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2  *
3  * This program and the accompanying materials are made available under
4  * the terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * $Id: IOptsParser.java,v 1.1.1.1 2004/05/09 16:57:56 vlad_r Exp $
8  */

9 package com.vladium.util.args;
10
11 import java.io.PrintWriter JavaDoc;
12
13 // ----------------------------------------------------------------------------
14
/**
15  * @author Vlad Roubtsov, (C) 2002
16  */

17 public
18 interface IOptsParser
19 {
20     // public: ................................................................
21

22     int SHORT_USAGE = 1;
23     int DETAILED_USAGE = 2;
24
25     interface IOpt
26     {
27         String JavaDoc getName ();
28         String JavaDoc getCanonicalName ();
29         
30         String JavaDoc getPatternPrefix ();
31         
32         int getValueCount ();
33         String JavaDoc getFirstValue ();
34         String JavaDoc [] getValues ();
35       
36     } // end of interface
37

38     
39     interface IOpts
40     {
41         /**
42          * 0: none, 1: short, 2: detailed
43          *
44          * @return
45          */

46         int usageRequestLevel ();
47         void error (PrintWriter JavaDoc out, int width);
48         
49         IOpt [] getOpts ();
50         boolean hasArg (String JavaDoc name);
51         
52         IOpt [] getOpts (String JavaDoc pattern);
53         
54         /**
55          *
56          * @return [never null, could be empty]
57          */

58         String JavaDoc [] getFreeArgs ();
59         
60     } // end of interface
61

62     void usage (PrintWriter JavaDoc out, int level, int width);
63     IOpts parse (String JavaDoc [] args);
64     
65     abstract class Factory
66     {
67         // TODO: pass short/long usage opt names in?
68

69         public static IOptsParser create (final String JavaDoc metadataResourceName, final ClassLoader JavaDoc loader,
70                                           final String JavaDoc msgPrefix, final String JavaDoc [] usageOpts)
71         {
72             return new OptsParser (metadataResourceName, loader, msgPrefix, usageOpts);
73         }
74         
75     } // end of nested class
76

77 } // end of interface
78
// ----------------------------------------------------------------------------
Popular Tags