You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Hickman, Craig" <Cr...@ADP.com> on 2007/05/02 01:49:42 UTC

Question on getFirstChildWithName(qName) within an iterator?

Working for a company that wants to hide much of the complexity of the Axis2
api.

I've been building some helper methods to allow the ability to use a set of
beans to manipulate and bind the xml to the POJO's without the need for
using the code generation tools, which is something the developers at this
company wish to refrain from using if possible.

So here is my problem:

I get the root element and then

        //GET THE FIRST ELEMENT
        OMElement root = utils.getOMRootElement(envelope);
        // SET THE PARTNER SERVICE OBJECTS
        QName serviceQN = new QName(WSConstants.SERVICE_ELEMENT);
        Iterator serviceIter =  root.getChildrenWithName(serviceQN);
        getService(serviceIter);

  //-- private method --//
   private void getService(Iterator serv) {
		Map aMap = new HashMap();
		
		//-- pass in iterator and constants for simple xml element
parsing --//
		try {
			aMap = utils.getSimpleOMSubElement(serv,
this.getServiceConstants()); // the utility method as seen below
			int mapsize = aMap.size();

			Iterator keyValuePairs1 =
aMap.entrySet().iterator();
			for (int i = 0; i < mapsize; i++)
			{
			  Map.Entry entry = (Map.Entry)
keyValuePairs1.next();
			  Object key = entry.getKey();
			  Object value = entry.getValue();
			  logger.debug("<<<<<<<<< map values >>>>>>>> "
+value.toString());
			  getServiceElementsSwitch(key, value);
			}
		} catch (SOAPException e) {
			logger.debug("getService SOAPException"
+e.getMessage());
			e.printStackTrace();
		} catch (XMLStreamException e) {
			logger.debug("getService XMLStreamException"
+e.getMessage());
			e.printStackTrace();
		}
	}

I pass in a list of the binded elements as strings in a list so that I can
iterate through them and then use the getChildWithNames iterator.
My only problem is that I can only get the first element text value even
though I loop through the list and pass I a new qName each time.
I have even tried another helper to get the text value taking in the
iterator and and the string value for the qName, but this still brings back
only one of the text values.

Am I missing something? I've logged it to make sure I'm iterating with the
correct elements for the binding, and have run test to make sure the payload
of text value is correct.
    
    
       /**
         * Walk the xml tree of elements
         * get the simple element and put
         * in map object for return.
         *
         * @param serv
         * @throws XMLStreamException
         * @throws SOAPException
         * @return Map map
         */
        public Map getSimpleOMSubElement(Iterator iter, List wsConstants)
