View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  package org.apache.jdo.impl.enhancer;
18  
19  import java.io.PrintWriter;
20  
21  
22  /***
23   * Set of options used by the JDO enhancer and its test programs.
24   *
25   * @author Martin Zaun
26   */
27  public class JdoMetaOptions
28      extends ClassArgOptions
29  {
30      /***
31       * The jdo path option.
32       */
33      public final StringOption jdoPath
34          = createStringOption("jdopath", "j",
35                               "<path>     : path for lookup of jdo files");
36  
37      /***
38       * The jdo properties option.
39       */
40      public final StringOption jdoPropertiesFile
41          = createStringOption("properties", null,
42                               "<file>  : use property file for JDO metadata");
43  
44      /***
45       * Creates an instance.
46       */
47      public JdoMetaOptions(PrintWriter out,
48                            PrintWriter err) 
49      {
50          super(out, err);
51      }
52  
53      // ----------------------------------------------------------------------
54  
55      /***
56       * Print a usage message to System.err.
57       */
58      public void printUsageHeader()
59      {
60          printlnErr("Usage: <options>.. <arguments>..");
61          printlnErr(indent
62                     + "JDO metadata options:");
63          printlnErr(indent
64                     + "  --properties <file> [-j <path>] use property file for JDO metadata");
65          printlnErr(indent
66                     + "  -j <path>                       lookup .jdo files in the specified path");
67          printlnErr(indent
68                     + "Source option and arguments:");
69          printlnErr(indent
70                     + "  -s <path>   <classname>..");
71          printlnErr(indent
72                     + "              <classfile>..");
73          printlnErr(indent
74                     + "              <archivefile>..");
75      }
76  
77      /***
78       * Check options and arguments.
79       */
80      public int check()
81      {
82          int res;
83          if ((res = super.check()) != OK) {
84              return res;
85          }
86          
87          // check jdopath option
88          if (jdoPropertiesFile.value == null && 
89              jdoPath.value == null && archiveFileNames.isEmpty()) {
90              printUsageError("No JDO metadata option: specify either properties file or jdo-path for lookup of jdo files");
91              return USAGE_ERROR;
92          }
93  
94          return OK;
95      }
96  
97      // ----------------------------------------------------------------------
98  
99      /***
100      * Tests the class.
101      */
102     static public void main(String[] args)
103     {
104         final PrintWriter out = new PrintWriter(System.out, true);
105         out.println("--> JdoMetaOptions.main()");
106         final JdoMetaOptions options = new JdoMetaOptions(out, out);
107         out.println("    options.process() ...");
108         int res = options.process(args);
109         out.println("    return value: " + res);
110         out.println("<-- JdoMetaOptions.main()");
111     }
112 }