You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ch...@apache.org on 2006/02/06 11:53:04 UTC
svn commit: r375242 - in /webservices/axis2/trunk/java/modules/adb:
src/org/apache/axis2/databinding/utils/ADBPullParser.java
test/org/apache/axis2/databinding/utils/ADBPullParserTest.java
Author: chinthaka
Date: Mon Feb 6 02:53:02 2006
New Revision: 375242
URL: http://svn.apache.org/viewcvs?rev=375242&view=rev
Log:
Extending ADBPullParser to handle QName,null case.
Modified:
webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/ADBPullParser.java
webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java
Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/ADBPullParser.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/ADBPullParser.java?rev=375242&r1=375241&r2=375242&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/ADBPullParser.java (original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/ADBPullParser.java Mon Feb 6 02:53:02 2006
@@ -3,6 +3,7 @@
import org.apache.axis2.databinding.ADBBean;
import org.apache.ws.commons.om.OMAttribute;
import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMAbstractFactory;
import org.apache.ws.commons.om.impl.llom.EmptyOMLocation;
import javax.xml.namespace.NamespaceContext;
@@ -123,50 +124,50 @@
* @param properties - this should contain all the stuff that stax events should be generated.
* Lets take an example of a bean.
* <pre>
- * <Person>
- * <DependentOne>
- * <Name>FooTwo</Name>
- * <Age>25</Age>
- * <Sex>Male</Sex>
- * </DependentOne>
- * </Person>
- * <p/>
- * <p/>
- * so the mapping bean for this is
- * class Person {
- * String Name;
- * Dependent dependentOne;
- * }
- * <p/>
- * <p/>
- * }
- * <p/>
- * <p/>
- * So if one needs to generate pull events out of a Person bean, the array he needs
- * to pass is like this.
- * ---------------------------------------------------------------------------------------------------
- * | "Name" | "FooOne" | QName("DependentOne") | Dependent object| null | Array of Dependent objects |
- * ---------------------------------------------------------------------------------------------------
- * This DependentObject can either be an ADBBean, OMElement or a POJO. If its an ADBBean
- * We directly get the pull parser from that. If not we create a reflection based
- * pull parser for that java bean.
+ * <Person>
+ * <DependentOne>
+ * <Name>FooTwo</Name>
+ * <Age>25</Age>
+ * <Sex>Male</Sex>
+ * </DependentOne>
+ * </Person>
+ * <p/>
+ * <p/>
+ * so the mapping bean for this is
+ * class Person {
+ * String Name;
+ * Dependent dependentOne;
+ * }
+ * <p/>
+ * <p/>
+ * }
+ * <p/>
+ * <p/>
+ * So if one needs to generate pull events out of a Person bean, the array he needs
+ * to pass is like this.
+ * ---------------------------------------------------------------------------------------------------
+ * | "Name" | "FooOne" | QName("DependentOne") | Dependent object| null | Array of Dependent objects |
+ * ---------------------------------------------------------------------------------------------------
+ * This DependentObject can either be an ADBBean, OMElement or a POJO. If its an ADBBean
+ * We directly get the pull parser from that. If not we create a reflection based
+ * pull parser for that java bean.
* <p/>
* <p/>
* <p/>
- * This is the how the passed array should look like
- * Key Value
- * String String
- * QName ADBBean, OMElement, Bean, String
- * String String[]
- * QName Object[] - this contains only one type of objects
- * <p/>
- * <p/>
- * This is how the passed attribute array should look like
- * Key Value
- * null OMAttribute[]
- * QName String
- * String String
- * </pre>
+ * This is the how the passed array should look like
+ * Key Value
+ * String String
+ * QName ADBBean, OMElement, Bean, String, null
+ * String String[]
+ * QName Object[] - this contains only one type of objects
+ * <p/>
+ * <p/>
+ * This is how the passed attribute array should look like
+ * Key Value
+ * null OMAttribute[]
+ * QName String
+ * String String
+ * </pre>
* @return XMLStreamReader
*/
public static XMLStreamReader createPullParser(QName adbBeansQName, Object[] properties, Object[] attributes) {
@@ -275,6 +276,13 @@
} else if (object instanceof String) {
processingADBNameValuePair = true;
return processADBNameValuePair((QName) o, (String) object);
+ } else if (object == null) {
+ OMElement omElement = OMAbstractFactory.getOMFactory().createOMElement((QName) o, null);
+ omElement.addAttribute("nil", "true", null);
+ childPullParser = omElement.getXMLStreamReader();
+
+ // here we are injecting one additional element. So need to accomodate that.
+// currentIndex --;
} else {
getPullParser(object, (QName) o);
}
@@ -649,7 +657,7 @@
public char[] getTextCharacters() {
if (accessingChildPullParser) return childPullParser.getTextCharacters();
- String text = parserInformation != null ? parserInformation.getText() : "";
+ String text = parserInformation != null ? parserInformation.getText() : "";
return text.toCharArray();
}
@@ -664,7 +672,7 @@
public int getTextLength() {
if (accessingChildPullParser) return childPullParser.getTextLength();
- String text = parserInformation != null ? parserInformation.getText() : "";
+ String text = parserInformation != null ? parserInformation.getText() : "";
return text.length();
}
Modified: webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java?rev=375242&r1=375241&r2=375242&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java (original)
+++ webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java Mon Feb 6 02:53:02 2006
@@ -101,6 +101,38 @@
}
+ public void testNullableAttribute() {
+ try {
+
+ /*
+ This is what I expect :
+
+ */
+ String exptectedXML = "<Person xmlns=\"\"><Name xmlns=\"\">FooOne</Name><DependentOne xmlns=\"\" nil=\"true\" />" +
+ "</Person>";
+
+ ArrayList propertyList = new ArrayList();
+ propertyList.add("Name");
+ propertyList.add("FooOne");
+ propertyList.add(new QName("DependentOne"));
+ propertyList.add(null);
+
+ QName projectQName = new QName("Person");
+ XMLStreamReader pullParser = ADBPullParser.createPullParser(projectQName, propertyList.toArray(), null);
+
+ Document actualDom = newDocument(getStringXML(pullParser));
+ Document expectedDocument = newDocument(exptectedXML);
+ assertXMLEqual(actualDom, expectedDocument);
+ } catch (ParserConfigurationException e) {
+ fail("Exception in parsing documents " + e);
+ } catch (SAXException e) {
+ fail("Exception in parsing documents " + e);
+ } catch (IOException e) {
+ fail("Exception in parsing documents " + e);
+ }
+
+ }
+
public void testComplexArrayList() {
try {