1 package org.apache.torque.generator.configuration.source;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.DRIVER_OPTION_ATTRIBUTE;
23 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.PASSWORD_OPTION_ATTRIBUTE;
24 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.SCHEMA_OPTION_ATTRIBUTE;
25 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.SOURCE_TAG;
26 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.URL_OPTION_ATTRIBUTE;
27 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.USERNAME_OPTION_ATTRIBUTE;
28
29 import org.apache.torque.generator.configuration.ConfigurationException;
30 import org.apache.torque.generator.configuration.ConfigurationHandlers;
31 import org.apache.torque.generator.configuration.ConfigurationProvider;
32 import org.apache.torque.generator.configuration.paths.ProjectPaths;
33 import org.apache.torque.generator.source.SourceProvider;
34 import org.apache.torque.generator.source.jdbc.JdbcMetadataSourceProvider;
35 import org.xml.sax.Attributes;
36 import org.xml.sax.SAXException;
37
38
39
40
41
42 public class JdbcMetadataSourceSaxHandler extends SourceSaxHandler
43 {
44
45
46
47 private SourceProvider sourceProvider;
48
49
50
51
52
53
54
55
56
57
58
59 public JdbcMetadataSourceSaxHandler(
60 ConfigurationProvider configurationProvider,
61 ProjectPaths projectPaths,
62 ConfigurationHandlers configurationHandlers)
63 {
64 super(configurationProvider, projectPaths, configurationHandlers);
65 }
66
67
68
69
70 @Override
71 public void startElement(String uri, String localName, String rawName,
72 Attributes attributes)
73 throws SAXException
74 {
75 if (rawName.equals(SOURCE_TAG))
76 {
77 String urlOption
78 = attributes.getValue(URL_OPTION_ATTRIBUTE);
79 String driverOption
80 = attributes.getValue(DRIVER_OPTION_ATTRIBUTE);
81 String usernameOption
82 = attributes.getValue(USERNAME_OPTION_ATTRIBUTE);
83 String passwordOption
84 = attributes.getValue(PASSWORD_OPTION_ATTRIBUTE);
85 String schemaOption
86 = attributes.getValue(SCHEMA_OPTION_ATTRIBUTE);
87 try
88 {
89 sourceProvider = new JdbcMetadataSourceProvider(
90 urlOption,
91 driverOption,
92 usernameOption,
93 passwordOption,
94 schemaOption);
95 }
96 catch (ConfigurationException e)
97 {
98 throw new SAXException(
99 "Could not parse Source Tag: " + e.getMessage(),
100 e);
101 }
102 }
103 super.startElement(uri, localName, rawName, attributes);
104 }
105
106
107
108
109 @Override
110 public void endElement(String uri, String localName, String rawName)
111 throws SAXException
112 {
113 super.endElement(uri, localName, rawName);
114 if (rawName.equals(SOURCE_TAG))
115 {
116 finished();
117 }
118 }
119
120
121
122
123
124
125
126 public SourceProvider getSourceProvider()
127 {
128 return sourceProvider;
129 }
130 }