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.jsonschema;
014
015import static org.apache.juneau.common.internal.ThrowableUtils.*;
016
017import org.apache.juneau.*;
018import org.apache.juneau.annotation.*;
019import org.apache.juneau.collections.*;
020import org.apache.juneau.parser.*;
021
022/**
023 * Metadata on bean properties specific to the JSON-Schema pulled from the {@link Schema @Schema} annotation
024 * on the bean property.
025 *
026 * <h5 class='section'>See Also:</h5><ul>
027 *    <li class='link'><a class="doclink" href="../../../../index.html#jm.JsonSchemaDetails">JSON-Schema Support</a>
028
029 * </ul>
030 */
031public class JsonSchemaBeanPropertyMeta extends ExtendedBeanPropertyMeta {
032
033   /**
034    * Default instance.
035    */
036   public static final JsonSchemaBeanPropertyMeta DEFAULT = new JsonSchemaBeanPropertyMeta();
037
038   private final JsonMap schema;
039
040   /**
041    * Constructor.
042    *
043    * @param bpm The metadata of the bean property of this additional metadata.
044    * @param mp JSON-schema metadata provider (for finding information about other artifacts).
045    */
046   public JsonSchemaBeanPropertyMeta(BeanPropertyMeta bpm, JsonSchemaMetaProvider mp) {
047      super(bpm);
048
049      this.schema = new JsonMap();
050
051      try {
052         bpm.forEachAnnotation(Schema.class, x -> true, x -> schema.append(SchemaAnnotation.asMap(x)));
053      } catch (ParseException e) {
054         throw asRuntimeException(e);
055      }
056   }
057
058   private JsonSchemaBeanPropertyMeta() {
059      super(null);
060      this.schema = JsonMap.EMPTY_MAP;
061   }
062
063   /**
064    * Returns the schema information gathered from all the {@link Schema @Schema} annotations on the bean property.
065    *
066    * @return The schema information as a generic map.  Never <jk>null</jk>.
067    */
068   protected JsonMap getSchema() {
069      return schema;
070   }
071}