[jboss-svn-commits] JBoss Common SVN: r2263 - in jbossxb/trunk/src: test/java/org/jboss/test/xml and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Feb 6 11:54:46 EST 2007


Author: adrian at jboss.org
Date: 2007-02-06 11:54:46 -0500 (Tue, 06 Feb 2007)
New Revision: 2263

Added:
   jbossxb/trunk/src/test/java/org/jboss/test/xml/TopLevelValueAdapterUnitTestCase.java
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/TopLevelValueAdapter.xml
Modified:
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/TypeBinding.java
Log:
The value adapter needs to be invoked on a top level type.
See TopLevelValueAdapterUnitTestCase.

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java	2007-02-06 16:53:51 UTC (rev 2262)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java	2007-02-06 16:54:46 UTC (rev 2263)
@@ -1091,6 +1091,7 @@
 
       if(stack.size() == 1)
       {
+         o = type.getValueAdapter().cast(o, Object.class);
          root = o;
          stack.clear();
       }

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/TypeBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/TypeBinding.java	2007-02-06 16:53:51 UTC (rev 2262)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/TypeBinding.java	2007-02-06 16:54:46 UTC (rev 2263)
@@ -296,6 +296,11 @@
       return charactersHandler;
    }
 
+   public void setCharactersHandler(CharactersHandler charactersHandler)
+   {
+      this.charactersHandler = charactersHandler;
+   }
+   
    /**
     * This method will create a new simple type binding with the passed in characters handler
     * and set this simple type as the simple type of the complex type the method was invoked on.

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/TopLevelValueAdapterUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/TopLevelValueAdapterUnitTestCase.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/TopLevelValueAdapterUnitTestCase.java	2007-02-06 16:54:46 UTC (rev 2263)
@@ -0,0 +1,73 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., 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 javax.xml.namespace.QName;
+
+import junit.framework.TestSuite;
+
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ValueAdapter;
+
+/**
+ * AnyComplexTypeUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TopLevelValueAdapterUnitTestCase extends AbstractJBossXBTest
+{  
+   private static final String NS = "http://www.jboss.org/test/xml/topLevelValueAdapter";
+   
+   public static final TestSuite suite()
+   {
+      return new TestSuite(TopLevelValueAdapterUnitTestCase.class);
+   }
+   
+   public TopLevelValueAdapterUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testTopLevelValueAdapter() throws Exception
+   {
+      SchemaBinding schema = bind("TopLevelValueAdapter.xsd");
+      schema.setIgnoreUnresolvedFieldOrClass(false);
+
+      ElementBinding element = schema.getElement(new QName(NS, "top"));
+      TypeBinding type = element.getType();
+      type.setValueAdapter(new ValueAdapter()
+      {
+         public Object cast(Object o, Class c)
+         {
+            String string = (String) o;
+            return string + "...";
+         }
+         
+      });
+
+      String string = (String) unmarshal("TopLevelValueAdapter.xml", schema, String.class);
+      assertEquals("string...", string);
+   }
+}

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/TopLevelValueAdapter.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/TopLevelValueAdapter.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/TopLevelValueAdapter.xml	2007-02-06 16:54:46 UTC (rev 2263)
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<top xmlns='http://www.jboss.org/test/xml/topLevelValueAdapter'>string</top>




More information about the jboss-svn-commits mailing list