001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau; 018 019import static org.apache.juneau.commons.utils.CollectionUtils.*; 020import static org.apache.juneau.commons.utils.Utils.*; 021 022import org.apache.juneau.commons.collections.*; 023 024/** 025 * Represents a simple bean property value and the meta-data associated with it. 026 */ 027public class BeanPropertyValue implements Comparable<BeanPropertyValue> { 028 029 private final BeanPropertyMeta pMeta; 030 private final String name; 031 private final Object value; 032 private final Throwable thrown; 033 034 /** 035 * Constructor. 036 * 037 * @param pMeta The bean property metadata. 038 * @param name The bean property name. 039 * @param value The bean property value. 040 * @param thrown The exception thrown by calling the property getter. 041 */ 042 public BeanPropertyValue(BeanPropertyMeta pMeta, String name, Object value, Throwable thrown) { 043 this.pMeta = pMeta; 044 this.name = name; 045 this.value = value; 046 this.thrown = thrown; 047 } 048 049 @Override /* Overridden from Comparable */ 050 public int compareTo(BeanPropertyValue o) { 051 return name.compareTo(o.name); 052 } 053 054 /** 055 * Returns the bean property metadata. 056 * 057 * @return The bean property metadata. 058 */ 059 public final ClassMeta<?> getClassMeta() { return pMeta.getClassMeta(); } 060 061 /** 062 * Returns the bean property metadata. 063 * 064 * @return The bean property metadata. 065 */ 066 public final BeanPropertyMeta getMeta() { return pMeta; } 067 068 /** 069 * Returns the bean property name. 070 * 071 * @return The bean property name. 072 */ 073 public final String getName() { return name; } 074 075 /** 076 * Returns the exception thrown by calling the property getter. 077 * 078 * @return The exception thrown by calling the property getter. 079 */ 080 public final Throwable getThrown() { return thrown; } 081 082 /** 083 * Returns the bean property value. 084 * 085 * @return The bean property value. 086 */ 087 public final Object getValue() { return value; } 088 089 protected FluentMap<String,Object> properties() { 090 // @formatter:off 091 return filteredBeanPropertyMap() 092 .a("name", name) 093 .a("value", value) 094 .a("type", cns(pMeta.getClassMeta())); 095 // @formatter:on 096 } 097 098 @Override /* Overridden from Object */ 099 public String toString() { 100 return r(properties()); 101 } 102}