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 aj...@apache.org on 2006/02/06 05:29:14 UTC
svn commit: r375168 - in /webservices/axis2/trunk/java/modules:
adb/src/org/apache/axis2/databinding/utils/
codegen/src/org/apache/axis2/schema/template/
codegen/src/org/apache/axis2/schema/writer/
Author: ajith
Date: Sun Feb 5 20:29:12 2006
New Revision: 375168
URL: http://svn.apache.org/viewcvs?rev=375168&view=rev
Log:
Almost done with supporting nil=true
Have to write the test cases though
Added:
webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/Constants.java
Modified:
webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachine.java
webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleElementReaderStateMachine.java
webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/States.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
Added: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/Constants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/Constants.java?rev=375168&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/Constants.java (added)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/Constants.java Sun Feb 5 20:29:12 2006
@@ -0,0 +1,22 @@
+package org.apache.axis2.databinding.utils;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public interface Constants {
+
+ static String NIL="nil";
+ static String TRUE="true";
+}
Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachine.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachine.java?rev=375168&r1=375167&r2=375168&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachine.java (original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachine.java Sun Feb 5 20:29:12 2006
@@ -25,10 +25,11 @@
/**
* A state machine that reads arrays with simple content. returns a string array
*/
-public class SimpleArrayReaderStateMachine implements States {
+public class SimpleArrayReaderStateMachine implements States,Constants {
private QName elementNameToTest = null;
private int currentState = INIT_STATE;
+ private boolean nillable = false;
private List list = new ArrayList();
/**
@@ -39,6 +40,10 @@
}
+ public void setNillable(){
+ nillable = true;
+ }
+
/**
* Resets the state machine. Once the reset is called
* the state machine is good enough for a fresh run
@@ -46,6 +51,7 @@
public void reset(){
elementNameToTest = null;
currentState = INIT_STATE;
+ nillable = false;
list=new ArrayList();
}
@@ -61,6 +67,17 @@
do{
updateState(reader);
+
+ //test for the nillable attribute
+ if (currentState==START_ELEMENT_FOUND_STATE &&
+ nillable){
+ if (TRUE.equals(reader.getAttributeValue("",NIL))){
+ list.add(null);
+ //force the state to be null found
+ currentState= NULLED_STATE;
+ }
+ }
+
if (currentState==TEXT_FOUND_STATE){
//read the text value and store it in the list
list.add(reader.getText());
@@ -82,26 +99,33 @@
}
- private void updateState(XMLStreamReader reader){
+
+
+
+ private void updateState(XMLStreamReader reader) throws XMLStreamException{
int event = reader.getEventType();
- //state 1
+ //Starting state
if (event== XMLStreamConstants.START_DOCUMENT && currentState==INIT_STATE){
currentState = STARTED_STATE;
+
+ //start element found at init
}else if (event==XMLStreamConstants.START_ELEMENT && currentState==INIT_STATE){
if (elementNameToTest.equals(reader.getName())){
currentState = START_ELEMENT_FOUND_STATE;
}else{
currentState = STARTED_STATE;
}
+ //start element found after starting
}else if (event==XMLStreamConstants.START_ELEMENT && currentState==STARTED_STATE) {
if (elementNameToTest.equals(reader.getName())){
currentState = START_ELEMENT_FOUND_STATE;
}
+ //characters found after start
}else if (event==XMLStreamConstants.CHARACTERS && currentState==START_ELEMENT_FOUND_STATE){
currentState = TEXT_FOUND_STATE;
- //state 3
+ //end element found after characters
} else if (event==XMLStreamConstants.END_ELEMENT && currentState==TEXT_FOUND_STATE){
if (elementNameToTest.equals(reader.getName())){
currentState = END_ELEMENT_FOUND_STATE;
@@ -109,17 +133,30 @@
currentState = ILLEGAL_STATE;
}
- //state 4
+ //another start element found after end-element
}else if (event==XMLStreamConstants.START_ELEMENT && currentState==END_ELEMENT_FOUND_STATE ) {
if (elementNameToTest.equals(reader.getName())){
currentState = START_ELEMENT_FOUND_STATE;
}else{
currentState = FINISHED_STATE;
}
+ //another end element found after end-element
}else if (event==XMLStreamConstants.END_ELEMENT && currentState==END_ELEMENT_FOUND_STATE ) {
currentState = FINISHED_STATE;
+ //end document found
}else if (event==XMLStreamConstants.END_DOCUMENT){
currentState = FINISHED_STATE;
+
+ //the element was found to be null and this state was forced.
+ //we are sure here that the parser was at the START_ELEMENT_FOUND_STATE before
+ //being forced. Hence we need to advance the parser upto the end element and
+ //set the state to be end element found
+ }else if (currentState==NULLED_STATE){
+ while (event!= XMLStreamConstants.END_ELEMENT){
+ event=reader.next();
+ }
+ currentState = END_ELEMENT_FOUND_STATE;
+ //all other combinations are invalid
}else{
currentState = ILLEGAL_STATE;
}
Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleElementReaderStateMachine.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleElementReaderStateMachine.java?rev=375168&r1=375167&r2=375168&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleElementReaderStateMachine.java (original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleElementReaderStateMachine.java Sun Feb 5 20:29:12 2006
@@ -25,12 +25,13 @@
* of the element and the stream reader will be one event beyond the
* end element at return
*/
-public class SimpleElementReaderStateMachine implements States{
+public class SimpleElementReaderStateMachine implements States,Constants{
private QName elementNameToTest = null;
private int currentState = INIT_STATE;
+ private boolean nillable = false;
private String text="";
/**
@@ -42,6 +43,12 @@
}
/**
+ * sets the nillable flag
+ */
+ public void setNillable(){
+ nillable = true;
+ }
+ /**
* the Qname of the element to be tested
* @param elementNameToTest
*/
@@ -56,6 +63,7 @@
public void reset(){
elementNameToTest = null;
currentState = INIT_STATE;
+ nillable = false;
text="";
}
/**
@@ -66,13 +74,24 @@
do{
updateState(reader);
+
+ //test for the nillable attribute
+ if (currentState==START_ELEMENT_FOUND_STATE &&
+ nillable){
+ if (TRUE.equals(reader.getAttributeValue("",NIL))){
+ text = null;
+ //force the state to be null found
+ currentState= NULLED_STATE;
+ }
+ }
+
if (currentState==TEXT_FOUND_STATE){
//read the text value and store it
text = reader.getText();
}
if (currentState!=FINISHED_STATE
- && currentState!= ILLEGAL_STATE){
- reader.next();
+ && currentState!= ILLEGAL_STATE){
+ reader.next();
}
}while(currentState!=FINISHED_STATE
@@ -89,26 +108,29 @@
* Updates the state depending on the parser
* @param reader
*/
- private void updateState(XMLStreamReader reader){
+ private void updateState(XMLStreamReader reader) throws XMLStreamException{
int event = reader.getEventType();
- //state 1
+ //start_document found at init
if (event==XMLStreamConstants.START_DOCUMENT && currentState==INIT_STATE){
currentState = STARTED_STATE;
+ //start element found at init
}else if (event==XMLStreamConstants.START_ELEMENT && currentState==INIT_STATE){
if (elementNameToTest.equals(reader.getName())){
currentState = START_ELEMENT_FOUND_STATE;
}else{
currentState = STARTED_STATE;
}
+ //start element found after started
}else if (event==XMLStreamConstants.START_ELEMENT && currentState==STARTED_STATE) {
if (elementNameToTest.equals(reader.getName())){
currentState = START_ELEMENT_FOUND_STATE;
}
+ //characteres found after starting
}else if (event==XMLStreamConstants.CHARACTERS && currentState==START_ELEMENT_FOUND_STATE){
currentState = TEXT_FOUND_STATE;
- //state 3
+ // end element found after characters
} else if (event==XMLStreamConstants.END_ELEMENT && currentState==TEXT_FOUND_STATE){
if (elementNameToTest.equals(reader.getName())){
currentState = END_ELEMENT_FOUND_STATE;
@@ -116,9 +138,20 @@
currentState = ILLEGAL_STATE;
}
- //state 4
+ //end has been reached
}else if (currentState==END_ELEMENT_FOUND_STATE) {
currentState = FINISHED_STATE;
+ //the element was found to be null and this state was forced.
+ //we are sure here that the parser was at the START_ELEMENT_FOUND_STATE before
+ //being forced. Hence we need to advance the parser upto the end element and
+ //set the state to be end element found
+ }else if (currentState==NULLED_STATE){
+ while (event!= XMLStreamConstants.END_ELEMENT){
+ event=reader.next();
+ }
+ currentState = END_ELEMENT_FOUND_STATE;
+ //all other combinations are invalid
+
}else{
currentState = ILLEGAL_STATE;
}
Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/States.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/States.java?rev=375168&r1=375167&r2=375168&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/States.java (original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/States.java Sun Feb 5 20:29:12 2006
@@ -25,5 +25,6 @@
static int FINISHED_STATE = 4;
static int ILLEGAL_STATE = 5;
static int CONTENT_FOUND_STATE = 6;
+ static int NULLED_STATE = 7;
}
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl?rev=375168&r1=375167&r2=375168&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl Sun Feb 5 20:29:12 2006
@@ -122,12 +122,12 @@
<xsl:if test="@array">
<xsl:if test="not(@unbound)">
if (param.length > <xsl:value-of select="@maxOccurs"></xsl:value-of>){
- throw new java.lang.RuntimeException();
+ throw new java.lang.RuntimeException();
}
</xsl:if>
<xsl:if test="@minOccurs">
if (param.length < <xsl:value-of select="@minOccurs"></xsl:value-of>){
- throw new java.lang.RuntimeException();
+ throw new java.lang.RuntimeException();
}
</xsl:if>
</xsl:if>
@@ -219,7 +219,7 @@
</xsl:for-each>
return org.apache.axis2.databinding.utils.ADBPullParser.createPullParser(qName, elementList.toArray(), attribList.toArray());
- <!-- end of when for type & anon -->
+ <!-- end of when for type & anon -->
</xsl:when>
<!-- Not a type and not anon. So it better be only one inclusion-->
<xsl:otherwise>
@@ -259,9 +259,9 @@
try {
int event = reader.getEventType();
- //event better be a START_ELEMENT. if not we should go up to the start element here
- while (!reader.isStartElement()){
- reader.next();
+ //event better be a START_ELEMENT. if not we should go up to the start element here
+ while (event!= javax.xml.stream.XMLStreamReader.START_ELEMENT) {
+ event = reader.next();
}
<xsl:if test="not(@type)">
@@ -270,19 +270,29 @@
}
</xsl:if>
+ <xsl:if test="@nillable">
+ if ("true".equals(reader.getAttributeValue("","nil"))){
+ return null;
+ }
+ </xsl:if>
+
<!-- populate attributes here!!!. The attributes are part of an element, not part of a
- type -->
+ type -->
<xsl:for-each select="property[@attribute]">
<xsl:variable name="propertyName"><xsl:value-of select="@name"/></xsl:variable>
<xsl:variable name="propertyType"><xsl:value-of select="@type"/></xsl:variable>
<xsl:variable name="shortTypeName"><xsl:value-of select="@shorttypename"/></xsl:variable>
<xsl:variable name="javaName"><xsl:value-of select="@javaname"></xsl:value-of></xsl:variable>
<xsl:variable name="namespace"><xsl:value-of select="@nsuri"/></xsl:variable>
+ <xsl:variable name="attribName">tempAttrib<xsl:value-of select="$propertyName"/></xsl:variable>
-
- object.set<xsl:value-of select="$javaName"/>(
+ String <xsl:value-of select="$attribName"/> =
+ reader.getAttributeValue("<xsl:value-of select="$namespace"/>","<xsl:value-of select="$propertyName"/>")
+ if (<xsl:value-of select="$attribName"/>!=null){
+ object.set<xsl:value-of select="$javaName"/>(
org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(
- reader.getAttributeValue("<xsl:value-of select="$namespace"/>","<xsl:value-of select="$propertyName"/>")));
+ <xsl:value-of select="$attribName"/>));
+ }
</xsl:for-each>
@@ -359,12 +369,18 @@
if (javax.xml.stream.XMLStreamConstants.START_ELEMENT == event
&& <xsl:value-of select="$startQname"/>.equals(reader.getName())){
- <!-- todo put the code here for nillable -->
-
+ <!-- if-block that handles nillable -->
+ <xsl:if test="@nillable">
+ if ("true".equals(reader.getAttributeValue("","nil"))){
+ object.set<xsl:value-of select="$javaName"/>(null);
+ }else{
+ </xsl:if>
// We need to wrap the reader so that it produces a fake START_DOCUEMENT event
- org.apache.axis2.databinding.utils.NamedStaxOMBuilder <xsl:value-of select="$builderName"/> = new org.apache.axis2.databinding.utils.NamedStaxOMBuilder(
- new org.apache.axis2.util.StreamWrapper(reader),<xsl:value-of select="$startQname"/>);
+ org.apache.axis2.databinding.utils.NamedStaxOMBuilder <xsl:value-of select="$builderName"/>
+ = new org.apache.axis2.databinding.utils.NamedStaxOMBuilder(
+ new org.apache.axis2.util.StreamWrapper(reader), <xsl:value-of select="$startQname"/>);
+
<xsl:value-of select="$listName"/>.add(<xsl:value-of select="$builderName"/>.getOMElement());
} else if (javax.xml.stream.XMLStreamConstants.START_ELEMENT == event &&
@@ -386,6 +402,8 @@
org.apache.axis2.databinding.utils.ConverterUtil.convertToArray(
<xsl:value-of select="$basePropertyType"/>.class,<xsl:value-of select="$listName"/>));
+ <!-- closing bracket for the if statement above -->
+ <xsl:if test="@nillable">}</xsl:if>
</xsl:when>
<!-- End of Array handling of ADB classes -->
<xsl:otherwise>
@@ -395,6 +413,9 @@
<xsl:value-of select="$stateMachineName"/>.setElementNameToTest(new javax.xml.namespace.QName(
"<xsl:value-of select="$namespace"/>",
"<xsl:value-of select="$propertyName"/>"));
+ <xsl:if test="@nillable">
+ <xsl:value-of select="$stateMachineName"/>.setNillable();
+ </xsl:if>
<xsl:value-of select="$stateMachineName"/>.read(reader);
String[] textArray = <xsl:value-of select="$stateMachineName"/>.getTextArray();
object.set<xsl:value-of select="$javaName"/>(
@@ -407,10 +428,11 @@
</xsl:choose>
</xsl:when>
<!-- end of array handling -->
-
<xsl:when test="@ours">
- object.set<xsl:value-of select="$javaName"/>(<xsl:value-of select="$propertyType"/>.Factory.parse(
- reader));
+ <!--No concerns of being nillable here. if it's ours and if the nillable attribute was present
+ we would have outputted a null already-->
+ object.set<xsl:value-of select="$javaName"/>(<xsl:value-of select="$propertyType"/>.Factory.parse(
+ reader));
</xsl:when>
<!-- end of adb type handling code -->
<!-- start of OMelement handling -->
@@ -447,10 +469,23 @@
"<xsl:value-of select="$namespace"/>",
"<xsl:value-of select="$propertyName"/>");
<xsl:value-of select="$stateMachineName"/>.setElementNameToTest(<xsl:value-of select="$startQname"/>);
+ <xsl:if test="@nillable">
+ <xsl:value-of select="$stateMachineName"/>.setNillable();
+ </xsl:if>
<xsl:value-of select="$stateMachineName"/>.read(reader);
object.set<xsl:value-of select="$javaName"/>(
- org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(
- <xsl:value-of select="$stateMachineName"/>.getText()));
+ <xsl:choose>
+ <xsl:when test="@nillable">
+ <xsl:value-of select="$stateMachineName"/>.getText()==null?null:
+ org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(
+ <xsl:value-of select="$stateMachineName"/>.getText()));
+ </xsl:when>
+ <xsl:otherwise>
+ org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(
+ <xsl:value-of select="$stateMachineName"/>.getText()));
+ </xsl:otherwise>
+ </xsl:choose>
+
</xsl:otherwise>
<!-- end of simple type handling -->
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java?rev=375168&r1=375167&r2=375168&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java Sun Feb 5 20:29:12 2006
@@ -356,6 +356,10 @@
XSLTUtils.addAttribute(model, "ordered", "yes", rootElt);
}
+ if (isElement && metainf.isNillable(qName)) {
+ XSLTUtils.addAttribute(model, "nillable", "yes", rootElt);
+ }
+
//populate all the information
populateInfo(metainf, model, rootElt, propertyNames, typeMap,false);