Solved

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

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

726 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