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: import com.sun.web.ui.event.*;
029:
030: import com.sun.data.provider.*;
031: import com.sun.data.provider.impl.ObjectListDataProvider;
032:
033: import com.sun.cacao.agent.JmxClient;
034:
035: import com.sun.portal.admin.common.util.AdminClientUtil;
036: import com.sun.portal.admin.console.common.PSBaseBean;
037:
038: public class CreateResourceDescriptionBean extends PSBaseBean {
039:
040: private String url = null;
041: private ObjectListDataProvider attributes = null;
042:
043: public CreateResourceDescriptionBean() {
044: url = (String) getSessionAttribute("search.createresourcedescription.url");
045: if (url == null) {
046: url = "";
047: setSessionAttribute("search.createresourcedescription.url",
048: url);
049: }
050:
051: attributes = (ObjectListDataProvider) getSessionAttribute("search.createresourcedescription.attributes");
052: if (attributes == null) {
053: ArrayList al = new ArrayList();
054: try {
055: LinkedList path = new LinkedList();
056: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
057: path
058: .addFirst((String) getSessionAttribute("search.server.selected"));
059: ObjectName on = AdminClientUtil
060: .getResourceMBeanObjectName(
061: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE,
062: path);
063:
064: Object[] params1 = {};
065: String[] signatures1 = {};
066: ArrayList data = (ArrayList) getMBeanServerConnection()
067: .invoke(on, "retrieveAllSchema", params1,
068: signatures1);
069: for (int index = 0; index < data.size(); index++) {
070: String name = (String) data.get(index);
071: Object[] params2 = { name };
072: String[] signatures2 = { "java.lang.String" };
073: Properties p = (Properties) getMBeanServerConnection()
074: .invoke(on, "getSchemaAttributes", params2,
075: signatures2);
076: if (p.containsKey("editable")
077: && p.getProperty("editable").equals("true")) {
078: ResourceDescriptionAttributeBean rdab = new ResourceDescriptionAttributeBean();
079: rdab.initialize(name, new ArrayList(), true);
080: al.add(rdab);
081: }
082: }
083: } catch (Exception e) {
084: log(
085: Level.SEVERE,
086: "CreateResourceDescriptionBean.retrieveAttributes() : Exception ",
087: e);
088: }
089: attributes = new ObjectListDataProvider(al);
090: attributes
091: .setObjectType(ResourceDescriptionAttributeBean.class);
092:
093: setSessionAttribute(
094: "search.createresourcedescription.attributes",
095: attributes);
096: }
097: }
098:
099: public boolean getShowError() {
100: String value = (String) getSessionAttribute("search.createresourcedescription.showerror");
101: if (value == null || value.equals("false")) {
102: return false;
103: } else {
104: return true;
105: }
106: }
107:
108: public String getUrl() {
109: return url;
110: }
111:
112: public void setUrl(String url) {
113: this .url = url;
114: setSessionAttribute("search.createresourcedescription.url", url);
115: }
116:
117: public ObjectListDataProvider getAttributes() {
118: return attributes;
119: }
120:
121: public void setAttributes(ObjectListDataProvider attributes) {
122: this .attributes = attributes;
123: setSessionAttribute(
124: "search.createresourcedescription.attributes",
125: attributes);
126: }
127:
128: public String gotoEditResourceDescriptionAttribute() {
129: FacesContext fc = FacesContext.getCurrentInstance();
130: ValueBinding vb = fc.getApplication().createValueBinding(
131: "#{attribute.value.key}");
132: String key = (String) vb.getValue(fc);
133:
134: attributes.commitChanges();
135: List l = attributes.getList();
136: for (int index = 0; index < l.size(); index++) {
137: ResourceDescriptionAttributeBean rdab = (ResourceDescriptionAttributeBean) l
138: .get(index);
139: if (rdab.key.equals(key)) {
140: setSessionAttribute(
141: "search.resourcedescriptionattribute.rdab",
142: rdab);
143: setSessionAttribute(
144: "search.resourcedescriptionattribute.return",
145: "gotoCreateResourceDescription");
146: return "gotoEditResourceDescriptionAttribute";
147: }
148: }
149: return null;
150: }
151:
152: public void validate(FacesContext fc, UIComponent component,
153: Object value) throws ValidatorException {
154: String id = component.getId();
155: if (id.equals("url")) {
156: if (Validators.containsSpace((String) value)) {
157: throw new ValidatorException(new FacesMessage(
158: FacesMessage.SEVERITY_ERROR,
159: getLocalizedString("search",
160: "search.error.error"),
161: getLocalizedString("search",
162: "search.error.space")));
163: }
164: if (Validators.containsSpecialCharacters((String) value)) {
165: throw new ValidatorException(new FacesMessage(
166: FacesMessage.SEVERITY_ERROR,
167: getLocalizedString("search",
168: "search.error.error"),
169: getLocalizedString("search",
170: "search.error.specialcharacters")));
171: }
172: }
173: }
174:
175: public String create() {
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.getResourceMBeanObjectName(
182: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
183:
184: HashMap hm = new HashMap();
185:
186: ArrayList al = new ArrayList();
187: al.add(url);
188: hm.put("url", al);
189:
190: attributes.commitChanges();
191: List l = attributes.getList();
192: for (int index = 0; index < l.size(); index++) {
193: ResourceDescriptionAttributeBean rdabScan = (ResourceDescriptionAttributeBean) l
194: .get(index);
195: hm.put(rdabScan.key, rdabScan.newValues);
196: }
197:
198: Object[] params = {
199: hm,
200: (String) getSessionAttribute("search.database.selected") };
201: String[] signatures = { "java.util.Map", "java.lang.String" };
202: getMBeanServerConnection().invoke(on,
203: "createResourceDescription", params, signatures);
204:
205: setSessionAttribute(
206: "search.createresourcedescription.showerror",
207: "false");
208: return "gotoDatabaseResourceDescriptionsHome";
209: } catch (Exception e) {
210: log(Level.SEVERE, "CreateResourceDescriptionBean.create()",
211: e);
212: setSessionAttribute(
213: "search.createresourcedescription.showerror",
214: "true");
215: return null;
216: }
217: }
218:
219: public String cancel() {
220: setSessionAttribute(
221: "search.createresourcedescription.showerror", "false");
222: return "gotoDatabaseResourceDescriptionsHome";
223: }
224:
225: }
|