001    package org.apache.maven.tools.plugin.javadoc;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.util.Map;
023    
024    import org.apache.maven.tools.plugin.extractor.java.JavaMojoAnnotation;
025    
026    import com.sun.tools.doclets.Taglet;
027    
028    /**
029     * The <tt>@parameter</tt> tag is used to populate Plexus component and has annotation parameters.
030     * <br/>
031     * The following is a sample declaration:
032     * <pre>
033     * public class MyMojo extends AbstractMojo
034     * {
035     *   &#x2f;&#x2a;&#x2a;
036     *   &#x20;&#x2a; Dummy parameter.
037     *   &#x20;&#x2a;
038     *   &#x20;&#x2a; &#64;component &lt;role="..."&gt; &lt;roleHint="..."&gt;
039     *   &#x20;&#x2a; ...
040     *   &#x20;&#x2a;&#x2f;
041     *   private Object parameterName;
042     * }
043     * </pre>
044     * To use it, calling the <code>Javadoc</code> tool with the following:
045     * <pre>
046     * javadoc ... -taglet 'org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet'
047     * </pre>
048     *
049     * @see <a href="package-summary.html#package_description">package-summary.html</a>
050     *
051     * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
052     * @version $Id: MojoComponentFieldTaglet.java 1133707 2011-06-09 08:28:59Z stephenc $
053     */
054    public class MojoComponentFieldTaglet
055        extends AbstractMojoFieldTaglet
056    {
057        /** The Javadoc annotation */
058        private static final String NAME = JavaMojoAnnotation.COMPONENT;
059    
060        private static final String[] COMPONENTS_NAME = {
061            JavaMojoAnnotation.COMPONENT_ROLE,
062            JavaMojoAnnotation.COMPONENT_ROLEHINT };
063    
064        /** The Javadoc text which will be added to the generated page. */
065        protected static final String HEADER = "Is a Plexus component defined by";
066    
067        /**
068         * @return By default, return the string defined in {@linkplain #HEADER}.
069         * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getHeader()
070         * @see #HEADER
071         */
072        public String getHeader()
073        {
074            return HEADER;
075        }
076    
077        /**
078         * @return <code>null</code> since <code>@component</code> has no value.
079         * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getAllowedValue()
080         */
081        public String getAllowedValue()
082        {
083            return null;
084        }
085    
086        /**
087         * @return <code>MojoComponentFieldTaglet#COMPONENTS_NAME</code> since <code>@component</code> has parameters.
088         * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getAllowedParameterNames()
089         */
090        public String[] getAllowedParameterNames()
091        {
092            return COMPONENTS_NAME;
093        }
094    
095        /**
096         * @return By default, return the name of this taglet.
097         * @see com.sun.tools.doclets.Taglet#getName()
098         * @see MojoComponentFieldTaglet#NAME
099         */
100        public String getName()
101        {
102            return NAME;
103        }
104    
105        /**
106         * Register this Taglet.
107         *
108         * @param tagletMap the map to register this tag to.
109         */
110        public static void register( Map<String, Taglet> tagletMap )
111        {
112            MojoComponentFieldTaglet tag = new MojoComponentFieldTaglet();
113            Taglet t = tagletMap.get( tag.getName() );
114            if ( t != null )
115            {
116                tagletMap.remove( tag.getName() );
117            }
118            tagletMap.put( tag.getName(), tag );
119        }
120    }