1 package org.apache.torque.generator.configuration.mergepoint;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import static org.apache.torque.generator.configuration.mergepoint.MergepointConfigurationTags.ACTION_ACCEPT_NOT_SET_ATTRIBUTE;
23 import static org.apache.torque.generator.configuration.mergepoint.MergepointConfigurationTags.ACTION_OPTION_ATTRIBUTE;
24
25 import org.apache.torque.generator.configuration.ConfigurationProvider;
26 import org.apache.torque.generator.configuration.SaxHelper;
27 import org.apache.torque.generator.configuration.paths.ProjectPaths;
28 import org.apache.torque.generator.control.action.OptionAction;
29 import org.xml.sax.Attributes;
30 import org.xml.sax.SAXException;
31
32 /**
33 * A SAX handler which reads the configuration for a OptionAction
34 * and creates and configures the Action according to the values in the
35 * configuration XML.
36 */
37 public class OptionActionSaxHandler extends ActionSaxHandler
38 {
39 /**
40 * Creates a OptionActionSaxHandler for reading the configuration
41 * of a OptionAction.
42 * @param uri - The Namespace URI, or the empty string if the
43 * element has no Namespace URI or if Namespace processing is not
44 * being performed.
45 * @param localName - The local name (without prefix), or
46 * the empty string if Namespace processing is not being performed.
47 * @param qName - The qualified name (with prefix), or the empty string if
48 * qualified names are not available.
49 * @param attributes - The attributes attached to the element.
50 * If there are no attributes, it shall be an empty Attributes
51 * object.
52 * @param configurationProvider The access object for the configuration
53 * files, not null.
54 * @param projectPaths The paths of the surrounding project, not null.
55 *
56 * @throws NullPointerException if an argument is null.
57 * @throws SAXException if the element cannot be processed correctly.
58 */
59 public OptionActionSaxHandler(
60 String uri,
61 String localName,
62 String qName,
63 Attributes attributes,
64 ConfigurationProvider configurationProvider,
65 ProjectPaths projectPaths)
66 throws SAXException
67 {
68 super(createAction(attributes), configurationProvider, projectPaths);
69 }
70
71 /**
72 * Creates the action from the attributes of the action element.
73 *
74 * @param attributes the attributes of the action element.
75 *
76 * @return the action filled with the attribute values, not null.
77 *
78 * @throws SAXException if the creation of the action fails.
79 */
80 private static OptionAction createAction(Attributes attributes)
81 throws SAXException
82 {
83 String option = attributes.getValue(ACTION_OPTION_ATTRIBUTE);
84 Boolean acceptNotSet = SaxHelper.getBooleanAttribute(
85 ACTION_ACCEPT_NOT_SET_ATTRIBUTE,
86 attributes,
87 "the OptionAction " + option);
88 OptionAction action = new OptionAction(option, acceptNotSet);
89 return action;
90 }
91
92 /**
93 * {@inheritDoc}
94 */
95 @Override
96 public void startElement(
97 String uri,
98 String localName,
99 String rawName,
100 Attributes attributes)
101 throws SAXException
102 {
103 throw new SAXException("Unknown tag " + rawName);
104 }
105 }