01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package java.beans;
19:
20: import org.apache.harmony.beans.internal.nls.Messages;
21:
22: public class Expression extends Statement {
23:
24: boolean valueIsDefined = false;
25:
26: Object value;
27:
28: public Expression(Object value, Object target, String methodName,
29: Object[] arguments) {
30: super (target, methodName, arguments);
31: this .value = value;
32: this .valueIsDefined = true;
33: }
34:
35: public Expression(Object target, String methodName,
36: Object[] arguments) {
37: super (target, methodName, arguments);
38: this .value = null;
39: this .valueIsDefined = false;
40: }
41:
42: @Override
43: public String toString() {
44: try {
45: StringBuilder sb = new StringBuilder();
46:
47: if (!valueIsDefined) {
48: sb.append("<unbound>"); //$NON-NLS-1$
49: } else {
50: if (value == null) {
51: sb.append("null"); //$NON-NLS-1$
52: } else {
53: sb.append(convertClassName(value.getClass()));
54: }
55: }
56: sb.append('=');
57: sb.append(super .toString());
58:
59: return sb.toString();
60: } catch (Exception e) {
61: return new String(Messages.getString(
62: "beans.0D", e.getClass())); //$NON-NLS-1$
63: }
64: }
65:
66: public void setValue(Object value) {
67: this .value = value;
68: this .valueIsDefined = true;
69: }
70:
71: public Object getValue() throws Exception {
72: if (!valueIsDefined) {
73: value = invokeMethod();
74: valueIsDefined = true;
75: }
76: return value;
77: }
78: }
|