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