Solved

How do these two functions work?

Posted on 2007-03-29
1
252 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This video teaches viewers about errors in exception handling.
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…

635 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