View Javadoc

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