001 /* 002 * Copyright 2001,2004 The Apache Software Foundation. 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 */ 016 017 package org.apache.commons.scaffold.util; 018 019 020 import java.util.Locale; 021 import java.util.Map; 022 023 import org.apache.commons.beanutils.BeanUtils; 024 025 // ------------------------------------------------------------------------ 78 026 027 /** 028 * Base implementation of ProcessBean with default functionality. 029 * The only method that must be overridden is 030 * <code>Object execute(Object)</code>. 031 * :TODO: Change from BeanUtil.populate to copyProperties in 1.1 032 * version. 033 * @author Ted Husted 034 * @version $Revision: 155464 $ $Date: 2005-02-26 13:26:54 +0000 (Sat, 26 Feb 2005) $ 035 */ 036 public abstract class ProcessBeanBase implements ProcessBean { 037 038 // ----------------------------------------------------------- Properties 039 040 041 /** 042 * The locale for this bean instance, if any. 043 */ 044 private Locale locale = null; 045 046 047 public Locale getLocale() { 048 return this.locale; 049 } 050 051 052 public void setLocale(Locale locale) { 053 this.locale = locale; 054 } 055 056 057 /** 058 * The remoteNode for this bean instance, if any. 059 */ 060 private Integer remoteNode = null; 061 062 063 public Integer getRemoteNode() { 064 return this.remoteNode; 065 } 066 067 068 public void setRemoteNode(Integer remoteNode) { 069 this.remoteNode = remoteNode; 070 } 071 072 073 /** 074 * Set the remoteNode using a String in 075 * the format usually given 076 * by the REMOTE_ADDR CGI variable, or 077 * ServletRequest.getRemoteAddr(). 078 * NOTE: <b>not implemented; returns 0</b>. 079 * @return An Integer value based on RemoteAddr string. 080 */ 081 public void setRemoteAddr(String remoteAddr) { 082 083 setRemoteNode(new Integer(0)); // :FIXME: 084 085 } 086 087 088 /** 089 * Return the String representation 090 * of an IP address expressed 091 * as an Integer, into the format usually given 092 * by the REMOTE_ADDR CGI variable, or 093 * ServletRequest.getRemoteAddr(). 094 * NOTE: <b>not implemented; returns zeros.</b> 095 * @return An Integer value based on RemoteAddr string. 096 */ 097 public String getRemoteAddr() { 098 099 return new String("000.000.000.000"); // :FIXME: 100 101 } 102 103 104 /** 105 * The remote server object for this bean instance, if any. 106 * This is often an application-scope object that can be used 107 * to process a JDBC query or equivalent. 108 * By default, the ProcessAction will set this to any 109 * application scope object found under the key "REMOTE_SERVER", 110 * or to null. 111 */ 112 private Object server = null; 113 114 115 public Object getRemoteServer() { 116 return this.server; 117 } 118 119 120 public void setRemoteServer(Object server) { 121 this.server = server; 122 } 123 124 125 /** 126 * The parameter 127 */ 128 private String parameter = null; 129 130 131 public String getParameter() { 132 return (this.parameter); 133 } 134 135 136 public void setParameter(String parameter) { 137 this.parameter = parameter; 138 } 139 140 141 // --------------------------------------------------------- Public Methods 142 143 144 /** 145 * Perform business logic for this bean. 146 * Called by other execute signatures (after populating 147 * subclass properties). 148 * The default implementation returns the bean instance (this). 149 * Subclasses should override to provide functionality. 150 * @exception Subclasses can throw any Exception 151 */ 152 public Object execute() throws Exception { 153 154 return this; 155 156 } // end execute 157 158 159 /** 160 * Perform business logic for this instance by obtaining any 161 * properties from the parameters object. 162 * The base implementation casts the parameters as a Map, 163 * populates the bean, and returns execute(). 164 * @exception Subclasses can throw any Exception 165 */ 166 public Object execute(Object parameters) throws Exception { 167 168 if (parameters!=null) { 169 Map map = (Map) parameters; 170 BeanUtils.copyProperties(this,map); 171 } 172 173 return execute(); 174 175 } // end execute 176 177 } // end ProcessBeanBase