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