01: /*
02: * Copyright 2006-2007 Luca Garulli (luca.garulli@assetdata.it)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.romaframework.core.domain.wrapper;
17:
18: import java.lang.reflect.InvocationTargetException;
19:
20: import org.romaframework.aspect.view.annotation.ViewField;
21:
22: /**
23: * It is a wrapper for a textArea to insert into an editable table
24: *
25: * @author Giordano Maestro(giordano.maestro@assetdata.it) 16/ott/07
26: */
27: public class TextWrapper extends TableEditWrapper implements
28: Comparable<TextWrapper> {
29: @ViewField(label="")
30: private String value;
31: private Class newInstanceClass;
32:
33: /**
34: * Creates the wrapper, the Class must have a a constructor with a string arg
35: *
36: * @param iValue
37: * @param iNewInstanceClass
38: */
39: public TextWrapper(Object iValue, Class iNewInstanceClass) {
40: newInstanceClass = iNewInstanceClass;
41: if (iValue == null) {
42: value = "";
43: } else {
44: value = iValue.toString();
45: }
46: }
47:
48: public String getValue() {
49: return value;
50: }
51:
52: public void setValue(String value) {
53: this .value = value;
54: }
55:
56: @Override
57: public Object getFinalValue() throws Exception,
58: IllegalAccessException, InvocationTargetException {
59: if (value != null && value.trim() != "") {
60: // TODO change the exception throwed
61: Class[] constrArg = new Class[1];
62: constrArg[0] = String.class;
63: Object[] args = new Object[1];
64: args[0] = value;
65: return newInstanceClass.getConstructor(constrArg)
66: .newInstance(args);
67: } else {
68: return null;
69: }
70: }
71:
72: public String toString() {
73: return value;
74: }
75:
76: public int compareTo(TextWrapper o) {
77: if (o == null)
78: return 1;
79: if (this .value == null && o.value != null)
80: return -1;
81: return this.value.compareTo(o.value);
82: }
83: }
|