1 package org.apache.torque.generator.configuration.outlet; 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.outlet.OutletConfigurationTags.OUTLET_NAME_ATTRIBUTE; 23 import static org.apache.torque.generator.configuration.outlet.OutletConfigurationTags.OUTLET_PATH_ATTRIBUTE; 24 25 import org.apache.torque.generator.configuration.ConfigurationException; 26 import org.apache.torque.generator.configuration.ConfigurationHandlers; 27 import org.apache.torque.generator.configuration.ConfigurationProvider; 28 import org.apache.torque.generator.configuration.paths.ProjectPaths; 29 import org.apache.torque.generator.qname.QualifiedName; 30 import org.apache.torque.generator.template.groovy.GroovyOutlet; 31 import org.xml.sax.Attributes; 32 import org.xml.sax.SAXException; 33 34 /** 35 * Handles a declaration of a velocity outlet within a outlet 36 * configuration file. 37 */ 38 class GroovyOutletSaxHandler extends OutletSaxHandler 39 { 40 /** 41 * Constructor. 42 * 43 * @param outletName the name for the outlet which configuration 44 * will be read in by the generated SaxHandlerFactory, 45 * or null if the name of the outlet should be determined from 46 * the parsed XML. 47 * @param configurationProvider The access object for the configuration 48 * files, not null. 49 * @param projectPaths The paths of the surrounding project, not null. 50 * @param configurationHandlers the available configuration handlers, 51 * not null. 52 * 53 * @throws SAXException if an error occurs during creation of the outlet. 54 */ 55 public GroovyOutletSaxHandler( 56 QualifiedName outletName, 57 ConfigurationProvider configurationProvider, 58 ProjectPaths projectPaths, 59 ConfigurationHandlers configurationHandlers) 60 throws SAXException 61 { 62 super(outletName, 63 configurationProvider, 64 projectPaths, 65 configurationHandlers); 66 } 67 68 /** 69 * Instantiates and configures a groovy outlet. 70 * 71 * @param outletName the name for the outlet which configuration 72 * will be read in by the generated SaxHandlerFactory, 73 * or null if the name of the outlet should be determined from 74 * the parsed xml. 75 * @param uri - The Namespace URI, or the empty string if the 76 * element has no Namespace URI or if Namespace processing is not 77 * being performed. 78 * @param localName - The local name (without prefix), or 79 * the empty string if Namespace processing is not being performed. 80 * @param rawName - The qualified name (with prefix), or the empty string if 81 * qualified names are not available. 82 * @param attributes - The attributes attached to the element. 83 * If there are no attributes, it shall be an empty Attributes 84 * object. 85 * 86 * @return the created outlet, not null. 87 * 88 * @throws SAXException if an error occurs during creation. 89 */ 90 protected GroovyOutlet createOutlet( 91 QualifiedName outletName, 92 String uri, 93 String localName, 94 String rawName, 95 Attributes attributes) 96 throws SAXException 97 { 98 if (outletName == null) 99 { 100 String nameAttribute 101 = attributes.getValue(OUTLET_NAME_ATTRIBUTE); 102 if (nameAttribute == null) 103 { 104 throw new SAXException("The attribute " 105 + OUTLET_NAME_ATTRIBUTE 106 + " must be set on the element " 107 + rawName 108 + " for Groovy Outlets"); 109 } 110 outletName = new QualifiedName(nameAttribute); 111 } 112 113 String path = attributes.getValue(OUTLET_PATH_ATTRIBUTE); 114 115 try 116 { 117 GroovyOutlet result 118 = new GroovyOutlet( 119 outletName, 120 getConfigurationProvider(), 121 path); 122 return result; 123 } 124 catch (ConfigurationException e) 125 { 126 throw new SAXException(e); 127 } 128 } 129 }