summaryrefslogtreecommitdiffstats
path: root/tags/java-M1-20060522/java/sampleapps/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/AccountStatusTag.java
blob: c11d3f9e46cdfbed833444192d98f25ec8f0b165 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
 *
 *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package bigbank.webclient.tags.account;

import java.util.Iterator;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.osoa.sca.CurrentModuleContext;
import org.osoa.sca.ModuleContext;

import bigbank.webclient.services.profile.ProfileService;

import com.bigbank.account.AccountReport;
import com.bigbank.account.AccountService;

/**
 * Retrieves and iterates over account summary information for the current profile by accessing the remotable account service component
 */

public class AccountStatusTag extends TagSupport {

    // ----------------------------------
    // Constructors
    // ----------------------------------

    public AccountStatusTag() {
        super();
    }

    // ----------------------------------
    // Methods
    // ----------------------------------

    private String mAccountService;

    public String getAccountService() {
        return mAccountService;
    }

    public void setAccountService(String pAccountService) {
        mAccountService = pAccountService;
    }

    private String mProfileService;

    public String getProfileService() {
        return mProfileService;
    }

    public void setProfileService(String pProfileService) {
        mProfileService = pProfileService;
    }

    private String mId;

    public String getId() {
        return mId;
    }

    public void setId(String pId) {
        mId = pId;
    }

    private Iterator mIterator;

    public int doStartTag() throws JspException {
        ModuleContext moduleContext = CurrentModuleContext.getContext();
        ProfileService profile = (ProfileService) moduleContext.locateService(mProfileService);
        if (profile == null) {
            throw new JspException("Profile [" + mProfileService + "] not found in current module context");
        }

        AccountService service = (AccountService) moduleContext.locateService(mAccountService);
        if (service == null) {
            throw new JspException("Service [" + mAccountService + "] not found in current module context");
        }
        List summaries;
        try {
            AccountReport accountReport = service.getAccountReport(profile.getId());
            pageContext.setAttribute("StockSummaries", accountReport.getStockSummaries());
            summaries = accountReport.getAccountSummaries();
        } catch (Exception e) {
            throw new JspException(e);
        }
        mIterator = summaries.iterator();
        if (mIterator.hasNext()) {
            pageContext.setAttribute(mId, mIterator.next());
            return EVAL_BODY_INCLUDE;
        } else {
            return SKIP_BODY;
        }
    }

    public int doAfterBody() {
        if (mIterator.hasNext()) {
            pageContext.setAttribute(mId, mIterator.next());
            return EVAL_BODY_AGAIN;
        } else {
            return SKIP_BODY;
        }
    }

    public void release() {
        super.release();
        mId = null;
        mIterator = null;
    }
}