Solved

What does this attribute array do in this java code snippet?

Posted on 2007-03-28
3
208 Views
Last Modified: 2010-03-31
What does this attribute array do in this Java Snippet?
public Attribute[] writeSessionLog(Session session) throws ManagementSupportException {

            TEServiceStub.SaveSession request = new TEServiceStub.SaveSession();
            request.setLabID(session.getLabid());
            request.setSessionUID(session.getSessionId());

            //create Attribute from the session
            TEServiceStub.AttributeArray array = new TEServiceStub.AttributeArray();

            TEServiceStub.Attribute hwVersion = new TEServiceStub.Attribute();
            hwVersion.setName("HW_VERSION");
            hwVersion.setValue(session.getHwVersion());
            array.addAttributes(hwVersion);

            TEServiceStub.Attribute startTime = new TEServiceStub.Attribute();
            startTime.setName("START_TIME");
            //FIXME: what format the time should be?
            startTime.setValue(session.getStartTime() == null ? new Date().toString() : session.getStartTime().toString());
            array.addAttributes(startTime);

            TEServiceStub.Attribute finishTime = new TEServiceStub.Attribute();
            finishTime.setName("FINISH_TIME");
            finishTime.setValue(session.getFinishTime() == null ? new Date().toString() : session.getFinishTime().toString());
            array.addAttributes(finishTime);

            TEServiceStub.Attribute tester = new TEServiceStub.Attribute();
            tester.setName("TESTER");
            tester.setValue(session.getTester());
            array.addAttributes(tester);

            TEServiceStub.Attribute testEvent = new TEServiceStub.Attribute();
            testEvent.setName("TEST_EVENT");
            testEvent.setValue(session.getTestEvent());
            array.addAttributes(testEvent);

            TEServiceStub.Attribute testOrg = new TEServiceStub.Attribute();
            testOrg.setName("TEST_ORG");
            testOrg.setValue(session.getTestOrg());
            array.addAttributes(testOrg);

            request.setAttributes(array);

            TEServiceStub.RequestStatus status = null;
            TEServiceStub.SaveSessionResponse response = null;
            try{
                  response = stub.saveSession(request);
                  status = response.getStatus();
            } catch(Exception e) {
                  logger.warn("Fail to call TEService :" + e);
                  throw new ManagementSupportException("Fail to call TEService :" + e);
            }

            if(!status.getSuccess()) {
                  logger.warn("TEService return failure while call saveSession()");
                  throw new ManagementSupportException("TEService return failure while call saveSession()");
            }

            return cast(response.getAttributes());
      }
0
Comment
Question by:yankeebushsoftware
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
elfe69 earned 250 total points
ID: 18814086
I do not know what TEServiceStub does, but as I see, array is used to store an array of attributes in the HTTP session (in order to retrieve those attributes later).
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 250 total points
ID: 18814093
1. All kind of attributes are stored in the array

>> array.addAttributes(hwVersion);
>> ...
>> array.addAttributes(startTime);
>> ...
>> ...
>> array.addAttributes(testOrg);

2. Then the array is set as an attribute on 'request'
    That way all the attributes are passed to the party that made the request

>> request.setAttributes(array);
0
 
LVL 37

Expert Comment

by:zzynx
ID: 18814591
thanx 4 axxepting
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

829 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