001: /**
002: * Copyright 2004-2005 jManage.org
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */package org.jmanage.webui.forms;
016:
017: import org.apache.struts.action.ActionErrors;
018: import org.apache.struts.action.ActionMapping;
019: import org.apache.struts.action.ActionError;
020: import org.jmanage.core.config.*;
021: import org.jmanage.core.util.ErrorCodes;
022: import org.jmanage.webui.validator.Validator;
023:
024: import javax.servlet.http.HttpServletRequest;
025:
026: /**
027: *
028: * date: Jun 25, 2004
029: * @author Rakesh Kalra, Shashank Bellary
030: */
031: public class ApplicationForm extends BaseForm {
032:
033: public static final String FORM_PASSWORD = "$$$$$$$$";
034:
035: private String appId;
036: private String name;
037: private String host;
038: private String port;
039: private String url;
040: private String username;
041: private String password;
042: private String type;
043:
044: // jsr160 only
045: private String jndiFactory;
046: private String jndiURL;
047:
048: public String getApplicationId() {
049: return appId;
050: }
051:
052: public void setApplicationId(String appId) {
053: this .appId = appId;
054: }
055:
056: public String getName() {
057: return name;
058: }
059:
060: public void setName(String name) {
061: this .name = name;
062: }
063:
064: public String getHost() {
065: return host;
066: }
067:
068: public void setHost(String host) {
069: this .host = host;
070: }
071:
072: public String getPort() {
073: return port;
074: }
075:
076: public void setPort(String port) {
077: this .port = port;
078: }
079:
080: public String getURL() {
081: return url;
082: }
083:
084: public void setURL(String url) {
085: this .url = url;
086: }
087:
088: public String getUsername() {
089: return username;
090: }
091:
092: public void setUsername(String username) {
093: this .username = username;
094: }
095:
096: public String getPassword() {
097: return password;
098: }
099:
100: public void setPassword(String password) {
101: this .password = password;
102: }
103:
104: public String getType() {
105: return type;
106: }
107:
108: public void setType(String type) {
109: this .type = type;
110: }
111:
112: public void setJndiFactory(String jndiFactory) {
113: if (jndiFactory != null && jndiFactory.length() > 0)
114: this .jndiFactory = jndiFactory;
115: }
116:
117: public String getJndiFactory() {
118: return jndiFactory;
119: }
120:
121: public void setJndiURL(String jndiURL) {
122: if (jndiURL != null && jndiURL.length() > 0)
123: this .jndiURL = jndiURL;
124: }
125:
126: public String getJndiURL() {
127: return jndiURL;
128: }
129:
130: public ActionErrors validate(ActionMapping mapping,
131: HttpServletRequest request) {
132: ActionErrors errors = super .validate(mapping, request);
133: if (errors == null || errors.isEmpty()) {
134: if (name.indexOf("/") != -1) {
135: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
136: ErrorCodes.INVALID_CHAR_APP_NAME));
137: }
138: ApplicationType appType = ApplicationTypes
139: .getApplicationType(type);
140: MetaApplicationConfig metaAppConfig = appType.getModule()
141: .getMetaApplicationConfig();
142: if (metaAppConfig.isDisplayHost()) {
143: Validator.validateRequired(host, "Host Name", errors);
144: }
145: if (metaAppConfig.isDisplayPort()) {
146: if (Validator.validateRequired(port, "Port Number",
147: errors)) {
148: Validator.validateInteger(port, "Port Number",
149: errors);
150: }
151: }
152: if (metaAppConfig.isDisplayURL()) {
153: Validator.validateRequired(url, "URL", errors);
154: }
155: }
156: return errors;
157: }
158: }
|