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_EMPTY_ATTRIBUTE;
23  import static org.apache.torque.generator.configuration.mergepoint.MergepointConfigurationTags.ACTION_ELEMENT_ATTRIBUTE;
24  import static org.apache.torque.generator.configuration.mergepoint.MergepointConfigurationTags.ACTION_OUTLET_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.MergepointAction;
30  import org.apache.torque.generator.control.action.TraverseAllAction;
31  import org.xml.sax.Attributes;
32  import org.xml.sax.SAXException;
33  
34  /**
35   * A SAX handler which reads the configuration for a TraverseAllAction
36   * and creates and configures the Action according to the values in the
37   * configuration XML.
38   */
39  public class TraverseAllActionSaxHandler extends ActionSaxHandler
40  {
41      /**
42       * Creates a TraverseAllActionSaxHandler for redaing the configuration
43       * of a TraverseAllAction.
44       * @param uri The namespace URI of the action element,
45       *        or the empty string if the element has no namespace URI
46       *        or if namespace processing is not being performed.
47       * @param localName The local name (without prefix), or
48       *        the empty string if Namespace processing is not being performed.
49       * @param qName - The qualified name (with prefix, if present),
50       *        or the empty string if  qualified names are not available.
51       * @param attributes The attributes attached to the element.
52       * @param configurationProvider for accessing the configuratiopn files,
53       *        not null.
54       * @param projectPaths The organization of the surrounding project,
55       *        not null.
56       *
57       * @throws NullPointerException if an argument is null.
58       * @throws SAXException if the element cannot be processed correctly.
59       */
60      public TraverseAllActionSaxHandler(
61              String uri,
62              String localName,
63              String qName,
64              Attributes attributes,
65              ConfigurationProvider configurationProvider,
66              ProjectPaths projectPaths)
67           throws SAXException
68       {
69          super(createAction(attributes), configurationProvider, projectPaths);
70       }
71  
72      /**
73       * Creates the action from the attributes of the action element.
74       *
75       * @param attributes the attributes of the action element.
76       *
77       * @return the action filled with the attribute values, not null.
78       *
79       * @throws SAXException if the creation of the action fails.
80       */
81      private static MergepointAction createAction(Attributes attributes)
82              throws SAXException
83      {
84          String element = attributes.getValue(ACTION_ELEMENT_ATTRIBUTE);
85          String outlet = attributes.getValue(ACTION_OUTLET_ATTRIBUTE);
86          Boolean acceptEmpty = SaxHelper.getBooleanAttribute(
87                  ACTION_ACCEPT_EMPTY_ATTRIBUTE,
88                  attributes,
89                  "the element " + element);
90          TraverseAllAction action = new TraverseAllAction(
91                  element,
92                  outlet,
93                  acceptEmpty);
94          return action;
95      }
96  
97      /**
98       * {@inheritDoc}
99       */
100     @Override
101     public void startElement(
102             String uri,
103             String localName,
104             String rawName,
105             Attributes attributes)
106         throws SAXException
107     {
108         throw new SAXException("Unknown tag " + rawName);
109     }
110 }