001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: JoramReaderWriterForm.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.joramplatform;
025:
026: import javax.management.MalformedObjectNameException;
027: import javax.management.ObjectName;
028: import javax.servlet.http.HttpServletRequest;
029:
030: import org.apache.struts.action.ActionErrors;
031: import org.apache.struts.action.ActionForm;
032: import org.apache.struts.action.ActionMapping;
033: import org.apache.struts.action.ActionMessage;
034: import org.objectweb.jonas.jmx.JoramObjectName;
035: import org.objectweb.jonas.jmx.JonasManagementRepr;
036: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
037:
038: /**
039: * @author Adriana Danes
040: */
041: public class JoramReaderWriterForm extends ActionForm {
042:
043: // --------------------------------------------------------- Constants
044:
045: // --------------------------------------------------------- Properties variables
046:
047: private String name = null;
048: private String id = null;
049:
050: // --------------------------------------------------------- Public Methods
051:
052: /**
053: * Reset all properties to their default values.
054: *
055: * @param mapping The mapping used to select this instance
056: * @param request The servlet request we are processing
057: */
058:
059: public void reset(ActionMapping mapping, HttpServletRequest request) {
060: name = null;
061: id = null;
062: }
063:
064: /**
065: * Validate the properties that have been set from this HTTP request,
066: * and return an <code>ActionErrors</code> object that encapsulates any
067: * validation errors that have been found. If no errors are found, return
068: * <code>null</code> or an <code>ActionErrors</code> object with no
069: * recorded error messages.
070: *
071: * @param mapping The mapping used to select this instance
072: * @param request The servlet request we are processing
073: * @return List of errors
074: */
075: public ActionErrors validate(ActionMapping mapping,
076: HttpServletRequest request) {
077:
078: WhereAreYou oWhere = (WhereAreYou) request.getSession()
079: .getAttribute(WhereAreYou.SESSION_NAME);
080: String serverName = oWhere.getCurrentJonasServerName();
081:
082: ActionErrors oErrors = new ActionErrors();
083: if ((getName() == null) || (getName().length() == 0)) {
084: oErrors.add("name", new ActionMessage(
085: "error.resource.jms.addreader.name.required"));
086: }
087: if (getId() == null) {
088: oErrors.add("id", new ActionMessage(
089: "error.resource.jms.addreader.id.required"));
090: }
091: String ons = getName() + "[" + id + "]";
092: try {
093: ObjectName userOn = JoramObjectName.joramUser(ons);
094: if (!JonasManagementRepr.isRegistered(userOn, serverName)) {
095: oErrors.add("name", new ActionMessage(
096: "error.resource.jms.addreader.name.error"));
097: }
098: } catch (MalformedObjectNameException e) {
099: oErrors.add("name", new ActionMessage(
100: "error.resource.jms.addreader.name.error"));
101:
102: }
103: return oErrors;
104: }
105:
106: // --------------------------------------------------------- Properties Methods
107:
108: public String getName() {
109: return name;
110: }
111:
112: public void setName(String name) {
113: this .name = name;
114: }
115:
116: /**
117: * @return Returns the id.
118: */
119: public String getId() {
120: return id;
121: }
122:
123: /**
124: * @param id The id to set.
125: */
126: public void setId(String id) {
127: this.id = id;
128: }
129:
130: }
|