[weld-dev] beans.xsd validation forbeans.xml

Marcin Mieszek marcin.mieszek at gmail.com
Sun Jun 6 15:54:38 EDT 2010


Hi,

I am working right now on issue:
Weld WELD-379Use beans.xsd for validation of beans.xml

1. Currently in MergedElements class there is a logic that checks
ifsome elements occur more then once, which is not allowed:

   private List<BeansXmlElement> getNamedElement(URL url, Element
beans, String name, XmlMessage multipleViolationMessage)
   {
      List<BeansXmlElement> elements = new ArrayList<BeansXmlElement>();
      NodeList nodeList = beans.getElementsByTagName(name);
      if (nodeList.getLength() > 1)
      {
         throw new WeldXmlException(multipleViolationMessage);
      }
      else if (nodeList.getLength() == 1)
      {
         BeansXmlElement element = BeansXmlElement.of(url, nodeList.item(0));
         elements.add(element);
      }
      return elements;
   }


Such files arenot valid according to XSD schema neither. I am planning
to add XSD validation during parsing of the file - it means that it
won't be possible to get error with message one of:
   @MessageId("001203") MULTIPLE_ALTERNATIVES,
   @MessageId("001204") MULTIPLE_DECORATORS,
   @MessageId("001205") MULTIPLE_INTERCEPTORS,

Please let me know how you would like to proceed with it as it is more
functional question then technical. For schema errors I will add new
message XSD_SCHEMA_ERROR.

2. Minor issue: all test beans.xml files must be changed after adding
schema validation so that it references correct namespace:

<beans xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">

I will prepare the patch for this one as well.

Cheers,

Marcin


More information about the weld-dev mailing list