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.validator.*;
022: import javax.servlet.http.HttpServletRequest;
023: import javax.management.*;
024:
025: import com.sun.web.ui.model.*;
026: import com.sun.web.ui.event.*;
027:
028: import com.sun.data.provider.*;
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 CreateSchemaBean extends PSBaseBean {
036:
037: public String name = "";
038: public String description = "";
039: public String aliases = "";
040: public String editable = "true";
041: public String indexable = "true";
042: public String scoreMultiplier = "";
043: public String dataType = "";
044:
045: public CreateSchemaBean() {
046: name = "";
047: description = "";
048: aliases = "";
049: editable = "true";
050: indexable = "true";
051: scoreMultiplier = "";
052: dataType = "";
053: }
054:
055: public boolean getShowError() {
056: String value = (String) getSessionAttribute("search.createschema.showerror");
057: if (value == null || value.equals("false")) {
058: return false;
059: } else {
060: return true;
061: }
062: }
063:
064: public Option[] getAvailableBoolean() {
065: Option[] options = new Option[2];
066: options[0] = new Option("true", getLocalizedString("search",
067: "search.general.true"));
068: options[1] = new Option("false", getLocalizedString("search",
069: "search.general.false"));
070: return options;
071: }
072:
073: public String getName() {
074: return name;
075: }
076:
077: public void setName(String name) {
078: this .name = name;
079: }
080:
081: public String getDescription() {
082: return description;
083: }
084:
085: public void setDescription(String description) {
086: this .description = description;
087: }
088:
089: public String getAliases() {
090: return aliases;
091: }
092:
093: public void setAliases(String aliases) {
094: this .aliases = aliases;
095: }
096:
097: public String getEditable() {
098: return editable;
099: }
100:
101: public void setEditable(String editable) {
102: this .editable = editable;
103: }
104:
105: public String getIndexable() {
106: return indexable;
107: }
108:
109: public void setIndexable(String indexable) {
110: this .indexable = indexable;
111: }
112:
113: public String getScoreMultiplier() {
114: return scoreMultiplier;
115: }
116:
117: public void setScoreMultiplier(String scoreMultiplier) {
118: this .scoreMultiplier = scoreMultiplier;
119: }
120:
121: public String getDataType() {
122: return dataType;
123: }
124:
125: public void setDataType(String dataType) {
126: this .dataType = dataType;
127: }
128:
129: public void validate(FacesContext fc, UIComponent component,
130: Object value) throws ValidatorException {
131: String id = component.getId();
132: if (id.equals("name")) {
133: if (Validators.containsSpace((String) value)) {
134: throw new ValidatorException(new FacesMessage(
135: FacesMessage.SEVERITY_ERROR,
136: getLocalizedString("search",
137: "search.error.error"),
138: getLocalizedString("search",
139: "search.error.space")));
140: }
141: if (Validators.containsSpecialCharacters((String) value)) {
142: throw new ValidatorException(new FacesMessage(
143: FacesMessage.SEVERITY_ERROR,
144: getLocalizedString("search",
145: "search.error.error"),
146: getLocalizedString("search",
147: "search.error.specialcharacters")));
148: }
149: if (Validators.containsInvalidCharacters((String) value)) {
150: throw new ValidatorException(new FacesMessage(
151: FacesMessage.SEVERITY_ERROR,
152: getLocalizedString("search",
153: "search.error.error"),
154: getLocalizedString("search",
155: "search.error.invalidcharacters")));
156: }
157: if (isDuplicate((String) value)) {
158: throw new ValidatorException(new FacesMessage(
159: FacesMessage.SEVERITY_ERROR,
160: getLocalizedString("search",
161: "search.error.error"),
162: getLocalizedString("search",
163: "search.error.duplicateschema")));
164: }
165: } else if (id.equals("description")) {
166: } else if (id.equals("aliases")) {
167: } else if (id.equals("scoreMultiplier")) {
168: if (!Validators.isFloat((String) value, true)) {
169: throw new ValidatorException(new FacesMessage(
170: FacesMessage.SEVERITY_ERROR,
171: getLocalizedString("search",
172: "search.error.error"),
173: getLocalizedString("search",
174: "search.error.positivenumber")));
175: }
176: }
177: }
178:
179: public String create() {
180: try {
181: LinkedList path = new LinkedList();
182: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
183: path
184: .addFirst((String) getSessionAttribute("search.server.selected"));
185: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
186: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
187:
188: Object[] params = { name, description, aliases,
189: new Boolean(editable), new Boolean(indexable),
190: scoreMultiplier, dataType };
191: String[] signatures = { "java.lang.String",
192: "java.lang.String", "java.lang.String",
193: "java.lang.Boolean", "java.lang.Boolean",
194: "java.lang.String", "java.lang.String" };
195: getMBeanServerConnection().invoke(on, "createSchema",
196: params, signatures);
197:
198: setSessionAttribute("search.createschema.showerror",
199: "false");
200: return "gotoDatabaseSchemasHome";
201: } catch (Exception e) {
202: log(Level.SEVERE, "CreateSchemaBean.create() : Exception ",
203: e);
204: setSessionAttribute("search.createschema.showerror", "true");
205: return null;
206: }
207: }
208:
209: public String cancel() {
210: setSessionAttribute("search.createschema.showerror", "false");
211: return "gotoDatabaseSchemasHome";
212: }
213:
214: private boolean isDuplicate(String value) {
215: try {
216: LinkedList path = new LinkedList();
217: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
218: path
219: .addFirst((String) getSessionAttribute("search.server.selected"));
220: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
221: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
222:
223: Object[] params = {};
224: String[] signatures = {};
225: ArrayList data = (ArrayList) getMBeanServerConnection()
226: .invoke(on, "retrieveAllSchema", params, signatures);
227: for (int index = 0; index < data.size(); index++) {
228: String name = (String) data.get(index);
229: if (name.equals(value)) {
230: return true;
231: }
232: }
233: } catch (Exception e) {
234: }
235: return false;
236: }
237:
238: }
|