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 org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.torque.generator.configuration.ConfigurationProvider;
25 import org.apache.torque.generator.configuration.paths.ProjectPaths;
26 import org.apache.torque.generator.control.action.MergepointAction;
27 import org.xml.sax.Attributes;
28 import org.xml.sax.SAXException;
29 import org.xml.sax.helpers.DefaultHandler;
30
31 /**
32 * A SAX Handler which handles for the action element in mergepoints.
33 *
34 */
35 public abstract class ActionSaxHandler extends DefaultHandler
36 {
37 /** The logger of the class. */
38 private static Log log = LogFactory.getLog(ActionSaxHandler.class);
39
40 /** The action which configured by this handler, not null. */
41 private MergepointAction action;
42
43 /** The paths of the underlying project, not null. */
44 private ProjectPaths projectPaths;
45
46 /** The configuration provider for accessing the configuration, not null. */
47 private ConfigurationProvider configurationProvider;
48
49 /**
50 * Constructor.
51 *
52 * @param action paths of the underlying project, not null.
53 * @param configurationProvider The access object for the configuration
54 * files, not null.
55 * @param projectPaths The paths of the surrounding project, not null.
56 *
57 * @throws NullPointerException if an argument is null.
58 */
59 public ActionSaxHandler(
60 MergepointAction action,
61 ConfigurationProvider configurationProvider,
62 ProjectPaths projectPaths)
63 {
64 if (action == null)
65 {
66 log.error("ActionSaxHandler: "
67 + " action is null");
68 throw new NullPointerException("Action is null");
69 }
70 if (configurationProvider == null)
71 {
72 log.error("ActionSaxHandler: "
73 + " configurationProvider is null");
74 throw new NullPointerException("configurationProvider is null");
75 }
76 if (projectPaths == null)
77 {
78 log.error("ActionSaxHandler: "
79 + " projectPaths is null");
80 throw new NullPointerException("projectPaths is null");
81 }
82 this.action = action;
83 this.configurationProvider = configurationProvider;
84 this.projectPaths = projectPaths;
85 }
86
87 /**
88 * {@inheritDoc}
89 */
90 @Override
91 public void startElement(
92 String uri,
93 String localName,
94 String rawName,
95 Attributes attributes)
96 throws SAXException
97 {
98 throw new SAXException("unknown Element " + rawName);
99 }
100
101 /**
102 * Returns the action which was configured by this handler.
103 *
104 * @return the action configured by this handler, not null.
105 */
106 public MergepointAction getAction()
107 {
108 return action;
109 }
110
111 /**
112 * Returns the configuration provider used by this handler.
113 *
114 * @return the configuration provider, not null.
115 */
116 protected ConfigurationProvider getConfigurationProvider()
117 {
118 return configurationProvider;
119 }
120
121 /**
122 * Returns the project paths used by this handler.
123 *
124 * @return the project paths, not null.
125 */
126 protected ProjectPaths getProjectPaths()
127 {
128 return projectPaths;
129 }
130 }