User: starksm
Date: 01/11/20 01:42:55
Modified: src/main/org/jboss/metadata Tag: Branch_2_4
BeanMetaData.java MetaData.java XmlFileLoader.java
Log:
Change to the unified log4j based org.jboss.logging.Logger class.
Revision Changes Path
No revision
No revision
1.23.2.4 +31 -2 jboss/src/main/org/jboss/metadata/BeanMetaData.java
Index: BeanMetaData.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/metadata/BeanMetaData.java,v
retrieving revision 1.23.2.3
retrieving revision 1.23.2.4
diff -u -r1.23.2.3 -r1.23.2.4
--- BeanMetaData.java 2001/11/12 19:32:56 1.23.2.3
+++ BeanMetaData.java 2001/11/20 09:42:54 1.23.2.4
@@ -29,7 +29,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel OConnor</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Ole Husgaard</a>
- * @version $Revision: 1.23.2.3 $
+ * @version $Revision: 1.23.2.4 $
*/
public abstract class BeanMetaData
extends MetaData
@@ -442,6 +442,7 @@
refMetaData.importEjbJarXml(resourceRef);
resourceEnvReferences.put(refMetaData.getRefName(), refMetaData);
}
+ trim();
}
public void importJbossXml(Element element) throws DeploymentException
@@ -510,8 +511,36 @@
}
ejbRefMetaData.importJbossXml(ejbRef);
}
+ trim();
}
-
+
+ /** Trim all string elements that correspond to class names which
+ cannot tolerate leading and trailing space.
+ */
+ public void trim()
+ {
+ if( ejbName != null )
+ ejbName = ejbName.trim();
+ if( homeClass != null )
+ homeClass = homeClass.trim();
+ if( remoteClass != null )
+ remoteClass = remoteClass.trim();
+ if( localHomeClass != null )
+ localHomeClass = localHomeClass.trim();
+ if( localClass != null )
+ localClass = localClass.trim();
+ if( ejbClass != null )
+ ejbClass = ejbClass.trim();
+ if( jndiName != null )
+ jndiName = jndiName.trim();
+ if( localJndiName != null )
+ localJndiName = localJndiName.trim();
+ if( configurationName != null )
+ configurationName = configurationName.trim();
+ if( securityProxy != null )
+ securityProxy = securityProxy.trim();
+ }
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
1.13.6.2 +158 -136 jboss/src/main/org/jboss/metadata/MetaData.java
Index: MetaData.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/metadata/MetaData.java,v
retrieving revision 1.13.6.1
retrieving revision 1.13.6.2
diff -u -r1.13.6.1 -r1.13.6.2
--- MetaData.java 2001/11/02 08:42:36 1.13.6.1
+++ MetaData.java 2001/11/20 09:42:54 1.13.6.2
@@ -18,157 +18,179 @@
/**
- * <description>
- *
+ * <description>
+ *
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
- * @version $Revision: 1.13.6.1 $
+ * @version $Revision: 1.13.6.2 $
*/
-public abstract class MetaData implements XmlLoadable {
- // Constants -----------------------------------------------------
- public static final byte TX_NOT_SUPPORTED = 0;
- public static final byte TX_REQUIRED = 1;
- public static final byte TX_SUPPORTS = 2;
- public static final byte TX_REQUIRES_NEW = 3;
- public static final byte TX_MANDATORY = 4;
- public static final byte TX_NEVER = 5;
- public static final byte TX_UNKNOWN = 6;
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
- public static Iterator getChildrenByTagName(Element element, String tagName) {
- if (element == null) return null;
-
- // getElementsByTagName gives the corresponding elements in the whole
descendance.
- // We want only children
-
- NodeList children = element.getChildNodes();
- ArrayList goodChildren = new ArrayList();
- for (int i=0; i<children.getLength(); i++) {
- Node currentChild = children.item(i);
- if (currentChild.getNodeType() == Node.ELEMENT_NODE &&
- ((Element)currentChild).getTagName().equals(tagName)) {
- goodChildren.add((Element)currentChild);
- }
- }
- return goodChildren.iterator();
- }
-
-
- public static Element getUniqueChild(Element element, String tagName) throws
DeploymentException {
-
- Iterator goodChildren = getChildrenByTagName(element, tagName);
-
- if (goodChildren != null && goodChildren.hasNext()) {
- Element child = (Element)goodChildren.next();
- if (goodChildren.hasNext()) {
- throw new DeploymentException("expected only one " +
tagName + " tag");
- }
- return child;
- } else {
- throw new DeploymentException("expected one " + tagName + "
tag");
- }
- }
-
-
- /**
- * Gets the child of the specified element having the
- * specified name. If the child with this name doesn't exist
- * then null is returned instead.
- *
- * @param element the parent element
- * @param tagName the name of the desired child
- * @return either the named child or null
- */
- public static Element getOptionalChild(Element element, String tagName) throws
DeploymentException {
- return getOptionalChild(element, tagName, null);
- }
-
- /**
- * Gets the child of the specified element having the
- * specified name. If the child with this name doesn't exist
- * then the supplied default element is returned instead.
- *
- * @param element the parent element
- * @param tagName the name of the desired child
- * @param defaultElement the element to return if the child
- * doesn't exist
- * @return either the named child or the supplied default
- */
- public static Element getOptionalChild(Element element, String tagName,
Element defaultElement) throws DeploymentException {
- Iterator goodChildren = getChildrenByTagName(element, tagName);
-
- if (goodChildren != null && goodChildren.hasNext()) {
- Element child = (Element)goodChildren.next();
- if (goodChildren.hasNext()) {
- throw new DeploymentException("expected only one " +
tagName + " tag");
- }
- return child;
- } else {
- return defaultElement;
- }
- }
-
- public static String getElementContent(Element element) throws
DeploymentException {
-
- return getElementContent(element, null);
- }
-
- public static String getElementContent(Element element, String defaultStr)
throws DeploymentException {
- if (element == null) return defaultStr;
-
- NodeList children = element.getChildNodes();
+public abstract class MetaData implements XmlLoadable
+{
+ // Constants -----------------------------------------------------
+ public static final byte TX_NOT_SUPPORTED = 0;
+ public static final byte TX_REQUIRED = 1;
+ public static final byte TX_SUPPORTS = 2;
+ public static final byte TX_REQUIRES_NEW = 3;
+ public static final byte TX_MANDATORY = 4;
+ public static final byte TX_NEVER = 5;
+ public static final byte TX_UNKNOWN = 6;
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+ public static Iterator getChildrenByTagName(Element element, String tagName)
+ {
+ if (element == null) return null;
+ // getElementsByTagName gives the corresponding elements in the whole
descendance.
+ // We want only children
+
+ NodeList children = element.getChildNodes();
+ ArrayList goodChildren = new ArrayList();
+ for (int i=0; i<children.getLength(); i++)
+ {
+ Node currentChild = children.item(i);
+ if (currentChild.getNodeType() == Node.ELEMENT_NODE &&
+ ((Element)currentChild).getTagName().equals(tagName))
+ {
+ goodChildren.add((Element)currentChild);
+ }
+ }
+ return goodChildren.iterator();
+ }
+
+
+ public static Element getUniqueChild(Element element, String tagName) throws
DeploymentException
+ {
+
+ Iterator goodChildren = getChildrenByTagName(element, tagName);
+
+ if (goodChildren != null && goodChildren.hasNext())
+ {
+ Element child = (Element)goodChildren.next();
+ if (goodChildren.hasNext())
+ {
+ throw new DeploymentException("expected only one " + tagName + " tag");
+ }
+ return child;
+ } else
+ {
+ throw new DeploymentException("expected one " + tagName + " tag");
+ }
+ }
+
+
+ /**
+ * Gets the child of the specified element having the
+ * specified name. If the child with this name doesn't exist
+ * then null is returned instead.
+ *
+ * @param element the parent element
+ * @param tagName the name of the desired child
+ * @return either the named child or null
+ */
+ public static Element getOptionalChild(Element element, String tagName) throws
DeploymentException
+ {
+ return getOptionalChild(element, tagName, null);
+ }
+
+ /**
+ * Gets the child of the specified element having the
+ * specified name. If the child with this name doesn't exist
+ * then the supplied default element is returned instead.
+ *
+ * @param element the parent element
+ * @param tagName the name of the desired child
+ * @param defaultElement the element to return if the child
+ * doesn't exist
+ * @return either the named child or the supplied default
+ */
+ public static Element getOptionalChild(Element element, String tagName, Element
defaultElement) throws DeploymentException
+ {
+ Iterator goodChildren = getChildrenByTagName(element, tagName);
+
+ if (goodChildren != null && goodChildren.hasNext())
+ {
+ Element child = (Element)goodChildren.next();
+ if (goodChildren.hasNext())
+ {
+ throw new DeploymentException("expected only one " + tagName + " tag");
+ }
+ return child;
+ } else
+ {
+ return defaultElement;
+ }
+ }
+
+ public static String getElementContent(Element element) throws
DeploymentException
+ {
+
+ return getElementContent(element, null);
+ }
+
+ public static String getElementContent(Element element, String defaultStr)
throws DeploymentException
+ {
+ if (element == null) return defaultStr;
+
+ NodeList children = element.getChildNodes();
+
if (children.getLength() > 0)
{
String result = "";
for (int i = 0; i < children.getLength(); i++)
{
- if (children.item(i).getNodeType() == Node.TEXT_NODE ||
- children.item(i).getNodeType() == Node.CDATA_SECTION_NODE)
+ if (children.item(i).getNodeType() == Node.TEXT_NODE ||
+ children.item(i).getNodeType() == Node.CDATA_SECTION_NODE)
result += children.item(i).getNodeValue();
else
- result += children.item(i).getFirstChild();
+ result += children.item(i).getFirstChild();
}
return result;
} else
{
return defaultStr;
+ }
+ }
+
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+ public void importXml(Element element) throws DeploymentException
+ {
+ String rootTag = element.getOwnerDocument().getDocumentElement().getTagName();
+
+ if (rootTag.equals("jboss"))
+ {
+ // import jboss.xml
+ importJbossXml(element);
+ } else if (rootTag.equals("ejb-jar"))
+ {
+ // import ejb-jar.xml
+ importEjbJarXml(element);
+ } else
+ {
+ throw new DeploymentException("Unrecognized root tag : "+ rootTag);
}
- }
-
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
- public void importXml (Element element) throws DeploymentException {
- String rootTag =
element.getOwnerDocument().getDocumentElement().getTagName();
-
- if (rootTag.equals("jboss")) {
- // import jboss.xml
- importJbossXml(element);
- } else if (rootTag.equals("ejb-jar")) {
- // import ejb-jar.xml
- importEjbJarXml(element);
- } else {
- throw new DeploymentException("Unrecognized root tag : "+
rootTag);
- }
- }
-
- public void importEjbJarXml (Element element) throws DeploymentException {}
- public void importJbossXml (Element element) throws DeploymentException {}
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
- protected boolean jdk13Enabled() {
- // should use "java.version" ?
- String javaVersion = System.getProperty("java.vm.version");
- return javaVersion.compareTo("1.3") >= 0;
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
+ }
+
+ public void importEjbJarXml(Element element) throws DeploymentException
+ {}
+ public void importJbossXml(Element element) throws DeploymentException
+ {}
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+ protected boolean jdk13Enabled()
+ {
+ // should use "java.version" ?
+ String javaVersion = System.getProperty("java.vm.version");
+ return javaVersion.compareTo("1.3") >= 0;
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
}
1.15.2.3 +326 -310 jboss/src/main/org/jboss/metadata/XmlFileLoader.java
Index: XmlFileLoader.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/metadata/XmlFileLoader.java,v
retrieving revision 1.15.2.2
retrieving revision 1.15.2.3
diff -u -r1.15.2.2 -r1.15.2.3
--- XmlFileLoader.java 2001/11/02 08:42:36 1.15.2.2
+++ XmlFileLoader.java 2001/11/20 09:42:55 1.15.2.3
@@ -37,190 +37,200 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Wolfgang Werner</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Darius Davidavicius</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>
- * @version $Revision: 1.15.2.2 $
+ * @version $Revision: 1.15.2.3 $
*
* Revisions:
* 20010620 Bill Burke: Print an error message when failing to load
standardjboss.xml
* or jboss.xml. It was a pain to debug a standardjboss.xml
* syntax error.
*/
-public class XmlFileLoader {
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
- private static boolean defaultValidateDTDs = false;
- private ClassLoader classLoader;
- private ApplicationMetaData metaData;
- private boolean validateDTDs;
-
- // Static --------------------------------------------------------
- public static boolean getDefaultValidateDTDs()
- {
- return defaultValidateDTDs;
- }
- public static void setDefaultValidateDTDs(boolean validate)
- {
- defaultValidateDTDs = validate;
- }
-
- // Constructors --------------------------------------------------
- public XmlFileLoader()
- {
- this(defaultValidateDTDs);
- }
- public XmlFileLoader(boolean validateDTDs)
- {
- this.validateDTDs = validateDTDs;
- }
-
- // Public --------------------------------------------------------
- public ApplicationMetaData getMetaData() {
- return metaData;
- }
-
+public class XmlFileLoader
+{
+ private static Logger log = Logger.getLogger(XmlFileLoader.class);
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+ private static boolean defaultValidateDTDs = false;
+ private ClassLoader classLoader;
+ private ApplicationMetaData metaData;
+ private boolean validateDTDs;
+
+ // Static --------------------------------------------------------
+ public static boolean getDefaultValidateDTDs()
+ {
+ return defaultValidateDTDs;
+ }
+ public static void setDefaultValidateDTDs(boolean validate)
+ {
+ defaultValidateDTDs = validate;
+ }
+
+ // Constructors --------------------------------------------------
+ public XmlFileLoader()
+ {
+ this(defaultValidateDTDs);
+ }
+ public XmlFileLoader(boolean validateDTDs)
+ {
+ this.validateDTDs = validateDTDs;
+ }
+
+ // Public --------------------------------------------------------
+ public ApplicationMetaData getMetaData()
+ {
+ return metaData;
+ }
+
/**
- Set the class loader
- @param ClassLoader cl - class loader
- */
- public void setClassLoader(ClassLoader cl) {
- classLoader = cl;
- }
-
+ Set the class loader
+ @param ClassLoader cl - class loader
+ */
+ public void setClassLoader(ClassLoader cl)
+ {
+ classLoader = cl;
+ }
+
/**
- Gets the class loader
- @return ClassLoader - the class loader
- */
- public ClassLoader getClassLoader() {
- return classLoader;
- }
-
+ Gets the class loader
+ @return ClassLoader - the class loader
+ */
+ public ClassLoader getClassLoader()
+ {
+ return classLoader;
+ }
+
/** Get the flag indicating that ejb-jar.dtd, jboss.dtd &
jboss-web.dtd conforming documents should be validated
against the DTD.
*/
public boolean getValidateDTDs()
{
- return validateDTDs;
+ return validateDTDs;
}
/** Set the flag indicating that ejb-jar.dtd, jboss.dtd &
jboss-web.dtd conforming documents should be validated
against the DTD.
*/
public void setValidateDTDs(boolean validate)
+ {
+ this.validateDTDs = validate;
+ }
+
+ /**
+ * load()
+ *
+ * This method creates the ApplicationMetaData.
+ * The configuration files are found in the classLoader.
+ * The default jboss.xml and jaws.xml files are always read first, then we
override
+ * the defaults if the user provides them
+ *
+ */
+ public ApplicationMetaData load() throws Exception
{
- this.validateDTDs = validate;
+ // create the metadata
+ metaData = new ApplicationMetaData();
+
+ // Load ejb-jar.xml
+
+ // we can always find the files in the classloader
+ URL ejbjarUrl = getClassLoader().getResource("META-INF/ejb-jar.xml");
+
+ if (ejbjarUrl == null)
+ {
+ throw new DeploymentException("no ejb-jar.xml found");
+ }
+
+ Document ejbjarDocument = getDocumentFromURL(ejbjarUrl);
+
+ // the url may be used to report errors
+ metaData.setUrl(ejbjarUrl);
+ metaData.importEjbJarXml(ejbjarDocument.getDocumentElement());
+
+ // Load jbossdefault.xml from the default classLoader
+ // we always load defaults first
+ // we use the context classloader, because this guy has to know where
+ // this file is
+ URL defaultJbossUrl =
Thread.currentThread().getContextClassLoader().getResource("standardjboss.xml");
+
+ if (defaultJbossUrl == null)
+ {
+ throw new DeploymentException("no standardjboss.xml found");
+ }
+
+ Document defaultJbossDocument = null;
+
+ try
+ {
+ defaultJbossDocument = getDocumentFromURL(defaultJbossUrl);
+
+ metaData.setUrl(defaultJbossUrl);
+ metaData.importJbossXml(defaultJbossDocument.getDocumentElement());
+ }
+ catch (Exception ex)
+ {
+ log.error("failed to load standardjboss.xml. There could be a syntax
error.");
+ throw ex;
+ }
+ // Load jboss.xml
+ // if this file is provided, then we override the defaults
+ try
+ {
+ URL jbossUrl = getClassLoader().getResource("META-INF/jboss.xml");
+
+ if (jbossUrl != null)
+ {
+ // Logger.debug(jbossUrl.toString() + " found.
Overriding defaults");
+ Document jbossDocument = getDocumentFromURL(jbossUrl);
+
+ metaData.setUrl(jbossUrl);
+ metaData.importJbossXml(jbossDocument.getDocumentElement());
+ }
+ }
+ catch (Exception ex)
+ {
+ log.error("failed to load jboss.xml. There could be a syntax error.");
+ throw ex;
+ }
+
+ return metaData;
}
-
- /**
- * load()
- *
- * This method creates the ApplicationMetaData.
- * The configuration files are found in the classLoader.
- * The default jboss.xml and jaws.xml files are always read first, then we
override
- * the defaults if the user provides them
- *
- */
- public ApplicationMetaData load() throws Exception {
- // create the metadata
- metaData = new ApplicationMetaData();
-
- // Load ejb-jar.xml
-
- // we can always find the files in the classloader
- URL ejbjarUrl = getClassLoader().getResource("META-INF/ejb-jar.xml");
-
- if (ejbjarUrl == null) {
- throw new DeploymentException("no ejb-jar.xml found");
- }
-
- Document ejbjarDocument = getDocumentFromURL(ejbjarUrl);
-
- // the url may be used to report errors
- metaData.setUrl(ejbjarUrl);
- metaData.importEjbJarXml(ejbjarDocument.getDocumentElement());
-
- // Load jbossdefault.xml from the default classLoader
- // we always load defaults first
- // we use the context classloader, because this guy has to know where
- // this file is
- URL defaultJbossUrl =
Thread.currentThread().getContextClassLoader().getResource("standardjboss.xml");
-
- if (defaultJbossUrl == null) {
- throw new DeploymentException("no standardjboss.xml found");
- }
-
- Document defaultJbossDocument = null;
-
- try
- {
- defaultJbossDocument = getDocumentFromURL(defaultJbossUrl);
-
- metaData.setUrl(defaultJbossUrl);
- metaData.importJbossXml(defaultJbossDocument.getDocumentElement());
- }
- catch (Exception ex)
- {
- Logger.error("failed to load standardjboss.xml. There could be a
syntax error.");
- throw ex;
- }
- // Load jboss.xml
- // if this file is provided, then we override the defaults
- try
- {
- URL jbossUrl = getClassLoader().getResource("META-INF/jboss.xml");
-
- if (jbossUrl != null) {
- // Logger.debug(jbossUrl.toString() + "
found. Overriding defaults");
- Document jbossDocument = getDocumentFromURL(jbossUrl);
-
- metaData.setUrl(jbossUrl);
- metaData.importJbossXml(jbossDocument.getDocumentElement());
- }
- }
- catch (Exception ex)
- {
- Logger.error("failed to load jboss.xml. There could be a syntax
error.");
- throw ex;
- }
-
- return metaData;
- }
-
- /** Invokes getDocument(url, defaultValidateDTDs)
- */
- public static Document getDocument(URL url) throws DeploymentException
- {
- return getDocument(url, defaultValidateDTDs);
- }
- /** Get the xml file from the URL and parse it into a Document object.
- Calls new XmlFileLoader(validateDTDs).getDocumentFromURL(url);
- @param url, the URL from which the xml doc is to be obtained.
+
+ /** Invokes getDocument(url, defaultValidateDTDs)
+ */
+ public static Document getDocument(URL url) throws DeploymentException
+ {
+ return getDocument(url, defaultValidateDTDs);
+ }
+ /** Get the xml file from the URL and parse it into a Document object.
+ Calls new XmlFileLoader(validateDTDs).getDocumentFromURL(url);
+ @param url, the URL from which the xml doc is to be obtained.
@return Document
*/
- public static Document getDocument(URL url, boolean validateDTDs) throws
DeploymentException
- {
- XmlFileLoader loader = new XmlFileLoader(validateDTDs);
- return loader.getDocumentFromURL(url);
- }
-
- /** Get the xml file from the URL and parse it into a Document object.
- Calls getDocument(url.openStream(), url.getPath());
- @param url, the URL from which the xml doc is to be obtained.
+ public static Document getDocument(URL url, boolean validateDTDs) throws
DeploymentException
+ {
+ XmlFileLoader loader = new XmlFileLoader(validateDTDs);
+ return loader.getDocumentFromURL(url);
+ }
+
+ /** Get the xml file from the URL and parse it into a Document object.
+ Calls getDocument(url.openStream(), url.getPath());
+ @param url, the URL from which the xml doc is to be obtained.
@return Document
*/
- public Document getDocumentFromURL(URL url) throws DeploymentException
- {
- try
- {
- InputStream is = url.openStream();
- String docPath = url.getPath();
- return getDocument(is, docPath);
- } catch (IOException e) {
- throw new DeploymentException("Failed to obtain xml doc from URL", e);
- }
- }
-
- /** Parses the xml document in is and created the DOM Document. DTD validation
+ public Document getDocumentFromURL(URL url) throws DeploymentException
+ {
+ try
+ {
+ InputStream is = url.openStream();
+ String docPath = url.getPath();
+ return getDocument(is, docPath);
+ } catch (IOException e)
+ {
+ throw new DeploymentException("Failed to obtain xml doc from URL", e);
+ }
+ }
+
+ /** Parses the xml document in is and created the DOM Document. DTD validation
is enabled if validateDTDs is true and we install an EntityResolver and
ErrorHandler to resolve J2EE DTDs and handle errors.
@param is, the InputStream container the xml descriptor to parse
@@ -228,43 +238,46 @@
only for error reporting.
@return Document
*/
- public Document getDocument(InputStream is, String inPath) throws
DeploymentException
- {
- try
- {
- DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
- // Enable DTD validation based on our validateDTDs flag
- docBuilderFactory.setValidating(validateDTDs);
- DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-
- LocalResolver lr = new LocalResolver();
- ErrorHandler eh = new LocalErrorHandler( inPath, lr );
- docBuilder.setEntityResolver(lr);
- docBuilder.setErrorHandler(eh );
-
- Document doc = docBuilder.parse(is);
- return doc;
- } catch (SAXParseException e) {
-
System.out.println(e.getMessage()+":"+e.getColumnNumber()+":"+e.getLineNumber());
- e.printStackTrace();
- throw new DeploymentException(e.getMessage(), e);
- } catch (SAXException e) {
- System.out.println(e.getException());
- throw new DeploymentException(e.getMessage(), e);
- } catch (Exception e) {
- throw new DeploymentException(e.getMessage(), e);
- }
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
- /**
+ public Document getDocument(InputStream is, String inPath) throws
DeploymentException
+ {
+ try
+ {
+ DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
+ // Enable DTD validation based on our validateDTDs flag
+ docBuilderFactory.setValidating(validateDTDs);
+ DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+
+ LocalResolver lr = new LocalResolver();
+ ErrorHandler eh = new LocalErrorHandler( inPath, lr );
+ docBuilder.setEntityResolver(lr);
+ docBuilder.setErrorHandler(eh );
+
+ Document doc = docBuilder.parse(is);
+ return doc;
+ } catch (SAXParseException e)
+ {
+
System.out.println(e.getMessage()+":"+e.getColumnNumber()+":"+e.getLineNumber());
+ e.printStackTrace();
+ throw new DeploymentException(e.getMessage(), e);
+ } catch (SAXException e)
+ {
+ System.out.println(e.getException());
+ throw new DeploymentException(e.getMessage(), e);
+ } catch (Exception e)
+ {
+ throw new DeploymentException(e.getMessage(), e);
+ }
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+ /**
* Local entity resolver to handle J2EE DTDs. With this a http connection
* to sun is not needed during deployment.
* Function boolean hadDTD() is here to avoid validation errors in
@@ -272,71 +285,74 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Wolfgang Werner</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Darius Davidavicius</a>
**/
- private static class LocalResolver implements EntityResolver
- {
- private Hashtable dtds = new Hashtable();
- private boolean hasDTD = false;
-
- public LocalResolver() {
- registerDTD("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans
1.1//EN", "ejb-jar.dtd");
- registerDTD("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans
2.0//EN", "ejb-jar_2_0.dtd");
- registerDTD("-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN",
"application_1_2.dtd");
- registerDTD("-//Sun Microsystems, Inc.//DTD Connector 1.0//EN",
"connector_1_0.dtd");
- registerDTD("-//JBoss//DTD JAWS//EN", "jaws.dtd");
- registerDTD("-//JBoss//DTD JAWS 2.4//EN", "jaws_2_4.dtd");
- registerDTD("-//JBoss//DTD JBOSS//EN","jboss.dtd");
- registerDTD("-//JBoss//DTD JBOSS 2.4//EN","jboss_2_4.dtd");
- }
-
- /**
- Registers available DTDs
- @param String publicId - Public ID of DTD
- @param String dtdFileName - the file name of DTD
- */
- public void registerDTD(String publicId, String dtdFileName) {
- dtds.put(publicId, dtdFileName);
- }
-
- /**
- Returns DTD inputSource. Is DTD was found in the hashtable and inputSource
was created
- flad hasDTD is ser to true.
- @param String publicId - Public ID of DTD
- @param String dtdFileName - the file name of DTD
- @return InputSource of DTD
- */
- public InputSource resolveEntity (String publicId, String systemId)
- {
- hasDTD = false;
- String dtd = (String)dtds.get(publicId);
-
- if (dtd != null)
+ private static class LocalResolver implements EntityResolver
+ {
+ private Hashtable dtds = new Hashtable();
+ private boolean hasDTD = false;
+
+ public LocalResolver()
+ {
+ registerDTD("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN",
"ejb-jar.dtd");
+ registerDTD("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN",
"ejb-jar_2_0.dtd");
+ registerDTD("-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN",
"application_1_2.dtd");
+ registerDTD("-//Sun Microsystems, Inc.//DTD Connector 1.0//EN",
"connector_1_0.dtd");
+ registerDTD("-//JBoss//DTD JAWS//EN", "jaws.dtd");
+ registerDTD("-//JBoss//DTD JAWS 2.4//EN", "jaws_2_4.dtd");
+ registerDTD("-//JBoss//DTD JBOSS//EN","jboss.dtd");
+ registerDTD("-//JBoss//DTD JBOSS 2.4//EN","jboss_2_4.dtd");
+ }
+
+ /**
+ Registers available DTDs
+ @param String publicId - Public ID of DTD
+ @param String dtdFileName - the file name of DTD
+ */
+ public void registerDTD(String publicId, String dtdFileName)
+ {
+ dtds.put(publicId, dtdFileName);
+ }
+
+ /**
+ Returns DTD inputSource. Is DTD was found in the hashtable and inputSource
was created
+ flad hasDTD is ser to true.
+ @param String publicId - Public ID of DTD
+ @param String dtdFileName - the file name of DTD
+ @return InputSource of DTD
+ */
+ public InputSource resolveEntity(String publicId, String systemId)
+ {
+ hasDTD = false;
+ String dtd = (String)dtds.get(publicId);
+
+ if (dtd != null)
+ {
+ hasDTD = true;
+ try
+ {
+ InputStream dtdStream = getClass().getResourceAsStream(dtd);
+ InputSource aInputSource = new InputSource(dtdStream);
+ return aInputSource;
+ } catch( Exception ex )
{
- hasDTD = true;
- try
- {
- InputStream dtdStream = getClass().getResourceAsStream(dtd);
- InputSource aInputSource = new InputSource(dtdStream);
- return aInputSource;
- } catch( Exception ex ) {
- // ignore
- }
+ // ignore
}
- return null;
- }
-
+ }
+ return null;
+ }
+
/**
- Returns the boolean value to inform id DTD was found in the XML file or not
- @return boolean - true if DTD was found in XML
- */
- public boolean hasDTD ()
- {
- return hasDTD;
- }
-
- }
-
- /** Local error handler for entity resolver to DocumentBuilder parser.
- Error is printed to output just if DTD was detected in the XML file.
+ Returns the boolean value to inform id DTD was found in the XML file or not
+ @return boolean - true if DTD was found in XML
+ */
+ public boolean hasDTD()
+ {
+ return hasDTD;
+ }
+
+ }
+
+ /** Local error handler for entity resolver to DocumentBuilder parser.
+ Error is printed to output just if DTD was detected in the XML file.
If DTD was not found in XML file it is assumed that the EJB builder
doesn't want to use DTD validation. Validation may have been enabled via
validateDTDs flag so we look to the hasDTD() function in the LocalResolver
@@ -344,61 +360,61 @@
@author <a href="mailto:[EMAIL PROTECTED]">Wolfgang Werner</a>
@author <a href="mailto:[EMAIL PROTECTED]">Darius Davidavicius</a>
**/
- private static class LocalErrorHandler implements ErrorHandler
- {
- // The xml file being parsed
- private String theFileName;
- private LocalResolver localResolver;
- public LocalErrorHandler( String inFileName, LocalResolver localResolver )
- {
- this.theFileName = inFileName;
- this.localResolver = localResolver;
- }
-
- public void error(SAXParseException exception)
- {
- if ( localResolver.hasDTD() )
- {
- System.out.println("XmlFileLoader: File "
- + theFileName
- + " process error. Line: "
- + String.valueOf(exception.getLineNumber())
- + ". Error message: "
- + exception.getMessage()
- );
- }//end if
- }
- public void fatalError(SAXParseException exception)
- {
- if ( localResolver.hasDTD() )
- {
- System.out.println("XmlFileLoader: File "
- + theFileName
- + " process fatal error. Line: "
- + String.valueOf(exception.getLineNumber())
- + ". Error message: "
- + exception.getMessage()
- );
- }//end if
- }
- public void warning(SAXParseException exception)
- {
- if ( localResolver.hasDTD() )
- {
- System.out.println("XmlFileLoader: File "
- + theFileName
- + " process warning. Line: "
- + String.valueOf(exception.getLineNumber())
- + ". Error message: "
- + exception.getMessage()
- );
- }//end if
- }
- }// end class LocalErrorHandler
-
+ private static class LocalErrorHandler implements ErrorHandler
+ {
+ // The xml file being parsed
+ private String theFileName;
+ private LocalResolver localResolver;
+ public LocalErrorHandler( String inFileName, LocalResolver localResolver )
+ {
+ this.theFileName = inFileName;
+ this.localResolver = localResolver;
+ }
+
+ public void error(SAXParseException exception)
+ {
+ if ( localResolver.hasDTD() )
+ {
+ System.out.println("XmlFileLoader: File "
+ + theFileName
+ + " process error. Line: "
+ + String.valueOf(exception.getLineNumber())
+ + ". Error message: "
+ + exception.getMessage()
+ );
+ }//end if
+ }
+ public void fatalError(SAXParseException exception)
+ {
+ if ( localResolver.hasDTD() )
+ {
+ System.out.println("XmlFileLoader: File "
+ + theFileName
+ + " process fatal error. Line: "
+ + String.valueOf(exception.getLineNumber())
+ + ". Error message: "
+ + exception.getMessage()
+ );
+ }//end if
+ }
+ public void warning(SAXParseException exception)
+ {
+ if ( localResolver.hasDTD() )
+ {
+ System.out.println("XmlFileLoader: File "
+ + theFileName
+ + " process warning. Line: "
+ + String.valueOf(exception.getLineNumber())
+ + ". Error message: "
+ + exception.getMessage()
+ );
+ }//end if
+ }
+ }// end class LocalErrorHandler
+
}
/* Change log:
-
+
* Author: starksm, Date: Thu Jun 14 17:14:14 2001 GMT
Incorporated Darius Davidavicius changes to support DTD validation.
*/
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development