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.application.FacesMessage;
020: import javax.faces.component.UIComponent;
021: import javax.faces.event.*;
022: import javax.faces.validator.*;
023: import javax.faces.el.ValueBinding;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.management.*;
026:
027: import com.sun.web.ui.model.*;
028: import com.sun.web.ui.event.*;
029: import com.sun.web.ui.component.*;
030:
031: import com.sun.data.provider.*;
032: import com.sun.data.provider.impl.ObjectListDataProvider;
033:
034: import com.sun.cacao.agent.JmxClient;
035:
036: import com.sun.portal.admin.common.AttrOptionConstants;
037: import com.sun.portal.admin.common.util.*;
038: import com.sun.portal.admin.console.common.PSBaseBean;
039:
040: public class SchedulingAutoclassifyBean extends SchedulingBaseBean {
041:
042: private String host = null;
043: private String startCommand = null;
044: private TableRowGroup tableRowGroup = null;
045: private TableSelectPhaseListener tspl = null;
046:
047: public SchedulingAutoclassifyBean() {
048: retrieveSearchServerHost();
049: retrieveStartCommand();
050:
051: ObjectListDataProvider startSchedules = (ObjectListDataProvider) getSessionAttribute("search.schedulingautoclassify.startschedules");
052: if (startSchedules == null) {
053: retrieveStartSchedules();
054: }
055:
056: tspl = new TableSelectPhaseListener();
057: }
058:
059: public ObjectListDataProvider getStartSchedules() {
060: return (ObjectListDataProvider) getSessionAttribute("search.schedulingautoclassify.startschedules");
061: }
062:
063: public void setStartSchedules(ObjectListDataProvider startSchedules) {
064: setSessionAttribute(
065: "search.schedulingautoclassify.startschedules",
066: startSchedules);
067: }
068:
069: public TableRowGroup getTableRowGroup() {
070: return tableRowGroup;
071: }
072:
073: public void setTableRowGroup(TableRowGroup tableRowGroup) {
074: this .tableRowGroup = tableRowGroup;
075: }
076:
077: public Object getSelected() {
078: return tspl.getSelected(getTableRow());
079: }
080:
081: public void setSelected(Object object) {
082: tspl.setSelected(getTableRow(), object);
083: }
084:
085: public String createStart() {
086: ObjectListDataProvider startSchedules = (ObjectListDataProvider) getSessionAttribute("search.schedulingautoclassify.startschedules");
087: if (startSchedules == null) {
088: retrieveStartSchedules();
089: }
090:
091: if (startSchedules.canAppendRow()) {
092: startSchedules.appendRow();
093: startSchedules.commitChanges();
094: setSessionAttribute(
095: "search.schedulingautoclassify.startschedules",
096: startSchedules);
097: }
098:
099: return null;
100: }
101:
102: public String deleteStart() {
103: ObjectListDataProvider startSchedules = (ObjectListDataProvider) getSessionAttribute("search.schedulingautoclassify.startschedules");
104: if (startSchedules == null) {
105: retrieveStartSchedules();
106: }
107:
108: RowKey[] rowKeys = tableRowGroup.getRenderedRowKeys();
109: if (rowKeys != null) {
110: for (int index = 0; index < rowKeys.length; index++) {
111: RowKey rowKey = rowKeys[index];
112: if (tspl.isSelected(rowKey)
113: && startSchedules.isRowAvailable(rowKey)
114: && startSchedules.canRemoveRow(rowKey)) {
115: startSchedules.removeRow(rowKey);
116: }
117: }
118: startSchedules.commitChanges();
119: setSessionAttribute(
120: "search.schedulingautoclassify.startschedules",
121: startSchedules);
122: tableRowGroup.setFirst(0);
123: tspl.clear();
124: }
125:
126: return null;
127: }
128:
129: public String save() {
130: ArrayList originalSchedules = new ArrayList();
131: try {
132: LinkedList path = new LinkedList();
133: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
134: path.addFirst("scheduler");
135: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
136: AdminClientUtil.SCHEDULER_MBEAN_TYPE, path);
137:
138: Object[] params = { host, startCommand };
139: String[] signatures = { "java.lang.String",
140: "java.lang.String" };
141: ArrayList data = (ArrayList) getMBeanServerConnection()
142: .invoke(on, "getSchedules", params, signatures);
143: for (int index = 0; index < data.size(); index++) {
144: String string = (String) data.get(index);
145: originalSchedules.add(string);
146: }
147: } catch (Exception e) {
148: log(Level.SEVERE,
149: "SchedulingAutoclassifyBean.save() : Exception ", e);
150: }
151:
152: ArrayList newSchedules = new ArrayList();
153: ObjectListDataProvider startSchedules = (ObjectListDataProvider) getSessionAttribute("search.schedulingautoclassify.startschedules");
154: startSchedules.commitChanges();
155: List l = startSchedules.getList();
156: for (int index = 0; index < l.size(); index++) {
157: ScheduleBean sb = (ScheduleBean) l.get(index);
158: if (sb.initialized()) {
159: newSchedules.add(sb.getSchedule(startCommand));
160: }
161: }
162:
163: try {
164: LinkedList path = new LinkedList();
165: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
166: path.addFirst("scheduler");
167: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
168: AdminClientUtil.SCHEDULER_MBEAN_TYPE, path);
169:
170: if (originalSchedules.size() > 0) {
171: Object[] params = { host, originalSchedules };
172: String[] signatures = { "java.lang.String",
173: "java.util.List" };
174: getMBeanServerConnection().invoke(on, "unschedule",
175: params, signatures);
176: }
177: if (newSchedules.size() > 0) {
178: Object[] params = { host, newSchedules };
179: String[] signatures = { "java.lang.String",
180: "java.util.List" };
181: getMBeanServerConnection().invoke(on, "schedule",
182: params, signatures);
183: }
184: } catch (Exception e) {
185: log(Level.SEVERE,
186: "SchedulingAutoclassifyBean.save() : Exception ", e);
187: }
188:
189: return null;
190: }
191:
192: public String reset() {
193: retrieveStartSchedules();
194: return null;
195: }
196:
197: private void retrieveSearchServerHost() {
198: try {
199: LinkedList path = new LinkedList();
200: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
201: path
202: .addFirst((String) getSessionAttribute("search.server.selected"));
203: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
204: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
205: host = (String) getMBeanServerConnection().getAttribute(on,
206: "Host");
207: } catch (Exception e) {
208: log(
209: Level.SEVERE,
210: "SchedulingAutoclassifyBean.retrieveSearchServerHost() : Exception ",
211: e);
212: }
213: }
214:
215: private void retrieveStartCommand() {
216: try {
217: LinkedList path = new LinkedList();
218: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
219: path
220: .addFirst((String) getSessionAttribute("search.server.selected"));
221: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
222: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
223: Object[] params = {};
224: String[] signatures = {};
225: startCommand = (String) getMBeanServerConnection().invoke(
226: on, "retrieveStartAutoclassifyCommand", params,
227: signatures);
228: } catch (Exception e) {
229: log(
230: Level.SEVERE,
231: "SchedulingAutoclassifyBean.retrieveStartCommand() : Exception ",
232: e);
233: }
234: }
235:
236: private void retrieveStartSchedules() {
237: ArrayList al = new ArrayList();
238: try {
239: LinkedList path = new LinkedList();
240: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
241: path.addFirst("scheduler");
242: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
243: AdminClientUtil.SCHEDULER_MBEAN_TYPE, path);
244:
245: Object[] params = { host, startCommand };
246: String[] signatures = { "java.lang.String",
247: "java.lang.String" };
248: ArrayList data = (ArrayList) getMBeanServerConnection()
249: .invoke(on, "getSchedules", params, signatures);
250: for (int index = 0; index < data.size(); index++) {
251: String string = (String) data.get(index);
252: String[] strings = string.split("\\|");
253:
254: ScheduleBean sb = new ScheduleBean();
255: sb.initialize(strings[1].trim());
256: al.add(sb);
257: }
258: } catch (Exception e) {
259: log(
260: Level.SEVERE,
261: "SchedulingAutoclassifyBean.retrieveStartSchedules() : Exception ",
262: e);
263: }
264: ObjectListDataProvider startSchedules = new ObjectListDataProvider(
265: al);
266: startSchedules.setObjectType(ScheduleBean.class);
267:
268: setSessionAttribute(
269: "search.schedulingautoclassify.startschedules",
270: startSchedules);
271: }
272:
273: private RowKey getTableRow() {
274: FacesContext fc = FacesContext.getCurrentInstance();
275: ValueBinding vb = fc.getApplication().createValueBinding(
276: "#{startSchedule.tableRow}");
277: return (RowKey) vb.getValue(fc);
278: }
279:
280: }
|