openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yingw...@apache.org
Subject svn commit: r930092 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/deployment/ main/java/org/apache/webbeans/util/ main/java/org/apache/webbeans/xml/ test/java/org/apache/webbeans/test/ test/java/org/apache/webbeans/test/unit...
Date Thu, 01 Apr 2010 20:48:31 GMT
Author: yingwang
Date: Thu Apr  1 20:48:31 2010
New Revision: 930092

URL: http://svn.apache.org/viewvc?rev=930092&view=rev
Log:
[OWB-310] switch to JVM DOM parser. There might be some bumps in my changes since I could not test all code path. 

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/deployment/XMLStereoTypeModel.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/Asserts.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLAnnotationTypeManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/XMLTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/deployment/XMLStereoTypeModel.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/deployment/XMLStereoTypeModel.java?rev=930092&r1=930091&r2=930092&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/deployment/XMLStereoTypeModel.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/deployment/XMLStereoTypeModel.java Thu Apr  1 20:48:31 2010
@@ -30,7 +30,9 @@ import org.apache.webbeans.exception.def
 import org.apache.webbeans.proxy.JavassistProxyFactory;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.xml.XMLUtil;
-import org.dom4j.Element;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 @SuppressWarnings("unchecked")
 public class XMLStereoTypeModel implements IStereoTypeModel
