2 Replies Latest reply on Jul 24, 2008 10:13 AM by Alexey Loubyansky

    Whitespace trimming in metadata

    Adrian Brock Master

      Currently we have a failing test because whitespace is not getting
      trimmed from a jndi-name. NOTE there is an extra space after SessionA

      2008-06-16 14:38:33,596 DEBUG [org.jboss.test.naming.ejb.TestEjbLinkBean] (WorkerThread#0[]) failed
      javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: SessionA not bound]
       at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1254)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:767)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:776)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at org.jboss.test.naming.ejb.TestEjbLinkBean.testEjbLinkCaller(TestEjbLinkBean.java:74)

      This is coming from the following jboss.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC
       "-//JBoss//DTD JBOSS 4.0//EN"
       <jndi-name>naming/SessionA </jndi-name>

      In our jboss.xml schema, jndi-name inhertis eventually from the simple xml type
      which has a facet defined that says to normalise space.

      However, in the dtd (used above), jndi-name is just defined as #PCDATA

      But correcting the schema/dtd types wouldn't be the complete fix if
      xml validation is turned off since then it wouldn't look at the dtd/schema anyway.

      What I'd suggest is that we introduce a convenience annotation
      so you can specify whether whitespace should be preserved at the shema level,
      e.g. something like
      @XmlRootElement(name="jboss", namespace=JavaEEMetaDataConstants.JBOSS_NS)
       xmlns={@XmlNs(namespaceURI = JavaEEMetaDataConstants.JAVAEE_NS, prefix = "jee")},
      // HERE
      @XmlType(name="jbossType", namespace=JavaEEMetaDataConstants.JBOSS_NS)
      public class JBoss50MetaData extends JBossMetaData

      With the option on paricular elements/attributes to do

      This would then more easily map to what we used to do in the old parsing
      where it trimmed everything (from the old org.jboss.metadata.MetaData utility class)
       public static String getElementContent(Element element, String defaultStr, boolean replace)
       if (element == null)
       return defaultStr;
       NodeList children = element.getChildNodes();
       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)
       result += children.item(i).getNodeValue();
       else if( children.item(i).getNodeType() == Node.COMMENT_NODE )
       // Ignore comment nodes
       result += children.item(i).getFirstChild();
      // HERE
       if (replace)
       return StringPropertyReplacer.replaceProperties(result.trim());
       return result.trim();