001: /**
002: * Copyright 2005 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.admin.console.search;
013:
014: import java.util.*;
015: import java.util.logging.Level;
016: import java.io.*;
017:
018: import javax.faces.context.FacesContext;
019: import javax.faces.el.ValueBinding;
020: import javax.servlet.http.HttpServletRequest;
021: import javax.management.*;
022:
023: import com.sun.web.ui.model.*;
024: import com.sun.web.ui.event.*;
025: import com.sun.web.ui.component.*;
026:
027: import com.sun.data.provider.*;
028: import com.sun.data.provider.impl.ObjectListDataProvider;
029:
030: import com.sun.portal.admin.common.util.AdminClientUtil;
031: import com.sun.portal.admin.console.common.PSBaseBean;
032:
033: public class SearchServersBean extends PSBaseBean {
034:
035: private ObjectListDataProvider searchServers = null;
036:
037: public SearchServersBean() {
038: retrieveSearchServers();
039: }
040:
041: public ObjectListDataProvider getSearchServers() {
042: return searchServers;
043: }
044:
045: public void setSearchServers(ObjectListDataProvider searchServers) {
046: this .searchServers = searchServers;
047: }
048:
049: public Option[] getAvailableSearchServers() {
050: searchServers.commitChanges();
051: List l = searchServers.getList();
052: Option[] options = new Option[l.size()];
053: for (int index = 0; index < l.size(); index++) {
054: SearchServerBean ssb = (SearchServerBean) l.get(index);
055: options[index] = new Option(ssb.id, ssb.id);
056: }
057: return options;
058: }
059:
060: public String getCurrentSearchServer() {
061: return (String) getSessionAttribute("search.server.selected");
062: }
063:
064: public void setCurrentSearchServer(String searchServer) {
065: setSessionAttribute("search.server.selected", searchServer);
066: }
067:
068: public String delete() {
069: try {
070: ObjectName on = AdminClientUtil
071: .getPortalDomainMBeanObjectName(AdminClientUtil.DEFAULT_DOMAIN);
072: List l = Checkbox.getSelected("checkbox");
073: for (int index = 0; index < l.size(); index++) {
074: Object[] params = { (String) l.get(index) };
075: String[] signatures = { "java.lang.String" };
076: getMBeanServerConnection().invoke(on,
077: "deleteSearchServer", params, signatures);
078: }
079: } catch (Exception e) {
080: log(Level.SEVERE,
081: "SearchServersBean.delete() : Exception ", e);
082: }
083: retrieveSearchServers();
084: return null;
085: }
086:
087: public String gotoServerHome() {
088: FacesContext fc = FacesContext.getCurrentInstance();
089: ValueBinding vb = fc.getApplication().createValueBinding(
090: "#{searchServer.value.id}");
091: setSessionAttribute("search.server.selected", (String) vb
092: .getValue(fc));
093: return "gotoServerHome";
094: }
095:
096: private void retrieveSearchServers() {
097: ArrayList al = new ArrayList();
098: try {
099: ObjectName on = AdminClientUtil
100: .getSearchServerPattern(AdminClientUtil.DEFAULT_DOMAIN);
101: Set objects = getMBeanServerConnection().queryNames(on,
102: null);
103: Iterator i = objects.iterator();
104: while (i.hasNext()) {
105: on = (ObjectName) i.next();
106: String id = (String) getMBeanServerConnection()
107: .getAttribute(on, "ID");
108: String host = (String) getMBeanServerConnection()
109: .getAttribute(on, "Host");
110: String port = (String) getMBeanServerConnection()
111: .getAttribute(on, "Port");
112: String instance = (String) getMBeanServerConnection()
113: .getAttribute(on, "Instance");
114:
115: SearchServerBean ssb = new SearchServerBean();
116: ssb.initialize(id, host, port, instance);
117: al.add(ssb);
118: }
119: } catch (Exception e) {
120: log(
121: Level.SEVERE,
122: "SearchServersBean.retrieveSearchServers() : Exception ",
123: e);
124: }
125: searchServers = new ObjectListDataProvider(al);
126: searchServers.setObjectType(SearchServerBean.class);
127: }
128:
129: }
|