Solved

Please comment this code so I can understand it...

Posted on 2007-03-28
2
192 Views
Last Modified: 2010-03-31
Would someone comment this code so I can understand it?
import org.muos.management.managementSupport.Attribute;
import org.muos.management.managementSupport.Lab;
import org.muos.management.managementSupport.ManagementSupport;
import org.muos.management.managementSupport.ManagementSupportException;
import org.muos.management.managementSupport.ManagementSupportFactory;
import org.muos.management.managementSupport.RequirementVerificationID;
import org.muos.management.managementSupport.Tree;


public class SampleCode {

      /**
       * @param args
       */
      public static void main(String[] args) {
            String serviceLocation = "http://localhost:8080/axis2/services/TEService";
            ManagementSupport supporter = null;
            try {
                  supporter = ManagementSupportFactory.getManagementSupport(serviceLocation);
            } catch (ManagementSupportException e) {
                  //If can not initialize the TEServiceStub, do something here
                  e.printStackTrace();
            }

            if(supporter == null) {
                  return;
            }

            /*
             * Sample of deleteLab,
             */
            try {
                  supporter.deleteLab(123L);
                  //delete success
            } catch (ManagementSupportException e) {
                  //delete fail
                  e.printStackTrace();
            }

            /*
             * GetLabAttribute()
             */
            try {
                  String attribute = supporter.getLabAttribute(123L, "lab_attribute_name");
                  //Successfully get the attribute
                  System.out.println(attribute);
            } catch (ManagementSupportException e) {
                  //Fail
                  e.printStackTrace();
            }

            try {
                  String attribute = supporter.getLabChangeAttribute(1234L, "attribute_name");
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] labIds = supporter.getLabChanges();
                  for(long id : labIds) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] ids = supporter.getLabChangesByLab(123L); //LabId
                  for(long id : ids) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] ids = supporter.getLabChangesByNode(1234L);//NodeId
                  for(long id :ids) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] ids = supporter.getLabs();
                  for(long id : ids)  {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  String value = supporter.getNodeAttribute(1234L, "attribute_name");
                  System.out.println(value);
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] ids = supporter.getNodeChildren(1234L);
                  for(long id : ids) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  String value = supporter.getProjectAttribute(1234L, "attriubte_name");
                  System.out.println(value);
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] ids = supporter.getProjects();
                  for(long id : ids) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  String value = supporter.getRequirementVerificationAttribute("requirementId", 123L, "attibute_name");
                  System.out.println(value);
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  RequirementVerificationID[]  ids = supporter.getRequirementVerifications(1243L);
                  for(RequirementVerificationID id : ids) {
                        System.out.println(id.getRequirementId());
                        System.out.println(id.getTestLogId());
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] nodeIds = supporter.getRootNodes(1244L);
                  for(long id : nodeIds) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  String value = supporter.getSessionAttribute(134L, "attribute_name");
                  System.out.println(value);
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] sessionIds = supporter.getSessions();
                  for(long id : sessionIds) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  String xml = supporter.getSTDTree();
                  System.out.println(xml);
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  String value = supporter.getTestLogAttribute(1234L, "attribute_name");
                  System.out.println(value);
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] testlogIds = supporter.getTestLogs();
                  for(long id : testlogIds) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] ids = supporter.getTestLogsByNode(1345L);
                  for(long id : ids) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            Lab lab = new Lab();
            lab.setDescription("This is a lab");
            lab.setId(4564L);
            lab.setLocation("Where the lab is");
            lab.setOwner("who the owner is");
            try {
                  Attribute[] attributes = supporter.saveLab(lab);
                  for(Attribute attr : attributes) {
                        System.out.println("name :" + attr.getName() + " ; value = " + attr.getValue());
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            Attribute[] labChangeAttributes = new Attribute[2];
            Attribute attr1 = new Attribute();
            attr1.setName("attributeName");
            attr1.setValue("attributeValue");
            Attribute attr2 = new Attribute();
            attr2.setName("attributeName");
            attr2.setValue("attributeValue");
            labChangeAttributes[0] = attr1;
            labChangeAttributes[1] = attr2;
            try {
                  Attribute[] returnedAttributes = supporter.saveLabChange("test log UID", labChangeAttributes);
                  for(Attribute attr : returnedAttributes) {
                        System.out.println("name :" + attr.getName() + " ; value = " + attr.getValue());
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            Attribute[] requirementVerificationAttributes = new Attribute[2];
            attr1 = new Attribute();
            attr1.setName("attributeName");
            attr1.setValue("attributeValue");
            attr2 = new Attribute();
            attr2.setName("attributeName");
            attr2.setValue("attributeValue");
            labChangeAttributes[0] = attr1;
            labChangeAttributes[1] = attr2;
            try {
                  Attribute[] returnedAttributes = supporter.saveRequirementVerification("RequirementId", "testLogUID", requirementVerificationAttributes);
                  for(Attribute attr : returnedAttributes) {
                        System.out.println("name :" + attr.getName() + " ; value = " + attr.getValue());
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            Attribute[] sessionAttibutes = new Attribute[2];
            attr1 = new Attribute();
            attr1.setName("attributeName");
            attr1.setValue("attributeValue");
            attr2 = new Attribute();
            attr2.setName("attributeName");
            attr2.setValue("attributeValue");
            labChangeAttributes[0] = attr1;
            labChangeAttributes[1] = attr2;
            try {
                  Attribute[] returnedAttributes = supporter.saveSession(123L, "sessionUID", sessionAttibutes);
                  for(Attribute attr : returnedAttributes) {
                        System.out.println("name :" + attr.getName() + " ; value = " + attr.getValue());
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            Attribute[] testLogSession = new Attribute[2];
            attr1 = new Attribute();
            attr1.setName("attributeName");
            attr1.setValue("attributeValue");
            attr2 = new Attribute();
            attr2.setName("attributeName");
            attr2.setValue("attributeValue");
            labChangeAttributes[0] = attr1;
            labChangeAttributes[1] = attr2;
            try {
                  Attribute[] returnedAttributes = supporter.saveTestLog("sessionUID", "testLogUID", testLogSession);
                  for(Attribute attr : returnedAttributes) {
                        System.out.println("name :" + attr.getName() + " ; value = " + attr.getValue());
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  Tree tree = supporter.populateTree(1234L);
                  System.out.println(tree.getNode().getNodeId());
                  for(Attribute att : tree.getNode().getAttributes()) {
                        System.out.println(att.getName());
                        System.out.println(att.getValue());
                  }
                  System.out.println("has children : "  + tree.getChildren().size());
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }
      }

}
0
Comment
Question by:yankeebushsoftware
2 Comments
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 18814648
first we must know what is the
org.muos.management.managementSupport
since most of functions are from it and the rest is documented.
0
 
LVL 8

Accepted Solution

by:
reach2piyush earned 500 total points
ID: 18814731
//Looks like you got a web service with the following address
String serviceLocation = "http://localhost:8080/axis2/services/TEService";

//ManagementSupportFactory class looks like a utility class to connect to that Web Service ^ returns you a stub to call methods on that Web service
supporter = ManagementSupportFactory.getManagementSupport(serviceLocation);

// The following piece of code  along with all other subsequent similar code demonstrate/test a business method call to the above mentioned web-service,
Each call is enclosed in a separate try-catch loop, this will ensure that the program will continue even if any of the calls fails.  
/*
* Sample of deleteLab,
*/
try {
supporter.deleteLab(123L);
//delete success
} catch (ManagementSupportException e) {
//delete fail
e.printStackTrace();
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now