@@ -59,105 +61,105 @@ public class XMLStereoTypeModel implemen
 
     private void configure(Element stereoTypeDecleration, String errorMessage)
     {
-        List<Element> childs = stereoTypeDecleration.elements();
-        if (childs != null && childs.size() > 0)
+        boolean scopeTypeFound = false;
+        Node node; Element child;
+        NodeList ns = stereoTypeDecleration.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
         {
-            boolean scopeTypeFound = false;
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	child = (Element)node;
+            Class<?> clazz = XMLUtil.getElementJavaType(child);
+            if (clazz == null)
+            {
+                throw new NonexistentTypeException(errorMessage + "Type is not exist with class name : " + XMLUtil.getElementJavaClassName(child) + " in namespace : " + XMLUtil.getElementNameSpace(child) );
+            }
 
-            for (Element child : childs)
+            Class<? extends Annotation> annClazz = null;
+            if (!clazz.isAnnotation())
             {
-                Class<?> clazz = XMLUtil.getElementJavaType(child);
-                if (clazz == null)
-                {
-                    throw new NonexistentTypeException(errorMessage + "Type is not exist with class name : " + XMLUtil.getElementJavaClassName(child) + " in namespace : " + XMLUtil.getElementNameSpace(child) );
-                }
+                throw new WebBeansConfigurationException(errorMessage + "Type is not annotation type with class name : " + XMLUtil.getElementJavaClassName(child) +  " in namespace : " + XMLUtil.getElementNameSpace(child));
+            }
 
-                Class<? extends Annotation> annClazz = null;
-                if (!clazz.isAnnotation())
+            annClazz = (Class<? extends Annotation>) clazz;
+            Annotation defaultAnn = JavassistProxyFactory.createNewAnnotationProxy(annClazz);
+
+            if (clazz.isAnnotationPresent(NormalScope.class) || clazz.isAnnotationPresent(Scope.class))
+            {
+                if (scopeTypeFound)
                 {
-                    throw new WebBeansConfigurationException(errorMessage + "Type is not annotation type with class name : " + XMLUtil.getElementJavaClassName(child) +  " in namespace : " + XMLUtil.getElementNameSpace(child));
+                    throw new WebBeansConfigurationException(errorMessage + "@StereoType annotation can not contain more than one @Scope/@NormalScope annotation");
                 }
 
-                annClazz = (Class<? extends Annotation>) clazz;
-                Annotation defaultAnn = JavassistProxyFactory.createNewAnnotationProxy(annClazz);
-
-                if (clazz.isAnnotationPresent(NormalScope.class) || clazz.isAnnotationPresent(Scope.class))
-                {
-                    if (scopeTypeFound)
-                    {
-                        throw new WebBeansConfigurationException(errorMessage + "@StereoType annotation can not contain more than one @Scope/@NormalScope annotation");
-                    }
+                defaultScopeType = defaultAnn;
+                scopeTypeFound = true;
+            }                
+            else if (AnnotationUtil.isInterceptorBindingAnnotation(annClazz))
+            {
+                Target target = clazz.getAnnotation(Target.class);
+                ElementType[] type = target.value();
 
-                    defaultScopeType = defaultAnn;
-                    scopeTypeFound = true;
-                }                
-                else if (AnnotationUtil.isInterceptorBindingAnnotation(annClazz))
+                if (type.length != 1 && !type[0].equals(ElementType.TYPE))
                 {
-                    Target target = clazz.getAnnotation(Target.class);
-                    ElementType[] type = target.value();
-
-                    if (type.length != 1 && !type[0].equals(ElementType.TYPE))
-                    {
-                        throw new WebBeansConfigurationException(errorMessage + "Stereotype with @InterceptorBinding must be defined as @Target{TYPE}");
-                    }
-
-                    interceptorBindingTypes.add(XMLUtil.getXMLDefinedAnnotationMember(child, annClazz, errorMessage));
+                    throw new WebBeansConfigurationException(errorMessage + "Stereotype with @InterceptorBinding must be defined as @Target{TYPE}");
                 }
-                else if (clazz.equals(Named.class))
-                {
-                    defaultName = defaultAnn;
-                    Named name = (Named) defaultName;
-                    if (!name.value().equals(""))
-                    {
-                        throw new WebBeansConfigurationException(errorMessage + "@StereoType annotation can not define @Named annotation with value");
-                    }
-                }
-                else if (AnnotationUtil.isQualifierAnnotation(annClazz))
+
+                interceptorBindingTypes.add(XMLUtil.getXMLDefinedAnnotationMember(child, annClazz, errorMessage));
+            }
+            else if (clazz.equals(Named.class))
+            {
+                defaultName = defaultAnn;
+                Named name = (Named) defaultName;
+                if (!name.value().equals(""))
                 {
-                    throw new WebBeansConfigurationException(errorMessage + "@StereoType annotation can not define @Qualifier annotation");
+                    throw new WebBeansConfigurationException(errorMessage + "@StereoType annotation can not define @Named annotation with value");
                 }
+            }
+            else if (AnnotationUtil.isQualifierAnnotation(annClazz))
+            {
+                throw new WebBeansConfigurationException(errorMessage + "@StereoType annotation can not define @Qualifier annotation");
+            }
 
-                else if (AnnotationUtil.isStereoTypeAnnotation(annClazz))
-                {
-                    Target innerStereo = clazz.getAnnotation(Target.class);
-                    Class<?> outerStereoClass = XMLUtil.getElementJavaType(stereoTypeDecleration);
-                    Target outerStereo = outerStereoClass.getAnnotation(Target.class);
+            else if (AnnotationUtil.isStereoTypeAnnotation(annClazz))
+            {
+                Target innerStereo = clazz.getAnnotation(Target.class);
+                Class<?> outerStereoClass = XMLUtil.getElementJavaType(stereoTypeDecleration);
+                Target outerStereo = outerStereoClass.getAnnotation(Target.class);
 
-                    ElementType[] innerValues = innerStereo.value();
-                    ElementType[] outerValues = outerStereo.value();
+                ElementType[] innerValues = innerStereo.value();
+                ElementType[] outerValues = outerStereo.value();
 
-                    for (ElementType innerValue : innerValues)
+                for (ElementType innerValue : innerValues)
+                {
+                    if (innerValue.equals(ElementType.METHOD) || innerValue.equals(ElementType.FIELD))
                     {
-                        if (innerValue.equals(ElementType.METHOD) || innerValue.equals(ElementType.FIELD))
+                        for (ElementType outerValue : outerValues)
                         {
-                            for (ElementType outerValue : outerValues)
+                            if (outerValue.equals(ElementType.TYPE))
                             {
-                                if (outerValue.equals(ElementType.TYPE))
-                                {
-                                    throw new WebBeansConfigurationException(errorMessage + "Inherited StereoType with class name : " + clazz.getName() + " must have compatible @Target annotation with Stereotype class name : " + outerStereoClass.getName());
-                                }
+                                throw new WebBeansConfigurationException(errorMessage + "Inherited StereoType with class name : " + clazz.getName() + " must have compatible @Target annotation with Stereotype class name : " + outerStereoClass.getName());
                             }
                         }
-                        else if (innerValue.equals(ElementType.TYPE))
+                    }
+                    else if (innerValue.equals(ElementType.TYPE))
+                    {
+                        for (ElementType outerValue : outerValues)
                         {
-                            for (ElementType outerValue : outerValues)
+                            if (outerValue.equals(ElementType.METHOD) || outerValue.equals(ElementType.FIELD))
                             {
-                                if (outerValue.equals(ElementType.METHOD) || outerValue.equals(ElementType.FIELD))
-                                {
-                                    throw new WebBeansConfigurationException(errorMessage + "Inherited StereoType with class name : " + clazz.getName() + " must have compatible @Target annotation with Stereotype class name : " + outerStereoClass.getName());
-                                }
+                                throw new WebBeansConfigurationException(errorMessage + "Inherited StereoType with class name : " + clazz.getName() + " must have compatible @Target annotation with Stereotype class name : " + outerStereoClass.getName());
                             }
                         }
                     }
+                }
 
-                    this.inherits.add(defaultAnn);
+                this.inherits.add(defaultAnn);
 
-                }
+            }
 
-                else
-                {
-                    throw new WebBeansConfigurationException(errorMessage + "Type with class name : " + XMLUtil.getElementJavaClassName(child) + " is not applicable for stereotype");
-                }
+            else
+            {
+                throw new WebBeansConfigurationException(errorMessage + "Type with class name : " + XMLUtil.getElementJavaClassName(child) + " is not applicable for stereotype");
             }
         }
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/Asserts.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/Asserts.java?rev=930092&r1=930091&r2=930092&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/Asserts.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/Asserts.java Thu Apr  1 20:48:31 2010
@@ -14,8 +14,7 @@
 package org.apache.webbeans.util;
 
 import java.lang.reflect.Method;
-
-import org.dom4j.Element;
+import org.w3c.dom.Element;
 
 /**
  * Simple utility classes with some assertions methods.

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java?rev=930092&r1=930091&r2=930092&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java Thu Apr  1 20:48:31 2010
@@ -42,6 +42,7 @@ import javax.enterprise.inject.Produces;
 import javax.inject.Inject;
 import javax.inject.Scope;
 import javax.interceptor.Interceptor;
+import javax.lang.model.util.Elements;
 
 import org.apache.webbeans.WebBeansConstants;
 import org.apache.webbeans.annotation.DefaultLiteral;
@@ -79,7 +80,10 @@ import org.apache.webbeans.util.Annotati
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
-import org.dom4j.Element;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
 
 /**
  * Configures the web beans from the xml declerations.
@@ -236,13 +240,14 @@ public final class WebBeansXMLConfigurat
     private void configureOwbSpecific(Element webBeansRoot)
     {
         List<Element> webBeanDeclerationList = new ArrayList<Element>();
-        List<Element> childs = webBeansRoot.elements();
-        Iterator<Element> it = childs.iterator();
 
-        Element child = null;
-        while (it.hasNext())
-        {
-            child = it.next();
+        Node node; Element child;
+        NodeList ns = webBeansRoot.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	child = (Element)node;
 
             /* WebBean element decleration */
             if (XMLUtil.isElementWebBeanDeclaration(child))
@@ -300,13 +305,13 @@ public final class WebBeansXMLConfigurat
      */
     private void configureSpecSpecific(Element webBeansRoot)
     {
-        List<Element> childs = webBeansRoot.elements();
-        Iterator<Element> it = childs.iterator();
-
-        Element child = null;
-        while (it.hasNext())
-        {
-            child = it.next();
+        Node node; Element child;
+        NodeList ns = webBeansRoot.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	child = (Element)node;
 
             /* <Interceptors> element decleration */
             if (XMLUtil.getName(child).equals(WebBeansConstants.WEB_BEANS_XML_SPEC_SPECIFIC_INTERCEPTORS_ELEMENT))
@@ -364,13 +369,13 @@ public final class WebBeansXMLConfigurat
         Class<?> clazz = XMLUtil.getElementJavaType(bindingTypeElement);
         if (clazz == null)
         {
-            throw new NonexistentTypeException(createConfigurationFailedMessage() + "Binding type with given class : " + bindingTypeElement.getName() + " not found");
+            throw new NonexistentTypeException(createConfigurationFailedMessage() + "Binding type with given class : " + bindingTypeElement.getLocalName() + " not found");
         }
 
         Class<? extends Annotation> clazzAnnot = null;
         if (!clazz.isAnnotation())
         {
-            throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Binding type with given class : " + bindingTypeElement.getName() + " is not an annotation type");
+            throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Binding type with given class : " + bindingTypeElement.getLocalName() + " is not an annotation type");
         }
         else
         {
@@ -379,7 +384,7 @@ public final class WebBeansXMLConfigurat
 
         if (xmlAnnotTypeManager.hasBindingType(clazzAnnot))
         {
-            throw new DeploymentException(createConfigurationFailedMessage() + "Binding type with given class : " + bindingTypeElement.getName() + " is already defined in the XML");
+            throw new DeploymentException(createConfigurationFailedMessage() + "Binding type with given class : " + bindingTypeElement.getLocalName() + " is already defined in the XML");
         }
 
         xmlAnnotTypeManager.addBindingType(clazzAnnot);
@@ -395,13 +400,13 @@ public final class WebBeansXMLConfigurat
         Class<?> clazz = XMLUtil.getElementJavaType(interceptorBindingTypeElement);
         if (clazz == null)
         {
-            throw new NonexistentTypeException(createConfigurationFailedMessage() + "InterceptorBinding type with given class : " + interceptorBindingTypeElement.getName() + " not found");
+            throw new NonexistentTypeException(createConfigurationFailedMessage() + "InterceptorBinding type with given class : " + interceptorBindingTypeElement.getLocalName() + " not found");
         }
 
         Class<? extends Annotation> clazzAnnot = null;
         if (!clazz.isAnnotation())
         {
-            throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "InterceptorBinding type with given class : " + interceptorBindingTypeElement.getName() + " is not an annotation type");
+            throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "InterceptorBinding type with given class : " + interceptorBindingTypeElement.getLocalName() + " is not an annotation type");
         }
         else
         {
@@ -410,12 +415,16 @@ public final class WebBeansXMLConfigurat
 
         if (xmlAnnotTypeManager.hasInterceptorBindingType(clazzAnnot))
         {
-            throw new DeploymentException(createConfigurationFailedMessage() + "InterceptorBinding type with given class : " + interceptorBindingTypeElement.getName() + " is already defined in the XML");
+            throw new DeploymentException(createConfigurationFailedMessage() + "InterceptorBinding type with given class : " + interceptorBindingTypeElement.getLocalName() + " is already defined in the XML");
         }
 
-        List<Element> childs = interceptorBindingTypeElement.elements();
-        for (Element child : childs)
+        Node node; Element child;
+        NodeList ns = interceptorBindingTypeElement.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
         {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	child = (Element)node;
             Class<?> clz = XMLUtil.getElementJavaType(child);
             if (clz == null)
             {
@@ -443,13 +452,13 @@ public final class WebBeansXMLConfigurat
         Class<?> clazz = XMLUtil.getElementJavaType(stereoTypeElement);
         if (clazz == null)
         {
-            throw new NonexistentTypeException(createConfigurationFailedMessage() + "Stereotype with given class : " + stereoTypeElement.getName() + " not found");
+            throw new NonexistentTypeException(createConfigurationFailedMessage() + "Stereotype with given class : " + stereoTypeElement.getLocalName() + " not found");
         }
 
         Class<? extends Annotation> clazzAnnot = null;
         if (!clazz.isAnnotation())
         {
-            throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Stereotype with given class : " + stereoTypeElement.getName() + " is not an annotation type");
+            throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Stereotype with given class : " + stereoTypeElement.getLocalName() + " is not an annotation type");
         }
         else
         {
@@ -458,7 +467,7 @@ public final class WebBeansXMLConfigurat
 
         if (xmlAnnotTypeManager.hasStereoType(clazzAnnot))
         {
-            throw new DeploymentException(createConfigurationFailedMessage() + "Stereotype with given class : " + stereoTypeElement.getName() + " is already defined in the XML");
+            throw new DeploymentException(createConfigurationFailedMessage() + "Stereotype with given class : " + stereoTypeElement.getLocalName() + " is already defined in the XML");
         }
 
         xmlAnnotTypeManager.addStereoType(clazzAnnot, stereoTypeElement, clazzAnnot.getName(), createConfigurationFailedMessage());
@@ -472,13 +481,14 @@ public final class WebBeansXMLConfigurat
      */
     private void configureInterceptorsElement(Element interceptorsElement)
     {
-        List<Element> childs = interceptorsElement.elements();
-        Iterator<Element> itChilds = childs.iterator();
-
-        InterceptorsManager manager = InterceptorsManager.getInstance();
-        while (itChilds.hasNext())
-        {
-            Element child = itChilds.next();
+    	InterceptorsManager manager = InterceptorsManager.getInstance();
+        Node node; Element child;
+        NodeList ns = interceptorsElement.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	child = (Element)node;
             Class<?> clazz = null;
             
             if(this.owbSpecificConfiguration)
@@ -487,13 +497,13 @@ public final class WebBeansXMLConfigurat
             }
             else
             {
-                clazz = ClassUtil.getClassFromName(child.getTextTrim());
+                clazz = ClassUtil.getClassFromName(child.getTextContent().trim());
             }
 
             if (clazz == null)
             {
                 throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " + 
-                		(this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextTrim()) + " not found");
+                		(this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextContent().trim()) + " not found");
             }
             else
             {
@@ -501,13 +511,13 @@ public final class WebBeansXMLConfigurat
                         !AnnotationUtil.hasInterceptorBindingMetaAnnotation(clazz.getDeclaredAnnotations()))
                 {
                     throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " + 
-                    		(this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextTrim()) + " must have at least one @InterceptorBindingType");
+                    		(this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextContent().trim()) + " must have at least one @InterceptorBindingType");
                 }
 
                 if (manager.isInterceptorEnabled(clazz))
                 {
                     throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " +
-                    		(this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextTrim()) + " is already defined");
+                    		(this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextContent().trim()) + " is already defined");
                 }
 
                 manager.addNewInterceptor(clazz);
@@ -524,13 +534,14 @@ public final class WebBeansXMLConfigurat
      */
     private void configureDecoratorsElement(Element decoratorsElement)
     {
-        List<Element> childs = decoratorsElement.elements();
-        Iterator<Element> itChilds = childs.iterator();
-
         DecoratorsManager manager = DecoratorsManager.getInstance();
-        while (itChilds.hasNext())
-        {
-            Element child = itChilds.next();
+        Node node; Element child;
+        NodeList ns = decoratorsElement.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	child = (Element)node;
             Class<?> clazz = null;
             
             if(this.owbSpecificConfiguration)
@@ -539,13 +550,13 @@ public final class WebBeansXMLConfigurat
             }
             else
             {
-                clazz = ClassUtil.getClassFromName(child.getTextTrim());
+                clazz = ClassUtil.getClassFromName(child.getTextContent().trim());
             }
 
             if (clazz == null)
             {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Decorator class : " +  
-                		   (this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextTrim()) +  " not found");
+                		   (this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextContent().trim()) +  " not found");
             }
             else
             {
@@ -553,7 +564,7 @@ public final class WebBeansXMLConfigurat
                 if (manager.isDecoratorEnabled(clazz))
                 {
                     throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Decorator class : " +
-                    		(this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextTrim()) + " is already defined");
+                    		(this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextContent().trim()) + " is already defined");
                 }
 
                 manager.addNewDecorator(clazz);
