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 EditResourceDescriptionBean extends PSBaseBean {
038:
039: private ObjectListDataProvider attributes = null;
040:
041: public EditResourceDescriptionBean() {
042: attributes = (ObjectListDataProvider) getSessionAttribute("search.editresourcedescription.attributes");
043: if (attributes == null) {
044: ArrayList al1 = 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: String searchType = "by_url";
056: String query = (String) getSessionAttribute("search.resourcedescription.selected");
057: ArrayList viewAttributes = new ArrayList();
058: Integer startPage = new Integer(0);
059: Integer hitsPerPage = new Integer(0);
060: String database = (String) getSessionAttribute("search.database.selected");
061: Object[] params1 = { searchType, query, viewAttributes,
062: startPage, hitsPerPage, database };
063: String[] signatures1 = { "java.lang.String",
064: "java.lang.String", "java.util.List",
065: "java.lang.Integer", "java.lang.Integer",
066: "java.lang.String" };
067: ArrayList data = (ArrayList) getMBeanServerConnection()
068: .invoke(on, "getAllResourceDescriptions",
069: params1, signatures1);
070:
071: ArrayList al2 = (ArrayList) data.get(3);
072: for (int index = 0; index < al2.size(); index++) {
073: HashMap hm = (HashMap) al2.get(index);
074: Iterator i = hm.keySet().iterator();
075: while (i.hasNext()) {
076: String key = (String) i.next();
077: ArrayList values = (ArrayList) hm.get(key);
078:
079: Object[] params2 = { key };
080: String[] signatures2 = { "java.lang.String" };
081: Properties p = (Properties) getMBeanServerConnection()
082: .invoke(on, "getSchemaAttributes",
083: params2, signatures2);
084: if (p.containsKey("editable")
085: && p.getProperty("editable").equals(
086: "true")) {
087: ResourceDescriptionAttributeBean rdab = new ResourceDescriptionAttributeBean();
088: rdab.initialize(key, values, true);
089: al1.add(rdab);
090: } else {
091: ResourceDescriptionAttributeBean rdab = new ResourceDescriptionAttributeBean();
092: rdab.initialize(key, values, false);
093: al1.add(rdab);
094: }
095: }
096: }
097: } catch (Exception e) {
098: log(
099: Level.SEVERE,
100: "EditResourceDescriptionBean.EditResourceDescriptionBean() : Exception ",
101: e);
102: }
103: attributes = new ObjectListDataProvider(al1);
104: attributes
105: .setObjectType(ResourceDescriptionAttributeBean.class);
106:
107: setSessionAttribute(
108: "search.editresourcedescription.attributes",
109: attributes);
110: }
111: }
112:
113: public boolean getShowError() {
114: String value = (String) getSessionAttribute("search.editresourcedescription.showerror");
115: if (value == null || value.equals("false")) {
116: return false;
117: } else {
118: return true;
119: }
120: }
121:
122: public String getPageTitle() {
123: MessageFormat mf = new MessageFormat("");
124: mf.applyPattern(getLocalizedString("search",
125: "search.editresourcedescription.pagetitle"));
126: return mf
127: .format(new Object[] { (String) getSessionAttribute("search.resourcedescription.selected") });
128: }
129:
130: public ObjectListDataProvider getAttributes() {
131: return attributes;
132: }
133:
134: public void setAttributes(ObjectListDataProvider attributes) {
135: this .attributes = attributes;
136: }
137:
138: public String gotoEditResourceDescriptionAttribute() {
139: FacesContext fc = FacesContext.getCurrentInstance();
140: ValueBinding vb = fc.getApplication().createValueBinding(
141: "#{attribute.value.key}");
142: String key = (String) vb.getValue(fc);
143:
144: attributes.commitChanges();
145: List l = attributes.getList();
146: for (int index = 0; index < l.size(); index++) {
147: ResourceDescriptionAttributeBean rdab = (ResourceDescriptionAttributeBean) l
148: .get(index);
149: if (rdab.key.equals(key)) {
150: setSessionAttribute(
151: "search.resourcedescriptionattribute.rdab",
152: rdab);
153: setSessionAttribute(
154: "search.resourcedescriptionattribute.return",
155: "gotoEditResourceDescription");
156: return "gotoEditResourceDescriptionAttribute";
157: }
158: }
159: return null;
160: }
161:
162: public String save() {
163: HashMap hm = new HashMap();
164:
165: attributes.commitChanges();
166: List l = attributes.getList();
167: for (int index = 0; index < l.size(); index++) {
168: ResourceDescriptionAttributeBean rdab = (ResourceDescriptionAttributeBean) l
169: .get(index);
170: if (rdab.getEditable() && rdab.changed()) {
171: hm.put(rdab.key, rdab.newValues);
172: }
173: }
174:
175: if (!hm.isEmpty()) {
176: try {
177: LinkedList path = new LinkedList();
178: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
179: path
180: .addFirst((String) getSessionAttribute("search.server.selected"));
181: ObjectName on = AdminClientUtil
182: .getResourceMBeanObjectName(
183: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE,
184: path);
185:
186: ArrayList al = new ArrayList();
187: al
188: .add((String) getSessionAttribute("search.resourcedescription.selected"));
189:
190: Object[] params = {
191: al,
192: hm,
193: (String) getSessionAttribute("search.database.selected") };
194: String[] signatures = { "java.util.List",
195: "java.util.Map", "java.lang.String" };
196: getMBeanServerConnection().invoke(on,
197: "editResourceDescriptions", params, signatures);
198:
199: setSessionAttribute(
200: "search.editresourcedescription.showerror",
201: "false");
202: return "gotoDatabaseResourceDescriptionsHome";
203: } catch (Exception e) {
204: log(
205: Level.SEVERE,
206: "EditResourceDescriptionBean.save() : Exception ",
207: e);
208: setSessionAttribute(
209: "search.editresourcedescription.showerror",
210: "true");
211: return null;
212: }
213: } else {
214: return "gotoDatabaseResourceDescriptionsHome";
215: }
216: }
217:
218: public String cancel() {
219: setSessionAttribute("search.editresourcedescription.showerror",
220: "false");
221: return "gotoDatabaseResourceDescriptionsHome";
222: }
223:
224: }
|