throws SOAPException, XMLStreamException {
                int j = 1;
                String qName = "";
                String text = "";
       
                        for (j = 0; j < wsConstants.size(); j++) {
                                qName = (String)wsConstants.get(j);
                                logger.debug("qName = " +qName);
                                while (iter.hasNext()) {
                                    Object o = iter.next();
                                   
                                    if  (o instanceof OMElement) {
                                            OMElement c = (OMElement) o;
                                            OMElement element =
getOMElement(c, qName); // helpe method - takes element and constant string
                                            text = element.getText();
                                    }
                               
                                        j++;
                                logger.debug("text = " + j + "" +text);
                                map.put(j, text);
                        }
                }
                return map;    
        }

        /**
          * Helper method to get the text elements in a type safe fashion
          *
         * @param element
         * @param name
         * @return
         */
       public  OMElement getOMElement(OMElement result, String element)
            throws SOAPException, XMLStreamException {

            QName qName = new QName(element);
            if (qName == null) {
              throw new RuntimeException("Missing required method
element.");
            }

            Iterator i = result.getChildrenWithName(qName);
            if (! i.hasNext()) {
              throw new RuntimeException("Missing required  element.");
            }

            OMElement omElement = (OMElement) i.next();

            return omElement;
          }

As you see in the logs I can only get the first text value of the seven
entries, and the others do have text in them just unable to get it with the
helper:

2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = partner-num
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.110 - text = 100250
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = auth-code
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = client-user
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = client-id2
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = browser-form-post
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = operation
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = client-id3
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG sso.SSOSkeleton
getService.142 - <<<<<<<<< map values >>>>>>>> 100250

I built it originally using the straight ahead manner of waliking the
elements, so why does it work below but above I cannot use the same idea
with a helper method using iteration?

while (service.hasNext()) {
                        Object o = service.next();
                        OMElement s = (OMElement) o;
                      
                        //----  test all data ----//
                        logger.debug("<<<<<  START OF SERVICE DATA >>>>> ");
                      
                        //--- use helper class for test ---//
                        //-- Test partner-num -- //
                                OMElement partnerData =
s.getFirstChildWithName(new QName(WSConstants.PARTNER_NUM));
                                logger.debug("<<<< Partner Data >>> "
+partnerData.getText());
                                assertEquals("wKsd898!iu",
partnerData.getText());
                              
                                // -- client-id --//
                                OMElement clientId =
s.getFirstChildWithName(new QName(WSConstants.CLIENT_ID));
                                logger.debug("<<<< client-id >>> "
+clientId.getText());
                                assertEquals("146", clientId.getText());
                              
                                // -- auth-code --//
                                OMElement authCode =
s.getFirstChildWithName(new QName(WSConstants.AUTH_CODE));
                                logger.debug("<<<< auth-code >>> "
+authCode.getText());
                                assertEquals("Ad897!df",
authCode.getText());
                              
                                 // -- client-user --//
                                OMElement clientUser =
s.getFirstChildWithName(new QName(WSConstants.CLIENT_USER));
                                logger.debug("<<<< client-user >>> "
+clientUser.getText());
                                assertEquals("1", clientUser.getText());
                              
                                 // -- client-id2 --//
                                OMElement clientId2 =
s.getFirstChildWithName(new QName(WSConstants.CLIENT_ID_2));
                                logger.debug("<<<< client-id2 >>> "
+clientId2.getText());
                                assertEquals("2", clientId2.getText());
                              
                                 // -- browser-form-post --//
                                OMElement browserFormPost =
s.getFirstChildWithName(new QName(WSConstants.BROWSER_FORM_POST));
                                logger.debug("<<<< browser-form-post >>> "
+browserFormPost.getText());
                                assertEquals("text data ",
browserFormPost.getText());
                              
                                 // -- operation  --//
                                OMElement operation =
s.getFirstChildWithName(new QName(WSConstants.OPERATION));
                                logger.debug("<<<< operation >>> "
+operation.getText());
                                assertEquals("create", operation.getText());
                              
                                 // -- client-id3 --//
                                OMElement clientId3 =
s.getFirstChildWithName(new QName(WSConstants.CLIENT_ID_3));
                                logger.debug("<<<< client-id3 >>> "
+clientId3.getText());
                                assertEquals("12345", clientId3.getText());
                              
                                logger.debug("<<<<<  END OF SERVICE DATA
>>>>> ");






---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Question on getFirstChildWithName(qName) within an iterator?

Posted by Paul Fremantle <pz...@gmail.com>.
Craig

There are some options that might be interesting:

* JIBX allows you to bind to existing POJOs by specifying a simple binding file
* ADB has a "helper" mode where it will generate POJOs and leave the
XML gorp in other files.
* JAXB generates pretty clean nice POJOs.

Paul

On 5/2/07, Hickman, Craig <Cr...@adp.com> wrote:
>
> Working for a company that wants to hide much of the complexity of the Axis2
> api.
>
> I've been building some helper methods to allow the ability to use a set of
> beans to manipulate and bind the xml to the POJO's without the need for
> using the code generation tools, which is something the developers at this
> company wish to refrain from using if possible.
>
> So here is my problem:
>
> I get the root element and then
>
>         //GET THE FIRST ELEMENT
>         OMElement root = utils.getOMRootElement(envelope);
>         // SET THE PARTNER SERVICE OBJECTS
>         QName serviceQN = new QName(WSConstants.SERVICE_ELEMENT);
>         Iterator serviceIter =  root.getChildrenWithName(serviceQN);
>         getService(serviceIter);
>
>   //-- private method --//
>    private void getService(Iterator serv) {
>                 Map aMap = new HashMap();
>
>                 //-- pass in iterator and constants for simple xml element
> parsing --//
>                 try {
>                         aMap = utils.getSimpleOMSubElement(serv,
> this.getServiceConstants()); // the utility method as seen below
>                         int mapsize = aMap.size();
>
>                         Iterator keyValuePairs1 =
> aMap.entrySet().iterator();
>                         for (int i = 0; i < mapsize; i++)
>                         {
>                           Map.Entry entry = (Map.Entry)
> keyValuePairs1.next();
>                           Object key = entry.getKey();
>                           Object value = entry.getValue();
>                           logger.debug("<<<<<<<<< map values >>>>>>>> "
> +value.toString());
>                           getServiceElementsSwitch(key, value);
>                         }
>                 } catch (SOAPException e) {
>                         logger.debug("getService SOAPException"
> +e.getMessage());
>                         e.printStackTrace();
>                 } catch (XMLStreamException e) {
>                         logger.debug("getService XMLStreamException"
> +e.getMessage());
>                         e.printStackTrace();
>                 }
>         }
>
> I pass in a list of the binded elements as strings in a list so that I can
> iterate through them and then use the getChildWithNames iterator.
> My only problem is that I can only get the first element text value even
> though I loop through the list and pass I a new qName each time.
> I have even tried another helper to get the text value taking in the
> iterator and and the string value for the qName, but this still brings back
> only one of the text values.
>
> Am I missing something? I've logged it to make sure I'm iterating with the
> correct elements for the binding, and have run test to make sure the payload
> of text value is correct.
>
>
>        /**
>          * Walk the xml tree of elements
>          * get the simple element and put
>          * in map object for return.
>          *
>          * @param serv
>          * @throws XMLStreamException
>          * @throws SOAPException
>          * @return Map map
>          */
>         public Map getSimpleOMSubElement(Iterator iter, List wsConstants)
> throws SOAPException, XMLStreamException {
>                 int j = 1;
>                 String qName = "";
>                 String text = "";
>
>                         for (j = 0; j < wsConstants.size(); j++) {
>                                 qName = (String)wsConstants.get(j);
>                                 logger.debug("qName = " +qName);
>                                 while (iter.hasNext()) {
>                                     Object o = iter.next();
>
>                                     if  (o instanceof OMElement) {
>                                             OMElement c = (OMElement) o;
>                                             OMElement element =
> getOMElement(c, qName); // helpe method - takes element and constant string
>                                             text = element.getText();
>                                     }
>
>                                         j++;
>                                 logger.debug("text = " + j + "" +text);
>                                 map.put(j, text);
>                         }
>                 }
>                 return map;
>         }
>
>         /**
>           * Helper method to get the text elements in a type safe fashion
>           *
>          * @param element
>          * @param name
>          * @return
>          */
>        public  OMElement getOMElement(OMElement result, String element)
>             throws SOAPException, XMLStreamException {
>
>             QName qName = new QName(element);
>             if (qName == null) {
>               throw new RuntimeException("Missing required method
> element.");
>             }
>
>             Iterator i = result.getChildrenWithName(qName);
>             if (! i.hasNext()) {
>               throw new RuntimeException("Missing required  element.");
>             }
>
>             OMElement omElement = (OMElement) i.next();
>
>             return omElement;
>           }
>
> As you see in the logs I can only get the first text value of the seven
> entries, and the others do have text in them just unable to get it with the
> helper:
>
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = partner-num
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.110 - text = 100250
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = auth-code
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = client-user
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = client-id2
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = browser-form-post
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = operation
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = client-id3
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG sso.SSOSkeleton
> getService.142 - <<<<<<<<< map values >>>>>>>> 100250
>
> I built it originally using the straight ahead manner of waliking the
> elements, so why does it work below but above I cannot use the same idea
> with a helper method using iteration?
>
> while (service.hasNext()) {
>                         Object o = service.next();
>                         OMElement s = (OMElement) o;
>
>                         //----  test all data ----//
>                         logger.debug("<<<<<  START OF SERVICE DATA >>>>> ");
>
>                         //--- use helper class for test ---//
>                         //-- Test partner-num -- //
>                                 OMElement partnerData =
> s.getFirstChildWithName(new QName(WSConstants.PARTNER_NUM));
>                                 logger.debug("<<<< Partner Data >>> "
> +partnerData.getText());
>                                 assertEquals("wKsd898!iu",
> partnerData.getText());
>
>                                 // -- client-id --//
>                                 OMElement clientId =
> s.getFirstChildWithName(new QName(WSConstants.CLIENT_ID));
>                                 logger.debug("<<<< client-id >>> "
> +clientId.getText());
>                                 assertEquals("146", clientId.getText());
>
>                                 // -- auth-code --//
>                                 OMElement authCode =
> s.getFirstChildWithName(new QName(WSConstants.AUTH_CODE));
>                                 logger.debug("<<<< auth-code >>> "
> +authCode.getText());
>                                 assertEquals("Ad897!df",
> authCode.getText());
>
>                                  // -- client-user --//
>                                 OMElement clientUser =
> s.getFirstChildWithName(new QName(WSConstants.CLIENT_USER));
>                                 logger.debug("<<<< client-user >>> "
> +clientUser.getText());
>                                 assertEquals("1", clientUser.getText());
>
>                                  // -- client-id2 --//
>                                 OMElement clientId2 =
> s.getFirstChildWithName(new QName(WSConstants.CLIENT_ID_2));
>                                 logger.debug("<<<< client-id2 >>> "
> +clientId2.getText());
>                                 assertEquals("2", clientId2.getText());
>
>                                  // -- browser-form-post --//
>                                 OMElement browserFormPost =
> s.getFirstChildWithName(new QName(WSConstants.BROWSER_FORM_POST));
>                                 logger.debug("<<<< browser-form-post >>> "
> +browserFormPost.getText());
>                                 assertEquals("text data ",
> browserFormPost.getText());
>
>                                  // -- operation  --//
>                                 OMElement operation =
> s.getFirstChildWithName(new QName(WSConstants.OPERATION));
>                                 logger.debug("<<<< operation >>> "
> +operation.getText());
>                                 assertEquals("create", operation.getText());
>
>                                  // -- client-id3 --//
>                                 OMElement clientId3 =
> s.getFirstChildWithName(new QName(WSConstants.CLIENT_ID_3));
>                                 logger.debug("<<<< client-id3 >>> "
> +clientId3.getText());
>                                 assertEquals("12345", clientId3.getText());
>
>                                 logger.debug("<<<<<  END OF SERVICE DATA
> >>>>> ");
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair

http://bloglines.com/blog/paulfremantle
paul@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Question on getFirstChildWithName(qName) within an iterator?

Posted by Martin Gainty <mg...@hotmail.com>.
Craig-

you may have a constraint on your WSDL for maxOccurs ="1" for the element 
you are anticipating
will be a list
Please post the wsdl to verify

Martin--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- 
From: "Hickman, Craig" <Cr...@ADP.com>
To: <ax...@ws.apache.org>
Sent: Tuesday, May 01, 2007 7:49 PM
Subject: Question on getFirstChildWithName(qName) within an iterator?


>
> Working for a company that wants to hide much of the complexity of the 
> Axis2
> api.
>
> I've been building some helper methods to allow the ability to use a set 
> of
> beans to manipulate and bind the xml to the POJO's without the need for
> using the code generation tools, which is something the developers at this
> company wish to refrain from using if possible.
>
> So here is my problem:
>
> I get the root element and then
>
>        //GET THE FIRST ELEMENT
>        OMElement root = utils.getOMRootElement(envelope);
>        // SET THE PARTNER SERVICE OBJECTS
>        QName serviceQN = new QName(WSConstants.SERVICE_ELEMENT);
>        Iterator serviceIter =  root.getChildrenWithName(serviceQN);
>        getService(serviceIter);
>
>  //-- private method --//
>   private void getService(Iterator serv) {
> Map aMap = new HashMap();
>
> //-- pass in iterator and constants for simple xml element
> parsing --//
> try {
> aMap = utils.getSimpleOMSubElement(serv,
> this.getServiceConstants()); // the utility method as seen below
> int mapsize = aMap.size();
>
> Iterator keyValuePairs1 =
> aMap.entrySet().iterator();
> for (int i = 0; i < mapsize; i++)
> {
>   Map.Entry entry = (Map.Entry)
> keyValuePairs1.next();
>   Object key = entry.getKey();
>   Object value = entry.getValue();
>   logger.debug("<<<<<<<<< map values >>>>>>>> "
> +value.toString());
>   getServiceElementsSwitch(key, value);
> }
> } catch (SOAPException e) {
> logger.debug("getService SOAPException"
> +e.getMessage());
> e.printStackTrace();
> } catch (XMLStreamException e) {
> logger.debug("getService XMLStreamException"
> +e.getMessage());
> e.printStackTrace();
> }
> }
>
> I pass in a list of the binded elements as strings in a list so that I can
> iterate through them and then use the getChildWithNames iterator.
> My only problem is that I can only get the first element text value even
> though I loop through the list and pass I a new qName each time.
> I have even tried another helper to get the text value taking in the
> iterator and and the string value for the qName, but this still brings 
> back
> only one of the text values.
>
> Am I missing something? I've logged it to make sure I'm iterating with the
> correct elements for the binding, and have run test to make sure the 
> payload
> of text value is correct.
>
>
>       /**
>         * Walk the xml tree of elements
>         * get the simple element and put
>         * in map object for return.
>         *
>         * @param serv
>         * @throws XMLStreamException
>         * @throws SOAPException
>         * @return Map map
>         */
>        public Map getSimpleOMSubElement(Iterator iter, List wsConstants)
> throws SOAPException, XMLStreamException {
>                int j = 1;
>                String qName = "";
>                String text = "";
>
>                        for (j = 0; j < wsConstants.size(); j++) {
>                                qName = (String)wsConstants.get(j);
>                                logger.debug("qName = " +qName);
>                                while (iter.hasNext()) {
>                                    Object o = iter.next();
>
>                                    if  (o instanceof OMElement) {
>                                            OMElement c = (OMElement) o;
>                                            OMElement element =
> getOMElement(c, qName); // helpe method - takes element and constant 
> string
>                                            text = element.getText();
>                                    }
>
>                                        j++;
>                                logger.debug("text = " + j + "" +text);
>                                map.put(j, text);
>                        }
>                }
>                return map;
>        }
>
>        /**
>          * Helper method to get the text elements in a type safe fashion
>          *
>         * @param element
>         * @param name
>         * @return
>         */
>       public  OMElement getOMElement(OMElement result, String element)
>            throws SOAPException, XMLStreamException {
>
>            QName qName = new QName(element);
>            if (qName == null) {
>              throw new RuntimeException("Missing required method
> element.");
>            }
>
>            Iterator i = result.getChildrenWithName(qName);
>            if (! i.hasNext()) {
>              throw new RuntimeException("Missing required  element.");
>            }
>
>            OMElement omElement = (OMElement) i.next();
>
>            return omElement;
>          }
>
> As you see in the logs I can only get the first text value of the seven
> entries, and the others do have text in them just unable to get it with 
> the
> helper:
>
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = partner-num
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.110 - text = 100250
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = auth-code
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = client-user
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = client-id2
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = browser-form-post
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = operation
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
> getSimpleOMSubElement.99 - qName = client-id3
> 2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG sso.SSOSkeleton
> getService.142 - <<<<<<<<< map values >>>>>>>> 100250
>
> I built it originally using the straight ahead manner of waliking the
> elements, so why does it work below but above I cannot use the same idea
> with a helper method using iteration?
>
> while (service.hasNext()) {
>                        Object o = service.next();
>                        OMElement s = (OMElement) o;
>
>                        //----  test all data ----//
>                        logger.debug("<<<<<  START OF SERVICE DATA >>>>> 
> ");
>
>                        //--- use helper class for test ---//
>                        //-- Test partner-num -- //
>                                OMElement partnerData =
> s.getFirstChildWithName(new QName(WSConstants.PARTNER_NUM));
>                                logger.debug("<<<< Partner Data >>> "
> +partnerData.getText());
>                                assertEquals("wKsd898!iu",
> partnerData.getText());
>
>                                // -- client-id --//
>                                OMElement clientId =
> s.getFirstChildWithName(new QName(WSConstants.CLIENT_ID));
>                                logger.debug("<<<< client-id >>> "
> +clientId.getText());
>                                assertEquals("146", clientId.getText());
>
>                                // -- auth-code --//
>                                OMElement authCode =
> s.getFirstChildWithName(new QName(WSConstants.AUTH_CODE));
>                                logger.debug("<<<< auth-code >>> "
> +authCode.getText());
>                                assertEquals("Ad897!df",
> authCode.getText());
>
>                                 // -- client-user --//
>                                OMElement clientUser =
> s.getFirstChildWithName(new QName(WSConstants.CLIENT_USER));
>                                logger.debug("<<<< client-user >>> "
> +clientUser.getText());
>                                assertEquals("1", clientUser.getText());
>
>                                 // -- client-id2 --//
>                                OMElement clientId2 =
> s.getFirstChildWithName(new QName(WSConstants.CLIENT_ID_2));
>                                logger.debug("<<<< client-id2 >>> "
> +clientId2.getText());
>                                assertEquals("2", clientId2.getText());
>
>                                 // -- browser-form-post --//
>                                OMElement browserFormPost =
> s.getFirstChildWithName(new QName(WSConstants.BROWSER_FORM_POST));
>                                logger.debug("<<<< browser-form-post >>> "
> +browserFormPost.getText());
>                                assertEquals("text data ",
> browserFormPost.getText());
>
>                                 // -- operation  --//
>                                OMElement operation =
> s.getFirstChildWithName(new QName(WSConstants.OPERATION));
>                                logger.debug("<<<< operation >>> "
> +operation.getText());
>                                assertEquals("create", 
> operation.getText());
>
>                                 // -- client-id3 --//
>                                OMElement clientId3 =
> s.getFirstChildWithName(new QName(WSConstants.CLIENT_ID_3));
>                                logger.debug("<<<< client-id3 >>> "
> +clientId3.getText());
>                                assertEquals("12345", clientId3.getText());
>
>                                logger.debug("<<<<<  END OF SERVICE DATA
>>>>>> ");
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: Question on getFirstChildWithName(qName) within an iterator?

Posted by "Sampige, Srinivas" <SS...@DIRECTV.com>.
Craig,

I have just completed a similar task of hiding AXIS2 complexities for
other developers. The only difference being, I am not hand coding the
webservice part as you are doing. I have written wrapper classes around
the generated code, written ant scripts to neatly take care of code
generation and build. 

Of course I haven' answered you question but my 2 cents..it is possible
to utilize the AXIS2 code generation and still hide the AXIS2 API
complexities by building a wrapper. The other developers would just be
dealing with your API and POJOS.

Thanks
Srinivas

-----Original Message-----
From: Hickman, Craig [mailto:Craig_Hickman@ADP.com] 
Sent: Tuesday, May 01, 2007 4:50 PM
To: 'axis-user@ws.apache.org'
Subject: Question on getFirstChildWithName(qName) within an iterator?


Working for a company that wants to hide much of the complexity of the
Axis2
api.

I've been building some helper methods to allow the ability to use a set
of
beans to manipulate and bind the xml to the POJO's without the need for
using the code generation tools, which is something the developers at
this
company wish to refrain from using if possible.

So here is my problem:

I get the root element and then

        //GET THE FIRST ELEMENT
        OMElement root = utils.getOMRootElement(envelope);
        // SET THE PARTNER SERVICE OBJECTS
        QName serviceQN = new QName(WSConstants.SERVICE_ELEMENT);
        Iterator serviceIter =  root.getChildrenWithName(serviceQN);
        getService(serviceIter);

  //-- private method --//
   private void getService(Iterator serv) {
		Map aMap = new HashMap();
		
		//-- pass in iterator and constants for simple xml
element
parsing --//
		try {
			aMap = utils.getSimpleOMSubElement(serv,
this.getServiceConstants()); // the utility method as seen below
			int mapsize = aMap.size();

			Iterator keyValuePairs1 =
aMap.entrySet().iterator();
			for (int i = 0; i < mapsize; i++)
			{
			  Map.Entry entry = (Map.Entry)
keyValuePairs1.next();
			  Object key = entry.getKey();
			  Object value = entry.getValue();
			  logger.debug("<<<<<<<<< map values >>>>>>>> "
+value.toString());
			  getServiceElementsSwitch(key, value);
			}
		} catch (SOAPException e) {
			logger.debug("getService SOAPException"
+e.getMessage());
			e.printStackTrace();
		} catch (XMLStreamException e) {
			logger.debug("getService XMLStreamException"
+e.getMessage());
			e.printStackTrace();
		}
	}

I pass in a list of the binded elements as strings in a list so that I
can
iterate through them and then use the getChildWithNames iterator.
My only problem is that I can only get the first element text value even
though I loop through the list and pass I a new qName each time.
I have even tried another helper to get the text value taking in the
iterator and and the string value for the qName, but this still brings
back
only one of the text values.

Am I missing something? I've logged it to make sure I'm iterating with
the
correct elements for the binding, and have run test to make sure the
payload
of text value is correct.
    
    
       /**
         * Walk the xml tree of elements
         * get the simple element and put
         * in map object for return.
         *
         * @param serv
         * @throws XMLStreamException
         * @throws SOAPException
         * @return Map map
         */
        public Map getSimpleOMSubElement(Iterator iter, List
wsConstants)
throws SOAPException, XMLStreamException {
                int j = 1;
                String qName = "";
                String text = "";
       
                        for (j = 0; j < wsConstants.size(); j++) {
                                qName = (String)wsConstants.get(j);
                                logger.debug("qName = " +qName);
                                while (iter.hasNext()) {
                                    Object o = iter.next();
                                   
                                    if  (o instanceof OMElement) {
                                            OMElement c = (OMElement) o;
                                            OMElement element =
getOMElement(c, qName); // helpe method - takes element and constant
string
                                            text = element.getText();
                                    }
                               
                                        j++;
                                logger.debug("text = " + j + "" +text);
                                map.put(j, text);
                        }
                }
                return map;    
        }

        /**
          * Helper method to get the text elements in a type safe
fashion
          *
         * @param element
         * @param name
         * @return
         */
       public  OMElement getOMElement(OMElement result, String element)
            throws SOAPException, XMLStreamException {

            QName qName = new QName(element);
            if (qName == null) {
              throw new RuntimeException("Missing required method
element.");
            }

            Iterator i = result.getChildrenWithName(qName);
            if (! i.hasNext()) {
              throw new RuntimeException("Missing required  element.");
            }

            OMElement omElement = (OMElement) i.next();

            return omElement;
          }

As you see in the logs I can only get the first text value of the seven
entries, and the others do have text in them just unable to get it with
the
helper:

2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = partner-num
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.110 - text = 100250
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = auth-code
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = client-user
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = client-id2
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = browser-form-post
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = operation
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG utils.XMLUtils
getSimpleOMSubElement.99 - qName = client-id3
2007-05-01 17:41:19,967 [ApplicationServerThread-0] DEBUG
sso.SSOSkeleton
getService.142 - <<<<<<<<< map values >>>>>>>> 100250

I built it originally using the straight ahead manner of waliking the
elements, so why does it work below but above I cannot use the same idea
with a helper method using iteration?

while (service.hasNext()) {
                        Object o = service.next();
                        OMElement s = (OMElement) o;
                      
                        //----  test all data ----//
                        logger.debug("<<<<<  START OF SERVICE DATA >>>>>
");
                      
                        //--- use helper class for test ---//
                        //-- Test partner-num -- //
                                OMElement partnerData =
s.getFirstChildWithName(new QName(WSConstants.PARTNER_NUM));
                                logger.debug("<<<< Partner Data >>> "
+partnerData.getText());
                                assertEquals("wKsd898!iu",
partnerData.getText());
                              
                                // -- client-id --//
                                OMElement clientId =
s.getFirstChildWithName(new QName(WSConstants.CLIENT_ID));
                                logger.debug("<<<< client-id >>> "
+clientId.getText());
                                assertEquals("146", clientId.getText());
                              
                                // -- auth-code --//
                                OMElement authCode =
s.getFirstChildWithName(new QName(WSConstants.AUTH_CODE));
                                logger.debug("<<<< auth-code >>> "
+authCode.getText());
                                assertEquals("Ad897!df",
authCode.getText());
                              
                                 // -- client-user --//
                                OMElement clientUser =
s.getFirstChildWithName(new QName(WSConstants.CLIENT_USER));
                                logger.debug("<<<< client-user >>> "
+clientUser.getText());
                                assertEquals("1", clientUser.getText());
                              
                                 // -- client-id2 --//
                                OMElement clientId2 =
s.getFirstChildWithName(new QName(WSConstants.CLIENT_ID_2));
                                logger.debug("<<<< client-id2 >>> "
+clientId2.getText());
                                assertEquals("2", clientId2.getText());
                              
                                 // -- browser-form-post --//
                                OMElement browserFormPost =
s.getFirstChildWithName(new QName(WSConstants.BROWSER_FORM_POST));
                                logger.debug("<<<< browser-form-post >>>
"
+browserFormPost.getText());
                                assertEquals("text data ",
browserFormPost.getText());
                              
                                 // -- operation  --//
                                OMElement operation =
s.getFirstChildWithName(new QName(WSConstants.OPERATION));
                                logger.debug("<<<< operation >>> "
+operation.getText());
                                assertEquals("create",
operation.getText());
                              
                                 // -- client-id3 --//
                                OMElement clientId3 =
s.getFirstChildWithName(new QName(WSConstants.CLIENT_ID_3));
                                logger.debug("<<<< client-id3 >>> "
+clientId3.getText());
                                assertEquals("12345",
clientId3.getText());
                              
                                logger.debug("<<<<<  END OF SERVICE DATA
>>>>> ");






---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org