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