Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ProcessBeanBase |
|
| 1.0833333333333333;1.083 |
1 | /* | |
2 | * Copyright 2001,2004 The Apache Software Foundation. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | package org.apache.commons.scaffold.util; | |
18 | ||
19 | ||
20 | import java.util.Locale; | |
21 | import java.util.Map; | |
22 | ||
23 | import org.apache.commons.beanutils.BeanUtils; | |
24 | ||
25 | // ------------------------------------------------------------------------ 78 | |
26 | ||
27 | /** | |
28 | * Base implementation of ProcessBean with default functionality. | |
29 | * The only method that must be overridden is | |
30 | * <code>Object execute(Object)</code>. | |
31 | * :TODO: Change from BeanUtil.populate to copyProperties in 1.1 | |
32 | * version. | |
33 | * @author Ted Husted | |
34 | * @version $Revision: 155464 $ $Date: 2005-02-26 13:26:54 +0000 (Sat, 26 Feb 2005) $ | |
35 | */ | |
36 | 0 | public abstract class ProcessBeanBase implements ProcessBean { |
37 | ||
38 | // ----------------------------------------------------------- Properties | |
39 | ||
40 | ||
41 | /** | |
42 | * The locale for this bean instance, if any. | |
43 | */ | |
44 | 0 | private Locale locale = null; |
45 | ||
46 | ||
47 | public Locale getLocale() { | |
48 | 0 | return this.locale; |
49 | } | |
50 | ||
51 | ||
52 | public void setLocale(Locale locale) { | |
53 | 0 | this.locale = locale; |
54 | 0 | } |
55 | ||
56 | ||
57 | /** | |
58 | * The remoteNode for this bean instance, if any. | |
59 | */ | |
60 | 0 | private Integer remoteNode = null; |
61 | ||
62 | ||
63 | public Integer getRemoteNode() { | |
64 | 0 | return this.remoteNode; |
65 | } | |
66 | ||
67 | ||
68 | public void setRemoteNode(Integer remoteNode) { | |
69 | 0 | this.remoteNode = remoteNode; |
70 | 0 | } |
71 | ||
72 | ||
73 | /** | |
74 | * Set the remoteNode using a String in | |
75 | * the format usually given | |
76 | * by the REMOTE_ADDR CGI variable, or | |
77 | * ServletRequest.getRemoteAddr(). | |
78 | * NOTE: <b>not implemented; returns 0</b>. | |
79 | * @return An Integer value based on RemoteAddr string. | |
80 | */ | |
81 | public void setRemoteAddr(String remoteAddr) { | |
82 | ||
83 | 0 | setRemoteNode(new Integer(0)); // :FIXME: |
84 | ||
85 | 0 | } |
86 | ||
87 | ||
88 | /** | |
89 | * Return the String representation | |
90 | * of an IP address expressed | |
91 | * as an Integer, into the format usually given | |
92 | * by the REMOTE_ADDR CGI variable, or | |
93 | * ServletRequest.getRemoteAddr(). | |
94 | * NOTE: <b>not implemented; returns zeros.</b> | |
95 | * @return An Integer value based on RemoteAddr string. | |
96 | */ | |
97 | public String getRemoteAddr() { | |
98 | ||
99 | 0 | 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 | 0 | private Object server = null; |
113 | ||
114 | ||
115 | public Object getRemoteServer() { | |
116 | 0 | return this.server; |
117 | } | |
118 | ||
119 | ||
120 | public void setRemoteServer(Object server) { | |
121 | 0 | this.server = server; |
122 | 0 | } |
123 | ||
124 | ||
125 | /** | |
126 | * The parameter | |
127 | */ | |
128 | 0 | private String parameter = null; |
129 | ||
130 | ||
131 | public String getParameter() { | |
132 | 0 | return (this.parameter); |
133 | } | |
134 | ||
135 | ||
136 | public void setParameter(String parameter) { | |
137 | 0 | this.parameter = parameter; |
138 | 0 | } |
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 | 0 | 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 | 0 | if (parameters!=null) { |
169 | 0 | Map map = (Map) parameters; |
170 | 0 | BeanUtils.copyProperties(this,map); |
171 | } | |
172 | ||
173 | 0 | return execute(); |
174 | ||
175 | } // end execute | |
176 | ||
177 | } // end ProcessBeanBase |