001: /*
002: * Created on Jun 27, 2005
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Style - Code Templates
006: */
007: package com.sun.portal.admin.console.sra.gateway;
008:
009: import java.util.Iterator;
010: import java.util.List;
011: import java.util.logging.Level;
012:
013: import javax.faces.event.ValueChangeEvent;
014: import javax.faces.context.FacesContext;
015:
016: import com.sun.data.provider.impl.ObjectArrayDataProvider;
017: import com.sun.data.provider.impl.ObjectListDataProvider;
018: import com.sun.data.provider.DataProvider;
019:
020: import com.sun.portal.admin.console.sra.SraBaseBean;
021: import com.sun.portal.admin.console.sra.monitoring.SRAProxiesBean;
022: import com.sun.portal.admin.console.sra.utils.Util;
023: import com.sun.portal.admin.console.common.PSBaseBean;
024:
025: import com.sun.web.ui.model.Option;
026:
027: public class ProfileBean extends SraBaseBean {
028:
029: public static final String SRA_SELECTED_PROFILE = "SRA_SELECTED_PROFILE";
030:
031: private ObjectListDataProvider profileListProvider;
032:
033: String profileUrl = "/faces/sra/gateway/Gateway.jsp";
034:
035: private String newProfileName = "";
036:
037: public Option[] getProfiles() {
038: List profileList = getSraProfiles();
039: Option[] profileArray = new Option[profileList.size()];
040:
041: Iterator iterator = profileList.iterator();
042: int i = 0;
043:
044: while (iterator.hasNext()) {
045: String profile = (String) iterator.next();
046: profileArray[i++] = new Option(profile, profile);
047: }
048: return profileArray;
049: }
050:
051: public String getSelectedProfile() {
052: List allProfiles = getSraProfiles();
053: String selectedProfile = "default";
054: if (allProfiles.size() >= 1)
055: selectedProfile = (String) allProfiles.get(0);
056:
057: return (String) getSessionAttribute(SRA_SELECTED_PROFILE) == null ? selectedProfile
058: : (String) getSessionAttribute(SRA_SELECTED_PROFILE);
059: }
060:
061: public void setSelectedProfile(ValueChangeEvent event) {
062: setSessionAttribute(SRA_SELECTED_PROFILE, (String) event
063: .getNewValue());
064: }
065:
066: public void setSelectedProfile(String profileName) {
067: setSessionAttribute(SRA_SELECTED_PROFILE, profileName);
068: }
069:
070: public void initData() {
071: }
072:
073: public DataProvider getProfileList() {
074: profileListProvider = new ObjectListDataProvider(
075: new SRAProxiesBean().getProfiles());
076: return profileListProvider;
077: }
078:
079: public void deleteProfile() {
080: resetErrorMessages();
081: profileListProvider.commitChanges();
082: List pList = profileListProvider.getList();
083: if (pList.size() == 1) {
084: displayAlert("psadmin.error.sra.profile.cannotDelete", "",
085: "error");
086: return;
087: }
088: for (int i = 0; i < pList.size(); i++) {
089: SRAProxiesBean.Profile profile = (SRAProxiesBean.Profile) pList
090: .get(i);
091: if (profile.getSelected()) {
092: deleteSraProfile(profile.getName());
093: break;
094: }
095: }
096: }
097:
098: public String getNewProfileName() {
099: return newProfileName;
100: }
101:
102: public void setNewProfileName(String newProfileName) {
103: this .newProfileName = newProfileName;
104: }
105:
106: public void createNewProfile() {
107: resetErrorMessages();
108: Boolean isCreated = createNewSraProfile(getSelectedProfile(),
109: this .newProfileName);
110: if (isCreated.booleanValue()) {
111: newProfileName = "";
112: // redirectTo("/faces/sra/SRAHome.jsp");
113: redirectTo("/faces/sra/gateway/NewProfileCreatedMessage.jsp");
114: }
115: }
116:
117: public void getProfileUrl() {
118: String selectedProfileValue = (String) Util
119: .getRequestParameter("selectedProfile");
120: setSelectedProfile(selectedProfileValue);
121: redirectTo("/faces/sra/gateway/Gateway.jsp");
122: return;
123: }
124:
125: public void redirectTo(String url) {
126: try {
127: FacesContext.getCurrentInstance().getExternalContext()
128: .redirect(
129: FacesContext.getCurrentInstance()
130: .getExternalContext()
131: .getRequestContextPath()
132: + url);
133: } catch (java.io.IOException ioe) {
134: PSBaseBean
135: .log(
136: Level.SEVERE,
137: "ProfileBean.redirectTo(): Unable to redirect to the page!!",
138: ioe);
139: }
140: }
141:
142: public void gotoCreateNewPage() {
143: resetErrorMessages();
144: redirectTo("/faces/sra/gateway/GatewayCreateNewProfile.jsp");
145: }
146:
147: /**
148: *
149: */
150: private void resetErrorMessages() {
151: displayError = Boolean.FALSE;
152: }
153:
154: public void gotoSraHomePage() {
155: resetErrorMessages();
156: newProfileName = "";
157: redirectTo("/faces/sra/SRAHome.jsp");
158: }
159:
160: }
|