01: /**
02: * EasyBeans
03: * Copyright (C) 2007 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: WARDeploymentDescLoader.java 2054 2007-11-20 14:43:55Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.deployment.xml.parsing;
25:
26: import java.net.URL;
27:
28: import org.ow2.easybeans.deployment.xml.struct.WAR;
29: import org.ow2.easybeans.util.xml.DocumentParser;
30: import org.ow2.easybeans.util.xml.DocumentParserException;
31: import org.ow2.util.log.Log;
32: import org.ow2.util.log.LogFactory;
33: import org.w3c.dom.Document;
34: import org.w3c.dom.Element;
35:
36: /**
37: * This class analyzes the WAR deployment descriptor and fill a struct with
38: * getters.
39: * @author Florent Benoit
40: */
41: public class WARDeploymentDescLoader extends AbsWebLoader {
42:
43: /**
44: * Logger.
45: */
46: private static Log logger = LogFactory
47: .getLog(WARDeploymentDescLoader.class);
48:
49: /**
50: * Constructor.
51: * @param url the url that is pointing to the web xml file.
52: */
53: protected WARDeploymentDescLoader(final URL url) {
54: super (url);
55: }
56:
57: /**
58: * Load the web.xml file.
59: * @param url the URL of the XML file.
60: * @throws ParsingException if parsing of XML file fails.
61: * @return an application object.
62: */
63: public static WAR loadDeploymentDescriptor(final URL url)
64: throws ParsingException {
65: logger.debug("Analyzing url {0}", url);
66:
67: WARDeploymentDescLoader warDeploymentDescLoader = new WARDeploymentDescLoader(
68: url);
69: warDeploymentDescLoader.parse();
70: return warDeploymentDescLoader.getWAR();
71: }
72:
73: /**
74: * Analyze the URL and build an EJB3 object which contains data of the XML.
75: * @throws ParsingException if the analyze of the file fails.
76: */
77: public void parse() throws ParsingException {
78: // Get document
79: Document document = null;
80: try {
81: document = DocumentParser.getDocument(getURL(), false,
82: new WAREntityResolver());
83: } catch (DocumentParserException e) {
84: throw new ParsingException("Cannot parse the url", e);
85: }
86:
87: // Root element = <web-app>
88: Element webAppRootElement = document.getDocumentElement();
89:
90: // Analyze the web-app element
91: analyzeServlets(webAppRootElement);
92: // And listeners
93: analyzeListeners(webAppRootElement);
94:
95: }
96:
97: }
|