@@ -570,12 +581,13 @@ public final class WebBeansXMLConfigurat
      */
     private void configureAlternativesElement(Element alternativesElement)
     {
-        List<Element> childs = alternativesElement.elements();
-        Iterator<Element> itChilds = childs.iterator();
-
-        while (itChilds.hasNext())
-        {
-            Element child = itChilds.next();
+        Node node; Element child;
+        NodeList ns = alternativesElement.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	child = (Element)node;
 
             if(XMLUtil.getName(child).equals(WebBeansConstants.WEB_BEANS_XML_SPEC_SPECIFIC_STEREOTYPE) ||
                     XMLUtil.getName(child).equals(WebBeansConstants.WEB_BEANS_XML_OWB_SPECIFIC_STEREOTYPE))
@@ -604,7 +616,7 @@ public final class WebBeansXMLConfigurat
         }
         else
         {
-            clazz = ClassUtil.getClassFromName(child.getTextTrim());
+            clazz = ClassUtil.getClassFromName(child.getTextContent().trim());
         }
 
         if (clazz == null)
@@ -719,11 +731,6 @@ public final class WebBeansXMLConfigurat
      */
     private <T> void configureWebBeanDeclerationChilds(XMLManagedBean<T> component, Element webBeanDecleration)
     {
-        List<Element> childs = webBeanDecleration.elements();
-        Iterator<Element> it = childs.iterator();
-
-        Element child = null;
-
         /* Constructor api type list */
         List<Class<?>> constTypeList = new ArrayList<Class<?>>();
 
@@ -738,9 +745,16 @@ public final class WebBeansXMLConfigurat
 
         boolean isConstructor = false;
         String fieldOrMethodName = null;
-        while (it.hasNext())
-        {
-            child = it.next();
+ 
+        Node node; Element child;
+        NodeList ns = webBeanDecleration.getChildNodes();
+
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	child = (Element)node;
+ 
             Class<?> type = XMLUtil.getElementJavaType(child);
 
             boolean isElementApplicable = false;
@@ -1034,6 +1048,17 @@ public final class WebBeansXMLConfigurat
         }
     }
 
+    private boolean hasTextOnlyChild(Element element)
+    {
+    	NodeList ns = element.getChildNodes();
+    	for(int i=0; i<ns.getLength(); i++)
+    	{
+    		if (ns.item(i) instanceof Text) continue;
+    		return false;
+    	}
+    	return true;
+    }
+    
     /**
      * Configures the given child element as field of the webbeans component.
      * 
@@ -1060,7 +1085,7 @@ public final class WebBeansXMLConfigurat
         boolean isValueElement = false;
 
         boolean isApplicable = false;
-        if (child.isTextOnly())
+        if (hasTextOnlyChild(child))
         {
             if (!isValueElement)
             {
@@ -1069,15 +1094,19 @@ public final class WebBeansXMLConfigurat
             }
         }
 
-        List<Element> directChilds = child.elements();
-        Iterator<Element> itChilds = directChilds.iterator();
-
         boolean isTypeElement = false;
 
         // it has some other elements
-        while (itChilds.hasNext())
-        {
-            Element directChild = itChilds.next();
+        int childElementNumber = 0;
+        Node node;
+        Element directChild = null;
+        NodeList directChilds = child.getChildNodes();
+        for(int i=0; i<directChilds.getLength(); i++)
+        {
+        	node = directChilds.item(i);
+        	if (!(node instanceof Element)) continue;
+        	directChild = (Element)node;
+        	childElementNumber++;
             if (XMLUtil.isElementInWebBeansNameSpaceWithName(directChild, WebBeansConstants.WEB_BEANS_XML_VALUE_ELEMENT))
             {
                 if (!isValueElement)
@@ -1120,7 +1149,7 @@ public final class WebBeansXMLConfigurat
             throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Field with name : " + fieldName + " element is not correctly defined");
         }
 
-        if (directChilds.size() > 1)
+        if (childElementNumber > 1)
         {
             if (!isValueElement)
             {
@@ -1136,8 +1165,10 @@ public final class WebBeansXMLConfigurat
         }
 
         // configure field values if available.
-        configureFieldValues(component, field, child, isValueElement);
-
+        if (directChild != null)
+        	configureFieldValues(component, field, directChild, isValueElement);
+        else 
+        	configureFieldValues(component, field, child, isValueElement);
     }
 
     /**
@@ -1157,9 +1188,6 @@ public final class WebBeansXMLConfigurat
             throw new NonexistentMethodException(createConfigurationFailedMessage() + "Method declaration with name " + XMLUtil.getName(child) + " is not found in the class : " + component.getReturnType().getName());
         }
 
-        List<Element> methodChilds = child.elements();
-        Iterator<Element> itMethodChilds = methodChilds.iterator();
-
         boolean isDefineType = false;
 
         /*
@@ -1175,11 +1203,14 @@ public final class WebBeansXMLConfigurat
         /* Method parameter xml elements */
         List<Element> methodParameterElements = new ArrayList<Element>();
 
+        Node node;
         Element methodChild = null;
-
-        while (itMethodChilds.hasNext())
+        NodeList mns = child.getChildNodes();
+        for(int j=0; j<mns.getLength(); j++)
         {
-            methodChild = itMethodChilds.next();
+        	node = mns.item(j);
+        	if (!(node instanceof Element)) continue;
+        	methodChild = (Element)node;
             Class<?> childClazz = XMLUtil.getElementJavaType(methodChild);
 
             final String moreThanOneChildTypeErrorMesg = createConfigurationFailedMessage() + XMLUtil.getName(methodChild) + "method declaration can not contain more than one <Initializer>, <Destructor>, <Produces>, <Disposes> or <Observes> element";
@@ -1392,15 +1423,16 @@ public final class WebBeansXMLConfigurat
      */
     private <T> void checkConfigureDisposes(AbstractOwbBean<T> component, Element disposes)
     {
-        List<Element> disposesChilds = disposes.elements();
+        NodeList disposesChilds = disposes.getChildNodes();
 
-        if (disposesChilds.size() != 1)
+        if (disposesChilds.getLength()!= 1)
         {
             throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Disposes element : " + XMLUtil.getName(disposes) + " can not contain more than one direct child elements");
         }
 
     }
 
+    
     /**
      * Configures the observer method of the webbeans component
      * 
@@ -1414,9 +1446,13 @@ public final class WebBeansXMLConfigurat
      */
     private <T> void checkConfigureObserves(AbstractOwbBean<T> component, Element observes)
     {
-        List<Element> observesChilds = observes.elements();
-
-        if (observesChilds.size() != 1)
+    	int childElementCount = 0;
+        NodeList observesChilds = observes.getChildNodes();
+        for(int i=0; i<observesChilds.getLength(); i++)
+        {
+        	if (observesChilds.item(i) instanceof Element) childElementCount++;
+        }
+        if (childElementCount != 1)
         {
             throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Observes element : " + XMLUtil.getName(observes) + " can not contain more than one direct child elements");
         }
@@ -1511,8 +1547,8 @@ public final class WebBeansXMLConfigurat
         boolean isDefined = XMLDefinitionUtil.defineXMLName(component, annotationSet);
         if (isDefined)
         {
-            Element element = webBeanDecleration.element(WebBeansConstants.WEB_BEANS_XML_NAMED_ELEMENT);
-            String name = element.getTextTrim();
+            Element element = (Element)webBeanDecleration.getElementsByTagName(WebBeansConstants.WEB_BEANS_XML_NAMED_ELEMENT).item(0);
+            String name = element.getTextContent().trim();
 
             if (name != null && !name.equals(""))
             {
@@ -1580,16 +1616,15 @@ public final class WebBeansXMLConfigurat
      */
     private void configureJMSEndpointComponent(Element webBeanElement)
     {
-        List<Element> childs = webBeanElement.elements();               
-        Element resource = webBeanElement.element(WebBeansConstants.WEB_BEANS_XML_JMS_RESOURCE);
+        Element resource = (Element)webBeanElement.getElementsByTagName(WebBeansConstants.WEB_BEANS_XML_JMS_RESOURCE).item(0);
         
         if(resource == null)
         {
             throw new WebBeansConfigurationException("Topic or Queue resource mut be defined in the XML");
         }
 
-        Element name = resource.element(WebBeansConstants.WEB_BEANS_XML_JMS_RESOURCE_NAME);
-        Element mappedName = resource.element(WebBeansConstants.WEB_BEANS_XML_JMS_RESOURCE_MAPPED_NAME);
+        Element name = (Element)resource.getElementsByTagName(WebBeansConstants.WEB_BEANS_XML_JMS_RESOURCE_NAME).item(0);
+        Element mappedName = (Element)resource.getElementsByTagName(WebBeansConstants.WEB_BEANS_XML_JMS_RESOURCE_MAPPED_NAME).item(0);
         
         if(name== null && mappedName == null)
         {
@@ -1597,9 +1632,14 @@ public final class WebBeansXMLConfigurat
         }
         
         List<Annotation> bindingTypes = new ArrayList<Annotation>();
-        for(Element child : childs)
-        {
-            if(child.getName() != WebBeansConstants.WEB_BEANS_XML_JMS_RESOURCE)
+        Node node; Element child;
+        NodeList ns = webBeanElement.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	child = (Element)node;
+            if(child.getLocalName() != WebBeansConstants.WEB_BEANS_XML_JMS_RESOURCE)
             {
                 Class<? extends Annotation> binding = (Class<Annotation>)XMLUtil.getElementJavaType(child);
                 
@@ -1612,7 +1652,7 @@ public final class WebBeansXMLConfigurat
                         
         JMSType type = null;
         
-        if(webBeanElement.getName().equals(WebBeansConstants.WEB_BEANS_XML_TOPIC_ELEMENT))
+        if(webBeanElement.getLocalName().equals(WebBeansConstants.WEB_BEANS_XML_TOPIC_ELEMENT))
         {
             type = JMSType.TOPIC;
         }
@@ -1622,8 +1662,8 @@ public final class WebBeansXMLConfigurat
         }
         
         
-        String jndiName = name == null ? null : name.getTextTrim();
-        String mapName = mappedName== null ? null : mappedName.getTextTrim();
+        String jndiName = name == null ? null : name.getTextContent().trim();
+        String mapName = mappedName== null ? null : mappedName.getTextContent().trim();
         
         
         JMSModel model = new JMSModel(type,jndiName,mapName);        
@@ -1656,7 +1696,7 @@ public final class WebBeansXMLConfigurat
             /* Field type */
             Class<?> fieldType = field.getType();
 
-            String value = child.getTextTrim();
+            String value = child.getTextContent().trim();
 
             try
             {
@@ -1849,10 +1889,14 @@ public final class WebBeansXMLConfigurat
             throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "List field type with field name : " + field.getName() + " must be declared as ParametrizedType");
         }
 
-        List<Element> valueElements = child.elements();
-        for (Element valueElement : valueElements)
-        {
-            String value = valueElement.getTextTrim();
+        Node valueNode;Text valueElement;
+        NodeList valueElements = child.getChildNodes();
+        for(int i=0; i<valueElements.getLength(); i++)
+        {	
+        	valueNode = valueElements.item(i);
+        	if (!(valueNode instanceof Text)) continue;
+        	valueElement = (Text)valueNode;
+            String value = valueElement.getTextContent().trim();
             if (isString)
             {
                 list.add(value);
@@ -1944,10 +1988,14 @@ public final class WebBeansXMLConfigurat
             throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Set field type with field name : " + field.getName() + " must be declared as ParametrizedType");
         }
 
-        List<Element> valueElements = child.elements();
-        for (Element valueElement : valueElements)
-        {
-            String value = valueElement.getTextTrim();
+        Node valueNode;Element valueElement;
+        NodeList valueElements = child.getChildNodes();
+        for(int i=0; i<valueElements.getLength(); i++)
+        {	
+        	valueNode = valueElements.item(i);
+        	if (!(valueNode instanceof Element)) continue;
+        	valueElement = (Element)valueNode;
+            String value = valueElement.getTextContent().trim();
             if (isString)
             {
                 set.add(value);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLAnnotationTypeManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLAnnotationTypeManager.java?rev=930092&r1=930091&r2=930092&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLAnnotationTypeManager.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLAnnotationTypeManager.java Thu Apr  1 20:48:31 2010
@@ -25,7 +25,7 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.deployment.StereoTypeManager;
 import org.apache.webbeans.deployment.XMLStereoTypeModel;
 import org.apache.webbeans.util.WebBeansUtil;
-import org.dom4j.Element;
+import org.w3c.dom.Element;
 
 public class XMLAnnotationTypeManager
 {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java?rev=930092&r1=930091&r2=930092&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java Thu Apr  1 20:48:31 2010
@@ -61,7 +61,9 @@ import org.apache.webbeans.util.Annotati
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
-import org.dom4j.Element;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 @SuppressWarnings("unchecked")
 public final class XMLDefinitionUtil
@@ -265,11 +267,16 @@ public final class XMLDefinitionUtil
 
     public static <T> void defineXMLMethodLevelInterceptorType(XMLManagedBean<T> component, Method interceptorMethod, Element interceptorMethodElement, String errorMessage)
     {
-        List<Element> bindingTypes = interceptorMethodElement.elements();
         Set<Annotation> bindingTypesSet = new HashSet<Annotation>();
-        for (Element bindingType : bindingTypes)
-        {
-            Class<? extends Annotation> annot = (Class<? extends Annotation>) XMLUtil.getElementJavaType(bindingType);
+        Node node; Element bindingType;
+        NodeList ns = interceptorMethodElement.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	bindingType = (Element)node;
+
+        	Class<? extends Annotation> annot = (Class<? extends Annotation>) XMLUtil.getElementJavaType(bindingType);
             Annotation bindingAnnot = XMLUtil.getXMLDefinedAnnotationMember(bindingType, annot, errorMessage);
 
             bindingTypesSet.add(bindingAnnot);
@@ -405,19 +412,24 @@ public final class XMLDefinitionUtil
 
         if (found)
         {
-            List<Element> childs = decoratorDecleration.elements();
-            for (Element child : childs)
+            Node node; Element child;
+            NodeList ns = decoratorDecleration.getChildNodes();
+
+            for(int i=0; i<ns.getLength(); i++)
             {
+            	node = ns.item(i);
+            	if (!(node instanceof Element)) continue;
+            	child = (Element)node;
                 if (XMLUtil.getElementNameSpace(child).equals(XMLUtil.getElementNameSpace(decoratorDecleration)) && XMLUtil.isElementHasDecoratesChild(child))
                 {
-                    Field field = ClassUtil.getFieldWithName(component.getReturnType(), child.getName());
+                    Field field = ClassUtil.getFieldWithName(component.getReturnType(), child.getLocalName());
                     if (field == null)
                     {
-                        throw new NonexistentFieldException(errorMessage + "Field with name : " + child.getName() + " not found in the decorator class : " + component.getReturnType().getName());
+                        throw new NonexistentFieldException(errorMessage + "Field with name : " + child.getLocalName() + " not found in the decorator class : " + component.getReturnType().getName());
                     }
-
-                    Element decorates = child.element(WebBeansConstants.WEB_BEANS_XML_DECORATES_ELEMENT);
-                    Element type = (Element) decorates.elements().get(0);
+                    Element type;
+                    NodeList ns1 = child.getElementsByTagName(WebBeansConstants.WEB_BEANS_XML_DECORATES_ELEMENT);
+                    type = (Element)ns1.item(0);
 
                     Class<?> apType = XMLUtil.getElementJavaType(type);
 
@@ -451,7 +463,6 @@ public final class XMLDefinitionUtil
     public static <T> XMLProducerBean<T> defineXMLProducerMethod(WebBeansXMLConfigurator configurator, XMLManagedBean<T> component, Method producesMethod, Element producerMethodElement, String errorMessage)
     {
         boolean producesDefined = false;
-        List<Element> childElements = producerMethodElement.elements();
         Class<T> type = null;
         Element typeElement = null;
         Element arrayElement = null;
@@ -459,8 +470,13 @@ public final class XMLDefinitionUtil
         List<Element> memberLevelElement = new ArrayList<Element>();
         List<XMLInjectionPointModel> injectedParameters = new ArrayList<XMLInjectionPointModel>();
 
-        for (Element childElement : childElements)
-        {
+        Node node; Element childElement;
+        NodeList ns = producerMethodElement.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	childElement = (Element)node;
             if (XMLUtil.isElementInWebBeansNameSpaceWithName(childElement, WebBeansConstants.WEB_BEANS_XML_PRODUCES_ELEMENT))
             {
                 if (producesDefined == false)
@@ -472,12 +488,16 @@ public final class XMLDefinitionUtil
                     throw new WebBeansConfigurationException(errorMessage + "More than one <Produces> element is defined");
                 }
 
-                List<Element> producesElementChilds = childElement.elements();
                 boolean definedType = false;
 
-                for (Element producesElementChild : producesElementChilds)
-                {
-                    if (producesElementChild.getName().equals(WebBeansConstants.WEB_BEANS_XML_ARRAY_ELEMENT))
+                Node producerNode; Element producesElementChild;
+                NodeList nsProducer = childElement.getChildNodes();
+                for(int j=0; j<nsProducer.getLength(); j++)
+                {
+                	producerNode = nsProducer.item(j);
+                	if (!(producerNode instanceof Element)) continue;
+                	producesElementChild= (Element)producerNode;
+                	if (producesElementChild.getLocalName().equals(WebBeansConstants.WEB_BEANS_XML_ARRAY_ELEMENT))
                     {
                         arrayElement = producesElementChild;
                         definedType = true;
@@ -638,8 +658,6 @@ public final class XMLDefinitionUtil
      */
     public static <T> void defineXMLDisposalMethod(XMLManagedBean<T> component, Method disposalMethod, Element disposalMethodElement, String errorMessage)
     {
-        /* Disposal method element childs */
-        List<Element> disposalChildElements = disposalMethodElement.elements();
 
         /* Multiple <Disposes> element control parameter */
         boolean disposalDefined = false;
@@ -649,8 +667,14 @@ public final class XMLDefinitionUtil
 
         XMLProducerBean<?> producerComponent = null;
 
-        for (Element childElement : disposalChildElements)
-        {
+        /* Disposal method element childs */
+        Node node; Element childElement;
+        NodeList ns = disposalMethodElement.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	childElement = (Element)node;
             if (XMLUtil.isElementInWebBeansNameSpaceWithName(childElement, WebBeansConstants.WEB_BEANS_XML_DISPOSES_ELEMENT))
             {
                 if (disposalDefined == false)
@@ -662,7 +686,8 @@ public final class XMLDefinitionUtil
                     throw new WebBeansConfigurationException(errorMessage + "More than one <Disposal> element is defined for defining disposal method : " + disposalMethod.getName());
                 }
 
-                Element typeElement = (Element) childElement.elements().get(0);
+                //TODO: verify the first node is element.
+                Element typeElement = (Element) childElement.getChildNodes().item(0);
 
                 /* Find disposal method model */
                 XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(typeElement, errorMessage);
@@ -707,8 +732,6 @@ public final class XMLDefinitionUtil
     {
         component.addObservableMethod(observesMethod);
 
-        /* Observes method element childs */
-        List<Element> observesChildElements = observesMethodElement.elements();
 
         /* Other parameter elements other than @Observes */
         List<Element> otherParameterElements = new ArrayList<Element>();
@@ -717,11 +740,19 @@ public final class XMLDefinitionUtil
 
         Class<K> eventType = null;
 
-        for (Element childElement : observesChildElements)
+        /* Observes method element childs */
+        Node node; Element childElement;
+        NodeList ns = observesMethodElement.getChildNodes();
+
+        for(int i=0; i<ns.getLength(); i++)
         {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	childElement = (Element)node;
             if (XMLUtil.isElementInWebBeansNameSpaceWithName(childElement, WebBeansConstants.WEB_BEANS_XML_OBSERVES_ELEMENT))
             {
-                Element typeElement = (Element) childElement.elements().get(0);
+            	//TODO: verify the first node is Element.
+                Element typeElement = (Element) childElement.getChildNodes().item(0);
 
                 eventType = (Class<K>) XMLUtil.getElementJavaType(typeElement);
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLUtil.java?rev=930092&r1=930091&r2=930092&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLUtil.java Thu Apr  1 20:48:31 2010
@@ -21,7 +21,6 @@ import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -40,24 +39,18 @@ import org.apache.webbeans.proxy.Javassi
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ClassUtil;
-import org.dom4j.Attribute;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.Element;
-import org.dom4j.ElementHandler;
-import org.dom4j.ElementPath;
-import org.dom4j.Namespace;
-import org.dom4j.io.SAXReader;
-
-/**
- * Used for getting information contained in the file web-beans.xml.
- * 
- * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
- * @since 1.0
- */
-@SuppressWarnings("unchecked")
-public final class XMLUtil
-{
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Attr; 
+import org.w3c.dom.NodeList;
+
+
+public class XMLUtil {
 
     private XMLUtil()
     {
@@ -65,77 +58,80 @@ public final class XMLUtil
 
     private static WebBeansLogger log = WebBeansLogger.getLogger(XMLUtil.class);
 
-    /**
-     * Gets new {@link SAXReader} instance.
-     * 
-     * @return sax reader instance
-     */
-    public static SAXReader getSaxReader()
+    protected static boolean verifyNameSpace(Element element)
     {
-        return new SAXReader();
-    }
-
-    /**
-     * Gets the root element of the parsed document.
-     * 
-     * @param stream parsed document
-     * @return root element of the document
-     * @throws WebBeansException if any runtime exception occurs
-     */
+    	boolean ret;
+    	if (element.getNamespaceURI() == null)
+    	{
+    		return false;
+    	}
+    	Node node;
+    	NodeList ns = element.getChildNodes();
+    	for(int i=0; i<ns.getLength(); i++) 
+    	{
+    		node = ns.item(i);
+    		if (!(node instanceof Element)) continue;
+    		ret = verifyNameSpace((Element)node);
+    		if (!ret) return false;
+    	}
+    	return true;
+    }
+	
+	protected static void updateNameSpacePackageMapping(Element root) 
+	{
+		if (!verifyNameSpace(root)) 
+		{
+            throw new WebBeansConfigurationException(log.getTokenString(OWBLogConst.EXCEPT_0012));			
+		}
+		if (root.getNamespaceURI() != null)
+		{
+			WebBeansNameSpaceContainer.getInstance().
+			addNewPackageNameSpace(root.getNamespaceURI());
+		} else {
+			String attr = root.getAttribute("xmlns");
+			if (attr != null) {
+				WebBeansNameSpaceContainer.getInstance().
+				addNewPackageNameSpace(root.getNamespaceURI());
+			} 
+		}
+		NamedNodeMap attrs = root.getAttributes();
+		for(int i=0; i<attrs.getLength(); i++)
+		{
+			// hack the code here, since I did'nt find NameSpace support
+			// in Java DOM.
+			Attr attr = (Attr)attrs.item(i);
+			if (attr.getName().toLowerCase().startsWith("xmlns")) 
+			{
+                WebBeansNameSpaceContainer.getInstance().addNewPackageNameSpace(attr.getValue());
+			}
+		}
+	}
+	
     public static Element getRootElement(InputStream stream) throws WebBeansException
     {
-        try
-        {  
-            SAXReader saxReader = getSaxReader();
-            saxReader.setMergeAdjacentText(true);
-            saxReader.setStripWhitespaceText(true);
-            saxReader.setErrorHandler(new WebBeansErrorHandler());
-            saxReader.setEntityResolver(new WebBeansResolver());
-            saxReader.setValidation(false);
-            saxReader.setDefaultHandler(new ElementHandler()
-            {
-                public void onEnd(ElementPath path)
-                {
-
-                }
-
-                public void onStart(ElementPath path)
-                {
-                    Element element = path.getCurrent();
-                    if (element.getNamespaceURI() == null || element.getNamespaceURI().equals(""))
-                    {
-                        throw new WebBeansConfigurationException(log.getTokenString(OWBLogConst.EXCEPT_0012));
-                    }
-                    else
-                    {
-                        if (element.isRootElement())
-                        {
-                            WebBeansNameSpaceContainer.getInstance().addNewPackageNameSpace(element.getNamespace().getURI());
-
-                            List allNs = element.declaredNamespaces();
-                            Iterator itNs = allNs.iterator();
-
-                            while (itNs.hasNext())
-                            {
-                                Namespace namespace = (Namespace)itNs.next();
-                                WebBeansNameSpaceContainer.getInstance().addNewPackageNameSpace(namespace.getURI());
-                            }
-                        }
-                    }
-                }
-
-            });
-
-            Document document = saxReader.read(stream);
-
-            return document.getRootElement();
-
-        }
-        catch (DocumentException e)
-        {
+    	
+    	try 
+    	{
+	    	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+			factory.setCoalescing(false);
+			factory.setExpandEntityReferences(true);
+			factory.setIgnoringComments(true);
+			factory.setIgnoringElementContentWhitespace(true);
+			factory.setNamespaceAware(true);
+			factory.setValidating(false);
+			DocumentBuilder documentBuilder = factory.newDocumentBuilder();
+			documentBuilder.setErrorHandler(new WebBeansErrorHandler());
+			documentBuilder.setEntityResolver(new WebBeansResolver());
+	    	
+			Document doc = documentBuilder.parse(stream);
+			Element root = doc.getDocumentElement();
+			updateNameSpacePackageMapping(root);
+			return root;
+    	} catch (Exception e)
+    	{
             log.fatal(OWBLogConst.FATAL_0002, e);
             throw new WebBeansException(log.getTokenString(OWBLogConst.EXCEPT_0013), e);
-        }
+    	}
     }
     
     /**
@@ -147,42 +143,34 @@ public final class XMLUtil
      */
     public static Element getSpecStrictRootElement(InputStream stream) throws WebBeansException
     {
-        try
-        {  
-            SAXReader saxReader = getSaxReader();
-            saxReader.setMergeAdjacentText(true);
-            saxReader.setStripWhitespaceText(true);
-            saxReader.setErrorHandler(new WebBeansErrorHandler());
-            saxReader.setEntityResolver(new WebBeansResolver());
-            saxReader.setValidation(false);
-            Document document = saxReader.read(stream);
-
-            return document.getRootElement();
-
-        }
-        catch (DocumentException e)
-        {
+    	try 
+    	{
+	    	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+			factory.setCoalescing(false);
+			factory.setExpandEntityReferences(true);
+			factory.setIgnoringComments(true);
+			factory.setIgnoringElementContentWhitespace(true);
+			factory.setNamespaceAware(true);
+			factory.setValidating(false);
+			DocumentBuilder documentBuilder = factory.newDocumentBuilder();
+			documentBuilder.setErrorHandler(new WebBeansErrorHandler());
+			documentBuilder.setEntityResolver(new WebBeansResolver());
+	    	
+			Element root = documentBuilder.parse(stream).getDocumentElement();
+			return root;
+    	} catch (Exception e)
+    	{
             log.fatal(OWBLogConst.FATAL_0002, e);
             throw new WebBeansException(log.getTokenString(OWBLogConst.EXCEPT_0013), e);
-        }
-    }
-    
+    	}    	
+    }    
 
     public static boolean isElementInNamespace(Element element, String namespace)
     {
         Asserts.assertNotNull(element, "element parameter can not be null");
         Asserts.assertNotNull(namespace, "namespace parameter can not be null");
-
-        Namespace ns = element.getNamespace();
-        if (!Namespace.NO_NAMESPACE.equals(ns))
-        {
-            if (ns.getURI().equals(namespace))
-            {
-                return true;
-            }
-        }
-
-        return false;
+        String nsURI = element.getNamespaceURI();
+        return nsURI.equals(namespace);
     }
 
     public static boolean isElementInWebBeansNameSpace(Element element)
@@ -197,15 +185,14 @@ public final class XMLUtil
 
         return false;
     }
-
+    
     public static boolean isElementInWebBeansNameSpaceWithName(Element element, String name)
     {
         nullCheckForElement(element);
 
         if (isElementInWebBeansNameSpace(element))
         {
-            String txtName = element.getName();
-
+            String txtName = element.getLocalName();
             if (name.equals(txtName))
             {
                 return true;
@@ -214,20 +201,14 @@ public final class XMLUtil
 
         return false;
     }
-
+    
     public static String getElementNameSpace(Element element)
     {
         nullCheckForElement(element);
 
-        Namespace ns = element.getNamespace();
-        if (!Namespace.NO_NAMESPACE.equals(ns))
-        {
-            return ns.getURI();
-        }
-
-        return null;
+        return element.getNamespaceURI();
     }
-
+    
     public static boolean isElementWebBeanDeclaration(Element element)
     {
         nullCheckForElement(element);
@@ -244,7 +225,7 @@ public final class XMLUtil
 
         return false;
 
-    }
+    }    
 
     /**
      * Returns true if element has a bindingtype child element in webbeans
@@ -388,10 +369,13 @@ public final class XMLUtil
     {
         nullCheckForElement(element);
 
-        List<Element> childs = element.elements();
-
-        for (Element child : childs)
-        {
+        Node node; Element child;
+        NodeList ns = element.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	child = (Element)node;
             if (!isElementInWebBeansNameSpaceWithName(child, WebBeansConstants.WEB_BEANS_XML_INITIALIZER_ELEMENT) && !isElementInWebBeansNameSpaceWithName(child, WebBeansConstants.WEB_BEANS_XML_DESTRUCTOR_ELEMENT) && !isElementInWebBeansNameSpaceWithName(child, WebBeansConstants.WEB_BEANS_XML_PRODUCES_ELEMENT) && !isElementInWebBeansNameSpaceWithName(child, WebBeansConstants.WEB_BEANS_XML_DISPOSES_ELEMENT) && !isElementInWebBeansNameSpaceWithName(child, WebBeansConstants.WEB_BEANS_XML_OBSERVES_ELEMENT) && !isElementInWebBeansNameSpaceWithName(child, WebBeansConstants.WEB_BEANS_XML_DECORATES_ELEMENT))
             {
 
@@ -429,12 +413,15 @@ public final class XMLUtil
      */
     public static boolean isElementMethod(Element element)
     {
-        Asserts.nullCheckForDomElement(element);
-
-        List<Element> childs = element.elements();
+    	nullCheckForElement(element);
 
-        for (Element child : childs)
-        {
+        Node node; Element child;
+        NodeList ns = element.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	child = (Element)node;
             if (isElementInWebBeansNameSpaceWithName(child, WebBeansConstants.WEB_BEANS_XML_INITIALIZER_ELEMENT) || isElementInWebBeansNameSpaceWithName(child, WebBeansConstants.WEB_BEANS_XML_DESTRUCTOR_ELEMENT) || isElementInWebBeansNameSpaceWithName(child, WebBeansConstants.WEB_BEANS_XML_PRODUCES_ELEMENT) || isElementInWebBeansNameSpaceWithName(child, WebBeansConstants.WEB_BEANS_XML_DISPOSES_ELEMENT) || isElementInWebBeansNameSpaceWithName(child, WebBeansConstants.WEB_BEANS_XML_OBSERVES_ELEMENT))
             {
                 return true;
@@ -466,7 +453,7 @@ public final class XMLUtil
     {
         nullCheckForElement(element);
 
-        return element.getName();
+        return element.getLocalName();
     }
 
     public static Class<?> getElementJavaType(Element element)
@@ -503,7 +490,7 @@ public final class XMLUtil
         
         return foundClazz;
     }
-
+    
     public static String getElementJavaClassName(Element element)
     {
         Class<?> clazz = getElementJavaType(element);
@@ -515,20 +502,29 @@ public final class XMLUtil
         
         return getName(element);
     }
-
+    
     private static void nullCheckForElement(Element element)
     {
-        Asserts.nullCheckForDomElement(element);
+        Asserts.assertNotNull(element, "element argument can not be null");
     }
-
+    
+    
     public static boolean hasChildElement(Element parent, String childName)
-    {
+    {Node node;
         Asserts.assertNotNull(parent, "parent parameter can not be null");
         Asserts.assertNotNull(childName, "childName parameter can not be null");
-
-        return parent.element(childName) != null ? true : false;
+        NodeList nl = parent.getChildNodes();
+        for(int i=0; i<nl.getLength(); i++)
+        {
+        	node = nl.item(i);
+        	if (node instanceof Element) 
+        	{
+	        	if (node.getNodeName().equals(childName)) return true;
+        	}
+        }
+        return false;
     }
-
+    
     /**
      * Return child element within webbeans namespace with given child name.
      * 
@@ -541,8 +537,21 @@ public final class XMLUtil
     {
         Asserts.assertNotNull(parent, "parent parameter can not be null");
         Asserts.assertNotNull(childName, "childName parameter can not be null");
-
-        Element child = parent.element(childName);
+        Node node; 
+        Element child = null;
+        NodeList nl = parent.getChildNodes();
+        for(int i=0; i<nl.getLength(); i++)
+        {
+        	node = nl.item(i);
+        	if (node instanceof Element) 
+        	{
+	        	if (node.getNodeName().equals(childName)) 
+	        	{
+	        		child = (Element)node;
+	        	}
+        	}
+        }
+        
         if (child == null)
         {
             return false;
@@ -551,7 +560,6 @@ public final class XMLUtil
         {
             return isElementInWebBeansNameSpace(child);
         }
-
     }
 
     /**
@@ -566,7 +574,7 @@ public final class XMLUtil
         Asserts.assertNotNull(typeElement, "typeElement parameter can not be null");
 
         /* Element <Array> */
-        if (typeElement.getName().equals(WebBeansConstants.WEB_BEANS_XML_ARRAY_ELEMENT))
+        if (typeElement.getLocalName().equals(WebBeansConstants.WEB_BEANS_XML_ARRAY_ELEMENT))
         {
             return getArrayInjectionPointModel(typeElement, errorMessage);
         }
@@ -577,7 +585,7 @@ public final class XMLUtil
         }
 
     }
-
+    
     /**
      * Injection point with Java type.
      * 
@@ -604,14 +612,18 @@ public final class XMLUtil
         {
             TypeVariable[] typeVariables = clazz.getTypeParameters();
             int actualTypeArgument = typeVariables.length;
-            List<Element> childElements = typeElement.elements();
             List<Type> typeArguments = new ArrayList<Type>();
             List<Annotation> bindingAnnots = new ArrayList<Annotation>();
 
             Class<? extends Annotation> definedBindingType = null;
-            for (Element childElement : childElements)
-            {
-                Type actualType = getElementJavaType(childElement);
+            Node node; Element childElement;
+            NodeList ns = typeElement.getChildNodes();
+            for(int i=0; i<ns.getLength(); i++)
+            {
+            	node = ns.item(i);
+            	if (!(node instanceof Element)) continue;
+            	childElement = (Element)node;
+            	Type actualType = getElementJavaType(childElement);
                 if (actualType == null)
                 {
                     throw new NonexistentTypeException(errorMessage + log.getTokenString(OWBLogConst.TEXT_JAVA_TYPENAME) + getElementJavaClassName(typeElement) + " is not found in the deployment");
@@ -686,6 +698,7 @@ public final class XMLUtil
         return model;
     }
 
+    
     /**
      * Creates new annotation with configured members values.
      * 
@@ -696,12 +709,13 @@ public final class XMLUtil
      */
     public static Annotation getXMLDefinedAnnotationMember(Element annotationElement, Class<? extends Annotation> annotClazz, String errorMessage)
     {
-        String value = annotationElement.getTextTrim();
-        List<Attribute> attrs = annotationElement.attributes();
+        String value = annotationElement.getTextContent().trim();
+        NamedNodeMap attrs = annotationElement.getAttributes();
         List<String> attrsNames = new ArrayList<String>();
-
-        for (Attribute attr : attrs)
+        
+        for(int i=0; i<attrs.getLength(); i++)
         {
+        	Attr attr = (Attr)attrs.item(i);
             attrsNames.add(attr.getName());
         }
 
@@ -779,12 +793,13 @@ public final class XMLUtil
      * @param errorMessage error message
      * @return new annotation
      */
-    private static WebBeansAnnotation createInjectionPointAnnotation(List<Attribute> attrs, Class<? extends Annotation> annotClazz, String valueText, String errorMessage)
+    private static WebBeansAnnotation createInjectionPointAnnotation(NamedNodeMap attrs, Class<? extends Annotation> annotClazz, String valueText, String errorMessage)
     {
         WebBeansAnnotation annotation = JavassistProxyFactory.createNewAnnotationProxy(annotClazz);
         boolean isValueAttrDefined = false;
-        for (Attribute attr : attrs)
+        for(int i=0; i<attrs.getLength(); i++)
         {
+        	Attr attr = (Attr)attrs.item(i);
             String attrName = attr.getName();
             String attrValue = attr.getValue();
 
@@ -853,6 +868,7 @@ public final class XMLUtil
         return annotation;
     }
 
+    
     /**
      * Injection point with array type.
      * 
@@ -864,13 +880,17 @@ public final class XMLUtil
     {
         XMLInjectionPointModel model = null;
 
-        List<Element> childElements = typeElement.elements();
         boolean isElementTypeDefined = false;
-
         Set<Annotation> anns = new HashSet<Annotation>();
-        for (Element childElement : childElements)
+        Node node; Element childElement;
+        NodeList ns = typeElement.getChildNodes();
+
+        for(int i=0; i<ns.getLength(); i++)
         {
-            Class<?> clazz = XMLUtil.getElementJavaType(childElement);
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	childElement = (Element)node;
+        	Class<?> clazz = XMLUtil.getElementJavaType(childElement);
 
             if (clazz == null)
             {
@@ -911,15 +931,18 @@ public final class XMLUtil
 
         return model;
     }
-
+    
     public static <T> void defineXMLProducerApiTypeFromArrayElement(XMLProducerBean<T> component, Element typeElement, String errorMessage)
     {
-        List<Element> childElements = typeElement.elements();
         boolean isElementTypeDefined = false;
-
         Set<Annotation> anns = new HashSet<Annotation>();
-        for (Element childElement : childElements)
-        {
+        Node node; Element childElement;
+        NodeList ns = typeElement.getChildNodes();
+        for(int i=0; i<ns.getLength(); i++)
+        {
+        	node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	childElement = (Element)node;
             Class<?> clazz = XMLUtil.getElementJavaType(childElement);
 
             if (clazz == null)
@@ -960,5 +983,6 @@ public final class XMLUtil
         }
 
     }
-
+    
 }
+

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java?rev=930092&r1=930091&r2=930092&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java Thu Apr  1 20:48:31 2010
@@ -74,7 +74,10 @@ import org.apache.webbeans.util.Annotati
 import org.apache.webbeans.util.WebBeansUtil;
 import org.apache.webbeans.xml.WebBeansXMLConfigurator;
 import org.apache.webbeans.xml.XMLUtil;
-import org.dom4j.Element;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
 
 /**
  * Superclass of all the unit test classes. It defines some methods for
@@ -353,9 +356,16 @@ public abstract class TestContext implem
         InputStream stream = XMLTest.class.getClassLoader().getResourceAsStream(xmlResourcePath);
         Assert.assertNotNull(stream);
 
+        Element beanElement = null;
         Element rootElement = XMLUtil.getRootElement(stream);
-        Element beanElement = (Element) rootElement.elements().get(0);
-
+        NodeList ns = rootElement.getChildNodes();
+        for(int i = 0; i<=ns.getLength(); i++)
+        {
+        	Node node = ns.item(i);
+        	if (!(node instanceof Element)) continue;
+        	beanElement = (Element)node;
+        	break;
+        }
         Class<?> clazz = XMLUtil.getElementJavaType(beanElement);
 
         XMLManagedBean<?> def = defineXMLSimpleWebBeans(clazz, beanElement);
@@ -378,10 +388,16 @@ public abstract class TestContext implem
         InputStream stream = XMLTest.class.getClassLoader().getResourceAsStream(xmlResourcePath);
         Assert.assertNotNull(stream);
 
+        Element beanElement;
         Element rootElement = XMLUtil.getRootElement(stream);
-
-        for (Element beanElement : (List<Element>) rootElement.elements())
+        NodeList nodes = rootElement.getChildNodes();
+        for(int i=0; i<nodes.getLength(); i++)
         {
+        	Node node = nodes.item(i);
+        	if (!(node instanceof Element)) {
+        		continue;
+        	}
+        	beanElement = (Element)node;
             Class<?> clazz = XMLUtil.getElementJavaType(beanElement);
 
             defineXMLSimpleWebBeans(clazz, beanElement);

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/XMLTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/XMLTest.java?rev=930092&r1=930091&r2=930092&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/XMLTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/XMLTest.java Thu Apr  1 20:48:31 2010
@@ -19,7 +19,7 @@ import junit.framework.Assert;
 
 import org.apache.webbeans.test.TestContext;
 import org.apache.webbeans.xml.XMLUtil;
-import org.dom4j.Element;
+import org.w3c.dom.Element;
 import org.junit.Test;
 
 public class XMLTest extends TestContext



Mime
View raw message