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 org.apache.juneau.collections.*;
020
021/**
022 * Represents a simple bean property value and the meta-data associated with it.
023 *
024 * <h5 class='section'>See Also:</h5><ul>
025 * </ul>
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   /**
050    * Returns the bean property metadata.
051    *
052    * @return The bean property metadata.
053    */
054   public final BeanPropertyMeta getMeta() {
055      return pMeta;
056   }
057
058   /**
059    * Returns the bean property metadata.
060    *
061    * @return The bean property metadata.
062    */
063   public final ClassMeta<?> getClassMeta() {
064      return pMeta.getClassMeta();
065   }
066
067   /**
068    * Returns the bean property name.
069    *
070    * @return The bean property name.
071    */
072   public final String getName() {
073      return name;
074   }
075
076   /**
077    * Returns the bean property value.
078    *
079    * @return The bean property value.
080    */
081   public final Object getValue() {
082      return value;
083   }
084
085   /**
086    * Returns the exception thrown by calling the property getter.
087    *
088    * @return The exception thrown by calling the property getter.
089    */
090   public final Throwable getThrown() {
091      return thrown;
092   }
093
094   @Override /* Comparable */
095   public int compareTo(BeanPropertyValue o) {
096      return name.compareTo(o.name);
097   }
098
099   @Override /* Object */
100   public String toString() {
101      return JsonMap.create()
102         .append("name", name)
103         .append("value", value)
104         .append("type", pMeta.getClassMeta().getInnerClass().getSimpleName())
105         .toString();
106   }
107}