1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jdo.impl.enhancer;
18
19 import java.io.PrintWriter;
20 import java.io.IOException;
21
22 import java.util.Properties;
23
24 import org.apache.jdo.impl.enhancer.meta.EnhancerMetaData;
25 import org.apache.jdo.impl.enhancer.meta.EnhancerMetaDataFatalError;
26 import org.apache.jdo.impl.enhancer.meta.model.EnhancerMetaDataJDOModelImpl;
27 import org.apache.jdo.impl.enhancer.meta.prop.EnhancerMetaDataPropertyImpl;
28 import org.apache.jdo.impl.enhancer.meta.util.EnhancerMetaDataTimer;
29
30 /***
31 * Base class for JDO command line enhancer and tests.
32 *
33 * @author Martin Zaun
34 */
35 public class JdoMetaMain
36 extends ClassArgMain
37 {
38 /***
39 * The options and arguments.
40 */
41 protected JdoMetaOptions options;
42
43 /***
44 * The metadata.
45 */
46 protected EnhancerMetaData jdoMeta;
47
48 /***
49 * Creates an instance.
50 */
51 public JdoMetaMain(PrintWriter out,
52 PrintWriter err)
53 {
54 this(out, err, new JdoMetaOptions(out, err));
55 }
56
57 /***
58 * Creates an instance.
59 */
60 public JdoMetaMain(PrintWriter out,
61 PrintWriter err,
62 JdoMetaOptions options)
63 {
64 super(out, err, options);
65 this.options = options;
66 }
67
68
69
70 /***
71 * Initializes the jdo metadata component.
72 */
73 protected void initJdoMetaData()
74 throws EnhancerMetaDataFatalError
75 {
76 final boolean verbose = options.verbose.value;
77 final String path = options.jdoPath.value;
78 final String jdoPropsFile = options.jdoPropertiesFile.value;
79
80 if (jdoPropsFile != null && jdoPropsFile.length() > 0) {
81
82 if (path != null && path.length() > 0) {
83
84
85 try {
86 final Properties props = new Properties();
87 props.load(classes.getInputStreamForResource(jdoPropsFile));
88 jdoMeta = new EnhancerMetaDataPropertyImpl(out,
89 verbose,
90 props);
91 } catch (IOException ex) {
92 throw new EnhancerMetaDataFatalError(ex);
93 }
94 } else {
95
96 jdoMeta = new EnhancerMetaDataPropertyImpl(out,
97 verbose,
98 jdoPropsFile);
99 }
100 } else {
101
102 jdoMeta = new EnhancerMetaDataJDOModelImpl(
103 out, verbose,
104 null,
105 options.archiveFileNames,
106 path);
107 }
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128 if (options.doTiming.value) {
129 jdoMeta = new EnhancerMetaDataTimer(jdoMeta);
130 }
131 }
132
133 /***
134 * Initializes all components.
135 */
136 protected void init()
137 throws EnhancerFatalError, EnhancerUserException
138 {
139 super.init();
140 try {
141 initJdoMetaData();
142 } catch (Exception ex) {
143 throw new EnhancerFatalError(ex);
144 }
145 }
146
147
148
149 /***
150 * Runs this class
151 */
152 static public void main(String[] args)
153 {
154 final PrintWriter out = new PrintWriter(System.out, true);
155 out.println("--> JdoMetaMain.main()");
156 final JdoMetaMain main = new JdoMetaMain(out, out);
157 int res = main.run(args);
158 out.println("<-- JdoMetaMain.main(): exit = " + res);
159 System.exit(res);
160 }
161 }