1:
31: package ;
32:
33: import ;
34:
35: import ;
36: import ;
37: import ;
38: import ;
39: import ;
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45:
46:
51: public class SQLDataFactoryReadHandler extends AbstractXmlReadHandler
52: implements DataFactoryReadHandler
53: {
54: private ConnectionReadHandler connectionProviderReadHandler;
55: private ArrayList queries;
56: private ConfigReadHandler configReadHandler;
57: private ReportDataFactory dataFactory;
58:
59: public SQLDataFactoryReadHandler()
60: {
61: queries = new ArrayList();
62: }
63:
64:
72: protected XmlReadHandler getHandlerForChild(final String uri,
73: final String tagName,
74: final Attributes atts)
75: throws SAXException
76: {
77:
78: final ConnectionReadHandlerFactory factory = ConnectionReadHandlerFactory.getInstance();
79: final ConnectionReadHandler handler = (ConnectionReadHandler) factory.getHandler(uri, tagName);
80: if (handler != null)
81: {
82: connectionProviderReadHandler = handler;
83: return connectionProviderReadHandler;
84: }
85:
86: if (isSameNamespace(uri) == false)
87: {
88: return null;
89: }
90: if ("config".equals(tagName))
91: {
92: configReadHandler = new ConfigReadHandler();
93: return configReadHandler;
94: }
95: if ("query".equals(tagName))
96: {
97: final XmlReadHandler queryReadHandler = new PropertyReadHandler();
98: queries.add(queryReadHandler);
99: return queryReadHandler;
100: }
101: return null;
102: }
103:
104:
109: protected void doneParsing() throws SAXException
110: {
111: ConnectionProvider provider = null;
112: if (connectionProviderReadHandler != null)
113: {
114: provider = connectionProviderReadHandler.getProvider();
115: }
116: if (provider == null)
117: {
118: provider = (ConnectionProvider)
119: getRootHandler().getHelperObject("connection-provider");
120: }
121: if (provider == null)
122: {
123: throw new ParseException
124: ("Unable to create SQL Factory: No connection provider.", getLocator());
125: }
126:
127: final SQLReportDataFactory srdf = new SQLReportDataFactory(provider);
128: if (configReadHandler != null)
129: {
130: final Boolean labelMapping = configReadHandler.isLabelMapping();
131: if (labelMapping != null)
132: {
133: srdf.setLabelMapping(labelMapping.booleanValue());
134: }
135: }
136: for (int i = 0; i < queries.size(); i++)
137: {
138: final PropertyReadHandler handler = (PropertyReadHandler) queries.get(i);
139: srdf.setQuery(handler.getName(), handler.getResult());
140: }
141: dataFactory = srdf;
142: }
143:
144:
151: public Object getObject() throws SAXException
152: {
153: return dataFactory;
154: }
155:
156: public ReportDataFactory getDataFactory()
157: {
158: return dataFactory;
159: }
160: }