[jboss-svn-commits] JBoss Common SVN: r2420 - in jbossxb/branches/1_0/src: main/java/org/jboss/xb/binding/parser/sax and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jun 20 05:08:14 EDT 2007
Author: alex.loubyansky at jboss.com
Date: 2007-06-20 05:08:14 -0400 (Wed, 20 Jun 2007)
New Revision: 2420
Added:
jbossxb/branches/1_0/src/test/java/org/jboss/test/xml/IgnorableWhitespaceUnitTestCase.java
jbossxb/branches/1_0/src/test/resources/org/jboss/test/xml/IgnorableWhitespaceContent.xml
Modified:
jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/ObjectModelBuilder.java
jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/UnmarshallingContext.java
jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/parser/sax/SaxJBossXBParser.java
jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaBinding.java
jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/TypeBinding.java
jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/XsdBinder.java
jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java
Log:
JBXB-103
Modified: jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/ObjectModelBuilder.java
===================================================================
--- jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/ObjectModelBuilder.java 2007-06-19 12:42:59 UTC (rev 2419)
+++ jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/ObjectModelBuilder.java 2007-06-20 09:08:14 UTC (rev 2420)
@@ -96,6 +96,9 @@
*/
private final NamespaceRegistry nsRegistry = new NamespaceRegistry();
+ // whether text content should be trimmed before it is set
+ private boolean trimTextContent = true; // for backwards compatibility
+
private XSTypeDefinition currentType;
private boolean trace = log.isTraceEnabled();
@@ -164,6 +167,16 @@
return nsRegistry;
}
+ public boolean isTrimTextContent()
+ {
+ return trimTextContent;
+ }
+
+ public void setTrimTextContent(boolean trimTextContent)
+ {
+ this.trimTextContent = trimTextContent;
+ }
+
/**
* Construct a QName from a value
*
@@ -352,11 +365,18 @@
Object acceptedElement = peekAccepted();
if(element.characters != null && element.characters.length() > 0)
{
- String characters = element.characters.toString().trim();
- if(characters.length() > 0)
+ if(trimTextContent)
{
- curFactory.setValue(acceptedElement, this, namespaceURI, localName, characters);
+ String characters = element.characters.toString().trim();
+ if (characters.length() > 0)
+ {
+ curFactory.setValue(acceptedElement, this, namespaceURI, localName, characters);
+ }
}
+ else
+ {
+ curFactory.setValue(acceptedElement, this, namespaceURI, localName, element.characters.toString());
+ }
}
}
Modified: jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/UnmarshallingContext.java
===================================================================
--- jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/UnmarshallingContext.java 2007-06-19 12:42:59 UTC (rev 2419)
+++ jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/UnmarshallingContext.java 2007-06-20 09:08:14 UTC (rev 2420)
@@ -51,7 +51,19 @@
*/
NamespaceContext getNamespaceContext();
+ /**
+ * @return true if the text content passed to the setValue(...) method
+ * is automatically trimmed (the default).
+ */
+ boolean isTrimTextContent();
+
/**
+ * Should the text content be automatically trimmed before setValue(...) is called.
+ * @param trimTextContent
+ */
+ void setTrimTextContent(boolean trimTextContent);
+
+ /**
* Returns child's content.
* todo consider deprecating this method
* @param namespaceURI
Modified: jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/parser/sax/SaxJBossXBParser.java
===================================================================
--- jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/parser/sax/SaxJBossXBParser.java 2007-06-19 12:42:59 UTC (rev 2419)
+++ jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/parser/sax/SaxJBossXBParser.java 2007-06-20 09:08:14 UTC (rev 2420)
@@ -161,6 +161,7 @@
}
catch(Exception e)
{
+e.printStackTrace();
throw new JBossXBException("Failed to parse source: " + getLocationAsString(systemId), e);
}
}
@@ -231,15 +232,15 @@
{
// todo look at this later
// do not notify content handler if these are just whitespaces
- int i = start;
- while(i < start + length)
- {
- if(!Character.isWhitespace(ch[i++]))
- {
+ //int i = start;
+ //while(i < start + length)
+ //{
+ // if(!Character.isWhitespace(ch[i++]))
+ // {
contentHandler.characters(ch, start, length);
- break;
- }
- }
+ // break;
+ // }
+ //}
}
public void ignorableWhitespace(char ch[], int start, int length)
Modified: jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaBinding.java
===================================================================
--- jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaBinding.java 2007-06-19 12:42:59 UTC (rev 2419)
+++ jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaBinding.java 2007-06-20 09:08:14 UTC (rev 2420)
@@ -85,6 +85,11 @@
/** The default property name to use for simple content bindings */
private String simpleContentProperty = "value";
+ /** if all the characters in the mixed content are whitespaces
+ * should they be considered indentation and ignored?
+ * the default is true for the backwards compatibility */
+ private boolean ignoreWhitespacesInMixedContent = true;
+
/** default XOP unmarshaller */
private XOPUnmarshaller xopUnmarshaller;
/** default XOP marshaller */
@@ -429,6 +434,16 @@
&& wildcard.getUnresolvedMarshaller() instanceof DomLocalMarshaller;
}
+ public boolean isIgnoreWhitespacesInMixedContent()
+ {
+ return ignoreWhitespacesInMixedContent;
+ }
+
+ public void setIgnoreWhitespacesInMixedContent(boolean value)
+ {
+ this.ignoreWhitespacesInMixedContent = value;
+ }
+
void addElementParticle(ParticleBinding particle)
{
ElementBinding element = (ElementBinding)particle.getTerm();
Modified: jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
===================================================================
--- jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java 2007-06-19 12:42:59 UTC (rev 2419)
+++ jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java 2007-06-20 09:08:14 UTC (rev 2420)
@@ -87,10 +87,96 @@
public void characters(char[] ch, int start, int length)
{
StackItem stackItem = stack.peek();
- if(stackItem.cursor == null)
+ if(stackItem.cursor != null)
{
- if(stackItem.textContent == null)
+ return;
+ }
+
+ ElementBinding e = (ElementBinding) stackItem.particle.getTerm();
+/* if(!stackItem.ended && e.getType().isTextContentAllowed())
+ {
+ int i = start;
+ while (i < start + length)
{
+ if(ch[i] == 0x0a)
+ {
+ stackItem.indentation = true;
+ }
+ else
+ {
+ if (ch[i] == ' ' || ch[i] == 0x0d)
+ {
+ }
+ else
+ {
+ stackItem.indentation = false;
+ break;
+ }
+ }
+ ++i;
+ }
+
+ if(!stackItem.indentation)
+ {
+ if (stackItem.textContent == null)
+ {
+ stackItem.textContent = new StringBuffer();
+ }
+ stackItem.textContent.append(ch, start, length);
+ }
+ }
+*/
+ // if current is ended the characters belong to its parent
+ if(stackItem.ended)
+ {
+ int i = 0;
+ do
+ {
+ stackItem = stack.peek(++i);
+ }
+ while(stackItem.cursor != null && i < stack.size());
+
+ e = (ElementBinding) stackItem.particle.getTerm();
+ }
+
+ // collect characters only if they are allowed content
+ if(e.getType().isTextContentAllowed())
+ {
+ if(stackItem.indentation != Boolean.FALSE)
+ {
+ if(e.getType().isSimple())
+ {
+ // simple content is not analyzed
+ stackItem.indentation = Boolean.FALSE;
+ stackItem.ignorableCharacters = false;
+ }
+ else if(e.getSchema() != null && !e.getSchema().isIgnoreWhitespacesInMixedContent())
+ {
+ stackItem.indentation = Boolean.FALSE;
+ stackItem.ignorableCharacters = false;
+ }
+ else
+ {
+ // the indentation is currently defined as whitespaces with next line characters
+ // this should probably be externalized in the form of a filter or something
+ for (int i = start; i < start + length; ++i)
+ {
+ if(ch[i] == 0x0a)
+ {
+ stackItem.indentation = Boolean.TRUE;
+ }
+ else if (!Character.isWhitespace(ch[i]))
+ {
+ stackItem.indentation = Boolean.FALSE;
+ stackItem.ignorableCharacters = false;
+ break;
+ }
+ }
+ }
+ }
+
+ if (stackItem.textContent == null)
+ {
stackItem.textContent = new StringBuffer();
}
stackItem.textContent.append(ch, start, length);
@@ -259,6 +345,7 @@
ElementBinding parentElement = (ElementBinding) item.particle.getTerm();
parentElement.setXopUnmarshaller(schema.getXopUnmarshaller());
+ flushIgnorableCharacters();
item.handler = DefaultHandlers.XOP_HANDLER;
item.ignoreCharacters = true;
item.o = item.handler.startParticle(stack.peek().o, startName, stack.peek().particle, null, nsRegistry);
@@ -284,6 +371,8 @@
}
else
{
+ flushIgnorableCharacters();
+
Object o = item.o;
// push all except the last one
for(int i = newCursors.size() - 1; i >= 0; --i)
@@ -770,6 +859,26 @@
// Private
+ private void flushIgnorableCharacters()
+ {
+ StackItem stackItem = stack.peek();
+ if(stackItem.cursor != null || stackItem.textContent == null)
+ {
+ return;
+ }
+
+ if(stackItem.indentation == Boolean.TRUE || stackItem.ignorableCharacters)
+ {
+ if(log.isTraceEnabled())
+ {
+ log.trace("ignored characters: " + ((ElementBinding) stackItem.particle.getTerm()).getQName() + " '"
+ + stackItem.textContent + "'");
+ }
+ stackItem.textContent = null;
+ stackItem.indentation = null;
+ }
+ }
+
private ParticleBinding getParentParticle()
{
ListIterator iter = stack.prevIterator();
@@ -805,6 +914,8 @@
// characters
//
+ flushIgnorableCharacters();
+
TypeBinding charType = type.getSimpleType();
if(charType == null)
{
@@ -1132,6 +1243,8 @@
Object o;
ValueList repeatableParticleValue;
StringBuffer textContent;
+ Boolean indentation;
+ boolean ignorableCharacters = true;
boolean ended;
public StackItem(ModelGroupBinding.Cursor cursor, Object o, ParticleHandler handler)
@@ -1171,6 +1284,9 @@
{
textContent.delete(0, textContent.length());
}
+
+ indentation = null;
+ ignorableCharacters = true;
}
}
Modified: jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/TypeBinding.java
===================================================================
--- jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/TypeBinding.java 2007-06-19 12:42:59 UTC (rev 2419)
+++ jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/TypeBinding.java 2007-06-20 09:08:14 UTC (rev 2420)
@@ -351,6 +351,11 @@
this.simple = simple ? Boolean.TRUE : Boolean.FALSE;
}
+ public boolean isTextContentAllowed()
+ {
+ return simpleType != null || isSimple();
+ }
+
public ClassMetaData getClassMetaData()
{
return classMetaData;
Modified: jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/XsdBinder.java
===================================================================
--- jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/XsdBinder.java 2007-06-19 12:42:59 UTC (rev 2419)
+++ jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/XsdBinder.java 2007-06-20 09:08:14 UTC (rev 2420)
@@ -400,6 +400,7 @@
{
Context ctx = new Context();
ctx.processAnnotations = processAnnotations;
+ ctx.simpleContentWithIdAsSimpleType = simpleContentWithIdAsSimpleType;
SchemaBinding schema = ctx.schema;
schema.setSchemaResolver(resolver);
@@ -675,10 +676,16 @@
XSObjectList attrs = type.getAttributeUses();
if (ctx.trace)
log.trace(typeName + " attributes " + attrs.getLength());
+
+ boolean hasOnlyIdAttrs = true;
for(int i = 0; i < attrs.getLength(); ++i)
{
XSAttributeUse attr = (XSAttributeUse)attrs.item(i);
- bindAttributes(ctx, binding, attr);
+ AttributeBinding attrBinding = bindAttributes(ctx, binding, attr);
+ if(hasOnlyIdAttrs && !Constants.QNAME_ID.equals(attrBinding.getType().getQName()))
+ {
+ hasOnlyIdAttrs = false;
+ }
}
// customize binding with xsd annotations
@@ -841,6 +848,17 @@
ctx.popType();
}
+ if(binding.getClassMetaData() == null &&
+ ctx.simpleContentWithIdAsSimpleType &&
+ particle == null && hasOnlyIdAttrs)
+ {
+ binding.setStartElementCreatesObject(false);System.out.println("no object for " + binding.getQName());
+ }
+ else
+ {
+ binding.setStartElementCreatesObject(true);
+ }
+
if(binding.hasOnlyXmlMimeAttributes())
{
addXOPInclude(binding, ctx.schema);
@@ -854,7 +872,7 @@
return binding;
}
- private static void bindAttributes(Context ctx, TypeBinding type, XSAttributeUse attrUse)
+ private static AttributeBinding bindAttributes(Context ctx, TypeBinding type, XSAttributeUse attrUse)
{
XSAttributeDeclaration attr = attrUse.getAttrDeclaration();
QName attrName = new QName(attr.getNamespace(), attr.getName());
@@ -940,6 +958,8 @@
log.trace(msg);
}
+
+ return binding;
}
private static void bindParticle(Context ctx, XSParticle particle)
@@ -1457,6 +1477,7 @@
public final SchemaBinding schema;
public SharedElements sharedElements = new SharedElements();
public boolean processAnnotations = true;
+ public boolean simpleContentWithIdAsSimpleType = true;
public boolean trace = log.isTraceEnabled();
private final List typeGroupStack = new ArrayList();
Modified: jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java
===================================================================
--- jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java 2007-06-19 12:42:59 UTC (rev 2419)
+++ jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java 2007-06-20 09:08:14 UTC (rev 2420)
@@ -387,8 +387,10 @@
if(!term.isModelGroup())
{
TypeBinding type = ((ElementBinding)term).getType();
- if(!type.isStartElementCreatesObject() ||
- classMetaData == null && mapEntryMetaData == null && Constants.QNAME_ANYTYPE.equals(type.getQName()))
+ if(type.isSimple() ||
+ classMetaData == null && mapEntryMetaData == null &&
+ (!type.isStartElementCreatesObject() ||
+ Constants.QNAME_ANYTYPE.equals(type.getQName())))
{
if(trace)
{
@@ -398,8 +400,6 @@
}
}
- Object o = null;
-
// if addMethod is specified, it's probably some collection field
// but should not be set as a property. Instead, items are added to it using the addMethod
ElementBinding arrayItem = null;
@@ -452,7 +452,7 @@
{
log.trace("startElement " + elementName + " new array " + itemType.getName());
}
- o = GenericValueContainer.FACTORY.array(itemType);
+ return GenericValueContainer.FACTORY.array(itemType);
}
}
else
@@ -495,38 +495,58 @@
}
}
- Class fieldType;
+ Class fieldType = null;
if(parentClass.isArray())
{
fieldType = parentClass.getComponentType();
}
else
{
- fieldType = FieldInfo.getFieldInfo(parentClass, propName, true).getType();
- if(particle.isRepeatable() && fieldType.isArray())
+ //fieldType = FieldInfo.getFieldInfo(parentClass, propName, true).getType();
+ // this was changed to false because allow overriding of handler.setParent()
+ // with an interceptor.add(). See CollectionOverridePropertyUnitTestCase
+ // In other words, don't treat it as an array wrapper.
+ FieldInfo fieldInfo = FieldInfo.getFieldInfo(parentClass, propName, false);
+ if(fieldInfo != null)
{
- fieldType = fieldType.getComponentType();
+ fieldType = fieldInfo.getType();
+ if (particle.isRepeatable() && fieldType.isArray())
+ {
+ fieldType = fieldType.getComponentType();
+ }
}
+ else if(arrayItem.getInterceptors().isEmpty())
+ {
+ QName typeName = ((ElementBinding)term).getType().getQName();
+ throw new JBossXBRuntimeException(
+ "Couldn't apply 'array wrapper' pattern for element " +
+ elementName + " of type " +
+ (typeName == null ? "anonymous" : typeName.toString()) +
+ ": failed to resolve property " + propName +
+ " and no interceptors applied to override handler.setParent(...)");
+ }
}
if(fieldType.isArray())
{
- o = GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType.getComponentType());
+ return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType.getComponentType());
}
else if(Collection.class.isAssignableFrom(fieldType))
{
- //System.out.println("GeenericValueContainer.child: " + elementName);
- o = new ValueListInitializer().newValueList(ValueListHandler.FACTORY.child(), Collection.class);
- //o = new ArrayList();
+ if (wrapperType == null)
+ {
+ return new ValueListInitializer().newValueList(ValueListHandler.FACTORY.child(), Collection.class);
+ //o = ArrayList();
+ }
}
else
{
- o = GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType);
+ return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType);
}
}
}
- else
- {
+
+ Object o = null;
if(mapEntryMetaData != null)
{
if(mapEntryMetaData.getImpl() != null)
@@ -728,7 +748,7 @@
o = newInstance(cls, elementName, noArgCtor);
}
}
- }
+
return o;
}
Added: jbossxb/branches/1_0/src/test/java/org/jboss/test/xml/IgnorableWhitespaceUnitTestCase.java
===================================================================
--- jbossxb/branches/1_0/src/test/java/org/jboss/test/xml/IgnorableWhitespaceUnitTestCase.java (rev 0)
+++ jbossxb/branches/1_0/src/test/java/org/jboss/test/xml/IgnorableWhitespaceUnitTestCase.java 2007-06-20 09:08:14 UTC (rev 2420)
@@ -0,0 +1,155 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.xml;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestSuite;
+
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.UnmarshallingContext;
+import org.jboss.xb.binding.metadata.ClassMetaData;
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.XsdBinder;
+import org.xml.sax.Attributes;
+
+
+/**
+ * IgnorableWhitespaceUnitTestCase.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision$
+ */
+public class IgnorableWhitespaceUnitTestCase extends AbstractJBossXBTest
+{
+ private static final String NS = "http://www.jboss.org/test/xml/simpleContent";
+
+ private static final String XSD =
+ "<?xml version='1.0' encoding='UTF-8'?>" +
+ "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
+ " targetNamespace='http://www.jboss.org/test/xml/simpleContent'" +
+ " xmlns='http://www.jboss.org/test/xml/simpleContent'" +
+ " elementFormDefault='qualified'" +
+ " attributeFormDefault='unqualified'" +
+ " version='1.0'>" +
+ " <xsd:element name='top'>" +
+ " <xsd:complexType>" +
+ " <xsd:sequence>" +
+ " <xsd:element name='string' type='myString' minOccurs='0' maxOccurs='unbounded'/>" +
+ " </xsd:sequence>" +
+ " </xsd:complexType>" +
+ " </xsd:element>" +
+ " <xsd:complexType name='myString'>" +
+ " <xsd:simpleContent>" +
+ " <xsd:extension base='xsd:string'>" +
+ " <xsd:attribute name='id' type='xsd:ID'/>" +
+ " </xsd:extension>" +
+ " </xsd:simpleContent>" +
+ " </xsd:complexType>" +
+ "</xsd:schema>";
+
+ public static final TestSuite suite()
+ {
+ return new TestSuite(IgnorableWhitespaceUnitTestCase.class);
+ }
+
+ public IgnorableWhitespaceUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testCollectionOverrideProperty() throws Exception
+ {
+ SchemaBinding schema = XsdBinder.bind(new StringReader(XSD), null);
+
+ schema.setIgnoreUnresolvedFieldOrClass(false);
+ schema.setIgnoreWhitespacesInMixedContent(false);
+
+ ClassMetaData classMetaData = new ClassMetaData();
+ classMetaData.setImpl(Top.class.getName());
+ ElementBinding element = schema.getElement(new QName(NS, "top"));
+ assertNotNull(element);
+ element.setClassMetaData(classMetaData);
+
+ Top top = (Top) unmarshal("IgnorableWhitespaceContent.xml", schema, Top.class);
+ assertNotNull(top.string);
+ assertEquals(2, top.string.size());
+ assertEquals(" ", top.string.get(0));
+ assertEquals("\n newline, 6 spaces, newline, 3 spaces\n ", top.string.get(1));
+ }
+
+ public void testObjectModelFactory() throws Exception
+ {
+ String url = findXML("IgnorableWhitespaceContent.xml");
+
+ ObjectModelFactory omf = new OMF();
+
+ Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+ Object o = unmarshaller.unmarshal(url, omf, null);
+
+ assertNotNull(o);
+ assertTrue(o instanceof Top);
+ Top top = (Top) o;
+ assertEquals(2, top.string.size());
+ assertEquals(" ", top.string.get(0));
+ assertEquals("\n newline, 6 spaces, newline, 3 spaces\n ", top.string.get(1));
+
+ }
+
+ public static final class OMF implements ObjectModelFactory
+ {
+ public Object completeRoot(Object root, UnmarshallingContext ctx, String namespaceURI, String localName)
+ {
+ return root;
+ }
+
+ public Object newRoot(Object root, UnmarshallingContext ctx, String namespaceURI, String localName, Attributes attrs)
+ {
+ ctx.setTrimTextContent(false);
+ return new Top();
+ }
+
+ public void setValue(Top top, UnmarshallingContext ctx, String ns, String name, String value)
+ {
+ if(name.equals("string"))
+ {
+ if(top.string == null)
+ {
+ top.string = new ArrayList();
+ }
+ top.string.add(value);
+ }
+ }
+ }
+
+ public static class Top
+ {
+ public List string;
+ }
+}
Added: jbossxb/branches/1_0/src/test/resources/org/jboss/test/xml/IgnorableWhitespaceContent.xml
===================================================================
--- jbossxb/branches/1_0/src/test/resources/org/jboss/test/xml/IgnorableWhitespaceContent.xml (rev 0)
+++ jbossxb/branches/1_0/src/test/resources/org/jboss/test/xml/IgnorableWhitespaceContent.xml 2007-06-20 09:08:14 UTC (rev 2420)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<top xmlns='http://www.jboss.org/test/xml/simpleContent'>
+ <string> </string>
+ <string>
+ newline, 6 spaces, newline, 3 spaces
+ </string>
+</top>
More information about the jboss-svn-commits
mailing list