[jboss-svn-commits] JBoss Common SVN: r2143 - jbossxb/branches/as405/src/test/java/org/jboss/test/xml
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Oct 25 09:10:56 EDT 2006
Author: heiko.braun at jboss.com
Date: 2006-10-25 09:10:54 -0400 (Wed, 25 Oct 2006)
New Revision: 2143
Modified:
jbossxb/branches/as405/src/test/java/org/jboss/test/xml/XOPUnitTestCase.java
Log:
added xopContent example
Modified: jbossxb/branches/as405/src/test/java/org/jboss/test/xml/XOPUnitTestCase.java
===================================================================
--- jbossxb/branches/as405/src/test/java/org/jboss/test/xml/XOPUnitTestCase.java 2006-10-25 13:10:40 UTC (rev 2142)
+++ jbossxb/branches/as405/src/test/java/org/jboss/test/xml/XOPUnitTestCase.java 2006-10-25 13:10:54 UTC (rev 2143)
@@ -24,14 +24,7 @@
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;
import org.jboss.xb.binding.sunday.marshalling.MarshallerImpl;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
-import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.SequenceBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.TermBeforeSetParentCallback;
-import org.jboss.xb.binding.sunday.unmarshalling.UnmarshallingContext;
-import org.jboss.xb.binding.sunday.unmarshalling.XsdBinder;
+import org.jboss.xb.binding.sunday.unmarshalling.*;
import org.jboss.xb.binding.sunday.xop.XOPMarshaller;
import org.jboss.xb.binding.sunday.xop.XOPObject;
import org.jboss.xb.binding.sunday.xop.XOPUnmarshaller;
@@ -39,6 +32,7 @@
import org.xml.sax.SAXException;
import javax.xml.transform.Source;
+import javax.xml.namespace.QName;
import javax.activation.DataSource;
import java.awt.*;
import java.awt.image.ImageObserver;
@@ -59,7 +53,8 @@
*/
public class XOPUnitTestCase
extends AbstractJBossXBTest
-{
+{
+
public static final TestSuite suite()
{
return new TestSuite(XOPUnitTestCase.class);
@@ -188,6 +183,13 @@
xopObject = new XOPObject("octets".getBytes());
xopObject.setContentType("application/octet-stream");
}
+ else if(cid.endsWith("xopContent"))
+ {
+ // The XOPUnmarshaller returns an object
+ // that doesn't match that actual java property
+ xopObject = new XOPObject("xopContent".getBytes());
+ xopObject.setContentType("application/octet-stream");
+ }
else
{
try
@@ -254,13 +256,13 @@
{
ElementBinding e = (ElementBinding) ctx.getParticle().getTerm();
Class propType = ctx.resolvePropertyType();
-
+
String localPart = e.getQName().getLocalPart();
if("image".equals(localPart) ||
- "sig".equals(localPart) ||
- "imageWithContentType".equals(localPart) ||
- "octets".equals(localPart) ||
- "jpeg".equals(localPart))
+ "sig".equals(localPart) ||
+ "imageWithContentType".equals(localPart) ||
+ "octets".equals(localPart) ||
+ "jpeg".equals(localPart))
{
assertEquals("expected " + byte[].class + " for " + localPart, byte[].class, propType);
}
@@ -290,8 +292,65 @@
{
ParticleBinding particle = (ParticleBinding) i.next();
ElementBinding child = (ElementBinding) particle.getTerm();
- child.setBeforeSetParentCallback(callback);
+ if(! "xopContent".equals( child.getQName().getLocalPart()))
+ child.setBeforeSetParentCallback(callback);
}
+
+ // ---------------------------------------------------
+
+ TermBeforeSetParentCallback interceptXOPUnmarshallerResults = new TermBeforeSetParentCallback()
+ {
+ public Object beforeSetParent(Object o, UnmarshallingContext ctx)
+ {
+
+ ElementBinding e = (ElementBinding) ctx.getParticle().getTerm();
+ Class propType = ctx.resolvePropertyType();
+
+ assertNotNull("Failed to resolve property type for "+e.getQName(), propType);
+
+ String localPart = e.getQName().getLocalPart();
+ if("xopContent".equals(localPart))
+ {
+ System.out.println("! xopContent handle on "+ e.getQName());
+ assertEquals(String.class, propType);
+ }
+ else if("Include".equals(localPart))
+ {
+ System.out.println("! include handle on "+ e.getQName());
+ assertEquals(String.class, propType);
+
+ assertTrue( (o instanceof byte[]));
+
+ // Type conversion required
+ if(propType.equals(String.class))
+ o = new String( (byte[])o);
+ }
+
+ return o;
+ }
+ };
+
+ // xmime complex types
+ TypeBinding xmimeBase64Type = SCHEMA.getType(new QName("http://www.w3.org/2005/05/xmlmime", "base64Binary"));
+ if(xmimeBase64Type!=null)
+ {
+ xmimeBase64Type.setBeforeSetParentCallback( interceptXOPUnmarshallerResults );
+
+ // xop:Include
+ // Uncomment the following lines in order to intercept the
+ // XOPUnmarshaller result _before_ the actual setter is invoked
+
+ /*
+ ModelGroupBinding modelGroup = (ModelGroupBinding)xmimeBase64Type.getParticle().getTerm();
+ ParticleBinding particle = (ParticleBinding)modelGroup.getParticles().iterator().next();
+ ElementBinding xopInclude = (ElementBinding)particle.getTerm();
+
+ if(! xopInclude.getQName().equals(new QName("http://www.w3.org/2004/08/xop/include", "Include")))
+ throw new RuntimeException("Looks like the JBossXB XOP implementation has changed, please open a JIRA issue");
+
+ xopInclude.setBeforeSetParentCallback(interceptXOPUnmarshallerResults);
+ */
+ }
}
if(NON_OPT_XML == null)
@@ -509,6 +568,23 @@
assertEquals("string", e.string);
}
+ public void testUnmarshalStringWithTypeConversion() throws Exception
+ {
+ SCHEMA.setXopUnmarshaller(XOP_ENABLED_UNMARSH);
+
+ String xml = getOptimizedXml("xopContent");
+
+ Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+ Object o = unmarshaller.unmarshal(new StringReader(xml), SCHEMA);
+
+ assertNotNull(o);
+ assertTrue(o instanceof E);
+
+ E e = (E)o;
+ assertNotNull(e.xopContent);
+ assertEquals("xopContent", e.xopContent);
+ }
+
public void testTopLevelUnmarshalling() throws Exception
{
String xsd =
@@ -601,5 +677,8 @@
public Source source;
public String string;
public byte[] octets;
+
+ public String xopContent;
}
+
}
More information about the jboss-svn-commits
mailing list