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 org.apache.juneau.*;
016import org.apache.juneau.collections.*;
017import org.apache.juneau.jsonschema.annotation.*;
018import org.apache.juneau.parser.*;
019
020/**
021 * Metadata on bean properties specific to the JSON-Schema pulled from the {@link Schema @Schema} annotation
022 * on the bean property.
023 */
024public class JsonSchemaBeanPropertyMeta extends ExtendedBeanPropertyMeta {
025
026   /**
027    * Default instance.
028    */
029   public static final JsonSchemaBeanPropertyMeta DEFAULT = new JsonSchemaBeanPropertyMeta();
030
031   private final OMap schema;
032
033   /**
034    * Constructor.
035    *
036    * @param bpm The metadata of the bean property of this additional metadata.
037    * @param mp JSON-schema metadata provider (for finding information about other artifacts).
038    */
039   public JsonSchemaBeanPropertyMeta(BeanPropertyMeta bpm, JsonSchemaMetaProvider mp) {
040      super(bpm);
041
042      this.schema = new OMap();
043
044      try {
045         for (Schema s : bpm.getAnnotations(Schema.class))
046            schema.appendAll(SchemaUtils.asMap(s));
047      } catch (ParseException e) {
048         throw new RuntimeException(e);
049      }
050   }
051
052   private JsonSchemaBeanPropertyMeta() {
053      super(null);
054      this.schema = OMap.EMPTY_MAP;
055   }
056
057   /**
058    * Returns the schema information gathered from all the {@link Schema @Schema} annotations on the bean property.
059    *
060    * @return The schema information as a generic map.  Never <jk>null</jk>.
061    */
062   protected OMap getSchema() {
063      return schema;
064   }
065}