001: /**
002: * EasyBeans
003: * Copyright (C) 2007 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: AbsDeploymentDescLoader.java 2054 2007-11-20 14:43:55Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.deployment.xml.parsing;
025:
026: import java.net.URL;
027:
028: import org.w3c.dom.Element;
029:
030: /**
031: * Common stuff for parsing XML files.
032: * @author Florent BENOIT
033: */
034: public abstract class AbsDeploymentDescLoader {
035:
036: /**
037: * Java EE namespace (Java EE).
038: */
039: public static final String JAVAEE_NS = "http://java.sun.com/xml/ns/javaee";
040:
041: /**
042: * J2EE namespace (J2EE).
043: */
044: public static final String J2EE_NS = "http://java.sun.com/xml/ns/j2ee";
045:
046: /**
047: * Validating with schema ?
048: */
049: private static boolean validating = true;
050:
051: /**
052: * URL of the file being analyzed.
053: */
054: private URL url = null;
055:
056: /**
057: * Namespace to use when analyzing the XML file. It depends if the archive is J2EE or Java EE module.
058: */
059: private String xmlns = null;
060:
061: /**
062: * Create a new Desc Loader for the given URL.
063: * @param url the url that is pointing to the EJB Xml file.
064: */
065: protected AbsDeploymentDescLoader(final URL url) {
066: this .url = url;
067: }
068:
069: /**
070: * @return the URL used by this loader.
071: */
072: protected URL getURL() {
073: return url;
074: }
075:
076: /**
077: * @return true if the deployment is being validated.
078: */
079: public static boolean isValidating() {
080: return validating;
081: }
082:
083: /**
084: * Defines the namespace that needs to be used for this XML parsing.
085: * @param element the DOM element used to get the namespace.
086: * @throws ParsingException if no namespace is found
087: */
088: protected void defineXMLNS(final Element element)
089: throws ParsingException {
090: // get the namespace of this element
091: String ns = element.getNamespaceURI();
092: if (JAVAEE_NS.equals(ns)) {
093: this .xmlns = JAVAEE_NS;
094: } else if (J2EE_NS.equals(ns)) {
095: this .xmlns = J2EE_NS;
096: } else {
097: throw new ParsingException("Unsupported XML namespace: "
098: + ns);
099: }
100: }
101:
102: /**
103: * @return the Namespace to use when analyzing the XML file.
104: */
105: protected String getXMLNS() {
106: return xmlns;
107: }
108:
109: }
|