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.marshall.markdown;
018
019import java.util.concurrent.atomic.*;
020
021import org.apache.juneau.marshall.*;
022
023/**
024 * Metadata on classes specific to the Markdown serializers and parsers pulled from the {@link Markdown @Markdown}
025 * annotation on the class.
026 *
027 */
028public class MarkdownClassMeta extends ExtendedClassMeta {
029
030   private final MarkdownFormat format;
031   private final boolean noTables;
032   private final boolean noHeaders;
033
034   /**
035    * Constructor.
036    *
037    * @param cm The class that this annotation is defined on.
038    * @param mp Markdown metadata provider (for finding information about other artifacts).
039    */
040   public MarkdownClassMeta(ClassMeta<?> cm, MarkdownMetaProvider mp) {
041      super(cm);
042      var ref = new AtomicReference<Markdown>();
043      cm.forEachAnnotation(Markdown.class, null, ref::set);
044      var a = ref.get();
045      format = a != null ? a.format() : MarkdownFormat.DEFAULT;
046      noTables = a != null && a.noTables();
047      noHeaders = a != null && a.noHeaders();
048   }
049
050   /**
051    * Returns the rendering format for this class.
052    *
053    * @return The format.
054    */
055   public MarkdownFormat getFormat() {
056      return format;
057   }
058
059   /**
060    * Returns whether tables should be suppressed for collections of this type.
061    *
062    * @return Whether no-tables is set.
063    */
064   public boolean isNoTables() {
065      return noTables;
066   }
067
068   /**
069    * Returns whether table header rows should be suppressed.
070    *
071    * @return Whether no-headers is set.
072    */
073   public boolean isNoHeaders() {
074      return noHeaders;
075   }
076}