Solved

How do these two functions work?

Posted on 2007-03-29
1
251 Views
Last Modified: 2010-03-31
Could someone show me how this code works or add some comments to it?
public String populateTreeAsXML() throws ManagementSupportException {
            StringBuffer buffer = new StringBuffer();
            long[] projectIds = this.getProjects();
            for(long id : projectIds) {
                  buffer.append(this.populateTreeAsXML(id)).append("\n");
            }
            return buffer.toString();
      }

      public String populateTreeAsXML(long nodeId) throws ManagementSupportException {
            TEServiceStub.GetProjectTree request = new TEServiceStub.GetProjectTree();

            request.setNodeID(nodeId);

            TEServiceStub.GetProjectTreeResponse response = null;
            try {
                  response = stub.getProjectTree(request);
            } catch (RemoteException e) {
                  logger.warn("Fail to call TEService :" + e);
                  throw new ManagementSupportException("Fail to call TEService :" + e);
            }

            if(!response.getStatus().getSuccess()) {
                  logger.warn("TEService return failure while call saveTestLog()");
                  throw new ManagementSupportException("TEService return failure while call saveTestLog()");
            }

            return response.getOMElement(TEServiceStub.GetProjectTreeResponse.MY_QNAME, OMAbstractFactory.getOMFactory()).toString();
      }
0
Comment
Question by:yankeebushsoftware
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 30

Accepted Solution

by:
Mayank S earned 500 total points
ID: 18818990
public String populateTreeAsXML() throws ManagementSupportException {
            StringBuffer buffer = new StringBuffer(); // create a new string buffer
            long[] projectIds = this.getProjects(); // get the project IDs in an array
            for(long id : projectIds) { // iterate through the array
                  // append the ID after populating the tree as XML, followed by new line
                  buffer.append(this.populateTreeAsXML(id)).append("\n");
            }
            // return the string contents
            return buffer.toString();
      }

      public String populateTreeAsXML(long nodeId) throws ManagementSupportException {
            TEServiceStub.GetProjectTree request = new TEServiceStub.GetProjectTree(); // create a new tree or tree node, I guess

            request.setNodeID(nodeId); // set the node ID for the tree or tree node

            TEServiceStub.GetProjectTreeResponse response = null;
            try {
                  // probably invoke a web service or something with the request
                  // and obtain a response
                  response = stub.getProjectTree(request);
            } catch (RemoteException e) {
                  logger.warn("Fail to call TEService :" + e);
                  throw new ManagementSupportException("Fail to call TEService :" + e);
            }

            // if the status is not success, throw an exception
            if(!response.getStatus().getSuccess()) {
                  logger.warn("TEService return failure while call saveTestLog()");
                  throw new ManagementSupportException("TEService return failure while call saveTestLog()");
            }

            return response.getOMElement(TEServiceStub.GetProjectTreeResponse.MY_QNAME, OMAbstractFactory.getOMFactory()).toString(); // return the OM element
      }
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
by zero exception 10 83
ejb on wildfly 5 65
going to wrong jsp page 2 71
Crystal Reports Licensing Questions 4 88
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question