Author: vitold
Date: 2009-03-24 06:41:17 -0400 (Tue, 24 Mar 2009)
New Revision: 2178
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironment.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
Log:
add method loadFileByUrn(...) into XmlEnvironment.java for loadin schema.xsd and namespace
files
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-03-24
10:09:28 UTC (rev 2177)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-03-24
10:41:17 UTC (rev 2178)
@@ -66,7 +66,7 @@
{
}
- public static void checkRootAttributes(Element root, Map<String,
Set<String>> packagesMap)
+ public static void checkRootAttributes(Element root, Map<String,
Set<String>> packagesMap, XmlEnvironment environment)
{
Iterator<?> rootAttrIterator = root.attributeIterator();
while (rootAttrIterator.hasNext())
@@ -82,14 +82,14 @@
if (attrVal.startsWith(XmlConstants.URN_PREFIX))
{
urn = attrVal;
- URL namespaceFile = loadFile(urn, XmlConstants.NAMESPACE_FILE_NAME);
+ URL namespaceFile = environment.loadFileByUrn(urn,
XmlConstants.NAMESPACE_FILE_NAME);
if (namespaceFile == null)
throw new DefinitionException("Could not find '" +
XmlConstants.NAMESPACE_FILE_NAME + "' file according to specified URN '"
+ urn + "'");
packagesSet.addAll(parseNamespaceFile(namespaceFile));
}
if (attribute.getName().equalsIgnoreCase(XmlConstants.SCHEMA_LOCATION)
&& attrVal.startsWith(XmlConstants.HTTP_PREFIX) && urn.trim().length()
> 0)
{
- URL schemaFile = loadFile(urn, XmlConstants.SCHEMA_FILE_NAME);
+ URL schemaFile = environment.loadFileByUrn(urn,
XmlConstants.SCHEMA_FILE_NAME);
if (schemaFile == null)
throw new DefinitionException("Could not find '" +
XmlConstants.SCHEMA_FILE_NAME + "' file according to specified URN '" +
urn + "'");
}
@@ -99,7 +99,7 @@
}
}
- public static void checkRootDeclaredNamespaces(Element root, Map<String,
Set<String>> packagesMap)
+ public static void checkRootDeclaredNamespaces(Element root, Map<String,
Set<String>> packagesMap, XmlEnvironment environment)
{
Iterator<?> namespacesIterator = root.declaredNamespaces().iterator();
while (namespacesIterator.hasNext())
@@ -111,7 +111,7 @@
{
Set<String> packagesSet = new HashSet<String>();
- URL namespaceFile = loadFile(uri, XmlConstants.NAMESPACE_FILE_NAME);
+ URL namespaceFile = environment.loadFileByUrn(uri,
XmlConstants.NAMESPACE_FILE_NAME);
if (namespaceFile != null)
{
packagesSet.addAll(parseNamespaceFile(namespaceFile));
@@ -166,16 +166,6 @@
return false;
}
- private static URL loadFile(String urn, String fileName)
- {
- char separator = '/';
- String packageName = urn.replaceFirst(XmlConstants.URN_PREFIX, "");
- String path = packageName.replace('.', separator);
- String filePath = separator + path + separator + fileName;
- URL namespaceFile = ParseXmlHelper.class.getResource(filePath);
- return namespaceFile;
- }
-
private static Set<String> parseNamespaceFile(URL namespaceFile)
{
Set<String> packages = new HashSet<String>();
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironment.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironment.java 2009-03-24
10:09:28 UTC (rev 2177)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironment.java 2009-03-24
10:41:17 UTC (rev 2178)
@@ -74,4 +74,13 @@
return serviceRegistry.get(ResourceLoader.class).getResource(filePath);
}
+ public URL loadFileByUrn(String urn, String fileName)
+ {
+ char separator = '/';
+ String packageName = urn.replaceFirst(XmlConstants.URN_PREFIX, "");
+ String path = packageName.replace('.', separator);
+ String filePath = separator + path + separator + fileName;
+ return serviceRegistry.get(ResourceLoader.class).getResource(filePath);
+ }
+
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-03-24 10:09:28
UTC (rev 2177)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-03-24 10:41:17
UTC (rev 2178)
@@ -14,7 +14,6 @@
import javax.inject.DefinitionException;
import javax.inject.DeploymentException;
-import javax.inject.manager.Bean;
import org.dom4j.Document;
import org.dom4j.DocumentException;
@@ -219,7 +218,7 @@
private void fullFillPackagesMap(Document document)
{
Element root = document.getRootElement();
- ParseXmlHelper.checkRootAttributes(root, packagesMap);
- ParseXmlHelper.checkRootDeclaredNamespaces(root, packagesMap);
+ ParseXmlHelper.checkRootAttributes(root, packagesMap, environment);
+ ParseXmlHelper.checkRootDeclaredNamespaces(root, packagesMap, environment);
}
}