Solved

Can someone comment what this if statements are doing in this method?

Posted on 2007-03-29
1
173 Views
Last Modified: 2010-03-31
Can someone comment what this if statements are doing in this method?
public Attribute[] saveLab(Lab lab) throws ManagementSupportException {
             // creating "request" object using service's method
            TEServiceStub.SaveLab request = new TEServiceStub.SaveLab();

            TEServiceStub.AttributeArray array = new TEServiceStub.AttributeArray();
            List<TEServiceStub.Attribute> attrs = new ArrayList<TEServiceStub.Attribute>();

            if(lab.getId() > 0) {
                  TEServiceStub.Attribute attr = new TEServiceStub.Attribute();
                  attr.setName("LAB_ID");
                  attr.setValue(String.valueOf(lab.getId()));
                  attrs.add(attr);
            }

            if(lab.getDescription() != null && lab.getDescription().length() > 0) {
                  TEServiceStub.Attribute attr = new TEServiceStub.Attribute();
                  attr.setName("DESCRIPTION");
                  attr.setValue(lab.getDescription());
                  attrs.add(attr);
            }

            if(lab.getLocation() != null && lab.getLocation().length() > 0) {
                  TEServiceStub.Attribute attr = new TEServiceStub.Attribute();
                  attr.setName("LOCATION");
                  attr.setValue(lab.getLocation());
                  attrs.add(attr);
            }

            if(lab.getOwner() != null && lab.getOwner().length() > 0) {
                  TEServiceStub.Attribute attr = new TEServiceStub.Attribute();
                  attr.setName("OWNER");
                  attr.setValue(lab.getOwner());
                  attrs.add(attr);
            }
            array.setAttributes((TEServiceStub.Attribute[]) attrs.toArray());

            request.setAttributes(array);
            // declaring "response" object
            TEServiceStub.SaveLabResponse response = null;
            try {
                  // invoking web service's method
                  response = stub.saveLab(request);
            } catch (RemoteException e) {
                  logger.warn("Fail to call TEService :" + e);
                  throw new ManagementSupportException("Fail to call TEService :" + e);
            }
            // processing "response" object
            if(!response.getStatus().getSuccess()) {
                  logger.warn("TEService return failure while call saveLab()");
                  throw new ManagementSupportException("TEService return failure while call saveLab()");
            }

            return cast(response.getAttributes());
      }
0
Comment
Question by:yankeebushsoftware
1 Comment
 
LVL 11

Accepted Solution

by:
elfe69 earned 500 total points
ID: 18817201
Let's take an example:
           if(lab.getDescription() != null && lab.getDescription().length() > 0) {
                  TEServiceStub.Attribute attr = new TEServiceStub.Attribute();
                  attr.setName("DESCRIPTION");
                  attr.setValue(lab.getDescription());
                  attrs.add(attr);
            }
It says that if the description of lab is not empty, this description is stored in a list of attributes (attrs) that will be later sent with the request
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…

743 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

11 Experts available now in Live!

Get 1:1 Help Now