1 /*
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,
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 package org.apache.juneau;
18
19 import static org.apache.juneau.commons.utils.CollectionUtils.*;
20 import static org.apache.juneau.commons.utils.Utils.*;
21
22 import org.apache.juneau.commons.collections.*;
23
24 /**
25 * Represents a simple bean property value and the meta-data associated with it.
26 */
27 public class BeanPropertyValue implements Comparable<BeanPropertyValue> {
28
29 private final BeanPropertyMeta pMeta;
30 private final String name;
31 private final Object value;
32 private final Throwable thrown;
33
34 /**
35 * Constructor.
36 *
37 * @param pMeta The bean property metadata.
38 * @param name The bean property name.
39 * @param value The bean property value.
40 * @param thrown The exception thrown by calling the property getter.
41 */
42 public BeanPropertyValue(BeanPropertyMeta pMeta, String name, Object value, Throwable thrown) {
43 this.pMeta = pMeta;
44 this.name = name;
45 this.value = value;
46 this.thrown = thrown;
47 }
48
49 @Override /* Overridden from Comparable */
50 public int compareTo(BeanPropertyValue o) {
51 return name.compareTo(o.name);
52 }
53
54 /**
55 * Returns the bean property metadata.
56 *
57 * @return The bean property metadata.
58 */
59 public final ClassMeta<?> getClassMeta() { return pMeta.getClassMeta(); }
60
61 /**
62 * Returns the bean property metadata.
63 *
64 * @return The bean property metadata.
65 */
66 public final BeanPropertyMeta getMeta() { return pMeta; }
67
68 /**
69 * Returns the bean property name.
70 *
71 * @return The bean property name.
72 */
73 public final String getName() { return name; }
74
75 /**
76 * Returns the exception thrown by calling the property getter.
77 *
78 * @return The exception thrown by calling the property getter.
79 */
80 public final Throwable getThrown() { return thrown; }
81
82 /**
83 * Returns the bean property value.
84 *
85 * @return The bean property value.
86 */
87 public final Object getValue() { return value; }
88
89 protected FluentMap<String,Object> properties() {
90 // @formatter:off
91 return filteredBeanPropertyMap()
92 .a("name", name)
93 .a("value", value)
94 .a("type", cns(pMeta.getClassMeta()));
95 // @formatter:on
96 }
97
98 @Override /* Overridden from Object */
99 public String toString() {
100 return r(properties());
101 }
102 }