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.cacao.agent.JmxClient;
031:
032: import com.sun.portal.admin.common.util.AdminClientUtil;
033: import com.sun.portal.admin.console.common.PSBaseBean;
034:
035: public class ImportAgentsBean extends PSBaseBean {
036:
037: private ObjectListDataProvider importAgents = null;
038:
039: public ImportAgentsBean() {
040: retrieveImportAgents();
041: }
042:
043: public boolean getIsRunning() {
044: try {
045: LinkedList path = new LinkedList();
046: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
047: path
048: .addFirst((String) getSessionAttribute("search.server.selected"));
049: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
050: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
051:
052: Object[] params = {};
053: String[] signatures = {};
054: Boolean result = (Boolean) getMBeanServerConnection()
055: .invoke(on, "isImportAgentsRunning", params,
056: signatures);
057: return result.booleanValue();
058: } catch (Exception e) {
059: log(Level.SEVERE, "ImportAgentsBean.getIsRunning()", e);
060: }
061: return false;
062: }
063:
064: public ObjectListDataProvider getImportAgents() {
065: return importAgents;
066: }
067:
068: public void setImportAgents(ObjectListDataProvider importAgents) {
069: this .importAgents = importAgents;
070: }
071:
072: public boolean getHasNoImportAgents() {
073: if (importAgents == null) {
074: return true;
075: }
076:
077: List l = importAgents.getList();
078: if (l.size() == 0) {
079: return true;
080: }
081:
082: return false;
083: }
084:
085: public String gotoEditImportAgent() {
086: HttpServletRequest hsr = (HttpServletRequest) FacesContext
087: .getCurrentInstance().getExternalContext().getRequest();
088: String id = (String) hsr
089: .getParameter("search.importagent.selected");
090:
091: setSessionAttribute("search.importagent.selected", id);
092:
093: ImportAgentBean iab = findImportAgent(id);
094: if (iab.inputFile != null && !iab.inputFile.equals("")) {
095: return "gotoEditImportAgent1";
096: } else {
097: return "gotoEditImportAgent2";
098: }
099: }
100:
101: public String enable() {
102: try {
103: LinkedList path = new LinkedList();
104: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
105: path
106: .addFirst((String) getSessionAttribute("search.server.selected"));
107: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
108: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
109:
110: Object[] params = { Checkbox.getSelected("checkbox") };
111: String[] signatures = { "java.util.List" };
112: getMBeanServerConnection().invoke(on, "enableImportAgents",
113: params, signatures);
114: } catch (Exception e) {
115: log(Level.SEVERE, "ImportAgentsBean.enable() : Exception ",
116: e);
117: }
118: retrieveImportAgents();
119: return null;
120: }
121:
122: public String disable() {
123: try {
124: LinkedList path = new LinkedList();
125: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
126: path
127: .addFirst((String) getSessionAttribute("search.server.selected"));
128: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
129: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
130:
131: Object[] params = { Checkbox.getSelected("checkbox") };
132: String[] signatures = { "java.util.List" };
133: getMBeanServerConnection().invoke(on,
134: "disableImportAgents", params, signatures);
135: } catch (Exception e) {
136: log(Level.SEVERE,
137: "ImportAgentsBean.disable() : Exception ", e);
138: }
139: retrieveImportAgents();
140: return null;
141: }
142:
143: public String delete() {
144: try {
145: LinkedList path = new LinkedList();
146: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
147: path
148: .addFirst((String) getSessionAttribute("search.server.selected"));
149: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
150: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
151:
152: Object[] params = { Checkbox.getSelected("checkbox") };
153: String[] signatures = { "java.util.List" };
154: getMBeanServerConnection().invoke(on, "deleteImportAgents",
155: params, signatures);
156: } catch (Exception e) {
157: log(Level.SEVERE, "ImportAgentsBean.delete() : Exception ",
158: e);
159: }
160: retrieveImportAgents();
161: return null;
162: }
163:
164: public String run() {
165: try {
166: LinkedList path = new LinkedList();
167: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
168: path
169: .addFirst((String) getSessionAttribute("search.server.selected"));
170: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
171: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
172:
173: Object[] params = {};
174: String[] signatures = {};
175: getMBeanServerConnection().invoke(on, "runImportAgents",
176: params, signatures);
177: } catch (Exception e) {
178: log(Level.SEVERE, "ImportAgentsBean.run() : Exception ", e);
179: }
180: return null;
181: }
182:
183: private void retrieveImportAgents() {
184: ArrayList al = new ArrayList();
185: try {
186: LinkedList path = new LinkedList();
187: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
188: path
189: .addFirst((String) getSessionAttribute("search.server.selected"));
190: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
191: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
192:
193: ArrayList attributes = new ArrayList();
194: Object[] params = { attributes };
195: String[] signatures = { "java.util.List" };
196: ArrayList data = (ArrayList) getMBeanServerConnection()
197: .invoke(on, "getAllImportAgents", params,
198: signatures);
199: for (int index = 0; index < data.size(); index++) {
200: Properties p = (Properties) data.get(index);
201:
202: ImportAgentBean iab = new ImportAgentBean();
203: iab.initialize(p);
204: if (!iab.compass301x) {
205: al.add(iab);
206: }
207: }
208: } catch (Exception e) {
209: log(
210: Level.SEVERE,
211: "ImportAgentsBean.retrieveImportAgents() : Exception ",
212: e);
213: }
214: importAgents = new ObjectListDataProvider(al);
215: importAgents.setObjectType(ImportAgentBean.class);
216: }
217:
218: private ImportAgentBean findImportAgent(String id) {
219: importAgents.commitChanges();
220: List l = importAgents.getList();
221: for (int index = 0; index < l.size(); index++) {
222: ImportAgentBean iab = (ImportAgentBean) l.get(index);
223: if (iab.id.equals(id)) {
224: return iab;
225: }
226: }
227: return null; /* This line better not happen! */
228: }
229:
230: }
|