Solved

How do these two functions work?

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Should localization be done inside spring controller 5 37
Is there a simpler dropbox system? 10 44
Print Rhino Java Array in Javascript 1 35
Running JavaFX on the Raspberry Pi 27 132
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

749 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