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

2007-05-03 Thread Martin Gainty

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" <[EMAIL PROTECTED]>

To: 
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

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

2007-05-02 Thread Hickman, Craig
 
Thanks, but I resolved the issue: see code below*

Craig Hickman, Sr. Architect ADP

Working with the previous Axis1 I was able to write a very easy
implementaion for a ServiceRouter and ServiceProcessor that worked for
exposing all my services through a properties lookup and hiding the Axis1
implementaion and complexity for users. Now I figure to do the same. Being a
java guy, I wondered why people needed to go through all these extra steps
to use code generators, even if they are nice and slick and supposedly are
there to help I have issues and concerns of maintainability and ease of use
of other developers in house who will be left to build on these services.
Not the way to go. So I figure its best to expose only what is worthwhile in
your api and create a set of utility classes that will help regular java
developers build the services easily without knowing all the goodies behind
the scenes.

I'm well on the way of doing this and simplifying things for others. I think
once I do this I'm defintely going to write a pro/con article on my
experience with the Axis2 api and third party tools which it uses. I like
Axis2 but think things could be improved greatly for users in the sense of
thinking in java and objects in a manner that is more user friendly.
Obviously this is just my own opinon and hopefully you will not take it as a
negative in a detrimental sense. 

After I finish this would it be worthwhile to send my findings to anyone
within the Axis2 community?


*
Test XML pull parsed:


   100250
   146
   potato123
   2
   3
 
http://www.someplace.com
   create
   7


The public method in the skeleton that is called by the receiver:

public org.apache.axiom.soap.SOAPEnvelope
create(org.apache.axis2.context.MessageContext msgContext) throws
ErrorException {


envelope = msgContext.getEnvelope();
try {
SOAPBody body = envelope.getBody();
if (body == null) {
ErrorException run =
utils.getErrorMessage(WSConstants.SOAP_MESSAGE_MISSING);
throw run;
}
// GET THE FIRST ELEMENT 
OMElement root =
utils.getOMRootElement(envelope);
// SET THE PARTNER SERVICE OBJECTS
QName serviceQN = new
QName(WSConstants.SERVICE);
Iterator serviceIter =
root.getChildrenWithName(serviceQN); 
getService(serviceIter); // the
private method that gets the elements and sets the bean 


// SET THE CANDIDATE SERVICE OBJECTS
QName candidateQN = new
QName(WSConstants.CANDIDATE);
Iterator candidate =
root.getChildrenWithName(candidateQN);
getCandidate(candidate);
 
// UNLOAD THE SERVICE AND SEND THE
OBJECTS TO THE SASSCORE SERVICES
service = new ServiceManagerImpl();
envelope =
service.create(this.getSsoBO()); // delegate that sends all to backend
POJO's


} catch (OMException e) {
ErrorException ex =
utils.getErrorMessage(WSConstants.SERVICE_FAILED);
throw ex;
}

return envelope;

}

The private util method in the skel:

private void getService(Iterator serv) {
Map aMap = new HashMap();

//-- pass in iterator and constants for simple xml element
parsing --//
try {
aMap = utils.getOMTextToMap(serv,
Arrays.asList(WSConstants.SERVICE_ARRAY)); // call to the
XMLUtils.getOMTextToMap(...)
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();
  getServiceElementsSwitch(key, value);
}
} catch (SOAPException e) {
logger.debug("getService SOAPException"
+e.getMessage());
e.printStackTrace();
} catch (XMLStreamException e) {
logger.debu

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

2007-05-02 Thread Paul Fremantle

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 <[EMAIL PROTECTED]> 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);
 

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

2007-05-01 Thread Sampige, Srinivas
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:[EMAIL PROTECTED] 
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;