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.ini; 018 019import org.apache.juneau.commons.bean.*; 020import org.apache.juneau.commons.reflect.*; 021import org.apache.juneau.marshall.*; 022 023/** 024 * Metadata on bean properties specific to INI serializers and parsers, from {@link Ini @Ini}. 025 */ 026public class IniBeanPropertyMeta extends ExtendedBeanPropertyMeta { 027 028 /** Default instance. */ 029 public static final IniBeanPropertyMeta DEFAULT = new IniBeanPropertyMeta(); 030 031 private final String section; 032 private final String comment; 033 private final boolean json5Encoding; 034 035 /** 036 * Constructor. 037 * 038 * @param bpm The bean property metadata. 039 * @param mp INI metadata provider. 040 */ 041 public IniBeanPropertyMeta(BeanPropertyMeta bpm, IniMetaProvider mp) { 042 super(bpm); 043 var a = bpm.getAnnotations(Ini.class).map(AnnotationInfo::inner).reduce((first, second) -> second).orElse(null); 044 section = a != null && !a.section().isEmpty() ? a.section() : ""; 045 comment = a != null && !a.comment().isEmpty() ? a.comment() : ""; 046 json5Encoding = a != null && a.json5Encoding(); 047 } 048 049 private IniBeanPropertyMeta() { 050 super(null); 051 section = ""; 052 comment = ""; 053 json5Encoding = false; 054 } 055 056 /** 057 * Returns the custom section name for this property. 058 * 059 * @return The section name, or empty string if not specified. 060 */ 061 public String getSection() { 062 return section; 063 } 064 065 /** 066 * Returns the comment text to emit before this property. 067 * 068 * @return The comment, or empty string if not specified. 069 */ 070 public String getComment() { 071 return comment; 072 } 073 074 /** 075 * Returns whether this property should be JSON5-encoded even when normally simple. 076 * 077 * @return Whether JSON5 encoding is forced. 078 */ 079 public boolean isJson5Encoding() { 080 return json5Encoding; 081 } 082}