Debian Codegraph @

src/main/java/net/sf/antcontrib/walls/WallsFileHandler.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.antcontrib.walls;
17
18 import java.io.File;
19
20 import org.apache.tools.ant.Project;
21 import org.xml.sax.*;
22
23
24 /**
25 * Handler for the root element. Its only child must be the "project" element.
26 */
27 class WallsFileHandler extends HandlerBase {
28
29 private final CompileWithWalls compilewithwalls;
30 private File file = null;
31 private Walls walls = null;
32 private Locator locator = null;
33
34 /**
35 * @param CompileWithWalls
36 */
37 WallsFileHandler(CompileWithWalls walls, File file) {
38 this.compilewithwalls = walls;
39 this.file = file;
40 }
41
42 /**
43 * Resolves file: URIs relative to the build file.
44 *
45 * @param publicId The public identifer, or <code>null</code>
46 * if none is available. Ignored in this
47 * implementation.
48 * @param systemId The system identifier provided in the XML
49 * document. Will not be <code>null</code>.
50 */
51 public InputSource resolveEntity(String publicId,
52 String systemId) {
53 compilewithwalls.log("publicId="+publicId+" systemId="+systemId,
54 Project.MSG_VERBOSE);
55 return null;
56 }
57
58 /**
59 * Handles the start of a project element. A project handler is created
60 * and initialised with the element name and attributes.
61 *
62 * @param tag The name of the element being started.
63 * Will not be <code>null</code>.
64 * @param attrs Attributes of the element being started.
65 * Will not be <code>null</code>.
66 *
67 * @exception SAXParseException if the tag given is not
68 * <code>"project"</code>
69 */
70 public void startElement(String name, AttributeList attrs) throws SAXParseException {
71 if (name.equals("walls")) {
72 if(attrs.getLength() > 0)
73 throw new SAXParseException("Error in file="+file.getAbsolutePath()
74 +", no attributes allowed for walls element", locator);
75 walls = this.compilewithwalls.createWalls();
76 } else if (name.equals("package")) {
77 handlePackage(attrs);
78 } else {
79 throw new SAXParseException("Error in file="+file.getAbsolutePath()
80 +", Unexpected element \"" + name + "\"", locator);
81 }
82 }
83
84 private void handlePackage(AttributeList attrs) throws SAXParseException {
85 if(walls == null)
86 throw new SAXParseException("Error in file="+file.getAbsolutePath()
87 +", package element must be nested in a walls element", locator);
88
89 String name = attrs.getValue("name");
90 String thePackage = attrs.getValue("package");
91 String depends = attrs.getValue("depends");
92 if(name == null)
93 throw new SAXParseException("Error in file="+file.getAbsolutePath()
94 +", package element must contain the 'name' attribute", locator);
95 else if(thePackage == null)
96 throw new SAXParseException("Error in file="+file.getAbsolutePath()
97 +", package element must contain the 'package' attribute", locator);
98
99 Package p = new Package();
100 p.setName(name);
101 p.setPackage(thePackage);
102 if(depends != null)
103 p.setDepends(depends);
104
105 walls.addConfiguredPackage(p);
106 }
107 /**
108 * Sets the locator in the project helper for future reference.
109 *
110 * @param locator The locator used by the parser.
111 * Will not be <code>null</code>.
112 */
113 public void setDocumentLocator(Locator locator) {
114 this.locator = locator;
115 }
116 }