001package ball.tools.javadoc;
002/*-
003 * ##########################################################################
004 * Utilities
005 * $Id: BeanInfoTaglet.html 5431 2020-02-12 19:03:17Z ball $
006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/hcf-dev/blog/2019-03-30-java-interface-facades/src/main/resources/javadoc/src-html/ball/tools/javadoc/BeanInfoTaglet.html $
007 * %%
008 * Copyright (C) 2008 - 2020 Allen D. Ball
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the "License");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 *
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an "AS IS" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * ##########################################################################
022 */
023import ball.annotation.ServiceProviderFor;
024import ball.beans.PropertyDescriptorsTableModel;
025import ball.xml.FluentNode;
026import com.sun.javadoc.ClassDoc;
027import com.sun.javadoc.Tag;
028import com.sun.tools.doclets.Taglet;
029import java.util.Map;
030import lombok.NoArgsConstructor;
031import lombok.ToString;
032
033import static org.apache.commons.lang3.StringUtils.isNotEmpty;
034
035/**
036 * Inline {@link Taglet} to provide a table of bean properties.
037 *
038 * For example:
039 *
040 * {@bean.info}
041 *
042 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
043 * @version $Revision: 5431 $
044 */
045@ServiceProviderFor({ Taglet.class })
046@TagletName("bean.info")
047@NoArgsConstructor @ToString
048public class BeanInfoTaglet extends AbstractInlineTaglet
049                            implements SunToolsInternalToolkitTaglet {
050    private static final BeanInfoTaglet INSTANCE = new BeanInfoTaglet();
051
052    public static void register(Map<Object,Object> map) {
053        register(map, INSTANCE);
054    }
055
056    @Override
057    public FluentNode toNode(Tag tag) throws Throwable {
058        ClassDoc doc = null;
059        String name = tag.text().trim();
060
061        if (isNotEmpty(name)) {
062            doc = getClassDocFor(tag, name);
063        } else {
064            doc = getContainingClassDocFor(tag);
065        }
066
067        Class<?> type = getClassFor(doc);
068        PropertyDescriptorsTableModel model =
069            new PropertyDescriptorsTableModel(getBeanInfo(type)
070                                              .getPropertyDescriptors());
071
072        return div(attr("class", "summary"),
073                   h3("Bean Property Summary"),
074                   table(tag, model));
075    }
076}