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 SchemasBean extends PSBaseBean {
036:
037: private ObjectListDataProvider schemas = null;
038:
039: public SchemasBean() {
040: retrieveSchemas();
041: }
042:
043: public Option[] getAvailableDataTypes() {
044: Option[] dataTypeOptions = new Option[5];
045: dataTypeOptions[0] = new Option("", getLocalizedString(
046: "search", "search.general.select"));
047: dataTypeOptions[1] = new Option("blob", getLocalizedString(
048: "search", "search.schema.datatype.blob"));
049: dataTypeOptions[2] = new Option("date", getLocalizedString(
050: "search", "search.schema.datatype.date"));
051: dataTypeOptions[3] = new Option("int", getLocalizedString(
052: "search", "search.schema.datatype.integer"));
053: dataTypeOptions[4] = new Option("string", getLocalizedString(
054: "search", "search.schema.datatype.string"));
055: return dataTypeOptions;
056: }
057:
058: public ObjectListDataProvider getSchemas() {
059: return schemas;
060: }
061:
062: public void setSchemas(ObjectListDataProvider schemas) {
063: this .schemas = schemas;
064: }
065:
066: public String gotoCreateSchema() {
067: return "gotoCreateSchema";
068: }
069:
070: public String gotoEditSchema() {
071: FacesContext fc = FacesContext.getCurrentInstance();
072: ValueBinding vb = fc.getApplication().createValueBinding(
073: "#{schema.value.name}");
074: setSessionAttribute("search.schema.selected", (String) vb
075: .getValue(fc));
076: return "gotoEditSchema";
077: }
078:
079: public String delete() {
080: try {
081: LinkedList path = new LinkedList();
082: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
083: path
084: .addFirst((String) getSessionAttribute("search.server.selected"));
085: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
086: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
087:
088: List l = Checkbox.getSelected("checkbox");
089: for (int index = 0; index < l.size(); index++) {
090: Object[] params = { (String) l.get(index) };
091: String[] signatures = { "java.lang.String" };
092: getMBeanServerConnection().invoke(on, "deleteSchema",
093: params, signatures);
094: }
095: } catch (Exception e) {
096: log(Level.SEVERE, "SchemasBean.delete() : Exception ", e);
097: }
098: retrieveSchemas();
099: return null;
100: }
101:
102: public String restore() {
103: try {
104: LinkedList path = new LinkedList();
105: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
106: path
107: .addFirst((String) getSessionAttribute("search.server.selected"));
108: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
109: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
110:
111: Object[] params = {};
112: String[] signatures = {};
113: getMBeanServerConnection().invoke(on, "restoreSchema",
114: params, signatures);
115: } catch (Exception e) {
116: log(Level.SEVERE, "SchemasBean.restore() : Exception ", e);
117: }
118: retrieveSchemas();
119: return null;
120: }
121:
122: private void retrieveSchemas() {
123: ArrayList al = new ArrayList();
124: try {
125: LinkedList path = new LinkedList();
126: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
127: path
128: .addFirst((String) getSessionAttribute("search.server.selected"));
129: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
130: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
131:
132: Object[] params1 = {};
133: String[] signatures1 = {};
134: ArrayList data = (ArrayList) getMBeanServerConnection()
135: .invoke(on, "retrieveAllSchema", params1,
136: signatures1);
137: for (int index = 0; index < data.size(); index++) {
138: String name = (String) data.get(index);
139:
140: Object[] params2 = { name };
141: String[] signatures2 = { "java.lang.String" };
142: Properties p = (Properties) getMBeanServerConnection()
143: .invoke(on, "getSchemaAttributes", params2,
144: signatures2);
145: if (p.getProperty("noninternal").equals("true")) {
146: SchemaBean sb = new SchemaBean();
147: sb.initialize(name, p);
148: al.add(sb);
149: }
150: }
151: } catch (Exception e) {
152: log(Level.SEVERE,
153: "SchemasBean.retrieveSchemas() : Exception ", e);
154: }
155: schemas = new ObjectListDataProvider(al);
156: schemas.setObjectType(SchemaBean.class);
157: }
158:
159: }
|