Solved

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

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Basic Java Case or If-Else statement... 3 50
Unhandled exception type Exception 18 31
How do I remove an object from a 3 26
eclipse console opening separately 2 21
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 video teaches viewers about errors in exception handling.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

773 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