Skip to content

Commit

Permalink
Allow an empty beans.xml
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1529 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Feb 15, 2009
1 parent 58f8b68 commit 5bd4333
Showing 1 changed file with 45 additions and 30 deletions.
@@ -1,6 +1,7 @@
package org.jboss.webbeans.bootstrap;

import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.ArrayList;
Expand Down Expand Up @@ -100,50 +101,64 @@ public void parse()
List<DeployElement> deployElements = new ArrayList<DeployElement>();
for (URL url : beansXml)
{
Document document;
InputStream is;
boolean fileHasContents;
try
{
document = documentBuilder.parse(url.openStream());
document.normalize();
}
catch (SAXException e)
{
throw new DeploymentException("Error parsing beans.xml " + url.toString());
is = url.openStream();
fileHasContents = is.available() > 0;
}
catch (IOException e)
{
throw new DeploymentException("Error loading beans.xml " + url.toString());
throw new DeploymentException("Error loading beans.xml " + url.toString(), e);
}
Element beans = document.getDocumentElement();
Map<String, String> namespaces = new HashMap<String, String>();
for (int i = 0; i < beans.getAttributes().getLength(); i++)
if (fileHasContents)
{
Node child = beans.getAttributes().item(i);
if (child instanceof Attr)
Document document;
try
{
document = documentBuilder.parse(is);
document.normalize();
}
catch (SAXException e)
{
throw new DeploymentException("Error parsing beans.xml " + url.toString(), e);
}
catch (IOException e)
{
throw new DeploymentException("Error loading beans.xml " + url.toString(), e);
}
Element beans = document.getDocumentElement();
Map<String, String> namespaces = new HashMap<String, String>();
for (int i = 0; i < beans.getAttributes().getLength(); i++)
{
Attr attr = (Attr) child;
if (attr.getName().startsWith("xmlns"))
Node child = beans.getAttributes().item(i);
if (child instanceof Attr)
{
String namespacePrefix;
if (attr.getName().length() == 5)
{
namespacePrefix = "";
}
else
Attr attr = (Attr) child;
if (attr.getName().startsWith("xmlns"))
{
namespacePrefix = attr.getName().substring(6);
String namespacePrefix;
if (attr.getName().length() == 5)
{
namespacePrefix = "";
}
else
{
namespacePrefix = attr.getName().substring(6);
}

String namespace = attr.getValue();
namespaces.put(namespacePrefix, namespace);
}

String namespace = attr.getValue();
namespaces.put(namespacePrefix, namespace);
}
}
}
for (Node child : new NodeListIterable(beans.getChildNodes()))
{
if (child instanceof Element && "Deploy".equals(child.getNodeName()))
for (Node child : new NodeListIterable(beans.getChildNodes()))
{
deployElements.add(new DeployElement(url, (Element) child, namespaces));
if (child instanceof Element && "Deploy".equals(child.getNodeName()))
{
deployElements.add(new DeployElement(url, (Element) child, namespaces));
}
}
}
}
Expand Down

0 comments on commit 5bd4333

Please sign in to comment.