View Javadoc

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_ATTRIBUTE_ATTRIBUTE;
24  import static org.apache.torque.generator.configuration.mergepoint.MergepointConfigurationTags.ACTION_ELEMENT_ATTRIBUTE;
25  
26  import org.apache.torque.generator.configuration.ConfigurationProvider;
27  import org.apache.torque.generator.configuration.SaxHelper;
28  import org.apache.torque.generator.configuration.paths.ProjectPaths;
29  import org.apache.torque.generator.control.action.SourceElementAttributeAction;
30  import org.xml.sax.Attributes;
31  import org.xml.sax.SAXException;
32  
33  /**
34   * A SAX handler which reads the configuration for a
35   * SourceElementAttributeAction and creates and configures the Action
36   * according to the values in the configuration XML.
37   */
38  public class SourceElementAttributeActionSaxHandler extends ActionSaxHandler
39  {
40      /**
41       * Creates a OptionActionSaxHandler for reading the configuration
42       * of a SourceElementAttributeAction.
43       * @param uri The namespace URI of the action element,
44       *        or the empty string if the element has no namespace URI
45       *        or if namespace processing is not being performed.
46       * @param localName The local name (without prefix), or
47       *        the empty string if Namespace processing is not being performed.
48       * @param qName - The qualified name (with prefix, if present),
49       *        or the empty string if  qualified names are not available.
50       * @param attributes The attributes attached to the element.
51       * @param configurationProvider for accessing the configuratiopn files,
52       *        not null.
53       * @param projectPaths The organization of the surrounding project,
54       *        not null.
55       *
56       * @throws NullPointerException if an argument is null.
57       * @throws SAXException if the element cannot be processed correctly.
58       */
59      public SourceElementAttributeActionSaxHandler(
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 SourceElementAttributeAction createAction(
81              Attributes attributes)
82          throws SAXException
83      {
84          String element = attributes.getValue(ACTION_ELEMENT_ATTRIBUTE);
85          String attribute = attributes.getValue(ACTION_ATTRIBUTE_ATTRIBUTE);
86          Boolean acceptNotSet = SaxHelper.getBooleanAttribute(
87                  ACTION_ACCEPT_NOT_SET_ATTRIBUTE,
88                  attributes,
89                  "the SourceElementAttributeAction " + element);
90          SourceElementAttributeAction action
91                  = new SourceElementAttributeAction(
92                          element,
93                          attribute,
94                          acceptNotSet);
95          return action;
96      }
97  
98      /**
99       * {@inheritDoc}
100      */
101     @Override
102     public void startElement(
103             String uri,
104             String localName,
105             String rawName,
106             Attributes attributes)
107         throws SAXException
108     {
109         throw new SAXException("Unknown tag " + rawName);
110     }
111 }