01: package org.geotools.maven.xmlcodegen;
02:
03: import java.io.File;
04: import java.io.IOException;
05: import java.net.URI;
06: import java.net.URISyntaxException;
07: import java.util.ArrayList;
08: import java.util.Iterator;
09: import java.util.logging.Level;
10:
11: import org.eclipse.xsd.XSDInclude;
12: import org.eclipse.xsd.XSDSchema;
13: import org.geotools.xml.Schemas;
14:
15: public class ConfigurationGenerator extends AbstractGenerator {
16: public void generate(XSDSchema schema) {
17:
18: try {
19: String result = execute("ConfigurationTemplate", schema);
20:
21: String prefix = Schemas.getTargetPrefix(schema)
22: .toUpperCase();
23: write(result, prefix + "Configuration");
24:
25: } catch (Exception e) {
26: logger.log(Level.SEVERE, "Error generating resolver", e);
27: }
28:
29: //copy over all included schemas
30: ArrayList includes = new ArrayList();
31:
32: File file = null;
33: try {
34: file = findSchemaFile(schema.getSchemaLocation());
35: } catch (IOException e) {
36: logger.log(Level.SEVERE, "", e);
37: }
38:
39: if (file != null) {
40: includes.add(file);
41: } else {
42: logger.log(Level.SEVERE, "Could not find: "
43: + schema.getSchemaLocation() + " to copy.");
44: }
45:
46: for (Iterator i = Schemas.getIncludes(schema).iterator(); i
47: .hasNext();) {
48: XSDInclude include = (XSDInclude) i.next();
49:
50: file = null;
51: try {
52: file = findSchemaFile(include.getSchemaLocation());
53: } catch (IOException e) {
54: logger.log(Level.SEVERE, "", e);
55: }
56:
57: if (file != null) {
58: includes.add(file);
59: } else {
60: logger.log(Level.SEVERE, "Could not find: "
61: + include.getSchemaLocation() + " to copy.");
62: }
63: }
64:
65: for (Iterator i = includes.iterator(); i.hasNext();) {
66: File include = (File) i.next();
67: try {
68: copy(include);
69: } catch (IOException e) {
70: logger.log(Level.WARNING, "Could not copy file "
71: + include, e);
72: }
73: }
74: }
75:
76: }
|