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: import java.text.*;
018:
019: import javax.faces.context.FacesContext;
020: import javax.faces.el.ValueBinding;
021: import javax.faces.application.FacesMessage;
022: import javax.faces.component.UIComponent;
023: import javax.faces.validator.*;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.management.*;
026:
027: import com.sun.web.ui.model.*;
028:
029: import com.sun.data.provider.*;
030: import com.sun.data.provider.impl.ObjectListDataProvider;
031:
032: import com.sun.cacao.agent.JmxClient;
033:
034: import com.sun.portal.admin.common.util.AdminClientUtil;
035: import com.sun.portal.admin.console.common.PSBaseBean;
036:
037: public class EditResourceDescriptionsBean extends PSBaseBean {
038:
039: private ObjectListDataProvider attributes = null;
040:
041: public EditResourceDescriptionsBean() {
042: attributes = (ObjectListDataProvider) getSessionAttribute("search.editresourcedescriptions.attributes");
043: if (attributes == null) {
044: ArrayList al = new ArrayList();
045: try {
046: LinkedList path = new LinkedList();
047: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
048: path
049: .addFirst((String) getSessionAttribute("search.server.selected"));
050: ObjectName on = AdminClientUtil
051: .getResourceMBeanObjectName(
052: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE,
053: path);
054:
055: Object[] params1 = {};
056: String[] signatures1 = {};
057: ArrayList data = (ArrayList) getMBeanServerConnection()
058: .invoke(on, "retrieveAllSchema", params1,
059: signatures1);
060: for (int index = 0; index < data.size(); index++) {
061: String key = (String) data.get(index);
062:
063: Object[] params2 = { key };
064: String[] signatures2 = { "java.lang.String" };
065: Properties p = (Properties) getMBeanServerConnection()
066: .invoke(on, "getSchemaAttributes", params2,
067: signatures2);
068: if (p.containsKey("editable")
069: && p.getProperty("editable").equals("true")) {
070: ResourceDescriptionAttributeBean rdab = new ResourceDescriptionAttributeBean();
071: rdab.initialize(key, new ArrayList(), true);
072: al.add(rdab);
073: }
074: }
075: } catch (Exception e) {
076: log(
077: Level.SEVERE,
078: "EditResourceDescriptionsBean.EditResourceDescriptionsBean() : Exception ",
079: e);
080: }
081: attributes = new ObjectListDataProvider(al);
082: attributes
083: .setObjectType(ResourceDescriptionAttributeBean.class);
084:
085: setSessionAttribute(
086: "search.editresourcedescriptions.attributes",
087: attributes);
088: }
089: }
090:
091: public boolean getShowError() {
092: String value = (String) getSessionAttribute("search.editresourcedescriptions.showerror");
093: if (value == null || value.equals("false")) {
094: return false;
095: } else {
096: return true;
097: }
098: }
099:
100: public ObjectListDataProvider getAttributes() {
101: return attributes;
102: }
103:
104: public void setAttributes(ObjectListDataProvider attributes) {
105: this .attributes = attributes;
106: }
107:
108: public String gotoEditResourceDescriptionAttribute() {
109: FacesContext fc = FacesContext.getCurrentInstance();
110: ValueBinding vb = fc.getApplication().createValueBinding(
111: "#{attribute.value.key}");
112: String key = (String) vb.getValue(fc);
113:
114: attributes.commitChanges();
115: List l = attributes.getList();
116: for (int index = 0; index < l.size(); index++) {
117: ResourceDescriptionAttributeBean rdab = (ResourceDescriptionAttributeBean) l
118: .get(index);
119: if (rdab.key.equals(key)) {
120: setSessionAttribute(
121: "search.resourcedescriptionattribute.rdab",
122: rdab);
123: setSessionAttribute(
124: "search.resourcedescriptionattribute.return",
125: "gotoEditResourceDescriptions");
126: return "gotoEditResourceDescriptionAttribute";
127: }
128: }
129: return null;
130: }
131:
132: public String save() {
133: HashMap hm = new HashMap();
134:
135: attributes.commitChanges();
136: List l = attributes.getList();
137: for (int index = 0; index < l.size(); index++) {
138: ResourceDescriptionAttributeBean rdab = (ResourceDescriptionAttributeBean) l
139: .get(index);
140: if (rdab.getApply()) {
141: hm.put(rdab.key, rdab.newValues);
142: }
143: }
144:
145: if (!hm.isEmpty()) {
146: try {
147: LinkedList path = new LinkedList();
148: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
149: path
150: .addFirst((String) getSessionAttribute("search.server.selected"));
151: ObjectName on = AdminClientUtil
152: .getResourceMBeanObjectName(
153: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE,
154: path);
155:
156: Object[] params = {
157: getSessionAttribute("search.resourcedescriptions.selected"),
158: hm,
159: (String) getSessionAttribute("search.database.selected") };
160: String[] signatures = { "java.util.List",
161: "java.util.Map", "java.lang.String" };
162: getMBeanServerConnection().invoke(on,
163: "editResourceDescriptions", params, signatures);
164:
165: setSessionAttribute(
166: "search.editresourcedescriptions.showerror",
167: "false");
168: return "gotoDatabaseResourceDescriptionsHome";
169: } catch (Exception e) {
170: log(
171: Level.SEVERE,
172: "EditResourceDescriptionsBean.save() : Exception ",
173: e);
174: setSessionAttribute(
175: "search.editresourcedescriptions.showerror",
176: "true");
177: return null;
178: }
179: } else {
180: return "gotoDatabaseResourceDescriptionsHome";
181: }
182: }
183:
184: public String cancel() {
185: setSessionAttribute(
186: "search.editresourcedescriptions.showerror", "false");
187: return "gotoDatabaseResourceDescriptionsHome";
188: }
189:
190: }
|