ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r391592 - in /webservices/axis2/trunk/java/modules: adb/src/org/apache/axis2/databinding/utils/ adb/src/org/apache/axis2/databinding/utils/reader/ adb/test/org/apache/axis2/databinding/utils/ codegen/src/org/apache/axis2/wsdl/codegen/
Date Wed, 05 Apr 2006 11:50:46 GMT
Author: ajith
Date: Wed Apr  5 04:50:45 2006
New Revision: 391592

URL: http://svn.apache.org/viewcvs?rev=391592&view=rev
Log:
1. Made improvements to the statemachines (re-wrote the code for updating the status in a
more readable manner)
2. Added a new test case to the SimpleArrayReaderStateMachineTest.java
3. Removed some unwanted code from the WrappingXMLStreamReader

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/reader/WrappingXMLStreamReader.java
    webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachineTest.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java

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=391592&r1=391591&r2=391592&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
Wed Apr  5 04:50:45 2006
@@ -105,72 +105,93 @@
     private void updateState(XMLStreamReader reader) throws XMLStreamException{
         int event = reader.getEventType();
 
-        //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;
-
-            //end element found after characters
-        } else if (event==XMLStreamConstants.END_ELEMENT && currentState==TEXT_FOUND_STATE){
-            if (elementNameToTest.equals(reader.getName())){
+        switch (currentState){
+
+            case INIT_STATE:
+                if (event== XMLStreamConstants.START_DOCUMENT){
+                    currentState = STARTED_STATE;
+                }else if (event== XMLStreamConstants.START_ELEMENT){
+                    if (elementNameToTest.equals(reader.getName())){
+                        currentState = START_ELEMENT_FOUND_STATE;
+                    }else{
+                        currentState = STARTED_STATE;
+                    }
+                }
+                break;
+
+            case STARTED_STATE:
+                if (event==XMLStreamConstants.END_ELEMENT){
+                    if (elementNameToTest.equals(reader.getName())){
+                        currentState = ILLEGAL_STATE;
+                    }else{
+                        currentState = FINISHED_STATE;
+                    }
+                }else if  (event==XMLStreamConstants.START_ELEMENT){
+                    QName name = reader.getName();
+                    if (elementNameToTest.equals(name)){
+                        currentState = START_ELEMENT_FOUND_STATE;
+                    }
+                }
+                break;
+
+            case START_ELEMENT_FOUND_STATE:
+                if (event==XMLStreamConstants.CHARACTERS){
+                    currentState  = TEXT_FOUND_STATE;
+                }
+                break;
+
+            case TEXT_FOUND_STATE:
+                if (event==XMLStreamConstants.END_ELEMENT){
+                    if (elementNameToTest.equals(reader.getName())){
+                        currentState = END_ELEMENT_FOUND_STATE;
+                    }else{
+                        currentState = ILLEGAL_STATE;
+                    }
+                }else if (event==XMLStreamConstants.CHARACTERS){
+                    //another char event -
+                    //so append it to the current text
+                }
+                break;
+            case NULLED_STATE:
+                //read upto the end and set the state to END_ELEMENT_FOUND_STATE
+                while (event!= XMLStreamConstants.END_ELEMENT){
+                    event=reader.next();
+                }
                 currentState = END_ELEMENT_FOUND_STATE;
-            }else{
-                currentState = ILLEGAL_STATE;
-            }
-
-            //characters found - if this is a characters event that was in the correct place
then
-            //it would have been handled already. we need to check whether this is a ignorable
-            //whitespace and if not push the state machine to a illegal state.
-        }else if (event==XMLStreamConstants.CHARACTERS){
-            if (reader.getText().trim().length()==0){
-                //the text is empty - don't change the state
-            }else{
-                //we do NOT handle mixed content
-                currentState = ILLEGAL_STATE;
-            }
-
-            //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;
+                break;
+            case END_ELEMENT_FOUND_STATE:
+                if (event==XMLStreamConstants.START_ELEMENT ) {
+                    //restart the parsing
+                    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 = FINISHED_STATE;
+                    //end  document found
+                }
+                break;
+            default:
+
+                //characters found - if this is a characters event that was in the correct
place then
+                //it would have been handled already. we need to check whether this is a
ignorable
+                //whitespace and if not push the state machine to a illegal state.
+                if (event==XMLStreamConstants.CHARACTERS){
+                    if (reader.getText().trim().length()==0){
+                        //the text is empty - don't change the state
+                    }else{
+                        //we do NOT handle mixed content
+                        currentState = ILLEGAL_STATE;
+                    }
+
+                } 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=391592&r1=391591&r2=391592&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
Wed Apr  5 04:50:45 2006
@@ -55,7 +55,7 @@
      */
     public void setElementNameToTest(QName elementNameToTest) {
         this.elementNameToTest = elementNameToTest;
-        
+
     }
 
     /**
@@ -114,77 +114,158 @@
     private void updateState(XMLStreamReader reader) throws XMLStreamException{
         int event = reader.getEventType();
 
-        //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 start element
-        }else if (event==XMLStreamConstants.CHARACTERS && currentState==START_ELEMENT_FOUND_STATE){
-            currentState  = TEXT_FOUND_STATE;
-
-            //characters found - if this is a characters event that was in the correct place
then
-            //it would have been handled already. we need to check whether this is a ignorable
-            //whitespace and if not push the state machine to a illegal state.
-        }else if (event==XMLStreamConstants.CHARACTERS){
-            if (reader.getText().trim().length()==0){
-                //the text is empty - don't change the state
-            }else{
-                //we do NOT handle mixed content
-                currentState = ILLEGAL_STATE;
-                errorMessage = "Mixed Content " +reader.getText();  //todo I18n this
-            }
 
-            //End element  found after starting This means we've found an empty element like
<foo/>
-        }else if (event==XMLStreamConstants.END_ELEMENT && currentState==START_ELEMENT_FOUND_STATE){
-            //force the text to be empty!
-            text = "";
+        switch(currentState){
+            case INIT_STATE:
+                if (event==XMLStreamConstants.START_DOCUMENT){
+                    currentState = STARTED_STATE;
+                    //start element found at init
+                }else  if (event==XMLStreamConstants.START_ELEMENT){
+                    if (elementNameToTest.equals(reader.getName())){
+                        currentState = START_ELEMENT_FOUND_STATE;
+                    }else{
+                        currentState = STARTED_STATE;
+                    }
+                }
+                break;
 
-            if (elementNameToTest.equals(reader.getName())){
-                currentState = END_ELEMENT_FOUND_STATE;
-            }else{
-                currentState = ILLEGAL_STATE;
-                errorMessage = "Wrong element name " +reader.getName();  //todo I18n this
-            }
+            case  STARTED_STATE:
+                if (event==XMLStreamConstants.START_ELEMENT ) {
+                    if (elementNameToTest.equals(reader.getName())){
+                        currentState = START_ELEMENT_FOUND_STATE;
+                    }
+                }
+                break;
 
-            // 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;
-            }else{
-                currentState = ILLEGAL_STATE;
-                //set the error message
-                errorMessage = "Wrong element name " +reader.getName();  //todo I18n this
-            }
+            case  START_ELEMENT_FOUND_STATE:
+                if (event==XMLStreamConstants.CHARACTERS){
+                    currentState  = TEXT_FOUND_STATE;
+                }else if (event==XMLStreamConstants.END_ELEMENT){
+                    //force the text to be empty!
+                    text = "";
+                    if (elementNameToTest.equals(reader.getName())){
+                        currentState = END_ELEMENT_FOUND_STATE;
+                    }else{
+                        currentState = ILLEGAL_STATE;
+                        errorMessage = "Wrong element name " +reader.getName();  //todo I18n
this
+                    }
+                }
+                break;
 
-            //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
+            case  TEXT_FOUND_STATE:
+                if (event==XMLStreamConstants.END_ELEMENT){
+                    if (elementNameToTest.equals(reader.getName())){
+                        currentState = END_ELEMENT_FOUND_STATE;
+                    }else{
+                        currentState = ILLEGAL_STATE;
+                        //set the error message
+                        errorMessage = "Wrong element name " +reader.getName();  //todo I18n
this
+                    }
+                }else if (event==XMLStreamConstants.CHARACTERS){
+                    text = text +  reader.getText();  //append the text
+                    //do not change the state
+                }
+                break;
 
-        }else{
-            currentState = ILLEGAL_STATE;
-            errorMessage = "Current state is " + currentState ;  //todo I18n this
+            case END_ELEMENT_FOUND_STATE:
+                 currentState = FINISHED_STATE;
+                break;
+
+                //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
+            case NULLED_STATE:
+                while (event!= XMLStreamConstants.END_ELEMENT){
+                    event=reader.next();
+                }
+                currentState = END_ELEMENT_FOUND_STATE;
+                break;
+
+            default:
+                if (event==XMLStreamConstants.CHARACTERS){
+                    if (reader.getText().trim().length()==0){
+                        //the text is empty - don't change the state
+                    }else{
+                        //we do NOT handle mixed content
+                        currentState = ILLEGAL_STATE;
+                        errorMessage = "Mixed Content " +reader.getText();  //todo I18n this
+                    }
+                }else{
+                    currentState = ILLEGAL_STATE;
+                    errorMessage = "Current state is " + currentState ;  //todo I18n this
+                }
+                break;
         }
+
+//        //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 start element
+//        }else if (event==XMLStreamConstants.CHARACTERS && currentState==START_ELEMENT_FOUND_STATE){
+//            currentState  = TEXT_FOUND_STATE;
+//
+//            //characters found - if this is a characters event that was in the correct
place then
+//            //it would have been handled already. we need to check whether this is a ignorable
+//            //whitespace and if not push the state machine to a illegal state.
+//        }else if (event==XMLStreamConstants.CHARACTERS){
+//            if (reader.getText().trim().length()==0){
+//                //the text is empty - don't change the state
+//            }else{
+//                //we do NOT handle mixed content
+//                currentState = ILLEGAL_STATE;
+//                errorMessage = "Mixed Content " +reader.getText();  //todo I18n this
+//            }
+//
+//            //End element  found after starting This means we've found an empty element
like <foo/>
+//        }else if (event==XMLStreamConstants.END_ELEMENT && currentState==START_ELEMENT_FOUND_STATE){
+//            //force the text to be empty!
+//            text = "";
+//
+//            if (elementNameToTest.equals(reader.getName())){
+//                currentState = END_ELEMENT_FOUND_STATE;
+//            }else{
+//                currentState = ILLEGAL_STATE;
+//                errorMessage = "Wrong element name " +reader.getName();  //todo I18n this
+//            }
+//
+//            // 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;
+//            }else{
+//                currentState = ILLEGAL_STATE;
+//                //set the error message
+//                errorMessage = "Wrong element name " +reader.getName();  //todo I18n this
+//            }
+//
+//            //end has been reached
+//        }else if (currentState==END_ELEMENT_FOUND_STATE) {
+//            currentState = FINISHED_STATE;
+//
+//        }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;
+//            errorMessage = "Current state is " + currentState ;  //todo I18n this
+//        }
     }
 
 

Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/WrappingXMLStreamReader.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/WrappingXMLStreamReader.java?rev=391592&r1=391591&r2=391592&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/WrappingXMLStreamReader.java
(original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/WrappingXMLStreamReader.java
Wed Apr  5 04:50:45 2006
@@ -24,30 +24,12 @@
 public class WrappingXMLStreamReader implements ADBXMLStreamReader{
 
     private XMLStreamReader reader;
-    private int depth = 0;
-    private boolean initState = true;
 
     public WrappingXMLStreamReader(XMLStreamReader reader) {
         this.reader = reader;
     }
 
     public boolean isDone() {
-        /////////////////////////////////
-//        try {
-//            System.out.println("1 -----------" + this.reader.hasNext());
-//            System.out.println("2  -----------" +(depth==0 && !initState));
-//        } catch (XMLStreamException e) {
-//            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-//        }
-//        ////////////////////////////////
-//        try {
-//            boolean b = hasNext();
-//            System.out.println("######" + b + "#####");
-//            System.out.println("----------" + (depth==0 && !initState &&
!b) + " -------");
-//            return (depth==0 && !initState && !b);
-//        } catch (XMLStreamException e) {
-//            throw new RuntimeException(e);
-//        }
         try {
             return !hasNext();
         } catch (XMLStreamException e) {
@@ -60,14 +42,7 @@
     }
 
     public int next() throws XMLStreamException {
-        int event = reader.next();
-        initState = false;
-        if (event==START_ELEMENT || event==START_DOCUMENT){
-            depth++;
-        }else if (event==END_ELEMENT || event==END_DOCUMENT){
-            depth = depth!=0?depth--:depth;
-        }
-        return event;
+         return reader.next();
     }
 
     public void require(int i, String string, String string1) throws XMLStreamException {

Modified: webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachineTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachineTest.java?rev=391592&r1=391591&r2=391592&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachineTest.java
(original)
+++ webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachineTest.java
Wed Apr  5 04:50:45 2006
@@ -84,20 +84,21 @@
         assertEquals("200",sm.getTextArray()[0]);
     }
 
-//     public void testStateMachine3() throws Exception{
-//        String xmlDoc="<myIntVal>200<a/></myIntVal>";
-//        XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(
-//                new StringReader(xmlDoc));
-//        SimpleElementReaderStateMachine  sm = new SimpleElementReaderStateMachine();
-//        sm.setElementNameToTest(new QName("myIntVal"));
-//        try {
-//            sm.read(reader);
-//            fail();
-//        } catch (Exception e) {
-//
-//        }
-//
-//
-//    }
+     public void testStateMachineEmptyArray() throws Exception{
+        String xmlDoc="<wrapper></wrapper>";
+        XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(
+                new StringReader(xmlDoc));
+        SimpleArrayReaderStateMachine  sm = new SimpleArrayReaderStateMachine();
+        sm.setElementNameToTest(new QName("myIntVal"));
+        try {
+            sm.read(reader);
+        } catch (Exception e) {
+
+        }
+
+        assertEquals(0,sm.getTextArray().length);
+
+
+    }
 
 }

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java?rev=391592&r1=391591&r2=391592&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java
Wed Apr  5 04:50:45 2006
@@ -77,6 +77,8 @@
         }
 
         configuration = new CodeGenConfiguration(wom, allOptions);
+
+        /////////////////////////////////////////////////////////////////
         try {
             configuration.setAxisService(new WSDL2AxisServiceBuilder(new FileInputStream(wsdlUri)).populateService());
         } catch (AxisFault axisFault) {
@@ -84,6 +86,8 @@
         } catch (FileNotFoundException e) {
             e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
         }
+        ///////////////////////////////////////////////////////////////////////
+        
         configuration.setBaseURI(getBaseURI(wsdlUri));
         loadExtensions();
     }



Mime
View raw message