Mercurial > hg > Members > sugi > MessagePack-java
comparison src/main/java/org/msgpack/template/builder/beans/Expression.java @ 0:cb825acd883a
first commit
author | sugi |
---|---|
date | Sat, 18 Oct 2014 15:06:15 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cb825acd883a |
---|---|
1 // MODIFIED FOR THE MSGPACK PROJECT | |
2 // Licensed to the Apache Software Foundation (ASF) under one or more | |
3 // contributor license agreements. See the NOTICE file distributed with | |
4 // this work for additional information regarding copyright ownership. | |
5 // The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 // (the "License"); you may not use this file except in compliance with | |
7 // the License. You may obtain a copy of the License at | |
8 // | |
9 // 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, WITHOUT | |
13 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
14 // License for the specific language governing permissions and limitations under | |
15 // the License. | |
16 // | |
17 | |
18 package org.msgpack.template.builder.beans; | |
19 | |
20 import org.apache.harmony.beans.BeansUtils; | |
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, Object[] arguments) { | |
36 super(target, methodName, arguments); | |
37 this.value = null; | |
38 this.valueIsDefined = false; | |
39 } | |
40 | |
41 @Override | |
42 public String toString() { | |
43 StringBuilder sb = new StringBuilder(); | |
44 if (!valueIsDefined) { | |
45 sb.append("<unbound>"); //$NON-NLS-1$ | |
46 } else { | |
47 if (value == null) { | |
48 sb.append(BeansUtils.NULL); | |
49 } else { | |
50 Class<?> clazz = value.getClass(); | |
51 sb.append(clazz == String.class ? BeansUtils.QUOTE : BeansUtils | |
52 .idOfClass(clazz)); | |
53 } | |
54 } | |
55 sb.append('='); | |
56 sb.append(super.toString()); | |
57 return sb.toString(); | |
58 } | |
59 | |
60 public void setValue(Object value) { | |
61 this.value = value; | |
62 this.valueIsDefined = true; | |
63 } | |
64 | |
65 public Object getValue() throws Exception { | |
66 if (!valueIsDefined) { | |
67 value = invokeMethod(); | |
68 valueIsDefined = true; | |
69 } | |
70 return value; | |
71 } | |
72 } |